From a70919b4f7baab856125f36e5bd41f5ee81be680 Mon Sep 17 00:00:00 2001
From: huliguo <2023611923@qq.com>
Date: 星期二, 13 五月 2025 09:41:35 +0800
Subject: [PATCH] 修改年份切换字段不为必填

---
 src/main/java/com/cl/service/impl/DataServiceImpl.java |  313 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 313 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/cl/service/impl/DataServiceImpl.java b/src/main/java/com/cl/service/impl/DataServiceImpl.java
new file mode 100644
index 0000000..6856acd
--- /dev/null
+++ b/src/main/java/com/cl/service/impl/DataServiceImpl.java
@@ -0,0 +1,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 "同比持平";
+        }
+
+    }
+
+}

--
Gitblit v1.7.1