|
@@ -0,0 +1,394 @@
|
|
|
+package com.jeeplus.test.cw.projectReport.service;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
+import com.jeeplus.sys.utils.StringUtils;
|
|
|
+import com.jeeplus.sys.utils.UserUtils;
|
|
|
+import com.jeeplus.test.cw.contractRegistration.domain.ContractInfo;
|
|
|
+import com.jeeplus.test.cw.projectRecords.domain.CwProjectRecords;
|
|
|
+import com.jeeplus.test.cw.projectRecords.service.dto.CwProjectRecordsDTO;
|
|
|
+import com.jeeplus.test.cw.projectRecords.service.mapstruct.CwProjectRecordsWrapper;
|
|
|
+import com.jeeplus.test.cw.projectReport.domain.*;
|
|
|
+import com.jeeplus.test.cw.projectReport.mapper.CwProjectInfoMapper;
|
|
|
+import com.jeeplus.test.cw.projectReport.mapper.CwProjectReportCancelMapper;
|
|
|
+import com.jeeplus.test.cw.projectReport.mapper.CwProjectReportMapper;
|
|
|
+import com.jeeplus.test.cw.projectReport.mapper.ProjectReportWorkAttachmentMapper;
|
|
|
+import com.jeeplus.test.cw.projectReport.service.dto.CwProjectReportDTO;
|
|
|
+import com.jeeplus.test.cw.projectReport.service.dto.ProjectReportWorkAttachmentDTO;
|
|
|
+import com.jeeplus.test.cw.projectReport.service.mapstruct.CwProjectReportFileWrapper;
|
|
|
+import com.jeeplus.test.cw.workClientInfo.domain.CwWorkClientBase;
|
|
|
+import com.jeeplus.test.cw.workClientInfo.service.dto.CwWorkClientBaseDTO;
|
|
|
+import com.jeeplus.test.cw.workClientInfo.service.mapstruct.CwWorkClientBaseWrapper;
|
|
|
+import com.jeeplus.test.mould.service.SerialnumTplService;
|
|
|
+import com.jeeplus.test.oss.domain.WorkAttachment;
|
|
|
+import com.jeeplus.test.oss.mapper.OssServiceMapper;
|
|
|
+import com.jeeplus.test.oss.service.OssService;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: 王强
|
|
|
+ * @create: 2022-11-16 14:17
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+@Transactional
|
|
|
+public class CwProjectReportService extends ServiceImpl<CwProjectReportMapper, CwProjectReport> {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CwProjectReportMapper reportMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CwProjectInfoMapper infoMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProjectReportWorkAttachmentMapper attachmentMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SerialnumTplService serialnumTplService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private OssService ossService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private OssServiceMapper ossServiceMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CwProjectReportCancelMapper cancelMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存项目以及其他相关信息
|
|
|
+ * @param reportData
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public String saveForm(CwProjectReportData reportData) throws Exception{
|
|
|
+ if (StringUtils.isNotEmpty(reportData.getId())){
|
|
|
+
|
|
|
+ CwProjectReport report = reportMapper.selectById(reportData.getId());
|
|
|
+ if (report != null){
|
|
|
+ reportData.setCreateBy(reportData.getCreateBy());
|
|
|
+ return update(reportData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return add(reportData);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同登记修改
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String update(CwProjectReportData reportData) throws Exception{
|
|
|
+ //获取当前登录人信息
|
|
|
+ UserDTO userDTO = UserUtils.getCurrentUserDTO();
|
|
|
+
|
|
|
+ CwProjectReport report = new CwProjectReport();
|
|
|
+ BeanUtils.copyProperties(reportData, report);
|
|
|
+ report.setUpdateBy(userDTO.getId());
|
|
|
+ report.setUpdateDate(new Date());
|
|
|
+ reportMapper.updateById(report);
|
|
|
+ //附件信息修改
|
|
|
+ //1、修改work_attachment_id信息
|
|
|
+ //删除在添加
|
|
|
+ List<CwProjectInfoData> infoList = new ArrayList<>();
|
|
|
+ if (!report.getCwProjectInfoList().isEmpty()){
|
|
|
+ infoList = report.getCwProjectInfoList();
|
|
|
+ infoList.forEach(info->{
|
|
|
+ //删除
|
|
|
+ List<String> attachmentId = attachmentMapper.getIdByAttachmentId(info.getId());
|
|
|
+ //根据这个id删除cw_project_report_file信息
|
|
|
+ if (attachmentId != null & !attachmentId.isEmpty()) {
|
|
|
+ attachmentId.forEach(atId->{
|
|
|
+ attachmentMapper.deleteByRepotyId(atId);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //删除work_attachment_id信息
|
|
|
+ attachmentMapper.deleteByAttachMnentId(info.getId());
|
|
|
+ });
|
|
|
+ infoList.forEach(in->{
|
|
|
+ in.setUpdateBy(UserUtils.getCurrentUserDTO().getId());
|
|
|
+ in.setUpdateDate(new Date());
|
|
|
+ //先去数据库中查是否有数据,有则更新,无则添加
|
|
|
+ CwProjectInfoData cwProjectInfoData = infoMapper.selectById(in.getId());
|
|
|
+ if (cwProjectInfoData == null){
|
|
|
+ infoMapper.insert(in);
|
|
|
+ }else {
|
|
|
+ infoMapper.updateById(in);
|
|
|
+ }
|
|
|
+
|
|
|
+ //对上传的文件数据进行持久化操作
|
|
|
+ List<ProjectReportWorkAttachmentDTO> fileInfoList = new ArrayList<>();
|
|
|
+ if (!in.getCwFileInfoList().isEmpty()){
|
|
|
+ fileInfoList = in.getCwFileInfoList();
|
|
|
+ }
|
|
|
+
|
|
|
+// UserDTO userDTO = UserUtils.getCurrentUserDTO();
|
|
|
+ ossServiceMapper.delete(new QueryWrapper<WorkAttachment>().lambda().eq(WorkAttachment::getAttachmentId, in.getId()));
|
|
|
+ AtomicInteger j = new AtomicInteger(1);
|
|
|
+ if (fileInfoList != null & !fileInfoList.isEmpty()){
|
|
|
+ fileInfoList.forEach(item -> {
|
|
|
+ WorkAttachment i = new WorkAttachment();
|
|
|
+ //包含了url、size、name
|
|
|
+ i.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ i.setCreateDate(new Date());
|
|
|
+ i.setUpdateDate(new Date());
|
|
|
+ i.setDelFlag(0);
|
|
|
+ i.setUrl(item.getUrl());
|
|
|
+ //文件类型处理
|
|
|
+ List<String> strings = Arrays.asList(item.getName().split("\\."));
|
|
|
+ if (CollectionUtils.isNotEmpty(strings)) {
|
|
|
+ i.setType(strings.get(1));
|
|
|
+ }
|
|
|
+ i.setAttachmentId(in.getId());
|
|
|
+ i.setAttachmentName(item.getName());
|
|
|
+ i.setAttachmentFlag("cw_project_report_file");
|
|
|
+ i.setFileSize(item.getSize());
|
|
|
+ i.setSort(j.get());
|
|
|
+ ossServiceMapper.insertWorkAttachment(i, userDTO);
|
|
|
+ j.getAndIncrement();
|
|
|
+ CwProjectReportFile cwProjectReportFile = CwProjectReportFileWrapper.INSTANCE.toEntity(item);
|
|
|
+ cwProjectReportFile.setReportFileId(i.getId());
|
|
|
+ attachmentMapper.insert(cwProjectReportFile);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return report.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String add(CwProjectReportData reportData) throws Exception{
|
|
|
+ //获取当前登录人信息
|
|
|
+ UserDTO userDTO = UserUtils.getCurrentUserDTO();
|
|
|
+ if(StringUtils.isBlank(reportData.getId())){
|
|
|
+ //单据编号生成
|
|
|
+ String documentNo = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), CwProjectReportDTO.BIZ_CODE);
|
|
|
+ reportData.setDocumentNo(documentNo);
|
|
|
+ }
|
|
|
+ CwProjectReport report = new CwProjectReport();
|
|
|
+ BeanUtils.copyProperties(reportData, report);
|
|
|
+ if (ObjectUtil.isNotEmpty(report)) {
|
|
|
+ if (StringUtils.isBlank(report.getCreateBy())) {
|
|
|
+ report.setCreateBy(UserUtils.getCurrentUserDTO().getId());
|
|
|
+ String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ report.setId(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //对新增行数据进行持久化操作
|
|
|
+ List<CwProjectInfoData> infoList = new ArrayList<>();
|
|
|
+ if (!report.getCwProjectInfoList().isEmpty()) {
|
|
|
+ infoList = report.getCwProjectInfoList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(infoList != null & !infoList.isEmpty()){
|
|
|
+ List<CwProjectInfoData> finalInfoList = infoList;
|
|
|
+ infoList.forEach(in->{
|
|
|
+ in.setCreateBy(UserUtils.getCurrentUserDTO().getId());
|
|
|
+ in.setCreateDate(new Date());
|
|
|
+ in.setUpdateBy(UserUtils.getCurrentUserDTO().getId());
|
|
|
+ in.setUpdateDate(new Date());
|
|
|
+ in.setReportId(report.getId());
|
|
|
+ //报告文号生成
|
|
|
+ String documentNo = "";
|
|
|
+ try {
|
|
|
+ documentNo = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), CwProjectInfoData.BIZ_CODE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //在插入报告文号前先去报告文号报废表中根据时间排序查看是否有报告文号,有则使用,delflag改为1
|
|
|
+ List<String> reportNo = infoMapper.getReportNo();
|
|
|
+ if (reportNo != null & !reportNo.isEmpty()){
|
|
|
+ for (int i = 0; i< finalInfoList.size(); i++){
|
|
|
+ in.setReportNo(reportNo.get(i));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ in.setReportNo(documentNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ infoMapper.insert(in);
|
|
|
+ //对上传的文件数据进行持久化操作
|
|
|
+ List<ProjectReportWorkAttachmentDTO> fileInfoList = new ArrayList<>();
|
|
|
+ if (!in.getCwFileInfoList().isEmpty()){
|
|
|
+ fileInfoList = in.getCwFileInfoList();
|
|
|
+ }
|
|
|
+ ossServiceMapper.delete(new QueryWrapper<WorkAttachment>().lambda().eq(WorkAttachment::getAttachmentId, in.getId()));
|
|
|
+ AtomicInteger j = new AtomicInteger(1);
|
|
|
+ if (fileInfoList != null){
|
|
|
+ fileInfoList.forEach(item -> {
|
|
|
+ WorkAttachment i = new WorkAttachment();
|
|
|
+ //包含了url、size、name
|
|
|
+ i.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ i.setCreateDate(new Date());
|
|
|
+ i.setUpdateDate(new Date());
|
|
|
+ i.setDelFlag(0);
|
|
|
+ i.setUrl(item.getUrl());
|
|
|
+ //文件类型处理
|
|
|
+ List<String> strings = Arrays.asList(item.getName().split("\\."));
|
|
|
+ if (CollectionUtils.isNotEmpty(strings)) {
|
|
|
+ i.setType(strings.get(1));
|
|
|
+ }
|
|
|
+ i.setAttachmentId(in.getId());
|
|
|
+ i.setAttachmentName(item.getName());
|
|
|
+ i.setAttachmentFlag("cw_project_report_file");
|
|
|
+ i.setFileSize(item.getSize());
|
|
|
+ i.setSort(j.get());
|
|
|
+ ossServiceMapper.insertWorkAttachment(i, userDTO);
|
|
|
+ j.getAndIncrement();
|
|
|
+ CwProjectReportFile cwProjectReportFile = CwProjectReportFileWrapper.INSTANCE.toEntity(item);
|
|
|
+ cwProjectReportFile.setReportFileId(i.getId());
|
|
|
+ attachmentMapper.insert(cwProjectReportFile);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.reportMapper.insert(report);
|
|
|
+ return report.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 差选项目列表信息
|
|
|
+ * @param page
|
|
|
+ * @param projectReportData
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public IPage<CwProjectReportData> findList(Page<CwProjectReportData> page, CwProjectReportData projectReportData) throws Exception{
|
|
|
+ QueryWrapper<CwProjectReportData> queryWrapper = QueryWrapperGenerator.buildQueryCondition (projectReportData,CwProjectReportData.class);
|
|
|
+ queryWrapper.eq("a.del_flag","0");
|
|
|
+ queryWrapper.orderByDesc("a.create_date");
|
|
|
+ //条件
|
|
|
+ if (StringUtils.isNotEmpty(projectReportData.getProjectNumber())) {
|
|
|
+ queryWrapper.like("b.project_number", projectReportData.getProjectNumber());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(projectReportData.getProjectName())) {
|
|
|
+ queryWrapper.like("b.project_name", projectReportData.getProjectName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(projectReportData.getProjectMasterName())) {
|
|
|
+ queryWrapper.like("e.name", projectReportData.getProjectMasterName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(projectReportData.getCreateBy().getName())) {
|
|
|
+ queryWrapper.like("e.name", projectReportData.getCreateBy().getName());
|
|
|
+ }
|
|
|
+ //4、签约时间(区间)
|
|
|
+ String[] contractDates = projectReportData.getContractDates();
|
|
|
+ if (contractDates != null) {
|
|
|
+
|
|
|
+ queryWrapper.between("a.create_date", contractDates[0], contractDates[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ IPage<CwProjectReportData> list = reportMapper.findList(page, queryWrapper);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改状态
|
|
|
+ * @param data
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String updateStatusById(CwProjectReportData data) {
|
|
|
+ CwProjectReport cwProjectRecords = new CwProjectReport();
|
|
|
+ BeanUtils.copyProperties(data, cwProjectRecords);
|
|
|
+ reportMapper.update(cwProjectRecords, new QueryWrapper<CwProjectReport>().lambda().eq(CwProjectReport::getId, cwProjectRecords.getId()));
|
|
|
+ return "操作成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ public CwProjectReportData queryById(String id) {
|
|
|
+
|
|
|
+ CwProjectReportData reportData = reportMapper.queryById(id);
|
|
|
+ //将新增行数据查询出来放入到cwProjectInfoList中
|
|
|
+ List<CwProjectInfoData> cwProjectInfoData = infoMapper.selectByReportId(id);
|
|
|
+ List<CwProjectInfoData> infoData = new ArrayList<>();
|
|
|
+ //根据新增行id查出上传的附件信息
|
|
|
+ cwProjectInfoData.forEach(info->{
|
|
|
+ //保存到work_attachment表中的信息
|
|
|
+ List<ProjectReportWorkAttachmentDTO> dtos = attachmentMapper.selectByInfoId(info.getId());
|
|
|
+ List<ProjectReportWorkAttachmentDTO> dtoList = new ArrayList<>();
|
|
|
+ dtos.forEach(d->{
|
|
|
+ //根据id查出cw_project_report_file文件表的其他信息
|
|
|
+ CwProjectReportFile file = attachmentMapper.selectInfoByFileId(d.getId());
|
|
|
+ d.setFileType(file.getFileType());
|
|
|
+ d.setSealType(file.getSealType());
|
|
|
+ d.setSealedFile(file.getSealedFile());
|
|
|
+ d.setSealUser(file.getSealUser());
|
|
|
+ d.setSealDate(file.getSealDate());
|
|
|
+ d.setRemarks(file.getRemarks());
|
|
|
+ dtoList.add(d);
|
|
|
+ });
|
|
|
+ info.setCwFileInfoList(dtoList);
|
|
|
+ infoData.add(info);
|
|
|
+ });
|
|
|
+ if (infoData != null & !infoData.isEmpty()){
|
|
|
+ reportData.setCwProjectInfoList(infoData);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return reportData;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResponseEntity deleteByIds(String ids) {
|
|
|
+ String idArray[] =ids.split(",");
|
|
|
+ //删除 cw_project_report_new_line表信息 cw_project_report_file信息 work_attachment_id表信息
|
|
|
+ //先根据ids找到cw_project_report_new_line表的id,根据id去work_attachment_id表中查出id信息删除cw_project_report_file信息
|
|
|
+ List<CwProjectInfoData> idList = infoMapper.selectIdByReportId(ids);
|
|
|
+ if (idList != null & !idList.isEmpty()){
|
|
|
+ idList.forEach(info->{
|
|
|
+ List<String> attachmentId = attachmentMapper.getIdByAttachmentId(info.getId());
|
|
|
+ //根据这个id删除cw_project_report_file信息
|
|
|
+ attachmentId.forEach(atId->{
|
|
|
+ attachmentMapper.deleteByRepotyId(atId);
|
|
|
+ });
|
|
|
+ //删除work_attachment_id信息
|
|
|
+ attachmentMapper.deleteByAttachMnentId(info.getId());
|
|
|
+ //删除cw_project_report_new_line表信息
|
|
|
+ //删除前先将report_no放入到cw_project_report_cancel报废表中
|
|
|
+ if (StringUtils.isNotEmpty(info.getReportNo())){
|
|
|
+ CwProjectReportCancel cancel = new CwProjectReportCancel();
|
|
|
+ cancel.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ cancel.setReportNo(info.getReportNo());
|
|
|
+ cancelMapper.insert(cancel);
|
|
|
+ }
|
|
|
+ infoMapper.deleteById(info.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.removeByIds (Lists.newArrayList (idArray));
|
|
|
+ return ResponseEntity.ok ("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ public IPage<CwWorkClientBaseDTO> findClineList(Page<CwWorkClientBaseDTO> page, CwWorkClientBaseDTO cwWorkClientBaseDTO,String projectId) throws Exception{
|
|
|
+ QueryWrapper<CwWorkClientBase> queryWrapper = QueryWrapperGenerator.buildQueryCondition ( CwWorkClientBaseWrapper.INSTANCE.toEntity(cwWorkClientBaseDTO), CwWorkClientBase.class );
|
|
|
+ queryWrapper.eq("cw_wcb.del_flag","0");
|
|
|
+ queryWrapper.eq("cw_pro.id",projectId);
|
|
|
+ queryWrapper.orderByDesc("cw_wcb.create_date");
|
|
|
+ if (ObjectUtil.isNotEmpty(cwWorkClientBaseDTO)) {
|
|
|
+ if (ArrayUtil.isNotEmpty(cwWorkClientBaseDTO.getCreateDates())) {
|
|
|
+ queryWrapper.between("cw_wcb.create_date", cwWorkClientBaseDTO.getCreateDates()[0], cwWorkClientBaseDTO.getCreateDates()[1]);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(cwWorkClientBaseDTO.getCwWorkClientTypeDTO())){
|
|
|
+ if (StringUtils.isNotBlank(cwWorkClientBaseDTO.getCwWorkClientTypeDTO().getOwnershipType())) {
|
|
|
+ queryWrapper.eq("cw_wct.ownership_type",cwWorkClientBaseDTO.getCwWorkClientTypeDTO().getOwnershipType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ IPage<CwWorkClientBaseDTO> list = reportMapper.findClineList(page, queryWrapper);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|