chengf
2025-08-18 eb0d880929fccd4998d6b9836077961d1f975fea
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
package com.java110.common.smo.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.java110.common.dao.ISmallProgramAdvertHistoryServiceDao;
import com.java110.common.dao.ISmallProgramAdvertServiceDao;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.dto.PageDto;
import com.java110.dto.smallProgramAdvert.*;
import com.java110.dto.user.UserDto;
import com.java110.intf.common.ISmallProgramAdvertServiceSMO;
import com.java110.intf.user.IUserInnerServiceSMO;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.BusinessException;
import com.java110.utils.exception.DAOException;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import static com.java110.utils.util.BeanConvertUtil.covertBeanList;
 
/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 广告信息内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class SmallProgramAdvertServiceSMOImpl extends BaseServiceSMO implements ISmallProgramAdvertServiceSMO {
 
    @Resource
    private ISmallProgramAdvertServiceDao smallProgramAdvertServiceDao;
    @Resource
    private ISmallProgramAdvertHistoryServiceDao smallProgramAdvertHistoryServiceDao;
    @Resource
    private IUserInnerServiceSMO userInnerServiceSMOImpl;
 
    @Override
    public ResultVo querySmallAdverts(QuertAdvertDto quertAdvertDto) {
        //校验是否传了 分页信息
        int page = quertAdvertDto.getPage();
        if (page != PageDto.DEFAULT_PAGE) {
            quertAdvertDto.setPage((page - 1) * quertAdvertDto.getRow());
        }
        int count = smallProgramAdvertServiceDao.querySmallProgramAdvertsCount(BeanConvertUtil.beanCovertMap(quertAdvertDto));
        List<SmallProgramAdvertDto> smallProgramAdvertListDtoList = Lists.newArrayList();
        if (count > 0) {
            smallProgramAdvertListDtoList = BeanConvertUtil.covertBeanList(smallProgramAdvertServiceDao.querySmallProgramAdvertInfoList(BeanConvertUtil.beanCovertMap(quertAdvertDto)), SmallProgramAdvertDto.class);
        }
        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) quertAdvertDto.getRow()), count, smallProgramAdvertListDtoList);
        return resultVo;
    }
 
    @Override
    public SmallProgramAdvertDto querySmallAdvertsInfo(QuertAdvertDto quertAdvertDto) {
        Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(quertAdvertDto));
        if(map != null){
            SmallProgramAdvertDto smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvertDto.class);
            List<Map> historyMap = smallProgramAdvertHistoryServiceDao.querySmallProgramAdvertInfoList(smallProgramAdvert.getId());
            List<SmallProgramAdvertHistoryDto> historyList = BeanConvertUtil.covertBeanList(historyMap, SmallProgramAdvertHistoryDto.class);
            for(SmallProgramAdvertHistoryDto smallProgramAdvertHistoryDto : historyList){
                UserDto userDto = new UserDto();
                userDto.setUserId(smallProgramAdvertHistoryDto.getOperateUserId());
                List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
                if(!CollectionUtils.isEmpty(userDtos)){
                    smallProgramAdvertHistoryDto.setOperateUserName(userDtos.get(0).getName());
                }
            }
            smallProgramAdvert.setHistoryList(historyList);
            return smallProgramAdvert;
        }else{
            throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息");
        }
    }
 
    @Override
    public void saveSmallAdverts(SmallProgramAdvert smallProgramAdvert) {
        smallProgramAdvertServiceDao.saveSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert));
    }
 
    @Override
    @Transactional
    public void updateSmallAdverts(SmallProgramAdvertSaveDto smallProgramAdvertSaveDto,String userId) {
        Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvertSaveDto));
        if(map != null){
            SmallProgramAdvert smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvert.class);
            String operation = "更新广告";
            if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getPosition())){
                smallProgramAdvert.setPosition(smallProgramAdvertSaveDto.getPosition());
            }
            if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getAdvertsName())){
                smallProgramAdvert.setAdvertsName(smallProgramAdvertSaveDto.getAdvertsName());
            }
            if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getPicUrl())){
                smallProgramAdvert.setPicUrl(smallProgramAdvertSaveDto.getPicUrl());
            }
            if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getOssUrl())){
                smallProgramAdvert.setOssUrl(smallProgramAdvertSaveDto.getOssUrl());
            }
            if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getUrl())){
                smallProgramAdvert.setUrl(smallProgramAdvertSaveDto.getUrl());
            }
            if(smallProgramAdvertSaveDto.getSort() != null){
                smallProgramAdvert.setSort(smallProgramAdvertSaveDto.getSort());
            }
            if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getSupplierName())){
                smallProgramAdvert.setSupplierName(smallProgramAdvertSaveDto.getSupplierName());
            }
            if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getDesc())){
                smallProgramAdvert.setDesc(smallProgramAdvertSaveDto.getDesc());
            }
            smallProgramAdvert.setUpdateTime(new Date());
            smallProgramAdvert.setUpdateUserId(userId);
            smallProgramAdvertServiceDao.updateSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert));
            //保存更新日志
            saveHistory(BeanConvertUtil.covertBean(map,SmallProgramAdvert.class),userId,operation);
        }else{
            throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息,广告id:"+smallProgramAdvertSaveDto.getId());
        }
    }
 
    @Override
    @Transactional
    public void updateSmallAdvertsStatus(SmallProgramAdvertSaveDto smallProgramAdvertSaveDto,String userId) {
        if(!CollectionUtils.isEmpty(smallProgramAdvertSaveDto.getIdList())){
            for(String id : smallProgramAdvertSaveDto.getIdList()){
                smallProgramAdvertSaveDto.setId(id);
                Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvertSaveDto));
                if(map != null){
                    SmallProgramAdvert smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvert.class);
                    String operation = "更新广告";
                    if(smallProgramAdvertSaveDto.getStatus() != null){
                        smallProgramAdvert.setStatus(smallProgramAdvertSaveDto.getStatus());
                        if(smallProgramAdvertSaveDto.getStatus() == 2){
                            operation = "下线广告";
                            smallProgramAdvert.setOfflineTime(new Date());
                            smallProgramAdvert.setOnlineTime(null);
                        }else if(smallProgramAdvertSaveDto.getStatus() == 1){
                            operation = "上线广告";
                            smallProgramAdvert.setOnlineTime(new Date());
                            smallProgramAdvert.setOfflineTime(null);
                        }
                    }
                    smallProgramAdvert.setUpdateTime(new Date());
                    smallProgramAdvert.setUpdateUserId(userId);
                    smallProgramAdvertServiceDao.updateSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert));
                    //保存更新日志
                    saveHistory(BeanConvertUtil.covertBean(map,SmallProgramAdvert.class),userId,operation);
                }else{
                    throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息,广告id:"+id);
                }
            }
        }
    }
 
    @Override
    @Transactional
    public void deleteSmallAdverts(SmallProgramAdvertSaveDto smallProgramAdvertSaveDto, String userId) {
        if(!CollectionUtils.isEmpty(smallProgramAdvertSaveDto.getIdList())){
            for(String id : smallProgramAdvertSaveDto.getIdList()){
                smallProgramAdvertSaveDto.setId(id);
                Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvertSaveDto));
                if(map != null){
                    SmallProgramAdvert smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvert.class);
                    smallProgramAdvert.setUpdateTime(new Date());
                    smallProgramAdvert.setUpdateUserId(userId);
                    smallProgramAdvert.setStatus(smallProgramAdvertSaveDto.getStatus());
                    smallProgramAdvertServiceDao.updateSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert));
                    //保存更新日志
                    saveHistory(BeanConvertUtil.covertBean(map,SmallProgramAdvert.class),userId,"删除广告");
                }else{
                    throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息,广告id:"+id);
                }
            }
        }
    }
 
    private void saveHistory(SmallProgramAdvert smallProgramAdvert,String userId ,String operation){
        SmallProgramAdvertHistoryDto historyDto = new SmallProgramAdvertHistoryDto();
        String historyId = GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_advertId);
        historyDto.setId(historyId);
        historyDto.setAdvertsId(smallProgramAdvert.getId());
        historyDto.setOperateTime(new Date());
        historyDto.setOperateUserId(userId);
        historyDto.setContent(JSONObject.toJSONString(smallProgramAdvert));
        historyDto.setOperation(operation);
        smallProgramAdvertHistoryServiceDao.saveSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(historyDto));
    }
 
 
}