aaa
doum
2026-06-08 cf2da3b2a63840888815c6a81cbd7948faf93533
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.doumee.service.business.impl;
 
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.WebParamMapper;
import com.doumee.dao.business.model.WebParam;
import com.doumee.dao.system.dto.UpdateWebParamDTO;
import com.doumee.service.business.WebParamService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 企业页面配置信息表Service实现
 * @author 江蹄蹄
 * @since 2023/09/12 11:18
 */
@Service
public class WebParamServiceImpl implements WebParamService {
 
    @Autowired
    private WebParamMapper webParamMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Override
    public WebParam findOne() {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>();
        wrapper.eq("COMPANY_ID",user.getCompanyId());
        wrapper.last(" limit 1  ");
        WebParam webParam = webParamMapper.selectOne(wrapper);
        if(!Objects.isNull(webParam)){
            webParam.setResourcePath(systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() +
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.WEB_PARAM).getCode());
            webParam.setAnchorPageVersion(normalizeAnchorPageVersion(webParam.getAnchorPageVersion()));
        }else{
            webParam = new WebParam();
            webParam.setResourcePath(systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() +
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.WEB_PARAM).getCode());
            webParam.setBgImg(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.BG_IMG).getCode());
            webParam.setTopImg(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.TOP_IMG).getCode());
            webParam.setPkImg(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.PK_IMG).getCode());
            webParam.setMainColor(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.MAIN_COLOR).getCode());
            webParam.setRangeSize(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.RANGE_SIZE).getCode());
            webParam.setAnchorPageVersion(ANCHOR_PAGE_V2);
        }
        return webParam;
    }
 
    @Override
    public WebParam findOneNew() {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(WebParam::getCompanyId,user.getCompanyId());
        wrapper.last(" limit 1  ");
        WebParam webParam = webParamMapper.selectOne(wrapper);
        if (webParam != null) {
            webParam.setAnchorPageVersion(normalizeAnchorPageVersion(webParam.getAnchorPageVersion()));
        }
        return webParam;
    }
 
 
    @Override
    public void renew(UpdateWebParamDTO updateWebParamDTO) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>();
        wrapper.eq("COMPANY_ID",user.getCompanyId());
        wrapper.last(" limit 1  ");
        WebParam webParam = webParamMapper.selectOne(wrapper);
        if(Objects.isNull(webParam)){
            webParam = new WebParam();
            BeanUtils.copyProperties(updateWebParamDTO,webParam);
            webParam.setCreateTime(new Date());
            webParam.setDeleted(Constants.ZERO);
            webParam.setCompanyId(user.getCompanyId());
            webParam.setCreateUser(user.getId());
            webParamMapper.insert(webParam);
        }else{
            BeanUtils.copyProperties(updateWebParamDTO,webParam);
            applyAnchorPageVersion(webParam, updateWebParamDTO.getAnchorPageVersion());
            webParam.setUpdateUser(user.getId());
            webParam.setUpdateTime(new Date());
            webParamMapper.updateById(webParam);
        }
    }
    @Override
    public void  renewUpdate(UpdateWebParamDTO updateWebParamDTO){
        if(StringUtils.isBlank(updateWebParamDTO.getNewParam())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(WebParam::getCompanyId,user.getCompanyId());
        wrapper.last(" limit 1  ");
        WebParam webParam = webParamMapper.selectOne(wrapper);
        if(Objects.isNull(webParam)){
            webParam = new WebParam();
            BeanUtils.copyProperties(updateWebParamDTO,webParam);
            webParam.setCreateTime(new Date());
            webParam.setDeleted(Constants.ZERO);
            webParam.setCompanyId(user.getCompanyId());
            webParam.setCreateUser(user.getId());
            webParamMapper.insert(webParam);
        }else{
            BeanUtils.copyProperties(updateWebParamDTO,webParam);
            applyAnchorPageVersion(webParam, updateWebParamDTO.getAnchorPageVersion());
            webParam.setUpdateUser(user.getId());
            webParam.setUpdateTime(new Date());
            webParamMapper.updateById(webParam);
        }
    }
 
    @Override
    public WebParam findOneAnchor() {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(WebParam::getCompanyId, user.getCompanyId());
        wrapper.last(" limit 1 ");
        WebParam webParam = webParamMapper.selectOne(wrapper);
        String resourcePath = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.WEB_PARAM).getCode();
        if (webParam == null) {
            webParam = new WebParam();
            webParam.setAnchorParam(getDefaultAnchorParam());
            webParam.setAnchorPageVersion(ANCHOR_PAGE_V2);
        } else if (StringUtils.isBlank(webParam.getAnchorParam())) {
            webParam.setAnchorParam(getDefaultAnchorParam());
        }
        webParam.setAnchorPageVersion(normalizeAnchorPageVersion(webParam.getAnchorPageVersion()));
        webParam.setResourcePath(resourcePath);
        return webParam;
    }
 
    @Override
    public void renewAnchorUpdate(UpdateWebParamDTO updateWebParamDTO) {
        if (StringUtils.isBlank(updateWebParamDTO.getAnchorParam())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(WebParam::getCompanyId, user.getCompanyId());
        wrapper.last(" limit 1 ");
        WebParam webParam = webParamMapper.selectOne(wrapper);
        if (Objects.isNull(webParam)) {
            webParam = new WebParam();
            webParam.setAnchorParam(updateWebParamDTO.getAnchorParam());
            applyAnchorPageVersion(webParam, updateWebParamDTO.getAnchorPageVersion());
            webParam.setCreateTime(new Date());
            webParam.setDeleted(Constants.ZERO);
            webParam.setCompanyId(user.getCompanyId());
            webParam.setCreateUser(user.getId());
            webParamMapper.insert(webParam);
        } else {
            webParam.setAnchorParam(updateWebParamDTO.getAnchorParam());
            applyAnchorPageVersion(webParam, updateWebParamDTO.getAnchorPageVersion());
            webParam.setUpdateUser(user.getId());
            webParam.setUpdateTime(new Date());
            webParamMapper.updateById(webParam);
        }
    }
 
    @Override
    public void updateAnchorPageVersion(String anchorPageVersion) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        String version = normalizeAnchorPageVersion(anchorPageVersion);
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(WebParam::getCompanyId, user.getCompanyId());
        wrapper.last(" limit 1 ");
        WebParam webParam = webParamMapper.selectOne(wrapper);
        if (Objects.isNull(webParam)) {
            webParam = new WebParam();
            webParam.setAnchorPageVersion(version);
            webParam.setCreateTime(new Date());
            webParam.setDeleted(Constants.ZERO);
            webParam.setCompanyId(user.getCompanyId());
            webParam.setCreateUser(user.getId());
            webParamMapper.insert(webParam);
        } else {
            webParam.setAnchorPageVersion(version);
            webParam.setUpdateUser(user.getId());
            webParam.setUpdateTime(new Date());
            webParamMapper.updateById(webParam);
        }
    }
 
    private static final String ANCHOR_PAGE_V2 = "v2";
    private static final String ANCHOR_PAGE_V3 = "v3";
 
    private String normalizeAnchorPageVersion(String version) {
        return ANCHOR_PAGE_V3.equalsIgnoreCase(StringUtils.trimToEmpty(version)) ? ANCHOR_PAGE_V3 : ANCHOR_PAGE_V2;
    }
 
    private void applyAnchorPageVersion(WebParam webParam, String anchorPageVersion) {
        if (StringUtils.isNotBlank(anchorPageVersion)) {
            webParam.setAnchorPageVersion(normalizeAnchorPageVersion(anchorPageVersion));
        }
    }
 
    private String getDefaultAnchorParam() {
        return "{\"rangeSize\":\"750\",\"main\":{\"bgType\":1,\"bgColor\":\"#E8DCC8\",\"alpha\":\"100\",\"bgImg\":{\"isShow\":1,\"type\":0}},"
                + "\"topImg\":{\"type\":0,\"img\":\"\",\"imgurl\":\"\"},"
                + "\"adImg\":{\"type\":0,\"img\":\"\",\"imgurl\":\"\"},"
                + "\"pkImg\":{\"type\":0,\"img\":\"\",\"imgurl\":\"\"},"
                + "\"header\":{\"backgroundType\":1,\"bgColor\":\"#4A3728\",\"bgAlpha\":\"100\",\"type\":1,\"color\":\"#FFFFFF\",\"alpha\":\"100\"},"
                + "\"table\":{\"headerBg\":\"#4A3728\",\"headerColor\":\"#FFFFFF\",\"rowBg\":\"#F5EFE6\",\"hoverScale\":1.05},"
                + "\"featured\":[{\"goodsId\":\"\",\"prefixUrl\":\"\",\"imgurl\":\"\",\"title\":\"\",\"tags\":[\"\",\"\"]},{\"goodsId\":\"\",\"prefixUrl\":\"\",\"imgurl\":\"\",\"title\":\"\",\"tags\":[\"\",\"\"]}],"
                + "\"search\":{\"bgType\":1,\"bgColor\":\"#FFFFFF\",\"bgAlpha\":\"100\"},"
                + "\"productList\":{\"bgType\":1,\"bgColor\":\"#F5EFE6\",\"bgAlpha\":\"100\"},"
                + "\"pk\":{\"vsColor\":\"#FF8C42\"}}";
    }
 
}