From c77cab7ca85f219df136ec2aac24a22efa7837f8 Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期五, 29 十一月 2024 02:38:46 +0800
Subject: [PATCH] 项目计划审批

---
 business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java |  155 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 145 insertions(+), 10 deletions(-)

diff --git a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java
index eeca686..05a25e8 100644
--- a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java
+++ b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java
@@ -1,21 +1,29 @@
 package com.ycl.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ycl.common.base.Result;
+import com.ycl.common.enums.business.FileTypeEnum;
+import com.ycl.common.utils.SecurityUtils;
+import com.ycl.domain.entity.File;
 import com.ycl.domain.entity.ProjectInfo;
+import com.ycl.domain.form.DocumentInfoForm;
 import com.ycl.domain.form.ProjectInfoForm;
 import com.ycl.domain.query.ProjectInfoQuery;
-import com.ycl.domain.vo.ProjectInfoVO;
+import com.ycl.domain.vo.*;
 import com.ycl.framework.utils.PageUtil;
+import com.ycl.mapper.FileMapper;
 import com.ycl.mapper.ProjectInfoMapper;
+import com.ycl.service.FileService;
 import com.ycl.service.ProjectInfoService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -29,41 +37,73 @@
 public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, ProjectInfo> implements ProjectInfoService {
 
     private final ProjectInfoMapper projectInfoMapper;
-
+    private final FileService fileService;
+    private final FileMapper fileMapper;
     /**
      * 娣诲姞
+     *
      * @param form
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result add(ProjectInfoForm form) {
+        //娣诲姞鍩烘湰淇℃伅
         ProjectInfo entity = ProjectInfoForm.getEntityByForm(form, null);
+        Long userId = SecurityUtils.getUserId();
+        entity.setCreateBy(userId);
+        entity.setUpdateBy(userId);
         baseMapper.insert(entity);
-        return Result.ok("娣诲姞鎴愬姛");
+        //娣诲姞鏂囦欢
+        List<File> fileList = form.getFileList();
+        fileList.forEach(item->{
+            item.setBusId(entity.getId());
+            item.setType(FileTypeEnum.PROJECT_INFO);
+        });
+        fileService.saveBatch(fileList);
+        return Result.ok("娣诲姞鎴愬姛").data(entity.getId());
     }
 
     /**
      * 淇敼
+     *
      * @param form
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result update(ProjectInfoForm form) {
         ProjectInfo entity = baseMapper.selectById(form.getId());
-
         // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊
         Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
-        BeanUtils.copyProperties(form, entity);
+        ProjectInfoForm.getEntityByForm(form,entity);
+        Long userId = SecurityUtils.getUserId();
+        entity.setUpdateBy(userId);
+        //鏇存柊椤圭洰淇℃伅
         baseMapper.updateById(entity);
+        List<File> fileList = form.getFileList();
+        fileList.forEach(item->{
+            item.setBusId(entity.getId());
+            item.setType(FileTypeEnum.PROJECT_INFO);
+        });
+        //鍒犻櫎鍘熸湁鏂囦欢
+        QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>();
+        fileQueryWrapper.eq("type",FileTypeEnum.PROJECT_INFO.getType());
+        fileQueryWrapper.eq("bus_id",entity.getId());
+        fileMapper.delete(fileQueryWrapper);
+        //鏇挎崲鎴愮幇鏈�
+        fileService.saveBatch(fileList);
         return Result.ok("淇敼鎴愬姛");
     }
 
     /**
      * 鎵归噺鍒犻櫎
+     *
      * @param ids
      * @return
      */
     @Override
+    //TODO:寰呭畬鍠�
     public Result remove(List<String> ids) {
         baseMapper.deleteBatchIds(ids);
         return Result.ok("鍒犻櫎鎴愬姛");
@@ -71,10 +111,12 @@
 
     /**
      * id鍒犻櫎
+     *
      * @param id
      * @return
      */
     @Override
+    //TODO:寰呭畬鍠�
     public Result removeById(String id) {
         baseMapper.deleteById(id);
         return Result.ok("鍒犻櫎鎴愬姛");
@@ -82,30 +124,47 @@
 
     /**
      * 鍒嗛〉鏌ヨ
+     *
      * @param query
      * @return
      */
     @Override
     public Result page(ProjectInfoQuery query) {
-        IPage<ProjectInfoVO> page = PageUtil.getPage(query, ProjectInfoVO.class);
+        IPage<ProjectInfo> page = PageUtil.getPage(query, ProjectInfo.class);
         baseMapper.getPage(page, query);
-        return Result.ok().data(page.getRecords()).total(page.getTotal());
+        List<ProjectInfo> records = page.getRecords();
+        List<ProjectInfoVO> list = records.stream()
+                .map(entity -> {
+                    ProjectInfoVO vo = ProjectInfoVO.getVoByEntity(entity, null);
+                    vo.setProjectColorCode("green");
+                    return vo;
+                })
+                .collect(Collectors.toList());
+        return Result.ok().data(list).total(page.getTotal());
     }
 
     /**
      * 鏍规嵁id鏌ユ壘
+     *
      * @param id
      * @return
      */
     @Override
     public Result detail(Integer id) {
-        ProjectInfoVO vo = baseMapper.getById(id);
-        Assert.notNull(vo, "璁板綍涓嶅瓨鍦�");
+        ProjectInfo entity = baseMapper.getById(id);
+        Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
+        ProjectInfoVO vo = ProjectInfoVO.getVoByEntity(entity, null);
+        QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>();
+        fileQueryWrapper.eq("type",FileTypeEnum.PROJECT_INFO.getType());
+        fileQueryWrapper.eq("bus_id",vo.getId());
+        List<File> files = fileMapper.selectList(fileQueryWrapper);
+        vo.setFileList(files);
         return Result.ok().data(vo);
     }
 
     /**
      * 鍒楄〃
+     *
      * @return
      */
     @Override
@@ -116,4 +175,80 @@
                 .collect(Collectors.toList());
         return Result.ok().data(vos);
     }
+
+    @Override
+    public IndexCountVO getIndexCount(IndexDTO indexDTO) {
+        // {"proPhaseCountVO":[{"type":"鍌ㄥ瑙勫垝闃舵","count":0,"amount":"0.00","text":"鍌�"},
+        // {"type":"椤圭洰鍓嶆湡闃舵","count":0,"amount":"0.00","text":"鏂�"},
+        // {"type":"瀹炴柦闃舵","count":0,"amount":"0.00","text":"寤�"},{"type":"绔e伐鎶曠敤闃舵","count":0,"amount":"0.00","text":"绔�"}],
+        // "impTypeCountVO":[{"type":"涓�鑸」鐩�","count":0,"amount":"0.00","text":"鏅�"},
+        // {"type":"鍘块噸鐐归」鐩�","count":0,"amount":"0.00","text":"鍘�"},{"type":"甯傞噸鐐归」鐩�","count":0,"amount":"0.00","text":"甯�"},
+        // {"type":"鐪侀噸鐐归」鐩�","count":0,"amount":"0.00","text":"鐪�"}]}}
+        IndexCountVO indexCountVO = new IndexCountVO();
+        List<IndexProPhaseCountVO> proPhaseCountVO = new ArrayList<>();
+        proPhaseCountVO.add(new IndexProPhaseCountVO("鍌ㄥ瑙勫垝闃舵", 0, "0.00", "鍌�"));
+        proPhaseCountVO.add(new IndexProPhaseCountVO("椤圭洰鍓嶆湡闃舵", 0, "0.00", "鏂�"));
+        proPhaseCountVO.add(new IndexProPhaseCountVO("瀹炴柦闃舵", 0, "0.00", "寤�"));
+        proPhaseCountVO.add(new IndexProPhaseCountVO("绔e伐鎶曠敤闃舵", 0, "0.00", "绔�"));
+        List<IndexImpTypeCountVO> impTypeCountVO = new ArrayList<>();
+        impTypeCountVO.add(new IndexImpTypeCountVO("涓�鑸」鐩�", 0, "0.00", "鏅�"));
+        impTypeCountVO.add(new IndexImpTypeCountVO("鍘块噸鐐归」鐩�", 0, "0.00", "鍘�"));
+        impTypeCountVO.add(new IndexImpTypeCountVO("甯傞噸鐐归」鐩�", 0, "0.00", "甯�"));
+        impTypeCountVO.add(new IndexImpTypeCountVO("鐪侀噸鐐归」鐩�", 0, "0.00", "鐪�"));
+        indexCountVO.setImpTypeCountVO(impTypeCountVO);
+        indexCountVO.setProPhaseCountVO(proPhaseCountVO);
+
+
+        return indexCountVO;
+    }
+
+    @Override
+    public Map<String, Integer> countExceptionProject(IndexDTO indexDTO) {
+        Map<String, Integer> map = new HashMap<>();
+        map.put("processExceptionProject", 0);
+        return map;
+    }
+
+    @Override
+    public Result docDetail(Integer id) {
+        DocumentInfoForm documentInfoForm = new DocumentInfoForm();
+        QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>();
+        fileQueryWrapper.eq("type",FileTypeEnum.DOCUMENT_INFO.getType());
+        fileQueryWrapper.eq("bus_id",id);
+        List<File> files = fileMapper.selectList(fileQueryWrapper);
+        documentInfoForm.setFileList(files);
+        return Result.ok().data(documentInfoForm);
+    }
+
+    @Override
+    public Result addDoc(DocumentInfoForm form) {
+        List<File> fileList = form.getFileList();
+        fileList.forEach(item->{
+            item.setBusId(form.getProjectId());
+            item.setType(FileTypeEnum.DOCUMENT_INFO);
+        });
+        //鍒犻櫎鍘熸湁鏂囦欢
+        QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>();
+        fileQueryWrapper.eq("type",FileTypeEnum.DOCUMENT_INFO.getType());
+        fileQueryWrapper.eq("bus_id",form.getProjectId());
+        fileMapper.delete(fileQueryWrapper);
+        //鏇挎崲鎴愮幇鏈�
+        fileService.saveBatch(fileList);
+        return Result.ok();
+    }
+
+    @Override
+    public Result getManagerFlag(Integer recordId) {
+        ProjectInfo projectInfo = baseMapper.selectById(recordId);
+        // 鍒ゆ柇褰撳墠鐢ㄦ埛id鏄惁鍦ㄤ富绠″垪琛ㄤ腑
+        String competentDepartment = projectInfo.getCompetentDepartment();
+        List<String> list = Arrays.asList(competentDepartment.split(","));
+        // 鑾峰緱褰撳墠鐢ㄦ埛id
+        Long userId = SecurityUtils.getUserId();
+        if (list.contains(userId.toString())) {
+            return Result.ok().data(true);
+        } else {
+            return Result.ok().data(false);
+        }
+    }
 }

--
Gitblit v1.8.0