huliguo
2025-05-13 a70919b4f7baab856125f36e5bd41f5ee81be680
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package com.cl.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cl.common.constant.DelFlagConstant;
import com.cl.common.context.BaseContext;
import com.cl.common.exception.data.DataException;
import com.cl.mapper.DataMapper;
import com.cl.pojo.dto.AddDataDTO;
import com.cl.pojo.entity.DataEntity;
import com.cl.pojo.vo.DataDetailVO;
import com.cl.pojo.vo.DataRateVO;
import com.cl.pojo.vo.DataVO;
import com.cl.pojo.vo.EditDataDTO;
import com.cl.pojo.vo.screen.*;
import com.cl.service.DataService;
import io.swagger.models.auth.In;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;
 
@Service
public class DataServiceImpl extends ServiceImpl<DataMapper, DataEntity> implements DataService {
 
    private final DataMapper dataMapper;
 
    public DataServiceImpl(DataMapper dataMapper) {
        this.dataMapper = dataMapper;
    }
 
    @Override
    public ScreenVO screen(Integer county,Integer year) {
        LocalDateTime createTime = LocalDateTime.of(year, 12, 31, 23, 59, 59);
        ScreenVO screenVO = new ScreenVO();
        DataEntity data =dataMapper.screen(county,createTime);
        if (null== data) {
            return screenVO;
        }
        screenVO.setAssistiveDeviceTotal(data.getAssistiveDeviceTotal());
        screenVO.setCreateTime(data.getCreateTime());
        screenVO.setTechnicalTraining(data.getTechnicalTraining());
        screenVO.setHomeAllowance(data.getHomeAllowance());
        screenVO.setEducationSubsidy(data.getEducationSubsidy());
 
        CertificateVO certificateVO = new CertificateVO();
        BeanUtils.copyProperties(data,certificateVO);
        screenVO.setCertificateVO(certificateVO);
 
        WorkerVO workerVO = new WorkerVO();
        BeanUtils.copyProperties(data,workerVO);
        screenVO.setWorkerVO(workerVO);
 
        DrillVO drillVO = new DrillVO();
        BeanUtils.copyProperties(data,drillVO);
        screenVO.setDrillVO(drillVO);
 
        SalvationVO salvationVO = new SalvationVO();
        BeanUtils.copyProperties(data,salvationVO);
        screenVO.setSalvationVO(salvationVO);
 
        DifficultyVO difficultyVO = new DifficultyVO();
        BeanUtils.copyProperties(data,difficultyVO);
        screenVO.setDifficultyVO(difficultyVO);
 
        AssistiveDeviceVO assistiveDeviceVO = new AssistiveDeviceVO();
        BeanUtils.copyProperties(data,assistiveDeviceVO);
        screenVO.setAssistiveDeviceVO(assistiveDeviceVO);
 
        AssistiveDeviceTypeVO assistiveDeviceTypeVO = new AssistiveDeviceTypeVO();
        BeanUtils.copyProperties(data,assistiveDeviceTypeVO);
        screenVO.setAssistiveDeviceTypeVO(assistiveDeviceTypeVO);
 
        AssistiveDeviceGradeVO assistiveDeviceGradeVO = new AssistiveDeviceGradeVO();
        BeanUtils.copyProperties(data,assistiveDeviceGradeVO);
        screenVO.setAssistiveDeviceGradeVO(assistiveDeviceGradeVO);
 
        StatutoryCertificateVO statutoryCertificateVO = new StatutoryCertificateVO();
        BeanUtils.copyProperties(data,statutoryCertificateVO);
        screenVO.setStatutoryCertificateVO(statutoryCertificateVO);
 
        EmployedVO employedVO = new EmployedVO();
        BeanUtils.copyProperties(data,employedVO);
        screenVO.setEmployedVO(employedVO);
 
        HighSchoolVO highSchoolVO = new HighSchoolVO();
        BeanUtils.copyProperties(data,highSchoolVO);
        screenVO.setHighSchoolVO(highSchoolVO);
 
        EducationVO educationVO = new EducationVO();
        BeanUtils.copyProperties(data,educationVO);
        screenVO.setEducationVO(educationVO);
 
        RightDownVO rightDownVO = new RightDownVO();
        BeanUtils.copyProperties(data,rightDownVO);
        screenVO.setRightDownVO(rightDownVO);
 
        return screenVO;
    }
 
    @Override
    public void add(AddDataDTO addDataDTO) {
        DataEntity dataEntity = new DataEntity();
        BeanUtils.copyProperties(addDataDTO,dataEntity);
        dataEntity.setCreateTime(LocalDateTime.now());
        dataEntity.setCreateBy(BaseContext.getCurrentUser().getId());
        int insert = dataMapper.insert(dataEntity);
        if (insert != 1) {
            throw new DataException("保存数据失败");
        }
    }
 
    @Override
    public IPage<DataVO> pageList(IPage<DataEntity> page, List<Integer> county, String name) {
        return dataMapper.pageList(page,county,name);
    }
 
    @Override
    public void delete(Integer id) {
        LambdaQueryWrapper<DataEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DataEntity::getId,id);
        queryWrapper.eq(DataEntity::getDelFlag, DelFlagConstant.UNDELETE);
        DataEntity dataEntity = dataMapper.selectOne(queryWrapper);
        if (dataEntity == null) {
            throw new DataException("删除数据失败,数据不存在");
        }
        dataEntity.setDelFlag(DelFlagConstant.DELETE);
        dataEntity.setUpdateTime(LocalDateTime.now());
        dataEntity.setUpdateBy(BaseContext.getCurrentUser().getId());
        int i = dataMapper.updateById(dataEntity);
        if (i != 1) {
            throw new DataException("删除失败");
        }
    }
 
    @Override
    public void edit(EditDataDTO editDataDTO) {
        LambdaQueryWrapper<DataEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DataEntity::getId,editDataDTO.getId());
        queryWrapper.eq(DataEntity::getDelFlag, DelFlagConstant.UNDELETE);
        DataEntity data = dataMapper.selectOne(queryWrapper);
        if (data == null) {
            throw new DataException("修改数据失败,数据id不存在");
        }
        DataEntity dataEntity = new DataEntity();
        BeanUtils.copyProperties(editDataDTO,dataEntity);
        dataEntity.setUpdateTime(LocalDateTime.now());
        dataEntity.setUpdateBy(BaseContext.getCurrentUser().getId());
        int i = dataMapper.updateById(dataEntity);
        if (i != 1) {
            throw new DataException("修改失败");
        }
    }
 
    @Override
    public DataDetailVO detail(Integer id) {
        LambdaQueryWrapper<DataEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DataEntity::getId,id);
        queryWrapper.eq(DataEntity::getDelFlag, DelFlagConstant.UNDELETE);
        DataEntity dataEntity = dataMapper.selectOne(queryWrapper);
        if (dataEntity == null) {
            throw new DataException("该条数据不存在");
        }
        DataDetailVO dataDetailVO = new DataDetailVO();
        //当前数据
        EditDataDTO data=new EditDataDTO();
        BeanUtils.copyProperties(dataEntity,data);
        dataDetailVO.setData(data);
        //当前数据的前一条数据
        EditDataDTO beforeData=new EditDataDTO();
        DataEntity beforeDataEntity= dataMapper.beforeOne(id);
        if (beforeDataEntity != null) {
            BeanUtils.copyProperties(beforeDataEntity,beforeData);
        }
        dataDetailVO.setBeforeData(beforeData);
        //计算比率
        DataRateVO dataRateVO = getRateVO(data,beforeData);
        dataDetailVO.setRateVO(dataRateVO);
        return dataDetailVO;
    }
 
    @Override
    public DataDetailVO addDetail(Integer county) {
        DataDetailVO dataDetailVO = new DataDetailVO();
        //通过区县获取上一次数据
        DataEntity dataEntity = dataMapper.getAddDetail(county);
        EditDataDTO editDataDTO=new EditDataDTO();
        BeanUtils.copyProperties(dataEntity,editDataDTO);
        dataDetailVO.setBeforeData(editDataDTO);
        return dataDetailVO;
    }
 
    @Override
    public List<Integer> getYearList(Integer county) {
        return dataMapper.getYearList( county);
 
    }
 
    @Override
    public Integer getAssistiveDeviceTotal(Integer county, Integer year) {
        LocalDateTime createTime = LocalDateTime.of(year, 12, 31, 23, 59, 59);
        return dataMapper.getAssistiveDeviceTotal(county,createTime);
    }
 
    private DataRateVO getRateVO(EditDataDTO data, EditDataDTO beforeData) {
        if (beforeData == null || beforeData.equals(new EditDataDTO())) {
            return null;
        }
        DataRateVO dataRateVO = new DataRateVO();
        //计算每个字段
        dataRateVO.setCertificateEyesight(calcRate(data.getCertificateEyesight(),beforeData.getCertificateEyesight()));
        dataRateVO.setCertificateIntellect(calcRate(data.getCertificateIntellect(),beforeData.getCertificateIntellect()));
        dataRateVO.setCertificateLimb(calcRate(data.getCertificateLimb(),beforeData.getCertificateLimb()));
        dataRateVO.setCertificateSpeech(calcRate(data.getCertificateSpeech(), beforeData.getCertificateSpeech()));
        dataRateVO.setCertificateHearing(calcRate(data.getCertificateHearing(), beforeData.getCertificateHearing()));
        dataRateVO.setCertificateSpirit(calcRate(data.getCertificateSpirit(), beforeData.getCertificateSpirit()));
        dataRateVO.setCertificateMultiple(calcRate(data.getCertificateMultiple(), beforeData.getCertificateMultiple()));
        dataRateVO.setWorkerCity(calcRate(data.getWorkerCity(), beforeData.getWorkerCity()));
        dataRateVO.setWorkerAssociation(calcRate(data.getWorkerAssociation(), beforeData.getWorkerAssociation()));
        dataRateVO.setWorkerServiceCorps(calcRate(data.getWorkerServiceCorps(), beforeData.getWorkerServiceCorps()));
        dataRateVO.setWorkerCounty(calcRate(data.getWorkerCounty(), beforeData.getWorkerCounty()));
        dataRateVO.setWorkerTownship(calcRate(data.getWorkerTownship(), beforeData.getWorkerTownship()));
        dataRateVO.setWorkerVillage(calcRate(data.getWorkerVillage(), beforeData.getWorkerVillage()));
        dataRateVO.setDrillAutism(calcRate(data.getDrillAutism(), beforeData.getDrillAutism()));
        dataRateVO.setDrillIntellect(calcRate(data.getDrillIntellect(), beforeData.getDrillIntellect()));
        dataRateVO.setDrillLimb(calcRate(data.getDrillLimb(), beforeData.getDrillLimb()));
        dataRateVO.setDrillSpeech(calcRate(data.getDrillSpeech(), beforeData.getDrillSpeech()));
        dataRateVO.setDrillHearing(calcRate(data.getDrillHearing(), beforeData.getDrillHearing()));
        dataRateVO.setDrillSpirit(calcRate(data.getDrillSpirit(), beforeData.getDrillSpirit()));
        dataRateVO.setSalvationBeforeSeven(calcRate(data.getSalvationBeforeSeven(), beforeData.getSalvationBeforeSeven()));
        dataRateVO.setSalvationAfterSeven(calcRate(data.getSalvationAfterSeven(), beforeData.getSalvationAfterSeven()));
        dataRateVO.setSalvationAutism(calcRate(data.getSalvationAutism(), beforeData.getSalvationAutism()));
        dataRateVO.setSalvationIntellect(calcRate(data.getSalvationIntellect(), beforeData.getSalvationIntellect()));
        dataRateVO.setSalvationLimb(calcRate(data.getSalvationLimb(), beforeData.getSalvationLimb()));
        dataRateVO.setSalvationSpeech(calcRate(data.getSalvationSpeech(), beforeData.getSalvationSpeech()));
        dataRateVO.setDifficultyMedication(calcRate(data.getDifficultyMedication(), beforeData.getDifficultyMedication()));
        dataRateVO.setDifficultyHospitalisation(calcRate(data.getDifficultyHospitalisation(), beforeData.getDifficultyHospitalisation()));
        dataRateVO.setAssistiveDeviceTotal(calcRate(data.getAssistiveDeviceTotal(), beforeData.getAssistiveDeviceTotal()));
        dataRateVO.setAssistiveDeviceOne(calcRate(data.getAssistiveDeviceOne(), beforeData.getAssistiveDeviceOne()));
        dataRateVO.setAssistiveDeviceTwo(calcRate(data.getAssistiveDeviceTwo(), beforeData.getAssistiveDeviceTwo()));
        dataRateVO.setAssistiveDeviceThree(calcRate(data.getAssistiveDeviceThree(), beforeData.getAssistiveDeviceThree()));
        dataRateVO.setAssistiveDeviceOther(calcRate(data.getAssistiveDeviceOther(), beforeData.getAssistiveDeviceOther()));
        dataRateVO.setAssistiveDeviceTypeOne(calcRate(data.getAssistiveDeviceTypeOne(), beforeData.getAssistiveDeviceTypeOne()));
        dataRateVO.setAssistiveDeviceTypeTwo(calcRate(data.getAssistiveDeviceTypeTwo(), beforeData.getAssistiveDeviceTypeTwo()));
        dataRateVO.setAssistiveDeviceTypeThree(calcRate(data.getAssistiveDeviceTypeThree(), beforeData.getAssistiveDeviceTypeThree()));
        dataRateVO.setAssistiveDeviceTypeFour(calcRate(data.getAssistiveDeviceTypeFour(), beforeData.getAssistiveDeviceTypeFour()));
        dataRateVO.setAssistiveDeviceGradeOne(calcRate(data.getAssistiveDeviceGradeOne(), beforeData.getAssistiveDeviceGradeOne()));
        dataRateVO.setAssistiveDeviceGradeTwo(calcRate(data.getAssistiveDeviceGradeTwo(), beforeData.getAssistiveDeviceGradeTwo()));
        dataRateVO.setAssistiveDeviceGradeThree(calcRate(data.getAssistiveDeviceGradeThree(), beforeData.getAssistiveDeviceGradeThree()));
        dataRateVO.setAssistiveDeviceGradeFour(calcRate(data.getAssistiveDeviceGradeFour(), beforeData.getAssistiveDeviceGradeFour()));
        dataRateVO.setTechnicalTraining(calcRate(data.getTechnicalTraining(), beforeData.getTechnicalTraining()));
        dataRateVO.setHomeAllowance(calcRate(data.getHomeAllowance(), beforeData.getHomeAllowance()));
        dataRateVO.setStatutoryCertificateEyesight(calcRate(data.getStatutoryCertificateEyesight(), beforeData.getStatutoryCertificateEyesight()));
        dataRateVO.setStatutoryCertificateIntellect(calcRate(data.getStatutoryCertificateIntellect(), beforeData.getStatutoryCertificateIntellect()));
        dataRateVO.setStatutoryCertificateLimb(calcRate(data.getStatutoryCertificateLimb(), beforeData.getStatutoryCertificateLimb()));
        dataRateVO.setStatutoryCertificateSpeech(calcRate(data.getStatutoryCertificateSpeech(), beforeData.getStatutoryCertificateSpeech()));
        dataRateVO.setStatutoryCertificateHearing(calcRate(data.getStatutoryCertificateHearing(), beforeData.getStatutoryCertificateHearing()));
        dataRateVO.setEmployedEmployment(calcRate(data.getEmployedEmployment(), beforeData.getEmployedEmployment()));
        dataRateVO.setEmployedConcentrated(calcRate(data.getEmployedConcentrated(), beforeData.getEmployedConcentrated()));
        dataRateVO.setEmployedPublicWelfare(calcRate(data.getEmployedPublicWelfare(), beforeData.getEmployedPublicWelfare()));
        dataRateVO.setEmployedAuxiliary(calcRate(data.getEmployedAuxiliary(), beforeData.getEmployedAuxiliary()));
        dataRateVO.setEmployedIndividual(calcRate(data.getEmployedIndividual(), beforeData.getEmployedIndividual()));
        dataRateVO.setHighSchoolEmployment(calcRate(data.getHighSchoolEmployment(), beforeData.getHighSchoolEmployment()));
        dataRateVO.setHighSchoolIndividual(calcRate(data.getHighSchoolIndividual(), beforeData.getHighSchoolIndividual()));
        dataRateVO.setHighSchoolFlexible(calcRate(data.getHighSchoolFlexible(), beforeData.getHighSchoolFlexible()));
        dataRateVO.setEducationOne(calcRate(data.getEducationOne(), beforeData.getEducationOne()));
        dataRateVO.setEducationTwo(calcRate(data.getEducationTwo(), beforeData.getEducationTwo()));
        dataRateVO.setEducationThree(calcRate(data.getEducationThree(), beforeData.getEducationThree()));
        dataRateVO.setEducationFour(calcRate(data.getEducationFour(), beforeData.getEducationFour()));
        dataRateVO.setEducationFive(calcRate(data.getEducationFive(), beforeData.getEducationFive()));
        dataRateVO.setEducationSix(calcRate(data.getEducationSix(), beforeData.getEducationSix()));
        dataRateVO.setEducationSeven(calcRate(data.getEducationSeven(), beforeData.getEducationSeven()));
        dataRateVO.setEducationEight(calcRate(data.getEducationEight(), beforeData.getEducationEight()));
        dataRateVO.setEducationNine(calcRate(data.getEducationNine(), beforeData.getEducationNine()));
        dataRateVO.setEducationSubsidy(calcRate(data.getEducationSubsidy(), beforeData.getEducationSubsidy()));
        dataRateVO.setActivityFrequency(calcRate(data.getActivityFrequency(), beforeData.getActivityFrequency()));
        dataRateVO.setEducationNumber(calcRate(data.getEducationNumber(), beforeData.getEducationNumber()));
        dataRateVO.setMatter(calcRate(data.getMatter(), beforeData.getMatter()));
        dataRateVO.setDoctorApprecitation(calcRate(data.getDoctorApprecitation(), beforeData.getDoctorApprecitation()));
        dataRateVO.setRemould(calcRate(data.getRemould(), beforeData.getRemould()));
        dataRateVO.setInterviewsOffice(calcRate(data.getInterviewsOffice(), beforeData.getInterviewsOffice()));
        dataRateVO.setInterviewsPhone(calcRate(data.getInterviewsPhone(), beforeData.getInterviewsPhone()));
        dataRateVO.setInterviewsSuperior(calcRate(data.getInterviewsSuperior(), beforeData.getInterviewsSuperior()));
        dataRateVO.setInterviewsHotline(calcRate(data.getInterviewsHotline(), beforeData.getInterviewsHotline()));
        return dataRateVO;
    }
 
    private String calcRate(Integer currentValue, Integer previousValue) {
        //去年的数据为0的情况
        if (previousValue == 0){
            return currentValue == 0 ? "同比持平" : "无同比数据";
        }
        // 计算变化率
        double changeRate = (currentValue - previousValue) * 100.0 / previousValue;
        // 格式化输出(保留两位小数,带正负号)
        DecimalFormat df = new DecimalFormat("0.00");
        String absoluteValue = df.format(Math.abs(changeRate));
        if (changeRate > 0) {
            return "同比增加" + absoluteValue + "%";
        } else if (changeRate < 0) {
            return "同比减少" + absoluteValue + "%";
        } else {
            return "同比持平";
        }
 
    }
 
}