songhuangfeng123
2022-08-15 c9529bd19a8d61666b71824dd751682c1e9dc288
incident-manage/incident-manage-service/src/main/java/com/gkhy/safePlatform/incidentManage/service/impl/AccidentExpressServiceImpl.java
@@ -1,6 +1,10 @@
package com.gkhy.safePlatform.incidentManage.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
@@ -23,14 +27,13 @@
import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressCasualtyInfoService;
import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressFileInfoService;
import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressInfoService;
import org.apache.dubbo.config.annotation.DubboReference;
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.*;
import java.util.stream.Collectors;
@Service("accidentExpressService")
@@ -44,6 +47,9 @@
    @Autowired
    private AccidentExpressCasualtyInfoService accidentExpressCasualtyInfoService;
    @DubboReference(check = false)
    private AccountDepartmentService accountDepartmentService;
    @Override
@@ -60,14 +66,28 @@
        List<AccidentExpressInfoPageDO> accidentExpressInfoPageDOList = accidentExpressInfoService.selectAccidentExpressList(page, accidentExpressDBQuery);
        List<AccidentExpressPageRespDTO> respList = BeanCopyUtils.copyBeanList(accidentExpressInfoPageDOList, AccidentExpressPageRespDTO.class);
        Map<Long, String> depPool = new HashMap<>();
        respList.forEach(AccidentExpressPageRespDTO ->{
            // 设置人员名称
            // 设置部门名称
            if (!depPool.containsKey(AccidentExpressPageRespDTO.getAccidentDepartmentId())) {
                ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(AccidentExpressPageRespDTO.getAccidentDepartmentId());
                if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
                    if (rpcResult.getData() != null) {
                        DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO) rpcResult.getData();
                        depPool.put(dep.getDepId(), dep.getDepName());
                    }
                }}
            String depName = depPool.get(AccidentExpressPageRespDTO.getAccidentDepartmentId());
            AccidentExpressPageRespDTO.setDeptName(depName);
        });
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
@@ -75,23 +95,29 @@
    }
    @Override
    public ResultVO addAccidentExpress(Long uid, AccidentExpressReqDTO accidentExpressReqDTO) {
    public ResultVO<AccidentExpressDetailRespDTO> addAccidentExpress(ContextCacheUser contextCacheUser, AccidentExpressReqDTO accidentExpressReqDTO) {
        Long uid = contextCacheUser.getUid();
        String uName = contextCacheUser.getRealName();
        //必填项验证
        checkRequired(accidentExpressReqDTO);
        Date nowDate = new Date();
        //1.新增应急队伍
        //1.新增事故快报
        AccidentExpressInfo accidentExpressInfo = new AccidentExpressInfo();
        BeanUtils.copyProperties(accidentExpressReqDTO, accidentExpressInfo);
        accidentExpressInfo.setDelFlag(false);
        accidentExpressInfo.setCreateUid(uid);
        accidentExpressInfo.setCreateName(uName);
        accidentExpressInfo.setGmtCreate(nowDate);
        accidentExpressInfoService.addAccidentExpress(accidentExpressInfo);
        //2.新增应急队伍附件
        //2.新增事故快报附件
        if (!CollectionUtils.isEmpty(accidentExpressReqDTO.getFileList())){
            addAccidentExpressFile(accidentExpressInfo.getId(),uid,nowDate,accidentExpressReqDTO.getFileList());
        }
        return new ResultVO(ResultCodes.OK);
        AccidentExpressDetailRespDTO accidentExpressDetailRespDTO = new AccidentExpressDetailRespDTO();
        BeanUtils.copyProperties(accidentExpressInfo,accidentExpressDetailRespDTO);
        return new ResultVO<>(ResultCodes.OK,accidentExpressDetailRespDTO);
    }
    private void  addAccidentExpressFile(Long accidentExpressId ,Long uid , Date nowDate , List<AccidentExpressFileReqDTO> AccidentExpressFileReqDTOList){
@@ -139,7 +165,7 @@
            accidentExpressInfo.setUpdateUid(uid);
            accidentExpressInfo.setGmtModitify(nowDate);
            accidentExpressInfoService.updateAccidentExpress(accidentExpressInfo);
            //修改应急队伍附件
            //修改事故快报附件
            updateAccidentExpressFile(uid,accidentExpressReqDTO.getId(),nowDate,accidentExpressReqDTO.getFileList());
            return new ResultVO(ResultCodes.OK);
        }
@@ -188,13 +214,12 @@
    @Override
    public ResultVO batchDeleteAccidentExpress(String ids) {
        if (StringUtils.isBlank(ids)){
    public ResultVO batchDeleteAccidentExpress(Long[] ids) {
        if (ids == null ||  ids.length==0){
            throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NULL);
        }else{
            String[] idArr = ids.split(",");
            for (String id : idArr) {
                deleteAccidentExpress(Long.valueOf(id));
            for (Long id : ids){
                deleteAccidentExpress(id);
            }
            return new ResultVO(ResultCodes.OK);
        }
@@ -209,6 +234,8 @@
            accidentExpressInfoService.deleteAccidentExpressById(id);
            //删除附件
            accidentExpressFileInfoService.deleteAccidentExpressFileByAccidentExpressId(id);
            //删除伤亡
            accidentExpressCasualtyInfoService.deleteAccidentExpressCasualtyByAccidentExpressId(id);
        }
    }