linwe
2024-06-17 448464bbb8e043c2b8e410947db1f07aa4fd9a4d
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
package org.springblade.modules.backblast.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springblade.common.param.CommonParamSet;
import org.springblade.common.param.GridSet;
import org.springblade.common.utils.SpringUtils;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.modules.backblast.entity.BackblastPubPersonEntity;
import org.springblade.modules.backblast.entity.BackblastPubRecordEntity;
import org.springblade.modules.backblast.excel.BackblastPubRecordExcel;
import org.springblade.modules.backblast.service.IBackblastPubPersonService;
import org.springblade.modules.backblast.vo.BackblastPubRecordVO;
import org.springblade.modules.backblast.mapper.BackblastPubRecordMapper;
import org.springblade.modules.backblast.service.IBackblastPubRecordService;
import org.springblade.modules.grid.entity.GridEntity;
import org.springblade.modules.grid.service.IGridService;
import org.springblade.modules.place.entity.PlacePractitionerEntity;
import org.springblade.modules.place.service.IPlacePractitionerService;
import org.springblade.modules.police.entity.PoliceAffairsGridEntity;
import org.springblade.modules.police.service.IPoliceAffairsGridService;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 反炸宣传记录表 服务实现类
 *
 * @author BladeX
 * @since 2024-03-15
 */
@Service
public class BackblastPubRecordServiceImpl extends ServiceImpl<BackblastPubRecordMapper, BackblastPubRecordEntity> implements IBackblastPubRecordService {
 
    /**
     * 自定义分页列表查询
     * @param page
     * @param backblastPubRecord
     * @return
     */
    @Override
    public IPage<BackblastPubRecordVO> selectBackblastPubRecordPage(IPage<BackblastPubRecordVO> page, BackblastPubRecordVO backblastPubRecord) {
        CommonParamSet commonParamSet = new CommonParamSet<>().invoke(BackblastPubRecordVO.class, backblastPubRecord);
        if (!Strings.isBlank(backblastPubRecord.getRoleName())){
            backblastPubRecord.setCreateUser(AuthUtil.getUserId());
        }
        return page.setRecords(baseMapper.selectBackblastPubRecordPage(page,
            backblastPubRecord,
            commonParamSet.getIsAdministrator(),
            commonParamSet.getRegionChildCodesList(),
            commonParamSet.getGridCodeList()));
    }
 
    /**
     * 反炸宣传记录表 自定义新增/修改
     * @param backblastPubRecord
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addOrUpdateBackblastPubRecordEntity(BackblastPubRecordVO backblastPubRecord) {
        backblastPubRecord.setCreateUser(AuthUtil.getUserId());
        boolean flag = false;
        // 点落面计算警格,网格,警格
        setGridInfo(backblastPubRecord);
        // 设置民警姓名电话(非民警暂时也记录)
        User user = SpringUtils.getBean(IUserService.class).getById(AuthUtil.getUserId());
        if (null!=user){
            backblastPubRecord.setPoliceman(user.getRealName());
            backblastPubRecord.setPolicemanPhone(user.getPhone());
        }
        if (null!=backblastPubRecord.getId()){
            // 更新
            flag = updateById(backblastPubRecord);
        }else {
            // 新增
            flag = save(backblastPubRecord);
        }
        // 宣防对象操作
        updateBackblastPubPerson(backblastPubRecord);
        // 返回
        return flag;
    }
 
    /**
     * 宣防对象操作
     * @param backblastPubRecord
     * @return
     */
    public void updateBackblastPubPerson(BackblastPubRecordVO backblastPubRecord) {
        IBackblastPubPersonService backblastPubPersonService = SpringUtil.getBean(IBackblastPubPersonService.class);
        if (backblastPubRecord.getBackblastPubPersonEntityList().size()>0){
            // 查询对应已存在的反诈宣传对象
            QueryWrapper<BackblastPubPersonEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("backblast_pub_record_id", backblastPubRecord.getId()).eq("is_deleted",0);
            List<BackblastPubPersonEntity> oldList = backblastPubPersonService.list(wrapper);
            // 取出反诈宣传对象信息
            List<BackblastPubPersonEntity> backblastPubPersonEntityList = backblastPubRecord.getBackblastPubPersonEntityList();
            for (BackblastPubPersonEntity pubPersonEntity : backblastPubPersonEntityList) {
                pubPersonEntity.setBackblastPubRecordId(backblastPubRecord.getId());
            }
            // 申明新增,修改,删除集合
            List<BackblastPubPersonEntity> newList = new ArrayList<>();
            List<BackblastPubPersonEntity> addList = new ArrayList<>();
            List<BackblastPubPersonEntity> updateList = new ArrayList<>();
            List<BackblastPubPersonEntity> removeList = new ArrayList<>();
            // 遍历设置数据
            for (BackblastPubPersonEntity pubPersonEntity : backblastPubPersonEntityList) {
                if (null == pubPersonEntity.getId()) {
                    // 新增
                    addList.add(pubPersonEntity);
                } else {
                    newList.add(pubPersonEntity);
                }
            }
            // 遍历去差集,判断是新增还是删除还是更新
            // 取旧数据和新提交数据差集--删除
            removeList = oldList.stream().filter(vo -> !newList.stream().map(e ->
                e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
            // 取旧数据和新提交数据交集--更新
            updateList = newList.stream().filter(vo -> oldList.stream().map(e ->
                e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
 
            // 批量新增
            if (addList.size() > 0) {
                backblastPubPersonService.saveBatch(addList);
            }
            // 批量修改
            if (updateList.size() > 0) {
                backblastPubPersonService.updateBatchById(updateList);
            }
            // 批量删除
            if (removeList.size() > 0) {
                backblastPubPersonService.removeBatchByIds(removeList);
            }
        }else {
            // 删除所有
            QueryWrapper<BackblastPubPersonEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("backblast_pub_record_id", backblastPubRecord.getId());
            boolean remove = backblastPubPersonService.remove(wrapper);
        }
    }
 
    /**
     * 设置警格网格信息
     * @param backblastPubRecord
     */
    public void setGridInfo(BackblastPubRecordVO backblastPubRecord) {
        // 根据位置设置网格,警格编号
        IGridService gridService = SpringUtils.getBean(IGridService.class);
        IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class);
        String point = "'POINT(" + backblastPubRecord.getLng() + " " + backblastPubRecord.getLat() + ")'";
        //点坐标解析网格
        List<GridEntity> gridEntityList = gridService.spatialAnalysis(point);
        if (gridEntityList.size()>0){
            GridEntity gridEntity = gridEntityList.get(0);
            backblastPubRecord.setGridCode(gridEntity.getGridCode());
        }
        //点坐标解析警格
        List<PoliceAffairsGridEntity> policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point);
        if (policeAffairsGridEntityList.size()>0){
            PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0);
            backblastPubRecord.setJwGridCode(policeAffairsGridEntity.getJwGridCode());
        }
    }
 
    /**
     * 反炸宣传记录表 自定义详情
     * @param backblastPubRecord
     * @return
     */
    @Override
    public BackblastPubRecordVO getDetail(BackblastPubRecordVO backblastPubRecord) {
        return baseMapper.getDetail(backblastPubRecord);
    }
 
    /**
     * 反炸宣传记录表 删除
     */
    @Override
    public boolean removeBackblastPubByIds(List<Long> toLongList) {
        // 先删除对应的宣传记录
        boolean flag = removeByIds(toLongList);
        // 再删除对应的宣传对象信息
        if (flag){
            IBackblastPubPersonService backblastPubPersonService = SpringUtil.getBean(IBackblastPubPersonService.class);
            for (Long id : toLongList) {
                // 删除所有
                QueryWrapper<BackblastPubPersonEntity> wrapper = new QueryWrapper<>();
                wrapper.eq("backblast_pub_record_id", id);
                backblastPubPersonService.remove(wrapper);
            }
        }
        return flag;
    }
 
    @Override
    public List<BackblastPubRecordExcel> export(BackblastPubRecordVO backblastPubRecord) {
        CommonParamSet commonParamSet = new CommonParamSet<>().invoke(BackblastPubRecordVO.class, backblastPubRecord);
        if (!Strings.isBlank(backblastPubRecord.getRoleName())){
            backblastPubRecord.setCreateUser(AuthUtil.getUserId());
        }
        return baseMapper.selectBackblastPubRecordExport(backblastPubRecord,
            commonParamSet.getIsAdministrator(),
            commonParamSet.getRegionChildCodesList(),
            commonParamSet.getGridCodeList());
    }
}