zhongrj
2024-11-28 d4a6c97b4c18ba90a206fbd5912ab91649edc662
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
package org.springblade.modules.yw.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.core.tool.utils.BeanUtil;
import org.springblade.modules.system.entity.Region;
import org.springblade.modules.system.service.IRegionService;
import org.springblade.modules.yw.entity.EmergencySpaceEntity;
import org.springblade.modules.yw.entity.IndParkInfoEntity;
import org.springblade.modules.yw.entity.RescueTeamEntity;
import org.springblade.modules.yw.excel.IndParkInfoExcel;
import org.springblade.modules.yw.service.*;
import org.springblade.modules.yw.vo.IndParkInfoVO;
import org.springblade.modules.yw.mapper.IndParkInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
import java.util.Objects;
 
/**
 * 园区基本信息表 服务实现类
 *
 * @author BladeX
 * @since 2024-10-28
 */
@Service
public class IndParkInfoServiceImpl extends ServiceImpl<IndParkInfoMapper, IndParkInfoEntity> implements IIndParkInfoService {
 
    @Autowired
    private IRegionService regionService;
 
    @Autowired
    private IFirmInfoService firmInfoService;
 
    @Autowired
    private IRescueTeamService rescueTeamService;
 
    @Autowired
    private IRiskSourceService riskSourceService;
 
    @Autowired
    private IProTarService proTarService;
 
    @Autowired
    private IEmergencySpaceService emergencySpaceService;
 
    /**
     * 自定义分页查询
     * @param page
     * @param indParkInfo
     * @return
     */
    @Override
    public IPage<IndParkInfoVO> selectIndParkInfoPage(IPage<IndParkInfoVO> page, IndParkInfoVO indParkInfo) {
        return page.setRecords(baseMapper.selectIndParkInfoPage(page, indParkInfo));
    }
 
    /**
     * 导入园区信息
     * @param data
     * @param isCovered 是否覆盖
     * @return
     */
    @Override
    public String importIndParkInfo(List<IndParkInfoExcel> data, boolean isCovered) {
        for (IndParkInfoExcel parkInfoExcel : data) {
            // 数据转换
            IndParkInfoEntity indParkInfoEntity = Objects.requireNonNull(BeanUtil.copy(parkInfoExcel, IndParkInfoEntity.class));
            // 区划转换
            if (!Strings.isBlank(parkInfoExcel.getAreaCode())) {
                String adCode = shiftResidentResidentAdCode(parkInfoExcel.getAreaCode());
                // 转换行政区code
                indParkInfoEntity.setAreaCode(adCode);
            }
            // 判断是否已经录入
            Long id = isSave(indParkInfoEntity);
            if (null!=id){
                // 更新
                if (isCovered){
                    indParkInfoEntity.setId(id);
                    updateById(indParkInfoEntity);
                    continue;
                }
            }
            // 保存
            boolean save = save(indParkInfoEntity);
        }
        return null;
    }
 
    /**
     * 判断是否已保存
     * @param indParkInfoEntity
     * @return
     */
    private Long isSave(IndParkInfoEntity indParkInfoEntity) {
        QueryWrapper<IndParkInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("name",indParkInfoEntity.getName()).eq("is_deleted",0);
        IndParkInfoEntity one = getOne(wrapper);
        if (null!=one){
            return one.getId();
        }
        return null;
    }
 
 
    /**
     * 根据名称转成code
     *
     * @param areaCode 行政区划
     */
    public String shiftResidentResidentAdCode(String areaCode) {
        String[] split = areaCode.split("-");
        // 根据省市县三级查询对应的区县code
        QueryWrapper<Region> wrapper = new QueryWrapper<>();
        wrapper.eq("province_name", split[0])
            .eq("city_name", split[1]);
        List<Region> list = regionService.list(wrapper);
        if (list.size() > 0) {
            return list.get(0).getProvinceCode()+","+list.get(0).getCityCode();
        }
        return "";
    }
 
    /**
     * 园区基本信息查询(包含企业统计信息)
     * @param indParkInfo
     * @return
     */
    @Override
    public IndParkInfoVO getDetail(IndParkInfoEntity indParkInfo) {
        // 查询详情信息
        IndParkInfoVO indParkInfoVO = baseMapper.getDetail(indParkInfo);
        // 查询企业的数量
        long count = firmInfoService.count();
        // 设置企业数量
        indParkInfoVO.setFirmNum((int) count);
        // 设置行政区划
        setRegionInfo(indParkInfoVO);
        // 设置救援人员数量
        indParkInfoVO.setRecNum(getRecNum());
        // 设置应急池容量
        indParkInfoVO.setEmePool(getEmePool());
        // 设置风险企业数量
        indParkInfoVO.setRiskFirmNum(getRiskFirmNum());
        // 设置保护目标数量
        indParkInfoVO.setProTarNum(getProTarNum());
        // 设置应急空间数量
        indParkInfoVO.setSpaceNum(getSpaceNum());
        // 返回
        return indParkInfoVO;
    }
 
    /**
     * 获取应急池容量
     * @return
     */
    private String getEmePool() {
        return emergencySpaceService.getEmePool();
    }
 
    /**
     * 查询应急空间数量
     * @return
     */
    private Integer getSpaceNum() {
        QueryWrapper<EmergencySpaceEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted",0).ne("type",7);
        return (int)emergencySpaceService.count(wrapper);
    }
 
    /**
     * 查询保护目标数量
     * @return
     */
    private Integer getProTarNum() {
        return (int)proTarService.count();
    }
 
    /**
     * 查询风险企业数量
     * @return
     */
    private Integer getRiskFirmNum() {
        return (int)riskSourceService.count();
    }
 
    /**
     * 获取救援人员数量
     * @return
     */
    private Integer getRecNum() {
        QueryWrapper<RescueTeamEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("type",1);
        long count = rescueTeamService.count(wrapper);
        return (int)count;
    }
 
    /**
     * 设置行政区划
     * @param indParkInfoVO
     */
    private void setRegionInfo(IndParkInfoVO indParkInfoVO) {
        QueryWrapper<Region> wrapper = new QueryWrapper<>();
        wrapper.eq("ancestors","000000000000,"+indParkInfoVO.getAreaCode());
        List<Region> list = regionService.list(wrapper);
        if (list.size()>0){
            Region region = list.get(0);
            indParkInfoVO.setRegionName(region.getProvinceName()+"-"+region.getCityName());
        }
    }
}