From 939b5e669c9bab83b7c9aaee3b285d8e09670910 Mon Sep 17 00:00:00 2001
From: songhuangfeng123 <shf18767906695@163.com>
Date: Tue, 19 Jul 2022 17:54:02 +0800
Subject: [PATCH] 事故快报

---
 incident-manage/incident-manage-service/src/main/java/com/gkhy/safePlatform/incidentManage/service/impl/AccidentExpressServiceImpl.java |  265 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 265 insertions(+), 0 deletions(-)

diff --git a/incident-manage/incident-manage-service/src/main/java/com/gkhy/safePlatform/incidentManage/service/impl/AccidentExpressServiceImpl.java b/incident-manage/incident-manage-service/src/main/java/com/gkhy/safePlatform/incidentManage/service/impl/AccidentExpressServiceImpl.java
new file mode 100644
index 0000000..418db46
--- /dev/null
+++ b/incident-manage/incident-manage-service/src/main/java/com/gkhy/safePlatform/incidentManage/service/impl/AccidentExpressServiceImpl.java
@@ -0,0 +1,265 @@
+package com.gkhy.safePlatform.incidentManage.service.impl;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gkhy.safePlatform.commons.enums.ResultCodes;
+import com.gkhy.safePlatform.commons.query.PageQuery;
+import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
+import com.gkhy.safePlatform.commons.utils.StringUtils;
+import com.gkhy.safePlatform.commons.vo.ResultVO;
+import com.gkhy.safePlatform.commons.vo.SearchResultVO;
+import com.gkhy.safePlatform.incidentManage.entity.*;
+import com.gkhy.safePlatform.incidentManage.enums.AccidentResultCodes;
+import com.gkhy.safePlatform.incidentManage.exception.AccidentException;
+import com.gkhy.safePlatform.incidentManage.model.dto.req.AccidentExpressFileReqDTO;
+import com.gkhy.safePlatform.incidentManage.model.dto.req.AccidentExpressReqDTO;
+import com.gkhy.safePlatform.incidentManage.model.dto.resp.AccidentExpressDetailRespDTO;
+import com.gkhy.safePlatform.incidentManage.model.dto.resp.AccidentExpressFileRespDTO;
+import com.gkhy.safePlatform.incidentManage.model.dto.resp.AccidentExpressPageRespDTO;
+import com.gkhy.safePlatform.incidentManage.query.AccidentExpressQuery;
+import com.gkhy.safePlatform.incidentManage.query.db.AccidentExpressDBQuery;
+import com.gkhy.safePlatform.incidentManage.service.AccidentExpressService;
+import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressFileInfoService;
+import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressInfoService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service("accidentExpressService")
+public class AccidentExpressServiceImpl implements AccidentExpressService {
+
+    @Autowired
+    private AccidentExpressInfoService accidentExpressInfoService;
+
+    @Autowired
+    private AccidentExpressFileInfoService accidentExpressFileInfoService;
+
+
+    @Override
+    public SearchResultVO<List<AccidentExpressPageRespDTO>> selectAccidentExpressList(PageQuery<AccidentExpressQuery> query) {
+        Long pageIndex = query.getPageIndex();
+        Long pageSize = query.getPageSize();
+        Page<AccidentExpressInfoPageDO> page = new Page<>(pageIndex, pageSize);
+
+        AccidentExpressDBQuery accidentExpressDBQuery = new AccidentExpressDBQuery();
+        if (query.getSearchParams() != null) {
+            BeanUtils.copyProperties(query.getSearchParams(), accidentExpressDBQuery);
+        }
+
+
+        List<AccidentExpressInfoPageDO> accidentExpressInfoPageDOList = accidentExpressInfoService.selectAccidentExpressList(page, accidentExpressDBQuery);
+        List<AccidentExpressPageRespDTO> respList = BeanCopyUtils.copyBeanList(accidentExpressInfoPageDOList, AccidentExpressPageRespDTO.class);
+
+        return new SearchResultVO<>(
+                true,
+                pageIndex,
+                pageSize,
+                page.getTotal(),
+                respList,
+                ResultCodes.OK
+        );
+    }
+
+    @Override
+    public ResultVO addAccidentExpress(Long uid, AccidentExpressReqDTO accidentExpressReqDTO) {
+        //必填项验证
+        checkRequired(accidentExpressReqDTO);
+
+        Date nowDate = new Date();
+        //1.新增应急队伍
+        AccidentExpressInfo accidentExpressInfo = new AccidentExpressInfo();
+        BeanUtils.copyProperties(accidentExpressReqDTO, accidentExpressInfo);
+        accidentExpressInfo.setDelFlag(false);
+        accidentExpressInfo.setCreateUid(uid);
+        accidentExpressInfo.setGmtCreate(nowDate);
+        accidentExpressInfoService.addAccidentExpress(accidentExpressInfo);
+        //2.新增应急队伍附件
+        if (!CollectionUtils.isEmpty(accidentExpressReqDTO.getFileList())){
+            addAccidentExpressFile(accidentExpressInfo.getId(),uid,nowDate,accidentExpressReqDTO.getFileList());
+        }
+        return new ResultVO(ResultCodes.OK);
+    }
+
+    private void  addAccidentExpressFile(Long accidentExpressId ,Long uid , Date nowDate , List<AccidentExpressFileReqDTO> AccidentExpressFileReqDTOList){
+        List<AccidentExpressFileInfo> fileInfoList = BeanCopyUtils.copyBeanList(AccidentExpressFileReqDTOList, AccidentExpressFileInfo.class);
+        fileInfoList.forEach(AccidentExpressFileInfo -> {
+            AccidentExpressFileInfo.setAccidentExpressId(accidentExpressId);
+            AccidentExpressFileInfo.setDelFlag(false);
+            AccidentExpressFileInfo.setCreateUid(uid);
+            AccidentExpressFileInfo.setGmtCreate(nowDate);
+        });
+        for (AccidentExpressFileInfo AccidentExpressFileInfo :fileInfoList){
+            accidentExpressFileInfoService.addAccidentExpressFile(AccidentExpressFileInfo);
+        }
+    }
+
+    @Override
+    public ResultVO<AccidentExpressDetailRespDTO> getAccidentExpressById(Long id) {
+        AccidentExpressDetailRespDTO AccidentExpressDetailRespDTO = new AccidentExpressDetailRespDTO();
+        //查询是否存在
+        AccidentExpressInfoDetailDO AccidentExpressInfoDetailDO = accidentExpressInfoService.selectAccidentExpressById(id);
+        if (AccidentExpressInfoDetailDO==null){
+            throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NOT_EXIST);
+        }else{
+            BeanUtils.copyProperties(AccidentExpressInfoDetailDO,AccidentExpressDetailRespDTO);
+            //查找对应的附件
+            List<AccidentExpressFileInfoDO> AccidentExpressFileInfoDOList = accidentExpressFileInfoService.selectByAccidentExpressId(id);
+            if (!CollectionUtils.isEmpty(AccidentExpressFileInfoDOList)){
+                List<AccidentExpressFileRespDTO> accidentExpressFileRespDTOList = BeanCopyUtils.copyBeanList(AccidentExpressFileInfoDOList , AccidentExpressFileRespDTO.class);
+                AccidentExpressDetailRespDTO.setFileList(accidentExpressFileRespDTOList);
+            }
+            return new ResultVO<>(ResultCodes.OK ,AccidentExpressDetailRespDTO);
+        }
+    }
+
+    @Override
+    public ResultVO updateAccidentExpress(Long uid, AccidentExpressReqDTO accidentExpressReqDTO) {
+        Date nowDate = new Date();
+        //查询是否存在
+        AccidentExpressInfoDetailDO AccidentExpressInfoDetailDO = accidentExpressInfoService.selectAccidentExpressById(accidentExpressReqDTO.getId());
+        if (AccidentExpressInfoDetailDO==null){
+            throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NOT_EXIST);
+        }else{
+            AccidentExpressInfo accidentExpressInfo = new AccidentExpressInfo();
+            BeanUtils.copyProperties(accidentExpressReqDTO,accidentExpressInfo);
+            accidentExpressInfo.setUpdateUid(uid);
+            accidentExpressInfo.setGmtModitify(nowDate);
+            accidentExpressInfoService.updateAccidentExpress(accidentExpressInfo);
+            //修改应急队伍附件
+            updateAccidentExpressFile(uid,accidentExpressReqDTO.getId(),nowDate,accidentExpressReqDTO.getFileList());
+            return new ResultVO(ResultCodes.OK);
+        }
+    }
+
+    private void updateAccidentExpressFile(Long uid ,Long accidentExpressId ,Date nowDate,List<AccidentExpressFileReqDTO> AccidentExpressFileReqDTOList){
+
+        List<AccidentExpressFileInfoDO> accidentExpressFileInfoDOList = accidentExpressFileInfoService.selectByAccidentExpressId(accidentExpressId);
+        List<Long> oldIdsList = accidentExpressFileInfoDOList.stream().map(AccidentExpressFileInfoDO::getId).collect(Collectors.toList());
+        List<Long> newIdsList = new ArrayList<>();
+
+        //新增的附件集合
+        List<AccidentExpressFileInfo> addList = new ArrayList<>();
+        //删除的附件集合(id)
+        List<Long> deleteList = new ArrayList<>();
+        for (AccidentExpressFileReqDTO AccidentExpressFileReqDTO : AccidentExpressFileReqDTOList){
+            //如果不存在id则表示页面新增的附件
+            if (AccidentExpressFileReqDTO.getId() == null){
+                AccidentExpressFileInfo AccidentExpressFileInfo = new AccidentExpressFileInfo();
+                BeanUtils.copyProperties(AccidentExpressFileReqDTO,AccidentExpressFileInfo);
+                AccidentExpressFileInfo.setDelFlag(false);
+                AccidentExpressFileInfo.setGmtCreate(nowDate);
+                AccidentExpressFileInfo.setCreateUid(uid);
+                AccidentExpressFileInfo.setAccidentExpressId(accidentExpressId);
+                addList.add(AccidentExpressFileInfo);
+            }
+            //如果存在id则判断页面是否删除
+            else{
+                newIdsList.add(AccidentExpressFileReqDTO.getId());
+            }
+        }
+        for (Long oldId : oldIdsList){
+            if (!newIdsList.contains(oldId)){
+                deleteList.add(oldId);
+            }
+        }
+        if (!CollectionUtils.isEmpty(addList)){
+            for (AccidentExpressFileInfo AccidentExpressFileInfo : addList){
+                accidentExpressFileInfoService.addAccidentExpressFile(AccidentExpressFileInfo);
+            }
+        }
+        if (!CollectionUtils.isEmpty(deleteList)){
+            accidentExpressFileInfoService.deleteAccidentExpressFileByIds(deleteList);
+        }
+    }
+
+
+    @Override
+    public ResultVO batchDeleteAccidentExpress(String ids) {
+        if (StringUtils.isBlank(ids)){
+            throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NULL);
+        }else{
+            String[] idArr = ids.split(",");
+            for (String id : idArr) {
+                deleteAccidentExpress(Long.valueOf(id));
+            }
+            return new ResultVO(ResultCodes.OK);
+        }
+    }
+
+    private void deleteAccidentExpress(Long id) {
+        //查询是否存在
+        AccidentExpressInfoDetailDO AccidentExpressInfoDetailDO = accidentExpressInfoService.selectAccidentExpressById(id);
+        if (AccidentExpressInfoDetailDO==null){
+            throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NOT_EXIST);
+        }else{
+            accidentExpressInfoService.deleteAccidentExpressById(id);
+            //删除附件
+            accidentExpressFileInfoService.deleteAccidentExpressFileByAccidentExpressId(id);
+        }
+    }
+
+
+
+
+    /**
+     * 验证必填项
+     * @return
+     */
+    private void checkRequired(AccidentExpressReqDTO AccidentExpressReqDTO) {
+       /* //名称
+        if (StringUtils.isBlank(AccidentExpressReqDTO.getTeamName())) {
+            throw new EmergencyException(EmergencyResultCodes.TEAM_NAME_NULL);
+        }
+        //级别
+        if (StringUtils.isBlank(AccidentExpressReqDTO.getTeamLevel())) {
+            throw new EmergencyException(EmergencyResultCodes.TEAM_LEVEL_NULL);
+        }
+        //负责人
+        if (AccidentExpressReqDTO.getPrincipalUid() == null || AccidentExpressReqDTO.getPrincipalUid() == 0) {
+            throw new EmergencyException(EmergencyResultCodes.TEAM_PRINCIPAL_NULL);
+        }
+        //负责人部门
+        if (AccidentExpressReqDTO.getPrincipalDepartmentId() == null || AccidentExpressReqDTO.getPrincipalDepartmentId() == 0) {
+            throw new EmergencyException(EmergencyResultCodes.TEAM_PRINCIPAL_DEPARTMENT_NULL);
+        }
+        //负责人手机
+        if (StringUtils.isBlank(AccidentExpressReqDTO.getPrincipalPhone())) {
+            throw new EmergencyException(EmergencyResultCodes.TEAM_PRINCIPAL_PHONE_NULL);
+        }
+        //固定电话
+        if (StringUtils.isBlank(AccidentExpressReqDTO.getTelephoneNumber())) {
+            throw new EmergencyException(EmergencyResultCodes.TEAM_TELEPHONE_NUMBER_NULL);
+        }
+        //人员列表如果不为空,则需要验证其中的必填项
+        if (!CollectionUtils.isEmpty(AccidentExpressReqDTO.getMemberList())){
+            for(AccidentExpressMemberReqDTO AccidentExpressMemberReqDTO : AccidentExpressReqDTO.getMemberList()){
+                //工号
+                if (StringUtils.isBlank(AccidentExpressMemberReqDTO.getJobNumber())) {
+                    throw new EmergencyException(EmergencyResultCodes.TEAM_USER_JOB_NUMBER_NULL);
+                }
+                //名称
+                if (StringUtils.isBlank(AccidentExpressMemberReqDTO.getName())) {
+                    throw new EmergencyException(EmergencyResultCodes.TEAM_USER_NAME_NULL);
+                }
+                //性别
+                if (AccidentExpressMemberReqDTO.getGender()==null) {
+                    throw new EmergencyException(EmergencyResultCodes.TEAM_USER_GENDER_NULL);
+                }
+                //手机号码
+                if (StringUtils.isBlank(AccidentExpressMemberReqDTO.getPhone())) {
+                    throw new EmergencyException(EmergencyResultCodes.TEAM_USER_PHONE_NULL);
+                }
+                //职务
+                if (StringUtils.isBlank(AccidentExpressMemberReqDTO.getPosition())) {
+                    throw new EmergencyException(EmergencyResultCodes.TEAM_USER_POSITION_NULL);
+                }
+            }
+        }*/
+    }
+
+}

--
Gitblit v1.9.2