|
@@ -0,0 +1,204 @@
|
|
|
+package cn.cslg.pas.service.business;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.dto.business.ReportAffairDTO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.Personnel;
|
|
|
+import cn.cslg.pas.common.model.cronModel.PersonnelVO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.SystemFile;
|
|
|
+import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.vo.invalidVO.InvalidRequestFileVO;
|
|
|
+import cn.cslg.pas.common.vo.invalidVO.ReportAffairVO;
|
|
|
+import cn.cslg.pas.domain.business.AssoReportAffairFile;
|
|
|
+import cn.cslg.pas.domain.business.InvalidRequestFile;
|
|
|
+import cn.cslg.pas.domain.business.ReportAffair;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
+import cn.cslg.pas.mapper.ReportAffairMapper;
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
+import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 报告事务Service层
|
|
|
+ * @Author xiexiang
|
|
|
+ * @Date 2023/12/23
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ReportAffairService extends ServiceImpl<ReportAffairMapper, ReportAffair> {
|
|
|
+ @Autowired
|
|
|
+ private CacheUtils cacheUtils;
|
|
|
+ @Autowired
|
|
|
+ private LoginUtils loginUtils;
|
|
|
+ @Autowired
|
|
|
+ private AssoReportAffairFileService assoReportAffairFileService;
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
+ @Autowired
|
|
|
+ private InvalidRequestFileService invalidRequestFileService;
|
|
|
+ @Autowired
|
|
|
+ private PermissionService permissionService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建报告事务
|
|
|
+ * @param reportAffairDTO
|
|
|
+ */
|
|
|
+ public Integer addReportAffair(ReportAffairDTO reportAffairDTO) {
|
|
|
+// PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ if (reportAffairDTO != null) {
|
|
|
+ ReportAffair reportAffair = new ReportAffair();
|
|
|
+ BeanUtils.copyProperties(reportAffairDTO, reportAffair);
|
|
|
+ reportAffair.setCreateId("328");
|
|
|
+ reportAffair.insert();
|
|
|
+ return reportAffair.getId();
|
|
|
+ } else {
|
|
|
+ throw new XiaoShiException("入参为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void delete(List<Integer> ids) {
|
|
|
+ for (Integer id : ids) {
|
|
|
+ LambdaQueryWrapper<ReportAffair> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(ReportAffair::getId, id);
|
|
|
+ ReportAffair reportAffair = this.getOne(queryWrapper, false);
|
|
|
+ if (reportAffair != null) {
|
|
|
+ LambdaQueryWrapper<AssoReportAffairFile> queryWrapper2 = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper2.eq(AssoReportAffairFile::getReportAffairId, id);
|
|
|
+ assoReportAffairFileService.remove(queryWrapper2);
|
|
|
+ if (reportAffair.getAffairType() == 1) {
|
|
|
+ LambdaQueryWrapper<InvalidRequestFile> queryWrapper1 = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper1.eq(InvalidRequestFile::getReportAffairId, id);
|
|
|
+ invalidRequestFileService.remove(queryWrapper1);
|
|
|
+ }
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询报告事务
|
|
|
+ * @param projectId
|
|
|
+ */
|
|
|
+ public List<ReportAffairVO> queryReportAffair(Integer projectId) {
|
|
|
+ List<ReportAffairVO> reportAffairVOS = new ArrayList<>();
|
|
|
+ //判空
|
|
|
+ if (projectId == null) {
|
|
|
+ throw new XiaoShiException("projectId为空");
|
|
|
+ }
|
|
|
+ //根据报告id查询事务
|
|
|
+ LambdaQueryWrapper<ReportAffair> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(ReportAffair::getProjectId, projectId);
|
|
|
+ List<ReportAffair> reportAffairs = this.list(queryWrapper);
|
|
|
+ if (reportAffairs.isEmpty()) {
|
|
|
+ return reportAffairVOS;
|
|
|
+ }
|
|
|
+ reportAffairVOS = this.loadReportAffairVOS(reportAffairs);
|
|
|
+ return reportAffairVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<ReportAffairVO> loadReportAffairVOS(List<ReportAffair> reportAffairs) {
|
|
|
+ List<ReportAffairVO> reportAffairVOS = new ArrayList<>();
|
|
|
+ reportAffairs.forEach(item -> {
|
|
|
+ ReportAffairVO reportAffairVO = new ReportAffairVO();
|
|
|
+ BeanUtils.copyProperties(item, reportAffairVO);
|
|
|
+ //根据事务类型选择不同的装载方式
|
|
|
+ Integer type = reportAffairVO.getAffairType();
|
|
|
+ if (type == 0) {
|
|
|
+
|
|
|
+ } else if (type == 1) {//无效请求书
|
|
|
+ this.loadInvalidRequestFile(reportAffairVO);
|
|
|
+ } else if (type == 2) {
|
|
|
+
|
|
|
+ } else if (type == 3) {
|
|
|
+
|
|
|
+ } else if (type == 4) {
|
|
|
+
|
|
|
+ }
|
|
|
+ reportAffairVOS.add(reportAffairVO);
|
|
|
+ });
|
|
|
+ if (!reportAffairVOS.isEmpty()) {
|
|
|
+ //装载文件信息
|
|
|
+ this.loadSystemFile(reportAffairVOS);
|
|
|
+ //装载创建人名
|
|
|
+ this.loadCreateName(reportAffairVOS);
|
|
|
+ }
|
|
|
+ return reportAffairVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载文件
|
|
|
+ * @param reportAffairVOS
|
|
|
+ */
|
|
|
+ public void loadSystemFile(List<ReportAffairVO> reportAffairVOS){
|
|
|
+ reportAffairVOS.forEach(item -> {
|
|
|
+ Integer reportAffairId = item.getId();
|
|
|
+ List<SystemFile> systemFiles = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<AssoReportAffairFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AssoReportAffairFile::getReportAffairId, reportAffairId);
|
|
|
+ List<AssoReportAffairFile> files = assoReportAffairFileService.list(queryWrapper);
|
|
|
+ if (!files.isEmpty()) {
|
|
|
+ List<String> fileGuids = files.stream().map(AssoReportAffairFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ //根据fileGuids查询文件信息
|
|
|
+ //查询文件
|
|
|
+ if (fileGuids.size() != 0) {
|
|
|
+ try {
|
|
|
+ String res = fileManagerService.getSystemFileFromFMS(fileGuids);
|
|
|
+ if (res != null && !res.trim().equals("")) {
|
|
|
+ systemFiles = JSONObject.parseArray(res, SystemFile.class);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException("查询文件详情错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.setSystemFileList(systemFiles);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载无效请求书
|
|
|
+ * @param reportAffairVO
|
|
|
+ */
|
|
|
+ public void loadInvalidRequestFile(ReportAffairVO reportAffairVO) {
|
|
|
+ Integer reportAffairId = reportAffairVO.getId();
|
|
|
+ InvalidRequestFileVO invalidRequestFileVO = invalidRequestFileService.getInvalidRequestFileVO(reportAffairId);
|
|
|
+ reportAffairVO.setInvalidRequestFileVO(invalidRequestFileVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void loadCreateName(List<ReportAffairVO> reportAffairVOS) {
|
|
|
+ List<String> createIds = new ArrayList<>();
|
|
|
+ reportAffairVOS.forEach(item -> {
|
|
|
+ if (item.getCreateId() != null) {
|
|
|
+ createIds.add(item.getCreateId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Personnel> personnels = new ArrayList<>();
|
|
|
+ //查询创建人名称
|
|
|
+ if (createIds.size() != 0) {
|
|
|
+ try {
|
|
|
+ String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (ReportAffairVO reportAffairVO : reportAffairVOS) {
|
|
|
+ Personnel personnel = personnels.stream().filter(item -> item.getId().equals(reportAffairVO.getCreateId())).findFirst().orElse(null);
|
|
|
+ if (personnel != null) {
|
|
|
+ reportAffairVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|