From 10b796c793c2e619e1ff185da58232739ef34520 Mon Sep 17 00:00:00 2001 From: zhn <947514737@qq.com> Date: Wed, 13 Sep 2023 13:47:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E4=BB=B6-=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ectCertificationInventoryEOController.java | 376 + ...ProjectCertificationInventoryEOMapper.java | 14 + ...mProjectCertificationInventoryEOMapper.xml | 31 + ...rojectCertificationInventoryEOService.java | 341 + ...ctCertificationInventoryEOServiceImpl.java | 6847 +++++++++++++++++ 5 files changed, 7609 insertions(+) create mode 100644 jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/controller/PlatformProjectCertificationInventoryEOController.java create mode 100644 jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/PlatformProjectCertificationInventoryEOMapper.java create mode 100644 jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/xml/PlatformProjectCertificationInventoryEOMapper.xml create mode 100644 jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/IPlatformProjectCertificationInventoryEOService.java create mode 100644 jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/impl/PlatformProjectCertificationInventoryEOServiceImpl.java diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/controller/PlatformProjectCertificationInventoryEOController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/controller/PlatformProjectCertificationInventoryEOController.java new file mode 100644 index 000000000..153f33036 --- /dev/null +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/controller/PlatformProjectCertificationInventoryEOController.java @@ -0,0 +1,376 @@ +package com.jero.modules.projectPlatform.controller; + +import com.alibaba.fastjson.JSONObject; +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.jero.common.api.vo.Result; +import com.jero.common.aspect.annotation.AutoLog; +import com.jero.common.system.base.controller.JeroController; +import com.jero.common.system.query.QueryGenerator; +import com.jero.modules.project.entity.ProjectCertificationInventoryEO; +import com.jero.modules.projectPlatform.service.IPlatformProjectCertificationInventoryEOService; +import com.jero.modules.system.entity.SysRole; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + + +/** +* @Description: 项目库-认证清单表 +* @Author: jero-boot +* @Date: 2023-03-03 +* @Version: V1.0 +*/ +@Api(tags="平台件项目库-认证清单表") +@RestController +@RequestMapping("/project/platformProjectCertificationInventoryEO") +@Slf4j +public class PlatformProjectCertificationInventoryEOController extends JeroController { + @Autowired + private IPlatformProjectCertificationInventoryEOService platformProjectCertificationInventoryEOService; + + /** + * 分页列表查询 + * + * @param projectCertificationInventoryEO + * @param pageNo + * @param pageSize + * @param req + * @return + */ + @AutoLog(value = "项目库-认证清单表-分页列表查询") + @ApiOperation(value="项目库-认证清单表-分页列表查询", notes="项目库-认证清单表-分页列表查询") + @GetMapping(value = "/page") + public Result queryPageList(ProjectCertificationInventoryEO projectCertificationInventoryEO, + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, + @RequestParam(name="cut", defaultValue="cn") String cut, + HttpServletRequest req) { + String flowStatusStr = ""; + if (StringUtils.isNotEmpty(projectCertificationInventoryEO.getFlowStatus())) { + flowStatusStr = projectCertificationInventoryEO.getFlowStatus(); + projectCertificationInventoryEO.setFlowStatus(null); + } + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(projectCertificationInventoryEO, req.getParameterMap()); + if (StringUtils.isNotEmpty(flowStatusStr)) { + String finalflowStatusStr = flowStatusStr.replaceAll("\\*",""); + queryWrapper.and(query -> { + query.lambda().like(ProjectCertificationInventoryEO::getFlowStatus, finalflowStatusStr); + if(StringUtils.contains(finalflowStatusStr,",")){ + String[] flowStatusArr = finalflowStatusStr.split(","); + for (String fs : flowStatusArr) { + query.or(q -> { + q.like("flow_status",fs); + }); + } + } + }); + } + queryWrapper.orderByDesc("create_time"); + Page page = new Page(pageNo, pageSize); + IPage pageList = this.platformProjectCertificationInventoryEOService.queryPage(queryWrapper,page,projectCertificationInventoryEO,cut); + return Result.OK(cut,pageList); + } + + /** + * 列表查询 + * + * @return + */ + @AutoLog(value = "项目库-认证清单表-列表查询") + @ApiOperation(value="项目库-认证清单表-列表查询", notes="项目库-认证清单表-列表查询") + @GetMapping(value = "/list") + public Result> queryList() { + List list = platformProjectCertificationInventoryEOService.queryList(); + return Result.OK(list); + } + + /** + * 添加 + * + * @param projectCertificationInventoryEO + * @return + */ + @AutoLog(value = "项目库-认证清单表-添加") + @ApiOperation(value="项目库-认证清单表-添加", notes="项目库-认证清单表-添加") + @PostMapping(value = "/add") + public Result add(@Validated @RequestBody ProjectCertificationInventoryEO projectCertificationInventoryEO) { + platformProjectCertificationInventoryEOService.add(projectCertificationInventoryEO); + return Result.OK("添加成功!"); + } + + /** + * 编辑 + * + * @param projectCertificationInventoryEO + * @return + */ + @AutoLog(value = "项目库-认证清单表-编辑") + @ApiOperation(value="项目库-认证清单表-编辑", notes="项目库-认证清单表-编辑") + @PutMapping(value = "/edit") + public Result edit(@Validated @RequestBody ProjectCertificationInventoryEO projectCertificationInventoryEO) { + platformProjectCertificationInventoryEOService.editById(projectCertificationInventoryEO); + return Result.OK("编辑成功!"); + } + + /** + * 通过id删除 + * + * @param id + * @return + */ + @AutoLog(value = "项目库-认证清单表-通过id删除") + @ApiOperation(value="项目库-认证清单表-通过id删除", notes="项目库-认证清单表-通过id删除") + @DeleteMapping(value = "/delete") + public Result delete(@RequestParam(name="id",required=true) String id) { + platformProjectCertificationInventoryEOService.deleteById(id); + return Result.OK("删除成功!"); + } + + /** + * 批量删除 + * + * @param ids + * @return + */ + @AutoLog(value = "项目库-认证清单表-批量删除") + @ApiOperation(value="项目库-认证清单表-批量删除", notes="项目库-认证清单表-批量删除") + @DeleteMapping(value = "/deleteBatch") + public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) { + this.platformProjectCertificationInventoryEOService.deleteByIds(Arrays.asList(ids.split(","))); + return Result.OK("批量删除成功!"); + } + + /** + * 通过id查询 + * + * @param id + * @return + */ + @AutoLog(value = "项目库-认证清单表-通过id查询") + @ApiOperation(value="项目库-认证清单表-通过id查询", notes="项目库-认证清单表-通过id查询") + @GetMapping(value = "/queryById") + public Result queryById(@RequestParam(name="id",required=true) String id) { + ProjectCertificationInventoryEO projectCertificationInventoryEO = platformProjectCertificationInventoryEOService.queryById(id); + if(projectCertificationInventoryEO==null) { + return Result.error("未找到对应数据"); + } + return Result.OK(projectCertificationInventoryEO); + } + + /** + * 导出excel + * + * @param request + * @param projectCertificationInventoryEO + */ + @RequestMapping(value = "/exportXls") + public ModelAndView exportXls(HttpServletRequest request, ProjectCertificationInventoryEO projectCertificationInventoryEO) { + return super.exportXls(request, projectCertificationInventoryEO, ProjectCertificationInventoryEO.class, "项目库-认证清单表"); + } + + /** + * 通过excel导入数据 + * + * @param request + * @param response + * @return + */ + @RequestMapping(value = "/importExcel", method = RequestMethod.POST) + public Result importExcel(HttpServletRequest request, HttpServletResponse response) { + return super.importExcel(request, response, ProjectCertificationInventoryEO.class); + } + + @AutoLog(value = "项目库-认证清单表-批量添加") + @ApiOperation(value="项目库-认证清单表-批量添加", notes="项目库-认证清单表-批量添加") + @PostMapping(value = "/batchAdd") + public Result batchAdd(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.batchAdd(json); + } + + @AutoLog(value = "项目库-认证清单表-批量设置") + @ApiOperation(value="项目库-认证清单表-批量设置", notes="项目库-认证清单表-批量设置") + @PostMapping(value = "/setBatch") + public Result setBatch(@RequestBody ProjectCertificationInventoryEO projectCertificationInventoryEO) { + return this.platformProjectCertificationInventoryEOService.setBatch(projectCertificationInventoryEO); + } + + @AutoLog(value = "项目库-认证清单表-studio发布") + @ApiOperation(value="项目库-认证清单表-studio发布", notes="项目库-认证清单表-studio发布") + @PostMapping(value = "/issue") + public Result issue(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.issue(json); + } + + @AutoLog(value = "项目库-认证清单表-当前登录用户角色") + @ApiOperation(value="项目库-认证清单表-当前登录用户角色", notes="项目库-认证清单表-当前登录用户角色") + @GetMapping(value = "/getRoleByUserId") + public Result> getRoleByUserId(@RequestParam Map params) { + return this.platformProjectCertificationInventoryEOService.getRoleByUserId(params); + } + + @AutoLog(value = "项目库-认证清单表-获取流程状态列表") + @ApiOperation(value="项目库-认证清单表-获取流程状态列表", notes="项目库-认证清单表-获取流程状态列表") + @GetMapping(value = "/getFlowStatusList") + public Result getFlowStatusList(@RequestParam("cut") String cut) { + return this.platformProjectCertificationInventoryEOService.getFlowStatusList(cut); + } + + @AutoLog(value = "项目库-认证清单表-认证流程统一提交任务接口") + @ApiOperation(value="项目库-认证清单表-认证流程统一提交任务接口", notes="项目库-认证清单表-认证流程统一提交任务接口") + @PostMapping(value = "/submitTask") + public Result submitTask(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.submitTask(json); + } + + @AutoLog(value = "项目库-认证清单表-批量保存") + @ApiOperation(value="项目库-认证清单表-批量保存", notes="项目库-认证清单表-批量保存") + @PostMapping(value = "/saveBatch") + public Result saveBatch(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.saveBatch(json); + } + + @AutoLog(value = "项目库-认证清单表-流程重置") + @ApiOperation(value="项目库-认证清单表-流程重置", notes="项目库-认证清单表-流程重置") + @PostMapping(value = "/resetFlow") + public Result resetFlow(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.resetFlow(json); + } + + @AutoLog(value = "项目库-认证清单表-转办") + @ApiOperation(value="项目库-认证清单表-转办", notes="项目库-认证清单表-转办") + @PostMapping(value = "/transferTask") + public Result transferTask(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.transferTask(json); + } + + @AutoLog(value = "项目库-认证清单表-催办") + @ApiOperation(value="项目库-认证清单表-催办", notes="项目库-认证清单表-催办") + @PostMapping(value = "/expediting") + public Result expediting(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.expediting(json); + } + + @AutoLog(value = "项目库-认证清单表-批量修改配置项") + @ApiOperation(value="项目库-认证清单表-批量修改配置项", notes="项目库-认证清单表-批量修改配置项") + @PostMapping(value = "/updateConfigItemBatch") + public Result updateConfigItemBatch(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.updateConfigItemBatch(json); + } + + @ApiOperation(value="项目库-认证清单表-模板下载", notes="项目库-认证清单表-模板下载") + @GetMapping(value = "/exportTemplate") + public void exportTemplate(ProjectCertificationInventoryEO projectCertificationInventoryEO, HttpServletResponse response, HttpServletRequest request) throws Exception { + platformProjectCertificationInventoryEOService.exportTemplate(projectCertificationInventoryEO,response,request); + } + + /** + * 导入数据 + * + * @param file + * @param projectCertificationInventoryEO + * @return + */ + @ApiOperation(value="项目库-认证清单表-导入数据", notes="项目库-认证清单表-导入数据") + @RequestMapping(value = "/importData", method = RequestMethod.POST) + public Result importData(@RequestParam(value = "file", required = false) MultipartFile file, + ProjectCertificationInventoryEO projectCertificationInventoryEO) { + platformProjectCertificationInventoryEOService.importData(file,projectCertificationInventoryEO); + return Result.OK("导入成功"); + } + /** + * 导出数据 + * @param request + * @param projectCertificationInventoryEO + */ + @ApiOperation(value="项目库-认证清单表-导出数据", notes="项目库-认证清单表-导出数据") + @RequestMapping(value = "/exportData",method = RequestMethod.GET) +// @RequiresPermissions("projectLawsInventory:exportData") + public void exportData(HttpServletResponse response, + HttpServletRequest request, + ProjectCertificationInventoryEO projectCertificationInventoryEO) { + platformProjectCertificationInventoryEOService.exportData(response,request, projectCertificationInventoryEO); + } + + @AutoLog(value = "项目库-认证清单表-调取添加") + @ApiOperation(value="项目库-认证清单表-调取添加", notes="项目库-认证清单表-调取添加") + @PostMapping(value = "/callAdd") + public Result callAdd(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.callAdd(json); + } + + @AutoLog(value = "项目库-认证清单表-引用交付物") + @ApiOperation(value="项目库-认证清单表-引用交付物", notes="项目库-认证清单表-引用交付物") + @PostMapping(value = "/citeDeliverable") + public Result citeDeliverable(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.citeDeliverable(json); + } + + /** + * 批量更新法规清单状态 + * @param json + * @return + */ + @AutoLog(value = "项目库-认证清单表-批量更新流程状态") + @ApiOperation(value="项目库-认证清单表-批量更新流程状态", notes="项目库-认证清单表-批量更新流程状态") + @PostMapping(value = "/updateStatusBatch") + public Result updateStatusBatch(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.updateStatusBatch(json); + } + + /** + * 添加配置 等同于 复制 + * @param json + * @return + */ + @AutoLog(value = "项目库-认证清单表-添加配置") + @ApiOperation(value="项目库-认证清单表-添加配置", notes="项目库-认证清单表-添加配置") + @PostMapping(value = "/addConfigByIds") + public Result addConfigByIds(@RequestBody JSONObject json) { + return this.platformProjectCertificationInventoryEOService.addConfigByIds(json); + } + + /** + * 获取责任人和接口人 + * @return + */ + @AutoLog(value = "项目库-认证清单表-获取责任人和接口人") + @ApiOperation(value="项目库-认证清单表-获取责任人和接口人", notes="项目库-认证清单表-获取责任人和接口人") + @GetMapping(value = "/queryDutyPersonByProjectId") + public Result queryDutyPersonByProjectId(@RequestParam Map params) { + return Result.OK(this.platformProjectCertificationInventoryEOService.queryDutyPersonByProjectId(params)); + } + + /** + * 匹配相关人员 + * @param params + * @return + */ + @AutoLog(value = "项目库-认证清单表-匹配相关人员") + @ApiOperation(value="项目库-认证清单表-匹配相关人员", notes="项目库-法规清单表-匹配相关人员") + @PostMapping(value = "/matchRelevantPeople") + public Result matchRelevantPeople(@RequestBody Map params){ + return this.platformProjectCertificationInventoryEOService.matchRelevantPeople(params); + } +} diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/PlatformProjectCertificationInventoryEOMapper.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/PlatformProjectCertificationInventoryEOMapper.java new file mode 100644 index 000000000..ccf496fab --- /dev/null +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/PlatformProjectCertificationInventoryEOMapper.java @@ -0,0 +1,14 @@ +package com.jero.modules.projectPlatform.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.jero.modules.project.entity.ProjectCertificationInventoryEO; + +/** + * @Description: 项目库-认证清单表 + * @Author: jero-boot + * @Date: 2023-03-03 + * @Version: V1.0 + */ +public interface PlatformProjectCertificationInventoryEOMapper extends BaseMapper { + +} diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/xml/PlatformProjectCertificationInventoryEOMapper.xml b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/xml/PlatformProjectCertificationInventoryEOMapper.xml new file mode 100644 index 000000000..2a72281e0 --- /dev/null +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/mapper/xml/PlatformProjectCertificationInventoryEOMapper.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/IPlatformProjectCertificationInventoryEOService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/IPlatformProjectCertificationInventoryEOService.java new file mode 100644 index 000000000..fb9be3985 --- /dev/null +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/IPlatformProjectCertificationInventoryEOService.java @@ -0,0 +1,341 @@ +package com.jero.modules.projectPlatform.service; + +import com.alibaba.fastjson.JSONObject; +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.IService; +import com.jero.common.api.vo.Result; +import com.jero.modules.project.entity.ProjectCertificationInventoryEO; +import com.jero.modules.system.entity.SysCategory; +import com.jero.modules.system.entity.SysDictItem; +import com.jero.modules.system.entity.SysRole; +import com.jero.modules.system.entity.SysUser; +import com.jero.modules.todoCenter.entity.ProcessInfoDetailEO; +import com.jero.modules.todoCenter.entity.ProcessInfoEO; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @Description: 项目库-认证清单表 + * @Author: jero-boot + * @Date: 2023-03-03 + * @Version: V1.0 + */ +public interface IPlatformProjectCertificationInventoryEOService extends IService { + + /** + * 保存 + * + * @param projectCertificationInventoryEO + * @return + */ + void add(ProjectCertificationInventoryEO projectCertificationInventoryEO); + + /** + * 更新 + * + * @param projectCertificationInventoryEO + * @return + */ + void editById(ProjectCertificationInventoryEO projectCertificationInventoryEO); + + /** + * 通过id删除 + * + * @param id + * @return + */ + void deleteById(String id); + + /** + * 批量删除 + * + * @param ids + * @return + */ + void deleteByIds(List ids); + + /** + * 通过id查询 + * + * @param id + * @return + */ + ProjectCertificationInventoryEO queryById(String id); + + /** + * 列表查询 + * + * @return + */ + List queryList(); + + /** + * 批量添加 + * @param json + * @return + */ + Result batchAdd(JSONObject json); + + /** + * 批量设置 + * @param projectCertificationInventoryEO + * @return + */ + Result setBatch(ProjectCertificationInventoryEO projectCertificationInventoryEO); + + /** + * 处理数据 + * @param datas + * @param cut + */ + void disposeData(List datas, String cut); + + /** + * 导入时的数据处理 + * @param datas + * @param cut + */ + void importDisposeData(List datas, String cut); + + String getTreeNameImport(String cut, List categoryList, List technologyTerritoryList); + + String getTreeName(String cut, List categoryList, List technologyTerritoryList); + + /** + * studio发布 + * @param json + * @return + */ + Result issue(JSONObject json); + + void addProcessInfoEO(ProcessInfoEO processInfoEO, String projectLibraryId); + + void addProcessInfoDetailEO(List processInfoDetailEOList, String processInfoId, String taskDefinitionKey); + + Result> getRoleByUserId(Map params); + + Result getFlowStatusList(String cut); + + IPage queryPage(QueryWrapper queryWrapper, + Page page, + ProjectCertificationInventoryEO projectCertificationInventoryEO, + String cut); + + void createQueryPermission(QueryWrapper queryWrapper, String roleCode); + + /** + * 认证流程统一提交任务 + * @param json + * @return + */ + Result submitTask(JSONObject json); + + /** + * 认证工程师发起任务 + * @param json + * @return + */ + Result certificationInitiatingTask(JSONObject json); + + /** + * 批量保存 + * @param json + * @return + */ + Result saveBatch(JSONObject json); + + /** + * 流程重置 + * @param json + * @return + */ + Result resetFlow(JSONObject json); + + /** + * 转办任务 + * @param json + * @return + */ + Result transferTask(JSONObject json); + + /** + * 催办任务 + * @param json + * @return + */ + Result expediting(JSONObject json); + + Map getCertificationInventoryLinkHrefFeishu(String projectLibraryId,String PRN_CN,String PRN_EN); + + Map getStandNameAndItemName(List projectCertificationInventoryEOList); + + /** + * 模板下载 + * @param projectCertificationInventoryEO + * @param response + * @param request + */ + void exportTemplate(ProjectCertificationInventoryEO projectCertificationInventoryEO, HttpServletResponse response, HttpServletRequest request); + + /** + * 批量修改配置项 + * @param json + * @return + */ + Result updateConfigItemBatch(JSONObject json); + + /** + * 调取添加 + * @param json + * @return + */ + Result callAdd(JSONObject json); + + /** + * 导入数据 + * @param file + * @param projectCertificationInventoryEO + */ + void importData(MultipartFile file, ProjectCertificationInventoryEO projectCertificationInventoryEO); + + /** + * projectCertificationInventoryEO + * @param response + * @param request + * @param projectCertificationInventoryEO + */ + void exportData(HttpServletResponse response, HttpServletRequest request, ProjectCertificationInventoryEO projectCertificationInventoryEO); + + /** + * 引用交付物 + * @param json + * @return + */ + Result citeDeliverable(JSONObject json); + + /** + * 根据模板返送消息 + * @param projectCertificationInventoryEOS + * @param templeteId + * @param userIdList + * @param userInfoList + */ + void sendMessageByTemplateId(List projectCertificationInventoryEOS, String templeteId, List userIdList, List userInfoList, Date endTimeString, String taskDefinitionKey); + + /** + * 数据唯一校验。 + * @param projectCertificationInventoryEOList + * @param cut + * @return + */ + List dataUniqueCheck(List projectCertificationInventoryEOList, String cut,List result,String projectLibraryId); + + /** + * + * @param json + * @return + */ + Result updateStatusBatch(JSONObject json); + + /** + * 添加配置 + * @param json + * @return + */ + Result addConfigByIds(JSONObject json); + String handlePhoneLink(String id, String prn_cn, String key); + void certificationInventoryEOListSortByEndTimeAsc(List projectCertificationInventoryEOList); + void certificationInventoryEOListSortByInventoryVerifyEndTimeAsc(List projectCertificationInventoryEOList); + void certificationInventoryEOListSortByTaskConfirmEndTimeAsc(List projectCertificationInventoryEOList); + Map>> queryDutyPersonByProjectId(Map params); + + /** + * 获取任务确认统计信息 + * @param pciEoList + * @return + */ + List> getTaskToConfirmStatistics(List pciEoList); + + /** + * 获取Pre-Homo统计信息 + * @param pciEoList + * @return + */ + List> getPrehomoStatistice(List pciEoList); + + /** + * 获取认证进度统计信息 全部 + * @param pciEoList + * @return + */ + List> getAllCertificationProgressStatistics(List pciEoList); + + /** + * 获取认证进度统计信息 整车 + * @param pciEoList + * @return + */ + List> getCarCertificationProgressStatistics(List pciEoList); + + /** + * 获取认证进度统计信息 零部件 + * @param pciEoList + * @return + */ + List> getPartCertificationProgressStatistics(List pciEoList); + + /** + * 按照认证任务确认状态分组 + * @param pciEos + * @return + */ + Map groupByFGRwqrStatus(List pciEos); + + /** + * 按照preHomo确认状态分组 + * @param pciEos + * @return + */ + Map groupByPreHomoStatus(List pciEos); + + /** + * 根据认证进度分组 + * @param pciEos + * @return + */ + Map groupByCertificationProgress(List pciEos); + + /** + * 同步待办中心明细数据-认证清单 截止日期 + * @param endTime + * @param editEndTimeCertificationInventoryEOS + */ + void syncProcessInfoDetailEndTime(Date endTime, List editEndTimeCertificationInventoryEOS); + + /** + * 获取用户的责任领域数组 + * @param params + * @return + */ + List getUserDutyTerritoryList(Map params); + + /** + * 替换用户 + * @param json + */ + void replacementUser(JSONObject json); + + /** + * 匹配相关人员 + * @param params + * @return + */ + Result matchRelevantPeople(Map params); +} diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/impl/PlatformProjectCertificationInventoryEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/impl/PlatformProjectCertificationInventoryEOServiceImpl.java new file mode 100644 index 000000000..5341e45f3 --- /dev/null +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/projectPlatform/service/impl/PlatformProjectCertificationInventoryEOServiceImpl.java @@ -0,0 +1,6847 @@ +package com.jero.modules.projectPlatform.service.impl; + +import cn.hutool.core.util.URLUtil; +import cn.hutool.core.util.ZipUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.utils.IOUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +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.jero.common.api.vo.Result; +import com.jero.common.constant.enums.CutEnum; +import com.jero.common.exception.JeroBootException; +import com.jero.common.system.query.QueryGenerator; +import com.jero.common.system.vo.LoginUser; +import com.jero.common.util.DateUtils; +import com.jero.common.util.oss.CosBootUtil; +import com.jero.modules.authDummy.entity.AuthDummyInventoryInfoEO; +import com.jero.modules.authDummy.service.IAuthDummyInventoryBaseEOService; +import com.jero.modules.authDummy.service.IAuthDummyInventoryInfoEOService; +import com.jero.modules.document.entity.BussDocumentLibraryEO; +import com.jero.modules.document.mapper.BussDocumentLibraryEOMapper; +import com.jero.modules.document.service.IBussDocumentLibraryEOService; +import com.jero.modules.dummy.enums.OrderEnum; +import com.jero.modules.enums.DictCodeEnum; +import com.jero.modules.feishu.enums.TemplateInfoEnum2; +import com.jero.modules.feishu.service.IFeishuService; +import com.jero.modules.oss.entity.OSSFile; +import com.jero.modules.oss.service.IOSSFileService; +import com.jero.modules.project.entity.ProjectCertificationInventoryDutyEnginnerEO; +import com.jero.modules.project.entity.ProjectCertificationInventoryDutyEnginnerEOEn; +import com.jero.modules.project.entity.ProjectCertificationInventoryEO; +import com.jero.modules.project.entity.ProjectCertificationInventoryEOEn; +import com.jero.modules.project.entity.ProjectCertificationInventoryLogEO; +import com.jero.modules.project.entity.ProjectLawsInventoryEO; +import com.jero.modules.project.entity.ProjectLibraryBase; +import com.jero.modules.project.entity.ProjectLibraryRoleRelEO; +import com.jero.modules.project.entity.ProjectRelatedPersonnel; +import com.jero.modules.project.entity.ProjectUserPermission; +import com.jero.modules.project.enums.CertificationFlowNodeEnum; +import com.jero.modules.project.enums.CertificationInventoryFlowStatusEnum; +import com.jero.modules.project.enums.CertificationProgressEnum; +import com.jero.modules.project.enums.JumpLinkEnum; +import com.jero.modules.project.enums.OperatorTypeEnum; +import com.jero.modules.project.enums.PermissionDescriptionEnum; +import com.jero.modules.project.enums.ProjectInventoryFieldEnum; +import com.jero.modules.project.enums.ProjectMessageEnum; +import com.jero.modules.project.enums.ProjectUserLocationEnum; +import com.jero.modules.project.enums.ReviewResultEnum; +import com.jero.modules.project.enums.RoleRelModelTypeEnum; +import com.jero.modules.project.enums.TaskAffirmStatusEnum; +import com.jero.modules.project.enums.TaskStatusEnum; +import com.jero.modules.project.mapper.ProjectLibraryBaseMapper; +import com.jero.modules.project.mapper.ProjectRelatedPersonnelMapper; +import com.jero.modules.project.service.IProjectCertificationInventoryLogEOService; +import com.jero.modules.project.service.IProjectLibraryBaseService; +import com.jero.modules.project.service.IProjectLibraryRoleRelEOService; +import com.jero.modules.project.service.IProjectRelatedPersonnelService; +import com.jero.modules.project.service.IProjectUserPermissionService; +import com.jero.modules.projectPlatform.mapper.PlatformProjectCertificationInventoryEOMapper; +import com.jero.modules.projectPlatform.service.IPlatformProjectCertificationInventoryEOService; +import com.jero.modules.projectPlatform.service.IPlatformProjectLawsInventoryEOService; +import com.jero.modules.split.common.FileUnZip; +import com.jero.modules.system.entity.SysCategory; +import com.jero.modules.system.entity.SysDictItem; +import com.jero.modules.system.entity.SysRole; +import com.jero.modules.system.entity.SysUser; +import com.jero.modules.system.enums.ProjectRoleEnum; +import com.jero.modules.system.enums.SysCategoryValueTypeEnum; +import com.jero.modules.system.mapper.SysCategoryMapper; +import com.jero.modules.system.mapper.SysRoleMapper; +import com.jero.modules.system.mapper.SysUserMapper; +import com.jero.modules.system.service.IProjectUserDutyTerritoryService; +import com.jero.modules.system.service.ISysCategoryService; +import com.jero.modules.system.service.ISysDictItemService; +import com.jero.modules.system.service.ISysUserService; +import com.jero.modules.system.service.impl.SysDictItemServiceImpl; +import com.jero.modules.todoCenter.entity.ProcessInfoDetailEO; +import com.jero.modules.todoCenter.entity.ProcessInfoEO; +import com.jero.modules.todoCenter.service.IProcessInfoDetailEOService; +import com.jero.modules.todoCenter.service.IProcessInfoEOService; +import com.jero.modules.wkflow.enums.FlowTypeEnum; +import com.jero.modules.wkflow.service.IProcessHistoryEOService; +import lombok.SneakyThrows; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.hssf.usermodel.HSSFRichTextString; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.shiro.SecurityUtils; +import org.aspectj.util.FileUtil; +import org.jeecgframework.poi.excel.ExcelExportUtil; +import org.jeecgframework.poi.excel.entity.ExportParams; +import org.jeecgframework.poi.excel.entity.enmus.ExcelType; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.Collator; +import java.text.DateFormat; +import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +import static com.jero.modules.document.service.impl.BussDocumentLibraryEOServiceImpl.copyFile; + +/** + * @Description: 项目库-认证清单表 + * @Author: jero-boot + * @Date: 2023-03-03 + * @Version: V1.0 + */ +@Service +@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class) +public class PlatformProjectCertificationInventoryEOServiceImpl extends ServiceImpl implements IPlatformProjectCertificationInventoryEOService { + + private static DecimalFormat df = new DecimalFormat("#.00"); + private static String percentSign = "%"; + + @Autowired + private ISysUserService sysUserService; + @Autowired + private ISysCategoryService sysCategoryService; + @Autowired + private ISysDictItemService sysDictItemService; + @Autowired + private SysDictItemServiceImpl sysDictItemServiceImpl; + @Autowired + private IProjectLibraryBaseService projectLibraryBaseService; + @Autowired + private IProcessInfoEOService processInfoEOService; + @Autowired + private IProcessInfoDetailEOService processInfoDetailEOService; + @Autowired + private IProjectRelatedPersonnelService projectRelatedPersonnelService; + @Autowired + private ProjectRelatedPersonnelMapper projectRelatedPersonnelMapper; + @Autowired + private SysRoleMapper sysRoleMapper; + @Autowired + private IFeishuService feishuService; + @Autowired + private IAuthDummyInventoryBaseEOService authDummyInventoryBaseEOService; + @Autowired + private IAuthDummyInventoryInfoEOService authDummyInventoryInfoEOService; + @Autowired + private IProjectCertificationInventoryLogEOService projectCertificationInventoryLogEOService; + @Autowired + private IPlatformProjectCertificationInventoryEOService platformProjectCertificationInventoryEOService; + @Autowired + private IProjectUserDutyTerritoryService projectUserDutyTerritoryService; + + @Autowired + private BussDocumentLibraryEOMapper bussDocumentLibraryEOMapper; + @Autowired + private IProjectUserPermissionService projectUserPermissionService; + @Autowired + private IPlatformProjectLawsInventoryEOService platformProjectLawsInventoryEOService; + + @Autowired + private ProjectLibraryBaseMapper projectLibraryBaseMapper; + + + @Value(value = "${jero.backUrl}") + private String backUrl; + @Value(value = "${jero.backUrlPhone}") + private String backUrlPhone; + + @Value(value = "${jero.path.upload}") + private String uploadpath; + @Autowired + private IOSSFileService ossFileService; + + @Autowired + SysCategoryMapper sysCategoryMapper; + @Autowired + private IBussDocumentLibraryEOService iBussDocumentLibraryEOService; + @Autowired + private IProjectRelatedPersonnelService iProjectRelatedPersonnelService; + @Autowired + private IOSSFileService iOSSFileService; + @Autowired + private SysUserMapper sysUserMapper; + @Autowired + private IProjectLibraryRoleRelEOService projectLibraryRoleRelEOService; + @Autowired + private IProcessHistoryEOService processHistoryEOService; + + /** + * 保存 + * + * @param projectCertificationInventoryEO + * @return + */ + @Override + public void add(ProjectCertificationInventoryEO projectCertificationInventoryEO) { + Date now = new Date(); + projectCertificationInventoryEO.setCreateTime(now); + projectCertificationInventoryEO.setUpdateTime(now); + save(projectCertificationInventoryEO); + } + + /** + * 更新 + * + * @param projectCertificationInventoryEO + * @return + */ + @Override + public void editById(ProjectCertificationInventoryEO projectCertificationInventoryEO) { + //获取当前用户 + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + QueryWrapper certificationQueryWrap = new QueryWrapper<>(); + certificationQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getId,projectCertificationInventoryEO.getId()); + List oldPciEoList = this.list(certificationQueryWrap); + if (StringUtils.isNotEmpty(projectCertificationInventoryEO.getSdt())) { + // 编辑工程接口人处理逻辑 + this.editSdt(projectCertificationInventoryEO, oldPciEoList, currentUser); + } + if (StringUtils.isNotEmpty(projectCertificationInventoryEO.getDutyPerson())) { + // 编辑责任人处理逻辑 + this.editDutyPerson(projectCertificationInventoryEO, oldPciEoList, currentUser); + } + if (projectCertificationInventoryEO.getEndTime() != null) { + // 编辑截至日期处理逻辑 + this.editEndTime(projectCertificationInventoryEO, oldPciEoList, currentUser); + } + if (StringUtils.isNotEmpty(projectCertificationInventoryEO.getDeliverableType())) { + // 编辑交付物类型逻辑 + this.editDeliverableType(projectCertificationInventoryEO, oldPciEoList, currentUser); + } + if (StringUtils.isNotEmpty(projectCertificationInventoryEO.getDeliverableTemplate())) { + // 编辑交付物模板逻辑 + this.editDeliverableTemplate(projectCertificationInventoryEO, oldPciEoList, currentUser); + + } + + // 获取编辑前的数据 + ProjectCertificationInventoryEO editBeforePciEo = this.queryById(projectCertificationInventoryEO.getId()); + Map savePciLogParams = new HashMap<>(); + List editBeforePciList = new ArrayList<>(); + editBeforePciList.add(editBeforePciEo); + List editAfterPciList = new ArrayList<>(); + editAfterPciList.add(projectCertificationInventoryEO); + savePciLogParams.put("editBeforePciList",editBeforePciList); + savePciLogParams.put("editAfterPciList",editAfterPciList); + savePciLogParams.put("operatorType",OperatorTypeEnum.CERTIFICATION_INVENTORY_EDIT.getValue()); + this.saveProjectCertificationInventoryLog(savePciLogParams); + + Date now = new Date(); + projectCertificationInventoryEO.setUpdateTime(now); + saveOrUpdate(projectCertificationInventoryEO); + + + //获取当前的projectId + String projectId = projectCertificationInventoryEO.getProjectLibraryId(); + String cut = projectCertificationInventoryEO.getCut(); + Map params = new HashMap<>(); + params.put("projectLibraryId",projectId); + params.put("userId",currentUser.getId()); + params.put("modelType",RoleRelModelTypeEnum.CERTIFICATION_INVENTORY.getValue()); + ProjectLibraryRoleRelEO projectLibraryRoleRelEO = projectLibraryRoleRelEOService.queryByProjectLibraryIdAndUserId(params); + String roleCode = projectLibraryRoleRelEO.getRoleCode(); + +// //判断当前用户与studio工程师是否一致,一致的话具有studio角色的切换 +// if(studionList.contains(currentUser)){ +// //用户有studio工程师的操作 +// } + + //获取当前的责任人 + String dutyPerson = projectCertificationInventoryEO.getDutyPerson(); + //获取当前的责任领域 + List dutyTerritoryList = new ArrayList<>(); + dutyTerritoryList = Arrays.asList(projectCertificationInventoryEO.getDutyTerritory().split(",")); + dutyTerritoryList = dutyTerritoryList.stream().distinct().collect(Collectors.toList()); + + //根据责任领域个projectId去查相关人员名单 + List projectRelatedPersonnelList = projectRelatedPersonnelService.queryByProjectIdAndDutyTerritoy(projectId, dutyTerritoryList); + + List allList = new ArrayList<>(); + List enginnerList = new ArrayList<>(); + List lawEnginnerList = new ArrayList<>(); + List enginnerLawSetList = new ArrayList<>(); + List enginnerAttSetList = new ArrayList<>(); + //根据相关人员名单获取的工程接口人 + for(ProjectRelatedPersonnel relatedPersonnel : projectRelatedPersonnelList){ + String enginneringInterfacePerson = relatedPersonnel.getEngineeringInterfacePerson(); + if(!StringUtils.isEmpty(enginneringInterfacePerson)){ + enginnerList = Arrays.stream(enginneringInterfacePerson.split(",")).collect(Collectors.toList()); + allList.addAll(enginnerList); + } + } + //获取相关人员名单中的法规工程师 + for(ProjectRelatedPersonnel relatedPersonnel : projectRelatedPersonnelList){ + String lawEngineer = relatedPersonnel.getLawEngineer(); + if(!StringUtils.isEmpty(lawEngineer)){ + lawEnginnerList = Arrays.stream(lawEngineer.split(",")).collect(Collectors.toList()); + allList.addAll(lawEnginnerList); + } + } + //获取相关人员名单中的工程接口-法规工程师设置 + for(ProjectRelatedPersonnel relatedPersonnel : projectRelatedPersonnelList){ + String engineerLawSet = relatedPersonnel.getEngineerLawSet(); + if(!StringUtils.isEmpty(engineerLawSet)){ + enginnerLawSetList = Arrays.stream(engineerLawSet.split(",")).collect(Collectors.toList()); + allList.addAll(enginnerLawSetList); + } + } + //获取相关人员名单中的工程接口-认证工程师设置 + for(ProjectRelatedPersonnel relatedPersonnel : projectRelatedPersonnelList){ + String engineerAttSet = relatedPersonnel.getEngineerAttSet(); + if(!StringUtils.isEmpty(engineerAttSet)){ + enginnerAttSetList = Arrays.stream(engineerAttSet.split(",")).collect(Collectors.toList()); + allList.addAll(enginnerAttSetList); + } + } + //获取当前项目库id的studio工程师和认证工程师 + List studionList = new ArrayList<>(); + List certificationEngineerList = new ArrayList<>(); + List projectLibraryBases = projectLibraryBaseService.queryById(projectId, cut); + for(ProjectLibraryBase projectLibraryBase : projectLibraryBases){ + studionList.add(projectLibraryBase.getStudioEngineer()); + + String certificationEngineer = projectLibraryBase.getCertificationEngineer(); + if(!StringUtils.isEmpty(certificationEngineer)){ + certificationEngineerList = Arrays.stream(certificationEngineer.split(",")).collect(Collectors.toList()); + allList.addAll(certificationEngineerList); + } + } +// studionList = studionList.stream().distinct().collect(Collectors.toList()); +// certificationEngineerList = certificationEngineerList.stream().distinct().collect(Collectors.toList()); + + allList = allList.stream().filter(all -> { + return StringUtils.isNotBlank(all); + }).distinct().collect(Collectors.toList()); + /** + for(String all : allList){ + if(all.equals("")){ + allList.remove(all); + } + } + */ + //遍历所有人alllist中是否包含责任人,如果包含,不用操作。 + //-------如果不包含,再去判断当前用户的角色是studio、法规还是认证 + for(ProjectRelatedPersonnel relatedPersonnel : projectRelatedPersonnelList){ + if(allList.size()>0){ + if(!allList.contains(dutyPerson)){ + if (StringUtils.isNotEmpty(roleCode)) { + if(roleCode.equals(com.jero.modules.project.enums.ProjectRoleEnum.STUDIO_ENGINEER.getValue())){ + if(relatedPersonnel.getEngineeringInterfacePerson() != null){ + String engineeringInterfacePerson = dutyPerson+","+relatedPersonnel.getEngineeringInterfacePerson(); + relatedPersonnel.setEngineeringInterfacePerson(engineeringInterfacePerson); + }else { + relatedPersonnel.setEngineeringInterfacePerson(dutyPerson); + } + }else if(roleCode.equals(com.jero.modules.project.enums.ProjectRoleEnum.REGULATI_ENGINEER.getValue())){ + if(relatedPersonnel.getEngineerLawSet() != null){ + String engineerLawSet = dutyPerson+","+relatedPersonnel.getEngineerLawSet(); + relatedPersonnel.setEngineerLawSet(engineerLawSet); + }else { + relatedPersonnel.setEngineerLawSet(dutyPerson); + } + }else if(roleCode.equals(com.jero.modules.project.enums.ProjectRoleEnum.HOMOLOGATION_ENGINEER.getValue())){ + if(relatedPersonnel.getEngineerAttSet() !=null){ + String engineerAttSet = dutyPerson+","+relatedPersonnel.getEngineerAttSet(); + relatedPersonnel.setEngineerAttSet(engineerAttSet); + }else { + relatedPersonnel.setEngineerAttSet(dutyPerson); + } + } + } + } + } + } +// for(ProjectRelatedPersonnel relatedPersonnel : projectRelatedPersonnelList){ +// //如果工程接口人不为空的话 +// if(enginnerList.size()>0){ +// //判断哪个不存在 再去去存入 +// if(!enginnerList.contains(dutyPerson)){ +// relatedPersonnel.setEngineerAttSet(dutyPerson); +//// projectRelatedPersonnelService.editById(relatedPersonnel); +// } +// }else { +// //工程接口人为空的话,直接将责任设置到认证工程师下 +// relatedPersonnel.setEngineerAttSet(dutyPerson); +//// projectRelatedPersonnelService.editById(relatedPersonnel); +// } +// } + + this.projectRelatedPersonnelService.updateBatchById(projectRelatedPersonnelList); + + //设置权限 先删后加 + List adds = new ArrayList<>(); + if (ObjectUtils.isNotEmpty(projectCertificationInventoryEO.getSdt())) { + setProjectCertificationInventoryPermission(projectCertificationInventoryEO.getSdt(), projectCertificationInventoryEO.getProjectLibraryId(), projectCertificationInventoryEO.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(projectCertificationInventoryEO.getDutyPerson())) { + setProjectCertificationInventoryPermission(projectCertificationInventoryEO.getDutyPerson(), projectCertificationInventoryEO.getProjectLibraryId(), projectCertificationInventoryEO.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + } + + private void editDeliverableTemplate(ProjectCertificationInventoryEO newPciEo, List oldPciEoList, LoginUser currentUser) { + String newDeliverableTemplate = newPciEo.getDeliverableTemplate(); + List oldPciEos = oldPciEoList.stream().filter(pldPciEo -> { + boolean flag = ( + !newDeliverableTemplate.equals(pldPciEo.getDeliverableTemplate()) + && ( + StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ) + ); + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(oldPciEos)){ + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(oldPciEos.get(0).getProjectLibraryId()); + if(ObjectUtils.isNotEmpty(projectLibraryBase)){ + int role = checkUserRole(oldPciEos.get(0).getProjectLibraryId(),currentUser.getId()); + for (ProjectCertificationInventoryEO oldPciEo : oldPciEos) { + String msgTitleCn = ""; + String msgTitleEn = ""; + String taskDefinitionKey = ""; + if (StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())) { + msgTitleCn = ProjectMessageEnum.RZRWQR.getCnName(); + msgTitleEn = ProjectMessageEnum.RZRWQR.getEnName(); + taskDefinitionKey = CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(); + }else if(StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())) { + msgTitleCn = ProjectMessageEnum.PREHOMEQR.getCnName(); + msgTitleEn = ProjectMessageEnum.PREHOMEQR.getEnName(); + taskDefinitionKey = CertificationFlowNodeEnum.TASK_HANDLING.getKey(); + } + List userIdList = new ArrayList<>(); + userIdList.add(oldPciEo.getDutyPerson()); + if(role == ProjectRoleEnum.STUDIO_ENGINEER.getIntValue()){ + userIdList.addAll(Arrays.asList(projectLibraryBase.getCertificationEngineer().split(","))); + } + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + oldPciEo.setEndTime(newPciEo.getEndTime()); + List PciEoList = new ArrayList<>(); + PciEoList.add(oldPciEo); + this.sendMessageByTemplateId( + PciEoList, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + oldPciEo.getEndTime(), + taskDefinitionKey, + msgTitleCn, + msgTitleEn, + ProjectMessageEnum.RZRWJFWMBBXG.getCnName(), + ProjectMessageEnum.RZRWJFWMBBXG.getEnName() + ); + } + } + } + } + + private void editDeliverableType(ProjectCertificationInventoryEO newPciEo, List oldPciEoList, LoginUser currentUser) { + String newDeliverableType = newPciEo.getDeliverableType(); + List oldPciEos = oldPciEoList.stream().filter(pldPciEo -> { + boolean flag = ( + !newDeliverableType.equals(pldPciEo.getDeliverableType()) + && ( + StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ) + ); + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(oldPciEos)){ + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(oldPciEos.get(0).getProjectLibraryId()); + if(ObjectUtils.isNotEmpty(projectLibraryBase)){ + int role = checkUserRole(oldPciEos.get(0).getProjectLibraryId(),currentUser.getId()); + for (ProjectCertificationInventoryEO oldPciEo : oldPciEos) { + String msgTitleCn = ""; + String msgTitleEn = ""; + String taskDefinitionKey = ""; + if (StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())) { + msgTitleCn = ProjectMessageEnum.RZRWQR.getCnName(); + msgTitleEn = ProjectMessageEnum.RZRWQR.getEnName(); + taskDefinitionKey = CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(); + }else if(StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())) { + msgTitleCn = ProjectMessageEnum.PREHOMEQR.getCnName(); + msgTitleEn = ProjectMessageEnum.PREHOMEQR.getEnName(); + taskDefinitionKey = CertificationFlowNodeEnum.TASK_HANDLING.getKey(); + } + List userIdList = new ArrayList<>(); + userIdList.add(oldPciEo.getDutyPerson()); + if(role == ProjectRoleEnum.STUDIO_ENGINEER.getIntValue()){ + userIdList.addAll(Arrays.asList(projectLibraryBase.getCertificationEngineer().split(","))); + } + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + oldPciEo.setEndTime(newPciEo.getEndTime()); + List PciEoList = new ArrayList<>(); + PciEoList.add(oldPciEo); + this.sendMessageByTemplateId( + PciEoList, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + oldPciEo.getEndTime(), + taskDefinitionKey, + msgTitleCn, + msgTitleEn, + ProjectMessageEnum.RZRWJFWLXBXG.getCnName(), + ProjectMessageEnum.RZRWJFWLXBXG.getEnName() + ); + } + } + } + } + + /** + * 编辑工程接口人处理逻辑 + */ + private void editSdt(ProjectCertificationInventoryEO pciEo, List oldPciEoList,LoginUser currentUser) { + // 过滤出来,旧数据的接口人与新修改的接口人不是同一个人 + List oldPciEos = oldPciEoList.stream().filter(oldPciEo -> { + boolean flag = ( + !StringUtils.equals(oldPciEo.getDutyPerson(), pciEo.getDutyPerson()) + && ( + StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ) + ); + return flag; + }).collect(Collectors.toList()); + for (ProjectCertificationInventoryEO oldPciEo : oldPciEos) { + List userIdList = new ArrayList<>(); + userIdList.add(oldPciEo.getSdt()); + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + + List PciEoList = new ArrayList<>(); + PciEoList.add(oldPciEo); + if (StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())) { + this.sendMessageByTemplateId( + PciEoList, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(), + ProjectMessageEnum.RZRWQR.getCnName(), + ProjectMessageEnum.RZRWQR.getEnName(), + ProjectMessageEnum.RWBFQRCH.getCnName(), + ProjectMessageEnum.RWBFQRCH.getEnName() + ); + }else if(StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())){ + this.sendMessageByTemplateId( + PciEoList, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_HANDLING.getKey(), + ProjectMessageEnum.PREHOMEQR.getCnName(), + ProjectMessageEnum.PREHOMEQR.getEnName(), + ProjectMessageEnum.RWBFQRCH.getCnName(), + ProjectMessageEnum.RWBFQRCH.getEnName() + ); + } + } + if (CollectionUtils.isNotEmpty(oldPciEos)) { + List userIdList = oldPciEos.stream().map(ProjectCertificationInventoryEO::getSdt).distinct().collect(Collectors.toList()); + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + if (StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())) { + this.sendMessageByTemplateId( + oldPciEos, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(), + ProjectMessageEnum.RZRWQR.getCnName(), + ProjectMessageEnum.RZRWQR.getEnName(), + ProjectMessageEnum.RZQRRWYQ.getCnName(), + ProjectMessageEnum.RZQRRWYQ.getEnName() + ); + }else if(StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())){ + this.sendMessageByTemplateId( + oldPciEos, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_HANDLING.getKey(), + ProjectMessageEnum.PREHOMEQR.getCnName(), + ProjectMessageEnum.PREHOMEQR.getEnName(), + ProjectMessageEnum.RZQRRWYQ.getCnName(), + ProjectMessageEnum.RZQRRWYQ.getEnName() + ); + } + } + } + + /** + * 编辑责任人处理逻辑 + * @param pciEo + */ + private void editDutyPerson(ProjectCertificationInventoryEO pciEo,List oldPciEoList,LoginUser currentUser) { + // 过滤出来,旧数据的责任人与新修改的责任人不是同一个人,并且流程状态是 任务待确认、结果待提交、审查退回的数据,这三个状态的流程数据在责任人节点。 + List oldPciEos = oldPciEoList.stream().filter(oldPciEo -> { + boolean flag = ( + !StringUtils.equals(oldPciEo.getDutyPerson(), pciEo.getDutyPerson()) + && ( + StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ) + ); + return flag; + }).collect(Collectors.toList()); + for (ProjectCertificationInventoryEO oldPciEo : oldPciEos) { + List userIdList = new ArrayList<>(); + userIdList.add(oldPciEo.getDutyPerson()); + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + List PciEoList = new ArrayList<>(); + PciEoList.add(oldPciEo); + if (StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())) { + this.sendMessageByTemplateId( + PciEoList, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(), + ProjectMessageEnum.RZRWQR.getCnName(), + ProjectMessageEnum.RZRWQR.getEnName(), + ProjectMessageEnum.RWBFQRCH.getCnName(), + ProjectMessageEnum.RWBFQRCH.getEnName() + ); + }else if(StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())){ + this.sendMessageByTemplateId( + PciEoList, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_HANDLING.getKey(), + ProjectMessageEnum.PREHOMEQR.getCnName(), + ProjectMessageEnum.PREHOMEQR.getEnName(), + ProjectMessageEnum.RWBFQRCH.getCnName(), + ProjectMessageEnum.RWBFQRCH.getEnName() + ); + } + } + if (CollectionUtils.isNotEmpty(oldPciEos)) { + List userIdList = oldPciEos.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList()); + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + if (StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())) { + this.sendMessageByTemplateId( + oldPciEos, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(), + ProjectMessageEnum.RZRWQR.getCnName(), + ProjectMessageEnum.RZRWQR.getEnName(), + ProjectMessageEnum.RZQRRWYQ.getCnName(), + ProjectMessageEnum.RZQRRWYQ.getEnName() + ); + }else if(StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())){ + this.sendMessageByTemplateId( + oldPciEos, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + pciEo.getEndTime(), + CertificationFlowNodeEnum.TASK_HANDLING.getKey(), + ProjectMessageEnum.PREHOMEQR.getCnName(), + ProjectMessageEnum.PREHOMEQR.getEnName(), + ProjectMessageEnum.RZQRRWYQ.getCnName(), + ProjectMessageEnum.RZQRRWYQ.getEnName() + ); + } + + // 如果责任人有变更,将之前责任人的待办中心任务,移交给新的责任人。 + QueryWrapper detailQueryWrap = new QueryWrapper<>(); + List idList = Arrays.asList(pciEo.getId().split(",")); + detailQueryWrap.lambda().in(ProcessInfoDetailEO::getProjectLawsInventoryId, idList); + detailQueryWrap.lambda().eq(ProcessInfoDetailEO::getFlowType, FlowTypeEnum.CERTIFICATION_LC.getValue()); + detailQueryWrap.lambda().eq(ProcessInfoDetailEO::getStatus, TaskStatusEnum.NOT_DONE.getValue()); + List taskDefinitionKeyList = new ArrayList<>(); + taskDefinitionKeyList.add(CertificationFlowNodeEnum.ZRRJSRW.getKey()); + taskDefinitionKeyList.add(CertificationFlowNodeEnum.ZRRTJRW.getKey()); + detailQueryWrap.lambda().in(ProcessInfoDetailEO::getTaskDefinitionKey, taskDefinitionKeyList); + + List processInfoDetailEOList = this.processInfoDetailEOService.list(detailQueryWrap); + if (CollectionUtils.isNotEmpty(processInfoDetailEOList)) { + processInfoDetailEOList.forEach(detail -> { + detail.setUserId(pciEo.getDutyPerson()); + }); + this.processInfoDetailEOService.updateBatchById(processInfoDetailEOList); + } + } + } + + /** + * 编辑截止日期处理逻辑 + * @param newPciEo 最新编辑的认证清单信息 + * @param oldPciEoList 旧的认证清单数组 + */ + private void editEndTime(ProjectCertificationInventoryEO newPciEo, List oldPciEoList,LoginUser currentUser) { + Date newEndTime = newPciEo.getEndTime(); + // 过滤出来,旧的截止日期不等于更改后的新截止日期,并且数据状态为 任务待确认、结果待提交、审查退回的数据。 + List oldPciEos = oldPciEoList.stream().filter(pldPciEo -> { + boolean flag = ( + !newEndTime.equals(pldPciEo.getEndTime()) + && ( + StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ) + ); + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(oldPciEos)){ + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(oldPciEos.get(0).getProjectLibraryId()); + if(ObjectUtils.isNotEmpty(projectLibraryBase)){ + // 同步更新待办中心-流程明细截止日期 + this.syncProcessInfoDetailEndTime(newEndTime, oldPciEos); + int role = checkUserRole(oldPciEos.get(0).getProjectLibraryId(),currentUser.getId()); + for (ProjectCertificationInventoryEO oldPciEo : oldPciEos) { + String msgTitleCn = ""; + String msgTitleEn = ""; + String taskDefinitionKey = ""; + if (StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())) { + msgTitleCn = ProjectMessageEnum.RZRWQR.getCnName(); + msgTitleEn = ProjectMessageEnum.RZRWQR.getEnName(); + taskDefinitionKey = CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(); + }else if(StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(oldPciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())) { + msgTitleCn = ProjectMessageEnum.PREHOMEQR.getCnName(); + msgTitleEn = ProjectMessageEnum.PREHOMEQR.getEnName(); + taskDefinitionKey = CertificationFlowNodeEnum.TASK_HANDLING.getKey(); + } + List userIdList = new ArrayList<>(); + userIdList.add(oldPciEo.getDutyPerson()); + if(role == ProjectRoleEnum.STUDIO_ENGINEER.getIntValue()){ + userIdList.addAll(Arrays.asList(projectLibraryBase.getCertificationEngineer().split(","))); + }else if(role == ProjectRoleEnum.HOMOLOGATION_ENGINEER.getIntValue()){ + userIdList.add(projectLibraryBase.getStudioEngineer()); + } + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + oldPciEo.setEndTime(newPciEo.getEndTime()); + List PciEoList = new ArrayList<>(); + PciEoList.add(oldPciEo); + this.sendMessageByTemplateId( + PciEoList, + TemplateInfoEnum2.CERTIFICATION_PUBLIC_MESSAGE_G.getValue(), + userIdList, + userInfoList, + oldPciEo.getEndTime(), + taskDefinitionKey, + msgTitleCn, + msgTitleEn, + ProjectMessageEnum.RZRWJZSJBXG.getCnName(), + ProjectMessageEnum.RZRWJZSJBXG.getEnName() + ); + } + } + } + } + + /** + * 通过id删除 + * + * @param id + * @return + */ + @Override + public void deleteById(String id) { + removeById(id); + + QueryWrapper detailRemoveWrap = new QueryWrapper<>(); + detailRemoveWrap.lambda().eq(ProcessInfoDetailEO::getProjectLawsInventoryId,id); + this.processInfoDetailEOService.remove(detailRemoveWrap); + } + + /** + * 批量删除 + * + * @param ids + * @return + */ + @Override + public void deleteByIds(List ids) { + QueryWrapper queryWrap = new QueryWrapper<>(); + queryWrap.lambda().in(ProjectCertificationInventoryEO::getId,ids); + List list = this.list(queryWrap); + removeByIds(ids); + + QueryWrapper detailRemoveWrap = new QueryWrapper<>(); + detailRemoveWrap.lambda().in(ProcessInfoDetailEO::getProjectLawsInventoryId,ids); + detailRemoveWrap.lambda().eq(ProcessInfoDetailEO::getProcessInfoId,list.get(0).getProjectLibraryId()); + this.processInfoDetailEOService.remove(detailRemoveWrap); + } + + /** + * 通过id查询 + * + * @param id + * @return + */ + @Override + public ProjectCertificationInventoryEO queryById(String id) { + return getById(id); + } + + /** + * 列表查询 + * + * @return + */ + @Override + public List queryList() { + return list(); + } + + @Override + public Result batchAdd(JSONObject json) { + String cut = json.getString("cut"); + List result = new ArrayList<>(); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + result.add("添加成功!"); + }else { + result.add("Successfully added!"); + } + try { + String serialNumber = json.getString("serialNumber"); + String wvtaId = json.getString("wvtaId"); + String bussDocumentLibraryId = json.getString("bussDocumentLibraryId"); + String projectLibraryId = json.getString("projectLibraryId"); + + + JSONArray dataList = json.getJSONArray("dataList"); + List projectCertificationInventoryEOList = new ArrayList<>(); + ProjectCertificationInventoryEO projectCertificationInventoryEO = null; + for (Object data : dataList) { + projectCertificationInventoryEO = JSONObject.parseObject(JSONObject.toJSONString(data),ProjectCertificationInventoryEO.class); + projectCertificationInventoryEO.setSerialNumber(serialNumber); + projectCertificationInventoryEO.setWvtaId(wvtaId); + projectCertificationInventoryEO.setBussDocumentLibraryId(bussDocumentLibraryId); + projectCertificationInventoryEO.setProjectLibraryId(projectLibraryId); + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()); + projectCertificationInventoryEO.setCertificationProgress(CertificationProgressEnum.NOT_START.getValue()); + projectCertificationInventoryEOList.add(projectCertificationInventoryEO); + } + // 处理提示信息, 类别+检验项目+配置项+编号+责任领域 作为唯一检验 + // List saveDataList = this.dataUniqueCheck(projectCertificationInventoryEOList,cut,result,projectLibraryId); + + if(CollectionUtils.isNotEmpty(projectCertificationInventoryEOList)){ + this.saveBatch(projectCertificationInventoryEOList); + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_ADD.getValue()); + + Date now = new Date(); + //设置权限 先删后加 + List adds = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci: projectCertificationInventoryEOList) { + if (ObjectUtils.isNotEmpty(pci.getSdt())) { + setProjectCertificationInventoryPermission(pci.getSdt(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(pci.getDutyPerson())) { + setProjectCertificationInventoryPermission(pci.getDutyPerson(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + } + }catch (Exception ex){ + ex.printStackTrace(); + log.error("批量添加认证清单失败:" + ex.getMessage()); + throw new JeroBootException("添加失败!"); + } + return Result.OK(result); + } + + @Override + public Result setBatch(ProjectCertificationInventoryEO projectCertificationInventoryEO) { + //获取当前用户 + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String ids = projectCertificationInventoryEO.getIds(); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行批量设置!"); + } + try { + List idList = Arrays.asList(ids.split(",")); + + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().in(ProjectCertificationInventoryEO::getId,idList); + List pciEoList = this.list(pciQueryWrap); + + List updateList = new ArrayList<>(); + for (String id : idList) { + ProjectCertificationInventoryEO updateProjectCertificationInventoryEO = new ProjectCertificationInventoryEO(); + BeanUtils.copyProperties(projectCertificationInventoryEO,updateProjectCertificationInventoryEO); + updateProjectCertificationInventoryEO.setId(id); + + /** + * 2023-03-30 17.36新增该需求。 + * 如果用户批量设置了工程接口人字段 + * 那就需要判断所选数据中责任人是否为空 + * 如果责任人字段为空时 需要将工程接口人带入到所选数据的责任人字段中 + */ + if(StringUtils.isNotBlank(projectCertificationInventoryEO.getSdt())){ + List pciEoListTemp = pciEoList.stream().filter(pciEo -> { + boolean flag = false; + if (StringUtils.equals(pciEo.getId(), id)) { + flag = true; + } + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(pciEoListTemp)){ + ProjectCertificationInventoryEO pciEo = pciEoListTemp.get(0); + if(StringUtils.isEmpty(pciEo.getDutyPerson())){ + updateProjectCertificationInventoryEO.setDutyPerson(projectCertificationInventoryEO.getSdt()); + } + } + } + + updateList.add(updateProjectCertificationInventoryEO); + } + if(StringUtils.isNotEmpty(projectCertificationInventoryEO.getSdt())){ + // 编辑工程接口人处理逻辑 + this.editSdt(projectCertificationInventoryEO,pciEoList,currentUser); + } + if(StringUtils.isNotEmpty(projectCertificationInventoryEO.getDutyPerson())){ + // 编辑责任人处理逻辑 + this.editDutyPerson(projectCertificationInventoryEO,pciEoList,currentUser); + } + if(projectCertificationInventoryEO.getEndTime() != null){ + // 编辑截至日期处理逻辑 + this.editEndTime(projectCertificationInventoryEO, pciEoList,currentUser); + } + if(StringUtils.isNotEmpty(projectCertificationInventoryEO.getDeliverableType()) ){ + // 编辑交付物类型逻辑 + this.editDeliverableType(projectCertificationInventoryEO, pciEoList, currentUser); + } + if(StringUtils.isNotEmpty(projectCertificationInventoryEO.getDeliverableTemplate())){ + // 编辑交付物模板逻辑 + this.editDeliverableTemplate(projectCertificationInventoryEO, pciEoList, currentUser); + } + +// List flowStatusList = new ArrayList<>(); +// flowStatusList.add(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()); +// +// QueryWrapper certificationQueryWrap = new QueryWrapper<>(); +// certificationQueryWrap.lambda().in(ProjectCertificationInventoryEO::getId,idList); +//// certificationQueryWrap.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); +// List projectCertificationInventoryEOS = this.list(certificationQueryWrap); +// +// if(CollectionUtils.isNotEmpty(projectCertificationInventoryEOS)){ +// List pciEoListTemp = projectCertificationInventoryEOS.stream().filter(certificationInventory -> { +// boolean flag = false; +// if(StringUtils.equals(certificationInventory.getFlowStatus(),CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())){ +// if(projectCertificationInventoryEO.getEndTime() != null && certificationInventory.getEndTime() != null){ +// if(!projectCertificationInventoryEO.getEndTime().equals(certificationInventory.getEndTime())){ +// flag = true; +// } +// } +// } +// return flag; +// }).collect(Collectors.toList()); +// +// if (CollectionUtils.isNotEmpty(pciEoListTemp)) { +// ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(pciEoListTemp.get(0).getProjectLibraryId()); +// if(ObjectUtils.isNotEmpty(projectLibraryBase)){ +// List userIdList = Arrays.asList(projectLibraryBase.getCertificationEngineer().split(",")); +// List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); +// +// this.sendMessageByTemplateId( +// pciEoListTemp, +// TemplateInfoEnum2.CERTIFICATION_MESSAGE14.getValue(), +// userIdList, +// userInfoList, +// projectCertificationInventoryEO.getEndTime(),"" +// ); +// } +// } +// +// this.syncProcessInfoDetailEndTime(projectCertificationInventoryEO.getEndTime(),projectCertificationInventoryEOS); +// } + if(CollectionUtils.isNotEmpty(updateList)){ + this.updateBatchById(updateList); + } + + Date now = new Date(); + //设置权限 先删后加 + List adds = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci: updateList) { + if (ObjectUtils.isNotEmpty(pci.getSdt())) { + setProjectCertificationInventoryPermission(pci.getSdt(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(pci.getDutyPerson())) { + setProjectCertificationInventoryPermission(pci.getDutyPerson(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + }catch (Exception ex){ + ex.printStackTrace(); + log.error("批量设置失败:" + ex.getMessage()); + throw new JeroBootException("批量设置失败!"); + } + return Result.OK("批量设置成功!"); + } + + /** + * 根据模板发送消息 + */ + @Override + public void sendMessageByTemplateId(List projectCertificationInventoryEOS, + String templeteId, + List userIdList, + List userInfoList, + Date endTime, + String taskDefinitionKey){ + this.sendMessageByTemplateId(projectCertificationInventoryEOS,templeteId,userIdList,userInfoList,endTime,taskDefinitionKey,"","","",""); + } + + /** + * 根据模板发送消息(可发送公共消息) + */ + private void sendMessageByTemplateId(List projectCertificationInventoryEOS, + String templeteId, + List userIdList, + List userInfoList, + Date endTime, + String taskDefinitionKey, + String msgTitleCn, + String msgTitleEn, + String contentCn, + String contentEn){ + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectCertificationInventoryEOS.get(0).getProjectLibraryId()); + if(ObjectUtils.isNotEmpty(projectLibraryBase)){ + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryBase.getId(), PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + String hrefFeishu_CN_P = (String) hrefFeishuMap.get("hrefFeishu_CN_P"); + if(StringUtils.isNotEmpty(taskDefinitionKey)){ + hrefFeishu_CN_P = this.handlePhoneLink(projectLibraryBase.getId(),PRN_CN,taskDefinitionKey); + } + + Map standNameAndItemName = this.platformProjectCertificationInventoryEOService.getStandNameAndItemName(projectCertificationInventoryEOS); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + try { + for (String userId : userIdList) { + String thirdId = this.sysUserService.getUserThirdIdByUserId(userInfoList,userId); + + if(StringUtils.isNotEmpty(thirdId)){ + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 +// this.certificationInventoryEOListSortByEndTimeAsc(projectCertificationInventoryEOS); +// Date endTime = projectCertificationInventoryEOS.get(0).getEndTime(); + + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", templeteId); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + if(StringUtils.isNotEmpty(msgTitleCn)){ + templateVariableMap.put("msgTitleCn",msgTitleCn); + } + if(StringUtils.isNotEmpty(msgTitleEn)){ + templateVariableMap.put("msgTitleEn",msgTitleEn); + } + if(StringUtils.isNotEmpty(contentCn)){ + templateVariableMap.put("contentCn",contentCn); + } + if(StringUtils.isNotEmpty(contentEn)){ + templateVariableMap.put("contentEn",contentEn); + } + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(endTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlCnPhone",hrefFeishu_CN_P); + + templateVariableMap.put("operateUserName",currentUser.getUsername()); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } + } + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + } + } + + /** + * 处理提示信息 + * @param projectCertificationInventoryEOList + * @param cut + * @param result + */ + @Override + public List dataUniqueCheck(List projectCertificationInventoryEOList, String cut,List result,String projectLibraryId) { + List pciSaveList = new ArrayList<>(); + + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,projectLibraryId); + List allDataList = this.list(pciQueryWrap); + // 重复数据数组 + List duplicateDataList = allDataList.stream().filter(data -> { + boolean flag = false; + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + boolean categoryFlag = StringUtils.equals(projectCertificationInventoryEO.getCategory(), data.getCategory()); + boolean inspectionItemFlag = StringUtils.equals(projectCertificationInventoryEO.getInspectionItem(), data.getInspectionItem()); + boolean configItemFlag = StringUtils.equals(projectCertificationInventoryEO.getConfigItem(), data.getConfigItem()); + boolean serialNumberFlag = StringUtils.equals(projectCertificationInventoryEO.getSerialNumber(), data.getSerialNumber()); + boolean dutyTerritoryFlag = StringUtils.equals(projectCertificationInventoryEO.getDutyTerritory(), data.getDutyTerritory()); + // 类别+检验项目+配置项+编号+责任领域 作为唯一检验 + if(categoryFlag && inspectionItemFlag && configItemFlag && serialNumberFlag && dutyTerritoryFlag){ + flag = true; + } + } + return flag; + }).collect(Collectors.toList()); + if(CollectionUtils.isNotEmpty(duplicateDataList)){ + if (StringUtils.equals(cut, CutEnum.CN.getValue())) { + result.add("您所选的数据中包含当前项目中已包含的条目信息,已为您过滤添加。"); + }else { + result.add("The data you have selected contains item information already included in the current project, which has been filtered and added for you."); + } + } + + // 过滤重复的数据 + pciSaveList = projectCertificationInventoryEOList.stream().filter(pciEO -> { + boolean flag = true; + for (ProjectCertificationInventoryEO allData : allDataList) { + boolean categoryFlag = StringUtils.equals(pciEO.getCategory(), allData.getCategory()); + boolean inspectionItemFlag = StringUtils.equals(pciEO.getInspectionItem(), allData.getInspectionItem()); + boolean configItemFlag = StringUtils.equals(pciEO.getConfigItem(), allData.getConfigItem()); + boolean serialNumberFlag = StringUtils.equals(pciEO.getSerialNumber(), allData.getSerialNumber()); + boolean dutyTerritoryFlag = StringUtils.equals(pciEO.getDutyTerritory(), allData.getDutyTerritory()); + // 类别+检验项目+配置项+编号+责任领域 作为唯一检验 + if(categoryFlag && inspectionItemFlag && configItemFlag && serialNumberFlag && dutyTerritoryFlag){ + flag = false; + break; + } + } + return flag; + }).collect(Collectors.toList()); + return pciSaveList; + } + + @Override + public Result updateStatusBatch(JSONObject json) { + String ids = json.getString("ids"); + String flowStatus = json.getString("flowStatus"); + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if(StringUtils.isNotEmpty(ids)){ + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().in(ProjectCertificationInventoryEO::getId,Arrays.asList(ids.split(","))); + List pciEoList = this.list(pciQueryWrap); + if(CollectionUtils.isNotEmpty(pciEoList)){ + pciEoList.forEach(pciEo -> { + pciEo.setFlowStatus(flowStatus); + processHistoryEOService.add(pciEo.getId(),CertificationFlowNodeEnum.TASK_SS.getKey(),currentUser.getId(),null,null,null); + }); + this.updateBatchById(pciEoList); + + // 如果是责任人操作补充提交按钮。给责任人生成对应待办中心的待办任务。 + if(StringUtils.equals(flowStatus,CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue())){ + List processInfoDetailEOList = new ArrayList<>(); + pciEoList.forEach(pciEo -> { + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(pciEo.getDutyPerson()); + processInfoDetailEO.setEndTime(pciEo.getEndTime()); + processInfoDetailEO.setProjectLawsInventoryId(pciEo.getId()); + processInfoDetailEOList.add(processInfoDetailEO); + }); + + // 给责任人分配待办中心的任务 (待提交) + this.addProcessInfoDetailEO(processInfoDetailEOList,pciEoList.get(0).getProjectLibraryId(),CertificationFlowNodeEnum.ZRRTJRW.getKey()); + } + } + } + return new Result<>().success("批量更新状态成功!"); + } + + @Override + public void importDisposeData(List datas, String cut) { + if(CollectionUtils.isNotEmpty(datas)){ + List categoryList = this.sysCategoryService.list(); + List sysDictItems = this.sysDictItemServiceImpl.getBaseMapper().selectItemsAll(); + + List userNameList = new ArrayList<>(); + + userNameList.addAll(datas.stream().map(ProjectCertificationInventoryEO::getSdtName).collect(Collectors.toList())); + userNameList.addAll(datas.stream().map(ProjectCertificationInventoryEO::getDutyPersonName).collect(Collectors.toList())); + List sysUserList = this.sysUserService.queryUserIdListByNameList(userNameList); + + for(ProjectCertificationInventoryEO data : datas){ + //通过工程接口人名字获取sdt + if(StringUtils.isNotEmpty(data.getSdtName())){ + String sdt = sysUserList.stream().filter(sysUser -> { + boolean flag = false; + if (StringUtils.equals(sysUser.getUsername(), data.getSdtName())) { + flag = true; + } + return flag; + }).map(SysUser::getId).collect(Collectors.joining(",")); + data.setSdt(sdt); + } + //通过责任人的名字获取dutyperson + if(StringUtils.isNotEmpty(data.getDutyPersonName())){ + String dutyPerson = sysUserList.stream().filter(sysUser -> { + boolean flag = false; + if (StringUtils.equals(sysUser.getUsername(), data.getDutyPersonName())) { + flag = true; + } + return flag; + }).map(SysUser::getId).collect(Collectors.joining(",")); + data.setDutyPerson(dutyPerson); + } + //交付物类型 + if(CutEnum.CN.getValue().equals(cut)){ + if(StringUtils.isNotEmpty(data.getDeliverableTypeName())){ + String deliverableType = this.getTreeNameImport(cut, categoryList, Arrays.asList(data.getDeliverableTypeName().split(","))); + data.setDeliverableType(deliverableType); + + String valueType = categoryList.stream().filter(category -> { + boolean flag = false; + if (StringUtils.equals(data.getDeliverableTypeName(), category.getName())) { + flag = true; + } + return flag; + }).map(SysCategory::getValueType).distinct().collect(Collectors.joining(",")); + data.setValueType(valueType); + } + }else { + if(StringUtils.isNotEmpty(data.getDeliverableTypeNameEn())){ + + String deliverableType = this.getTreeNameImport(CutEnum.EN.getValue(), categoryList, Arrays.asList(data.getDeliverableTypeNameEn().split(","))); + data.setDeliverableType(deliverableType); + + String valueType = categoryList.stream().filter(category -> { + boolean flag = false; + if (StringUtils.equals(data.getDeliverableTypeNameEn(), category.getEnName())) { + flag = true; + } + return flag; + }).map(SysCategory::getValueType).distinct().collect(Collectors.joining(",")); + data.setValueType(valueType); + } + } + //责任领域 + if(StringUtils.isNotEmpty(data.getDutyTerritoryName())){ + String dutyTerritory = this.sysDictItemService.disposeShowDictItemText(sysDictItems,data.getDutyTerritoryName(),cut, ProjectInventoryFieldEnum.DUTY_TERRITORY.getValue()); + data.setDutyTerritory(dutyTerritory); + } + //通过编号查找文档库的id + if(StringUtils.isNotEmpty(data.getSerialNumber())){ + BussDocumentLibraryEO bySerialNumber = bussDocumentLibraryEOMapper.getBySerialNumber(data.getSerialNumber()); + data.setBussDocumentLibraryId(bySerialNumber.getId()); + } + List list = new ArrayList<>(); + list.add(data); + if (list!=null&&list.size()>0) { + platformProjectCertificationInventoryEOService.saveBatch(list); + } + Date now = new Date(); + //设置权限 先删后加 + List adds = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci: list) { + if (ObjectUtils.isNotEmpty(pci.getSdt())) { + setProjectCertificationInventoryPermission(pci.getSdt(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(pci.getDutyPerson())) { + setProjectCertificationInventoryPermission(pci.getDutyPerson(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + } + } + } + + @Override + public String getTreeNameImport(String cut, List categoryList, List technologyTerritoryList) { + StringBuilder sb = new StringBuilder(); + for (String technologyTerritory : technologyTerritoryList) { + List collect = new ArrayList<>(); + if(CutEnum.CN.getValue().equals(cut)){ + collect = categoryList.stream().filter(e -> technologyTerritory.equals(e.getName())).collect(Collectors.toList()); + }else { + collect = categoryList.stream().filter(e -> technologyTerritory.equals(e.getEnName())).collect(Collectors.toList()); + } + if(collect!=null&&collect.size()>0){ + sb.append(collect.get(0).getId()); + } + } + String technologyTerritoryId = ""; + if (StringUtils.isNotBlank(sb)) { + technologyTerritoryId = sb.substring(0, sb.length()-0); + } + return technologyTerritoryId; + } + + @Override + public void disposeData(List datas, String cut) { + if (CollectionUtils.isNotEmpty(datas)) { + List categoryList = this.sysCategoryService.list(); + List sysDictItems = this.sysDictItemServiceImpl.getBaseMapper().selectItemsAll(); + List certificationProgress = this.sysDictItemServiceImpl.selectItemsByDictCode("certification_progress"); + + List userIdList = new ArrayList<>(); + + userIdList.addAll(datas.stream().map(ProjectCertificationInventoryEO::getSdt).collect(Collectors.toList())); + userIdList.addAll(datas.stream().map(ProjectCertificationInventoryEO::getDutyPerson).collect(Collectors.toList())); + List sysUserList = this.sysUserService.querySysUserListByIdList(userIdList); + + for (ProjectCertificationInventoryEO data : datas) { + if(StringUtils.isNotEmpty(data.getSdt())){ + String sdtName = sysUserList.stream().filter(sysUser -> { + boolean flag = false; + if (StringUtils.equals(sysUser.getId(), data.getSdt())) { + flag = true; + } + return flag; + }).map(SysUser::getUsername).collect(Collectors.joining(",")); + data.setSdtName(sdtName); + } + if(StringUtils.isNotEmpty(data.getDutyPerson())){ + String dutyPersonName = sysUserList.stream().filter(sysUser -> { + boolean flag = false; + if (StringUtils.equals(sysUser.getId(), data.getDutyPerson())) { + flag = true; + } + return flag; + }).map(SysUser::getUsername).collect(Collectors.joining(",")); + data.setDutyPersonName(dutyPersonName); + } + if(StringUtils.isNotEmpty(data.getFlowStatus())){ + data.setFlowStatusName(CertificationInventoryFlowStatusEnum.getTextByValue(data.getFlowStatus(),cut)); + } + if(StringUtils.isNotEmpty(data.getDeliverableType())){ + String deliverableTypeName = this.getTreeName(cut, categoryList, Arrays.asList(data.getDeliverableType().split(","))); + data.setDeliverableTypeName(deliverableTypeName); + + String deliverableTypeNameEn = this.getTreeName(CutEnum.EN.getValue(), categoryList, Arrays.asList(data.getDeliverableType().split(","))); + data.setDeliverableTypeNameEn(deliverableTypeNameEn); + + String valueType = categoryList.stream().filter(category -> { + boolean flag = false; + if (StringUtils.equals(data.getDeliverableType(), category.getId())) { + flag = true; + } + return flag; + }).map(SysCategory::getValueType).distinct().collect(Collectors.joining(",")); + data.setValueType(valueType); + } + if(StringUtils.isNotEmpty(data.getDutyTerritory())){ + String dutyTerritoryName = this.sysDictItemService.disposeShowDictItemValue(sysDictItems,data.getDutyTerritory(),cut, ProjectInventoryFieldEnum.DUTY_TERRITORY.getValue()); + data.setDutyTerritoryName(dutyTerritoryName); + } + if(StringUtils.isNotEmpty(data.getCertificationProgress())){ + String certificationProgress_dictText = ""; + List collect = certificationProgress.stream() + .filter(dict -> StringUtils.equals(dict.getItemValue(), data.getCertificationProgress())) + .collect(Collectors.toList()); + if(CollectionUtils.isNotEmpty(collect)){ + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + certificationProgress_dictText = collect.get(0).getItemText(); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + certificationProgress_dictText = collect.get(0).getEnName(); + } + } + data.setCertificationProgress_dictText(certificationProgress_dictText); + } +// String GetEndTime = String.valueOf(data.getEndTime()); +// if(StringUtils.isNotEmpty(GetEndTime)){ +// Date endTime = new Date(); +// if(StringUtils.equals(cut,CutEnum.CN.getValue())){ +// endTime = data.getEndTime(); +// }else { +// endTime = data.getEndTime(); +// } +// data.setEndTimeStr(String.valueOf(endTime)); +// } + if(StringUtils.isNotEmpty(data.getAttestationType())){ + String attestationTypeName = this.sysDictItemService.disposeShowDictItemValue(sysDictItems,data.getAttestationType(),cut, "ren4_zheng4_qing1_dan1_-_ren4_zheng4_lei4_xing2"); + data.setAttestationTypeName(attestationTypeName); + } + + if(StringUtils.isNotEmpty(data.getCertificationProgress())){ + String cpNumber = CertificationProgressEnum.getNumberByValue(data.getCertificationProgress()); + data.setCertificationProgressNumber(cpNumber); + } + } + } + } + + + + @Override + public String getTreeName(String cut, List categoryList, List technologyTerritoryList) { + StringBuilder sb = new StringBuilder(); + for (String technologyTerritory : technologyTerritoryList) { + List collect = categoryList.stream().filter(e -> technologyTerritory.equals(e.getId())).collect(Collectors.toList()); + if(collect.size() != 0){ + if (CutEnum.CN.getValue().equals(cut)) { + sb.append(collect.get(0).getName() + ","); + } else { + sb.append(collect.get(0).getEnName()+ ","); + } + } + } + String technologyTerritoryName = ""; + if (StringUtils.isNotBlank(sb)) { + technologyTerritoryName = sb.substring(0, sb.length() - 1); + } + return technologyTerritoryName; + } + + + /** + * 发布 + * @param json + * @return + */ + @Override + public Result issue(JSONObject json) { + String ids = json.getString("ids"); + String projectLibraryId = json.getString("projectLibraryId"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行发布!"); + } + String inventoryVerifyEndTimeStr = json.getString("inventoryVerifyEndTime"); + Date inventoryVerifyEndTime = DateUtils.str2Date(inventoryVerifyEndTimeStr, DateUtils.date_sdf.get()); + + String cut = json.getString("cut"); + + List idList = Arrays.asList(ids.split(",")); + + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue()); + + // 根据页面选择的认证清单数据id,查询出状态为’清单待发布‘的数据,进行发布处理 + QueryWrapper certificationQueryWrap = new QueryWrapper<>(); + certificationQueryWrap.lambda().in(ProjectCertificationInventoryEO::getId,idList); + certificationQueryWrap.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(certificationQueryWrap); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + throw new JeroBootException("Select at least one data flow whose status is' List to be released or Certification returned '!"); + }else { + throw new JeroBootException("至少选择一条数据流程状态为'清单待发布 或 认证退回'的数据!"); + } + + } + List processInfoDetailEOList = new ArrayList<>(); + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + // 将数据的状态更新为:清单待校核,更新截止时间。等待认证工程师进行操作。 + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()); + projectCertificationInventoryEO.setInventoryVerifyEndTime(inventoryVerifyEndTime); + processHistoryEOService.add(projectCertificationInventoryEO.getId(),CertificationFlowNodeEnum.LIST_CONFIRMATION.getKey(),currentUser.getId(),null,null,null); + } + + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_ISSUE.getValue()); + + this.updateBatchById(projectCertificationInventoryEOList); + + // 根据项目库id查询当前项目认证清单数据,获取清单校核截止时间 最早的一个时间 + flowStatusList.clear(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue()); + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,projectLibraryId); + pciQueryWrap.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List pciEoList = this.list(pciQueryWrap); + if(CollectionUtils.isNotEmpty(pciEoList)){ + List inventoryVerifyEndTimeList = pciEoList.stream().map(ProjectCertificationInventoryEO::getInventoryVerifyEndTime).distinct().collect(Collectors.toList()); + inventoryVerifyEndTimeList.add(inventoryVerifyEndTime); + Collections.sort(inventoryVerifyEndTimeList, (d1, d2) -> d1.compareTo(d2)); // 根据时间顺序排序 + inventoryVerifyEndTime = inventoryVerifyEndTimeList.get(0); + } + + // 获取项目信息,获取认证工程师,给认证工程师分配待办任务 + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectLibraryId); + if(ObjectUtils.isNotEmpty(projectLibraryBase)){ + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + if(ObjectUtils.isEmpty(projectLibraryBase)){ + throw new JeroBootException("无法获取项目信息,请稍后重试!"); + } + String certificationEngineer = projectLibraryBase.getCertificationEngineer(); + if(StringUtils.isEmpty(certificationEngineer)){ + if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + throw new JeroBootException("There is no certified engineer in this project. Please maintain the certified engineer first!"); + }else { + throw new JeroBootException("该项目中认证工程师为空,请先维护认证工程师!"); + } + } + + List certificationEngineerIdList = Arrays.asList(certificationEngineer.split(",")); + // 给认证工程师分配任务 + for (String userId : certificationEngineerIdList) { + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(userId); + processInfoDetailEO.setTaskDefinitionKey(CertificationFlowNodeEnum.RZGCSJSRW.getKey()); + processInfoDetailEO.setCreateTime(new Date()); + processInfoDetailEO.setStatus(TaskStatusEnum.NOT_DONE.getValue()); + processInfoDetailEO.setProcessInfoId(projectLibraryId); + processInfoDetailEO.setActiProcInstId(projectLibraryId); + processInfoDetailEO.setFlowType(FlowTypeEnum.CERTIFICATION_LC.getValue()); + processInfoDetailEO.setEndTime(inventoryVerifyEndTime); + processInfoDetailEOList.add(processInfoDetailEO); + } + + ProcessInfoEO processInfoEO = new ProcessInfoEO(); + this.addProcessInfoEO(processInfoEO,projectLibraryId); + + // 删除该项目数据的待办任务,key为 认证工程师接受任务的数据 + QueryWrapper deleteDetailWrap = new QueryWrapper<>(); + deleteDetailWrap.lambda().eq(ProcessInfoDetailEO::getProcessInfoId,processInfoEO.getId()); + deleteDetailWrap.lambda().eq(ProcessInfoDetailEO::getTaskDefinitionKey,CertificationFlowNodeEnum.RZGCSJSRW.getKey()); + deleteDetailWrap.lambda().eq(ProcessInfoDetailEO::getFlowType,FlowTypeEnum.CERTIFICATION_LC.getValue()); + this.processInfoDetailEOService.remove(deleteDetailWrap); + this.processInfoDetailEOService.saveBatch(processInfoDetailEOList); + + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryId, PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + String hrefFeishu_CN_P = (String) hrefFeishuMap.get("hrefFeishu_CN_P"); + + + List certificationEngineerUserInfoList = this.sysUserService.querySysUserListByIdList(certificationEngineerIdList); + Date finalInventoryVerifyEndTime = inventoryVerifyEndTime; + certificationEngineerIdList.forEach(userId -> { + try { + String thirdId = this.sysUserService.getUserThirdIdByUserId(certificationEngineerUserInfoList,userId); + + if(StringUtils.isNotEmpty(thirdId)){ + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE2.getValue()); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(finalInventoryVerifyEndTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlCnPhone",hrefFeishu_CN_P); + + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + }); + } + + return Result.OK("发布成功!"); + } + + + /** + * 添加流程信息 + * @param processInfoEO + * @param projectLibraryId + */ + @Override + public void addProcessInfoEO(ProcessInfoEO processInfoEO,String projectLibraryId){ + processInfoEO.setId(projectLibraryId); + processInfoEO.setProjectLibraryId(projectLibraryId); + processInfoEO.setActiProcInstId(projectLibraryId); + processInfoEO.setFlowType(FlowTypeEnum.CERTIFICATION_LC.getValue()); + // processInfoEO.setStatus(TodoCenterStatusEnum.LIST_TO_CONFIRM.getValue()); + + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + processInfoEO.setCreateBy(currentUser.getId()); + + QueryWrapper deleteWrap = new QueryWrapper<>(); + deleteWrap.lambda().eq(ProcessInfoEO::getId,projectLibraryId); + this.processInfoEOService.remove(deleteWrap); + this.processInfoEOService.add(processInfoEO); + } + + /** + * 添加流程信息,用户的待办信息。 + * @param processInfoDetailEOList + * @param processInfoId + */ + @Override + public void addProcessInfoDetailEO(List processInfoDetailEOList,String processInfoId,String taskDefinitionKey){ + processInfoDetailEOList.forEach(detail -> { + detail.setActiProcInstId(processInfoId); + detail.setProcessInfoId(processInfoId); + detail.setFlowType(FlowTypeEnum.CERTIFICATION_LC.getValue()); + detail.setTaskDefinitionKey(taskDefinitionKey); + detail.setStatus(TaskStatusEnum.NOT_DONE.getValue()); + detail.setCreateTime(new Date()); + }); + + List userIdList = processInfoDetailEOList.stream().map(ProcessInfoDetailEO::getUserId).distinct().collect(Collectors.toList()); + QueryWrapper removeWrap = new QueryWrapper<>(); + removeWrap.lambda().eq(ProcessInfoDetailEO::getProcessInfoId,processInfoId); + removeWrap.lambda().in(ProcessInfoDetailEO::getUserId,userIdList); + removeWrap.lambda().eq(ProcessInfoDetailEO::getTaskDefinitionKey,taskDefinitionKey); + if(!StringUtils.equals(taskDefinitionKey,CertificationFlowNodeEnum.RZGCSSC.getKey())){ + List dataIdList = processInfoDetailEOList.stream().map(ProcessInfoDetailEO::getProjectLawsInventoryId).distinct().collect(Collectors.toList()); + removeWrap.lambda().in(ProcessInfoDetailEO::getProjectLawsInventoryId,dataIdList); + } + // 删除用户在这个认证清单流程中其它的待办任务 + this.processInfoDetailEOService.remove(removeWrap); + + this.processInfoDetailEOService.saveBatch(processInfoDetailEOList); + } + + @Override + public Result> getRoleByUserId(Map params) { + Result> result = new Result<>(); + String projectLibraryId = (String) params.get("projectLibraryId"); + String cut = (String) params.get("cut"); + + List sysRoles = new LinkedList<>(); + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + //项目详情中取R&H Studio和认证工程师 + List projectLibraryBases = projectLibraryBaseService.queryById(projectLibraryId,null); + String certificationEngineerName = ""; + if(projectLibraryBases.size() != 0){ + certificationEngineerName = projectLibraryBases.get(0).getCertificationEngineerName(); + String studioEngineerName = projectLibraryBases.get(0).getStudioEngineerName(); + // studio + if(StringUtils.isNotBlank(studioEngineerName) && studioEngineerName.equals(loginUser.getUsername())){ + SysRole sysRole = new SysRole(); + sysRole.setRoleCode(ProjectRoleEnum.STUDIO_ENGINEER.getValue()); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.STUDIO_ENGINEER.getName()); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.STUDIO_ENGINEER.getCode()); + } + + sysRoles.add(sysRole); + } + + // 认证 + if((StringUtils.isNotBlank(certificationEngineerName) && certificationEngineerName.contains(loginUser.getUsername()))){ + SysRole sysRole = new SysRole(); + sysRole.setRoleCode(ProjectRoleEnum.HOMOLOGATION_ENGINEER.getValue()); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.HOMOLOGATION_ENGINEER.getName()); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.HOMOLOGATION_ENGINEER.getCode()); + } + sysRoles.add(sysRole); + } + + // 法规 + //相关人员名单中取法规工程师 + List projectRelatedPersonnels = this.projectRelatedPersonnelService.queryPageList(projectLibraryId,null,null,null,null,null,null); + List lawEngineerNameList = new ArrayList<>(); + if(projectRelatedPersonnels.size() != 0){ + for (ProjectRelatedPersonnel projectRelatedPersonnel : projectRelatedPersonnels) { + String lawEngineerName = projectRelatedPersonnel.getLawEngineerName(); + if(StringUtils.isNotBlank(lawEngineerName)){ + lawEngineerName = lawEngineerName.replaceAll(" ",""); + lawEngineerNameList.addAll(Arrays.asList(lawEngineerName.split(","))); + } + } + + if(lawEngineerNameList.contains(loginUser.getUsername())){ + SysRole sysRole = new SysRole(); + sysRole.setRoleCode(ProjectRoleEnum.REGULATI_ENGINEER.getValue()); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.REGULATI_ENGINEER.getName()); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.REGULATI_ENGINEER.getCode()); + } + sysRoles.add(sysRole); + } + } + + // 接口人 + QueryWrapper querySdtCountWrap = new QueryWrapper<>(); + querySdtCountWrap.lambda().eq(ProjectCertificationInventoryEO::getSdt,loginUser.getId()); + querySdtCountWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,projectLibraryId); + Integer sdtCount = this.baseMapper.selectCount(querySdtCountWrap); + if(sdtCount > 0){ + SysRole sysRole = new SysRole(); + sysRole.setRoleCode(ProjectRoleEnum.INTERFACE_PERSON.getValue()); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.INTERFACE_PERSON.getName()); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.INTERFACE_PERSON.getCode()); + } + sysRoles.add(sysRole); + } + + // 责任人 + QueryWrapper queryDutyPersonCountWrap = new QueryWrapper<>(); + queryDutyPersonCountWrap.lambda().eq(ProjectCertificationInventoryEO::getDutyPerson,loginUser.getId()); + queryDutyPersonCountWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,projectLibraryId); + Integer dutyPersonCount = this.baseMapper.selectCount(queryDutyPersonCountWrap); + if(dutyPersonCount > 0){ + SysRole sysRole = new SysRole(); + sysRole.setRoleCode(ProjectRoleEnum.PERSON_LIABLE.getValue()); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.PERSON_LIABLE.getName()); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + sysRole.setRoleName(ProjectRoleEnum.PERSON_LIABLE.getCode()); + } + sysRoles.add(sysRole); + } + } + + // 领导、系统管理员、Viewer、品牌管理员 处理 + List roleList = this.sysRoleMapper.getRoleByUserId(loginUser.getId()); + if (roleList.size() != 0) { + List manager = roleList.stream().filter(e -> ProjectRoleEnum.MANAGER.getCode().equals(e.getRoleCode())).collect(Collectors.toList()); + List admin = roleList.stream().filter(e -> ProjectRoleEnum.ADMIN.getCode().equals(e.getRoleCode())).collect(Collectors.toList()); + List Viewer = roleList.stream().filter(e -> ProjectRoleEnum.VIEWER.getCode().equals(e.getRoleCode())).collect(Collectors.toList()); + List brandAdministrator = roleList.stream().filter(e -> ProjectRoleEnum.BRAND_ADMINISTRATOR.getCode().equals(e.getRoleCode())).collect(Collectors.toList()); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + if (manager.size() != 0) { + manager.get(0).setRoleCode(ProjectRoleEnum.MANAGER.getValue()); + sysRoles.addAll(manager); + } + if (admin.size() != 0) { + admin.get(0).setRoleCode(ProjectRoleEnum.ADMIN.getValue()); + sysRoles.addAll(admin); + } + if (Viewer.size() != 0) { + Viewer.get(0).setRoleCode(ProjectRoleEnum.VIEWER.getValue()); + sysRoles.addAll(Viewer); + } + if (brandAdministrator.size() != 0) { + brandAdministrator.get(0).setRoleCode(ProjectRoleEnum.BRAND_ADMINISTRATOR.getValue()); + sysRoles.addAll(brandAdministrator); + } + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + if (manager.size() != 0) { + manager.get(0).setRoleCode(ProjectRoleEnum.MANAGER.getValue()); + manager.get(0).setRoleName(ProjectRoleEnum.MANAGER.getCode()); + sysRoles.addAll(manager); + } + if (admin.size() != 0) { + admin.get(0).setRoleCode(ProjectRoleEnum.ADMIN.getValue()); + admin.get(0).setRoleName(ProjectRoleEnum.ADMIN.getCode()); + sysRoles.addAll(admin); + } + if (Viewer.size() != 0) { + Viewer.get(0).setRoleCode(ProjectRoleEnum.VIEWER.getValue()); + Viewer.get(0).setRoleName(ProjectRoleEnum.VIEWER.getCode()); + sysRoles.addAll(Viewer); + } + if (brandAdministrator.size() != 0) { + brandAdministrator.get(0).setRoleCode(ProjectRoleEnum.BRAND_ADMINISTRATOR.getValue()); + brandAdministrator.get(0).setRoleName(ProjectRoleEnum.BRAND_ADMINISTRATOR.getCode()); + sysRoles.addAll(brandAdministrator); + } + + } + + } + + if(sysRoles==null||sysRoles.size()<=0) { + result.error500("未找到角色信息"); + }else { + result.setResult(sysRoles); + result.setSuccess(true); + } + return result; + } + + @Override + public Result getFlowStatusList(String cut) { + List> result = new ArrayList<>(); + CertificationInventoryFlowStatusEnum[] values = CertificationInventoryFlowStatusEnum.values(); + for (CertificationInventoryFlowStatusEnum value : values) { + Map flowStatusMap = new HashMap<>(); + String name = value.getCnName(); + if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + name = value.getEnName(); + } + flowStatusMap.put("name",name); + flowStatusMap.put("value",value.getValue()); + result.add(flowStatusMap); + } + return Result.OK(result); + } + + @Override + public IPage queryPage(QueryWrapper queryWrapper, + Page page, + ProjectCertificationInventoryEO projectCertificationInventoryEO, + String cut) { + + String roleCode = projectCertificationInventoryEO.getRoleCode(); + // 创建查询权限 + this.createQueryPermission(queryWrapper,roleCode); + // 根据一级责任领域(统计节点),查询该一级责任领域下所有子责任领域的法规清单数据。 + String dutyTerritoryStr = ""; + if(StringUtils.isNotEmpty(projectCertificationInventoryEO.getFirstLevelDutyTerritory())){ + List sysDictItems = this.sysDictItemServiceImpl.selectItemsAll(); + List dutyTerritorys = new ArrayList<>(); + Map> firstLevelDTMap = this.sysDictItemServiceImpl.getFirstLevelSysDictItemByDictCode(DictCodeEnum.DUTY_TERRITORY.getValue(), sysDictItems); + String[] firstLevelDTArr = projectCertificationInventoryEO.getFirstLevelDutyTerritory().split(","); + for (String firstLevelDT : firstLevelDTArr){ + if(CollectionUtils.isNotEmpty(firstLevelDTMap.get(firstLevelDT))){ + dutyTerritorys.addAll(firstLevelDTMap.get(firstLevelDT)); + } + } + if(CollectionUtils.isNotEmpty(dutyTerritorys)){ + dutyTerritoryStr = dutyTerritorys.stream().map(SysDictItem::getItemValue).distinct().collect(Collectors.joining(",")); + } + } + if (StringUtils.isNotEmpty(dutyTerritoryStr)) { + String finalDutyTerritoryStr = dutyTerritoryStr.replaceAll("\\*",""); + queryWrapper.and(query -> { + query.lambda().like(ProjectCertificationInventoryEO::getDutyTerritory, finalDutyTerritoryStr); + if(StringUtils.contains(finalDutyTerritoryStr,",")){ + String[] dutyTerritoryArr = finalDutyTerritoryStr.split(","); + for (String duty : dutyTerritoryArr) { + query.or(q -> { + q.like("duty_territory",duty); + }); + } + } + }); + } + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + int isProjectRole = Integer.parseInt(roleCode); + if (isProjectRole == Integer.parseInt(com.jero.modules.project.enums.ProjectRoleEnum.VIEWER.getValue())) { + //查当前用户Viewer对应责任领域 + List dutyTerritoryList = this.projectUserDutyTerritoryService.queryDutyTerritoryByUserId(currentUser.getId()); + if (ObjectUtils.isNotEmpty(dutyTerritoryList)) { + queryWrapper.and(query -> { + for (String duty : dutyTerritoryList) { + query.or(q -> { + q.like("duty_territory", duty); + }); + } + }); + } + } + IPage pageList = this.page(page, queryWrapper); + this.disposeData(pageList.getRecords(),cut); + List records = this.hearSort(projectCertificationInventoryEO, pageList.getRecords()); + pageList.setRecords(records); + return pageList; + } + + /** + * 表头排序 + * @param pciEo + * @param datas + * @return + */ + private List hearSort(ProjectCertificationInventoryEO pciEo, List datas) { + String orderBy = pciEo.getOrderBy(); + String orderByField = pciEo.getOrderByField(); + if(ObjectUtils.isNotEmpty(orderByField)){ + Collator comparator = Collator.getInstance(Locale.CHINESE); + // 类别 category + if(StringUtils.equals("category",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1Category = (StringUtils.isNotEmpty(e1.getCategory()) ? e1.getCategory() : ""); + String e2Category = (StringUtils.isNotEmpty(e2.getCategory()) ? e2.getCategory() : ""); + return comparator.compare(e1Category,e2Category); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1Category = (StringUtils.isNotEmpty(e1.getCategory()) ? e1.getCategory() : ""); + String e2Category = (StringUtils.isNotEmpty(e2.getCategory()) ? e2.getCategory() : ""); + return comparator.compare(e2Category,e1Category); + }); + } + } + + // 检验项目 inspectionItem + if(StringUtils.equals("inspectionItem",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1InspectionItem = (StringUtils.isNotEmpty(e1.getInspectionItem()) ? e1.getInspectionItem() : ""); + String e2InspectionItem = (StringUtils.isNotEmpty(e2.getInspectionItem()) ? e2.getInspectionItem() : ""); + return comparator.compare(e1InspectionItem,e2InspectionItem); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1InspectionItem = (StringUtils.isNotEmpty(e1.getInspectionItem()) ? e1.getInspectionItem() : ""); + String e2InspectionItem = (StringUtils.isNotEmpty(e2.getInspectionItem()) ? e2.getInspectionItem() : ""); + return comparator.compare(e2InspectionItem,e1InspectionItem); + }); + } + } + + // 认证类型 attestationTypeName + if(StringUtils.equals("attestationTypeName",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1AttestationTypeName = (StringUtils.isNotEmpty(e1.getAttestationTypeName()) ? e1.getAttestationTypeName() : ""); + String e2AttestationTypeName = (StringUtils.isNotEmpty(e2.getAttestationTypeName()) ? e2.getAttestationTypeName() : ""); + return comparator.compare(e1AttestationTypeName,e2AttestationTypeName); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1AttestationTypeName = (StringUtils.isNotEmpty(e1.getAttestationTypeName()) ? e1.getAttestationTypeName() : ""); + String e2AttestationTypeName = (StringUtils.isNotEmpty(e2.getAttestationTypeName()) ? e2.getAttestationTypeName() : ""); + return comparator.compare(e2AttestationTypeName,e1AttestationTypeName); + }); + } + } + + // WVTA ID wvtaId + if(StringUtils.equals("wvtaId",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1WvtaId = (StringUtils.isNotEmpty(e1.getWvtaId()) ? e1.getWvtaId() : ""); + String e2WvtaId = (StringUtils.isNotEmpty(e2.getWvtaId()) ? e2.getWvtaId() : ""); + return comparator.compare(e1WvtaId,e2WvtaId); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1WvtaId = (StringUtils.isNotEmpty(e1.getWvtaId()) ? e1.getWvtaId() : ""); + String e2WvtaId = (StringUtils.isNotEmpty(e2.getWvtaId()) ? e2.getWvtaId() : ""); + return comparator.compare(e2WvtaId,e1WvtaId); + }); + } + } + + // 标准编号 serialNumber + if(StringUtils.equals("serialNumber",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1SerialNumber = (StringUtils.isNotEmpty(e1.getSerialNumber()) ? e1.getSerialNumber() : ""); + String e2SerialNumber = (StringUtils.isNotEmpty(e2.getSerialNumber()) ? e2.getSerialNumber() : ""); + return comparator.compare(e1SerialNumber,e2SerialNumber); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1SerialNumber = (StringUtils.isNotEmpty(e1.getSerialNumber()) ? e1.getSerialNumber() : ""); + String e2SerialNumber = (StringUtils.isNotEmpty(e2.getSerialNumber()) ? e2.getSerialNumber() : ""); + return comparator.compare(e2SerialNumber,e1SerialNumber); + }); + } + } + + // 责任领域 dutyTerritoryName + if(StringUtils.equals("dutyTerritoryName",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1DutyTerritoryName = (StringUtils.isNotEmpty(e1.getDutyTerritoryName()) ? e1.getDutyTerritoryName() : ""); + String e2DutyTerritoryName = (StringUtils.isNotEmpty(e2.getDutyTerritoryName()) ? e2.getDutyTerritoryName() : ""); + return comparator.compare(e1DutyTerritoryName,e2DutyTerritoryName); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1DutyTerritoryName = (StringUtils.isNotEmpty(e1.getDutyTerritoryName()) ? e1.getDutyTerritoryName() : ""); + String e2DutyTerritoryName = (StringUtils.isNotEmpty(e2.getDutyTerritoryName()) ? e2.getDutyTerritoryName() : ""); + return comparator.compare(e2DutyTerritoryName,e1DutyTerritoryName); + }); + } + } + + // 工程接口人 sdtName + if(StringUtils.equals("sdtName",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1SdtName = (StringUtils.isNotEmpty(e1.getSdtName()) ? e1.getSdtName() : ""); + String e2SdtName = (StringUtils.isNotEmpty(e2.getSdtName()) ? e2.getSdtName() : ""); + return comparator.compare(e1SdtName,e2SdtName); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1SdtName = (StringUtils.isNotEmpty(e1.getSdtName()) ? e1.getSdtName() : ""); + String e2SdtName = (StringUtils.isNotEmpty(e2.getSdtName()) ? e2.getSdtName() : ""); + return comparator.compare(e2SdtName,e1SdtName); + }); + } + } + + // 责任人 dutyPersonName + if(StringUtils.equals("dutyPersonName",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1DutyPersonName = (StringUtils.isNotEmpty(e1.getDutyPersonName()) ? e1.getDutyPersonName() : ""); + String e2DutyPersonName = (StringUtils.isNotEmpty(e2.getDutyPersonName()) ? e2.getDutyPersonName() : ""); + return comparator.compare(e1DutyPersonName,e2DutyPersonName); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1DutyPersonName = (StringUtils.isNotEmpty(e1.getDutyPersonName()) ? e1.getDutyPersonName() : ""); + String e2DutyPersonName = (StringUtils.isNotEmpty(e2.getDutyPersonName()) ? e2.getDutyPersonName() : ""); + return comparator.compare(e2DutyPersonName,e1DutyPersonName); + }); + } + } + + // 交付物类型 deliverableTypeName + if(StringUtils.equals("deliverableTypeName",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1DeliverableTypeName = (StringUtils.isNotEmpty(e1.getDeliverableTypeName()) ? e1.getDeliverableTypeName() : ""); + String e2DeliverableTypeName = (StringUtils.isNotEmpty(e2.getDeliverableTypeName()) ? e2.getDeliverableTypeName() : ""); + return comparator.compare(e1DeliverableTypeName,e2DeliverableTypeName); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1DeliverableTypeName = (StringUtils.isNotEmpty(e1.getDeliverableTypeName()) ? e1.getDeliverableTypeName() : ""); + String e2DeliverableTypeName = (StringUtils.isNotEmpty(e2.getDeliverableTypeName()) ? e2.getDeliverableTypeName() : ""); + return comparator.compare(e2DeliverableTypeName,e1DeliverableTypeName); + }); + } + } + + // 截止日期 endTime + if(StringUtils.equals("endTime",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1EndTime = (e1.getEndTime() != null ? DateUtils.formatDate(e1.getEndTime()) : ""); + String e2EndTime = (e2.getEndTime() != null ? DateUtils.formatDate(e2.getEndTime()) : ""); + return comparator.compare(e1EndTime,e2EndTime); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1EndTime = (e1.getEndTime() != null ? DateUtils.formatDate(e1.getEndTime()) : ""); + String e2EndTime = (e2.getEndTime() != null ? DateUtils.formatDate(e2.getEndTime()) : ""); + return comparator.compare(e2EndTime,e1EndTime); + }); + } + } + + // 流程状态 flowStatusName + if(StringUtils.equals("flowStatusName",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1FlowStatusName = (StringUtils.isNotEmpty(e1.getFlowStatusName()) ? e1.getFlowStatusName() : ""); + String e2FlowStatusName = (StringUtils.isNotEmpty(e2.getFlowStatusName()) ? e2.getFlowStatusName() : ""); + return comparator.compare(e1FlowStatusName,e2FlowStatusName); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1FlowStatusName = (StringUtils.isNotEmpty(e1.getFlowStatusName()) ? e1.getFlowStatusName() : ""); + String e2FlowStatusName = (StringUtils.isNotEmpty(e2.getFlowStatusName()) ? e2.getFlowStatusName() : ""); + return comparator.compare(e2FlowStatusName,e1FlowStatusName); + }); + } + } + + // 认证进度 certificationProgress + if(StringUtils.equals("certificationProgress",orderByField)){ + if(OrderEnum.POSITIVE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1, e2)->{ + String e1CertificationProgressNumber = (StringUtils.isNotEmpty(e1.getCertificationProgressNumber()) ? e1.getCertificationProgressNumber() : ""); + String e2CertificationProgressNumber = (StringUtils.isNotEmpty(e2.getCertificationProgressNumber()) ? e2.getCertificationProgressNumber() : ""); + return comparator.compare(e1CertificationProgressNumber,e2CertificationProgressNumber); + }); + }else if(OrderEnum.REVERSE.getValue().equals(orderBy)){ + Collections.sort(datas,(e1,e2)->{ + String e1CertificationProgressNumber = (StringUtils.isNotEmpty(e1.getCertificationProgressNumber()) ? e1.getCertificationProgressNumber() : ""); + String e2CertificationProgressNumber = (StringUtils.isNotEmpty(e2.getCertificationProgressNumber()) ? e2.getCertificationProgressNumber() : ""); + return comparator.compare(e2CertificationProgressNumber,e1CertificationProgressNumber); + }); + } + } + } + return datas; + } + + @Override + public void createQueryPermission(QueryWrapper queryWrapper, String roleCode) { + /** + * 处理查询权限 + * studio、法规工程师、领导、系统管理员、Viewer、品牌管理员: 可以查询所有数据 + * 认证工程师:可以查询所有数据 + * 接口人:可查看所有接口人为自己的数据 + * 责任人:可以查看流程状态为:任务待确认、结果待提交 、审查通过(并且责任人为自己) + */ + ProjectRoleEnum projectRoleEnum = ProjectRoleEnum.getByValue(roleCode); + if(ObjectUtils.isEmpty(projectRoleEnum)){ + throw new JeroBootException("当前用户角色有误,请重新选择后角色进行操作!"); + } + + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + switch (projectRoleEnum){ + case STUDIO_ENGINEER: + break; + case REGULATI_ENGINEER: + break; + case MANAGER: + break; + case ADMIN: + break; + case VIEWER: + break; + case BRAND_ADMINISTRATOR: + break; + case HOMOLOGATION_ENGINEER: + break; + case INTERFACE_PERSON: + queryWrapper.lambda().eq(ProjectCertificationInventoryEO::getSdt,currentUser.getId()); + break; + case PERSON_LIABLE: + /*List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()); + + queryWrapper.lambda().and(queryWrap -> { + queryWrap.and(query -> { + query.eq(ProjectCertificationInventoryEO::getDutyPerson,currentUser.getId()); + query.in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + }).or(query -> { + query.eq(ProjectCertificationInventoryEO::getSdt,currentUser.getId()); + query.eq(ProjectCertificationInventoryEO::getFlowStatus,CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()); + }); + });*/ + // 修改UAT问题清单 82条 + queryWrapper.lambda().eq(ProjectCertificationInventoryEO::getDutyPerson,currentUser.getId()); + break; + default: + throw new JeroBootException("当前用户角色有误,请重新选择后角色进行操作!"); + } + } + + + @Override + public Result submitTask(JSONObject json) { + if (!json.containsKey("nodeKey")) { + throw new JeroBootException("nodeKey不能为空,请联系管理员!"); + } + + String nodeKey = json.getString("nodeKey"); + + CertificationFlowNodeEnum flowNodeEnum = CertificationFlowNodeEnum.getEnumByKey(nodeKey); + if(ObjectUtils.isEmpty(flowNodeEnum)){ + throw new JeroBootException("根据" + nodeKey + " 的操作节点没有获取到节点信息,请联系管理员!"); + } + + String projectLibraryId = json.getString("projectLibraryId"); + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectLibraryId); + if(ObjectUtils.isEmpty(projectLibraryBase)){ + throw new JeroBootException("无法获取项目库信息,项目库id为:" + projectLibraryId + " 请联系管理员!"); + } + json.put("projectLibraryBase",projectLibraryBase); + + + switch (flowNodeEnum){ + case RZGCSJSRW: + return this.certificationInitiatingTask(json); + case RZGCSTHRW: + return this.certificationReturnedStudioTask(json); + case ZRRJSRW: + return this.dutyPersonAcceptTask(json); + case ZRRJJRW: + return this.dutyPersonRejectTask(json); + case ZRRTJRW: + return this.dutyPersonSubmitTask(json); + case RZGCSSC: + + break; + case RZGCSSC_TG: + return this.certificationReviewThrough(json); + case RZGCSSC_TH: + return this.certificationReviewReturned(json); + default: + throw new JeroBootException(nodeKey + " 的操作节点传递有误,请联系管理员!"); + } + + return Result.OK("提交任务成功!"); + } + + /** + * 认证工程师审查退回 + * @param json + * @return + */ + private Result certificationReviewReturned(JSONObject json) { + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + String reasonForReturn = json.getString("reasonForReturn"); + + List idList = Arrays.asList(ids.split(",")); + + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'结果待审查'的数据!"); + } + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()); + projectCertificationInventoryEO.setReasonForReturn(reasonForReturn); + processHistoryEOService.add(projectCertificationInventoryEO.getId(),CertificationFlowNodeEnum.TASK_REVIEW.getKey(),currentUser.getId(),ReviewResultEnum.RETURNED.getValue(),reasonForReturn,null); + } + + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_REVIEW_RETURNED.getValue()); + + ProjectLibraryBase projectLibraryBase = JSONObject.parseObject(JSONObject.toJSONString(json.get("projectLibraryBase")), ProjectLibraryBase.class); + List dutyPersonIdList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList()); + List dutyPersonList = this.sysUserService.querySysUserListByIdList(dutyPersonIdList); + + // 获取当前项目下,认证清单,截止日期最早的一个,更新到流程明细表中,认证工程师审查任务节点的截止时间中 + flowStatusList.clear(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + this.updateProcessInfoDetailEndTime( + flowStatusList, + CertificationFlowNodeEnum.RZGCSSC.getKey(), + projectLibraryBase, + "end_time", + idList + ); + try { + // 给责任人分配待办中心的任务 + List processInfoDetailEOList = new ArrayList<>(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(projectCertificationInventoryEO.getDutyPerson()); + processInfoDetailEO.setEndTime(projectCertificationInventoryEO.getEndTime()); + processInfoDetailEO.setProjectLawsInventoryId(projectCertificationInventoryEO.getId()); + processInfoDetailEOList.add(processInfoDetailEO); + } + this.addProcessInfoDetailEO(processInfoDetailEOList,projectLibraryBase.getId(),CertificationFlowNodeEnum.ZRRTJRW.getKey()); + + // 更新数据状态为 审查退回 + this.updateBatchById(projectCertificationInventoryEOList); + + List flowStatus = new ArrayList<>(); + flowStatus.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + + // 更新该项目认证流程中,认证工程师的任务状态。 + // 如果还有 结果待审查 的数据,不做操作,如果没有 将这个项目认证流程的所有认证工程师待办任务转为已办 flowStatus + this.updateProcessInfoDetailStatus(projectLibraryBase,CertificationFlowNodeEnum.RZGCSSC.getKey(),flowStatus); + + this.certificationInventoryEOListSortByEndTimeAsc(projectCertificationInventoryEOList); + this.sendMessageByTemplateId( + projectCertificationInventoryEOList, + TemplateInfoEnum2.CERTIFICATION_MESSAGE24.getValue(), + dutyPersonIdList, + dutyPersonList, + projectCertificationInventoryEOList.get(0).getEndTime(), + CertificationFlowNodeEnum.TASK_HANDLING.getKey() + ); + }catch (Exception ex){ + ex.printStackTrace(); + log.error("认证工程师-审批退回失败:" + ex.getMessage()); + throw new JeroBootException("审批退回失败!"); + } + + return Result.OK("审批退回成功!"); + } + + /** + * 认证工程师审查通过 + * @param json + * @return + */ + private Result certificationReviewThrough(JSONObject json) { + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + List idList = Arrays.asList(ids.split(",")); + + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'结果待审查'的数据!"); + } + + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()); + processHistoryEOService.add(projectCertificationInventoryEO.getId(),CertificationFlowNodeEnum.TASK_REVIEW.getKey(),currentUser.getId(),null,null,null); + + } + + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_REVIEW_THROUGH.getValue()); + + ProjectLibraryBase projectLibraryBase = JSONObject.parseObject(JSONObject.toJSONString(json.get("projectLibraryBase")), ProjectLibraryBase.class); + List dutyPersonIdList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList()); + List dutyPersonList = this.sysUserService.querySysUserListByIdList(dutyPersonIdList); + + // 获取当前项目下,认证清单,截止日期最早的一个,更新到流程明细表中,认证工程师审查任务节点的截止时间中 + this.updateProcessInfoDetailEndTime( + flowStatusList, + CertificationFlowNodeEnum.RZGCSSC.getKey(), + projectLibraryBase, + "end_time", + idList + ); + try { + // 更新数据状态为 审查通过 + this.updateBatchById(projectCertificationInventoryEOList); + + List flowStatus = new ArrayList<>(); + flowStatus.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + + // 更新该项目认证流程中,认证工程师的任务状态。 + // 如果还有 结果待审查 的数据,不做操作,如果没有 将这个项目认证流程的所有认证工程师待办任务转为已办 flowStatus + this.updateProcessInfoDetailStatus(projectLibraryBase,CertificationFlowNodeEnum.RZGCSSC.getKey(),flowStatus); + + this.certificationInventoryEOListSortByEndTimeAsc(projectCertificationInventoryEOList); + this.sendMessageByTemplateId( + projectCertificationInventoryEOList, + TemplateInfoEnum2.CERTIFICATION_MESSAGE25.getValue(), + dutyPersonIdList, + dutyPersonList, + projectCertificationInventoryEOList.get(0).getEndTime(),"" + ); + }catch (Exception ex){ + ex.printStackTrace(); + log.error("认证工程师-审批通过失败:" + ex.getMessage()); + throw new JeroBootException("审批通过失败!"); + } + + + return Result.OK("审批通过成功!"); + } + + /** + * 更新截止日期 + * @param flowStatusList + * @param taskDefinitionKey + * @param projectLibraryBase + */ + private void updateProcessInfoDetailEndTime(List flowStatusList, + String taskDefinitionKey, + ProjectLibraryBase projectLibraryBase, + String orderByField, + List excludeIdList) { + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId, projectLibraryBase.getId()); + pciQueryWrap.lambda().in(ProjectCertificationInventoryEO::getFlowStatus, flowStatusList); + if(CollectionUtils.isNotEmpty(excludeIdList)){ + pciQueryWrap.lambda().notIn(ProjectCertificationInventoryEO::getId, excludeIdList); + } + pciQueryWrap.orderByAsc(orderByField); + List pciEoList = this.list(pciQueryWrap); + if(CollectionUtils.isNotEmpty(pciEoList)){ + Date endTime = null; + if(StringUtils.equals("inventory_verify_end_time",orderByField)){ + endTime = pciEoList.get(0).getInventoryVerifyEndTime(); + } else if(StringUtils.equals("end_time",orderByField)){ + endTime = pciEoList.get(0).getEndTime(); + } + + QueryWrapper detailQueryWrapper = new QueryWrapper<>(); + detailQueryWrapper.lambda().eq(ProcessInfoDetailEO::getProcessInfoId, projectLibraryBase.getId()); + detailQueryWrapper.lambda().eq(ProcessInfoDetailEO::getTaskDefinitionKey,taskDefinitionKey); + List detailEOList = this.processInfoDetailEOService.list(detailQueryWrapper); + Date finalEndTime = endTime; + detailEOList.forEach(detailEO -> { + detailEO.setEndTime(finalEndTime); + }); + this.processInfoDetailEOService.updateBatchById(detailEOList); + } + } + + /** + * 更新任务状态为已办 + * @param projectLibraryBase + */ + private void updateProcessInfoDetailStatus(ProjectLibraryBase projectLibraryBase,String taskDefinitionKey,List flowStatusList) { + + QueryWrapper queryCountWrap = new QueryWrapper<>(); + queryCountWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId, projectLibraryBase.getId()); + queryCountWrap.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + int notDoneCount = this.count(queryCountWrap); + + if(notDoneCount == 0){ + QueryWrapper detailQueryWrapper = new QueryWrapper<>(); + detailQueryWrapper.lambda().eq(ProcessInfoDetailEO::getProcessInfoId, projectLibraryBase.getId()); + detailQueryWrapper.lambda().eq(ProcessInfoDetailEO::getTaskDefinitionKey,taskDefinitionKey); + List detailEOList = this.processInfoDetailEOService.list(detailQueryWrapper); + + for (ProcessInfoDetailEO processInfoDetailEO : detailEOList) { + processInfoDetailEO.setStatus(TaskStatusEnum.HAVE_DONE.getValue()); + } + + this.processInfoDetailEOService.updateBatchById(detailEOList); + } + } + + + /** + * 责任人提交任务 + * @param json + * @return + */ + private Result dutyPersonSubmitTask(JSONObject json) { + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + List idList = Arrays.asList(ids.split(",")); + + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(queryWrapper); + this.disposeData(projectCertificationInventoryEOList,CutEnum.CN.getValue()); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'结果待提交 或 审查退回'的数据!"); + } + this.certificationInventoryEOListSortByEndTimeAsc(projectCertificationInventoryEOList); + + ProjectLibraryBase projectLibraryBase = JSONObject.parseObject(JSONObject.toJSONString(json.get("projectLibraryBase")), ProjectLibraryBase.class); + + // 给认证工程师分配待办中心的任务 + String certificationEngineer = projectLibraryBase.getCertificationEngineer(); + if(StringUtils.isEmpty(certificationEngineer)){ + throw new JeroBootException("该项目中认证工程师为空,请先维护认证工程师!"); + } + + // 根据项目库id查询当前项目认证清单数据,获取数据状态为 结果待审查的 截止时间 最早的一个时间 + Date endTime = null; + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,projectLibraryBase.getId()); + pciQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getFlowStatus,CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + pciQueryWrap.lambda().isNotNull(ProjectCertificationInventoryEO::getEndTime); + List pciEoList = this.list(pciQueryWrap); + if(CollectionUtils.isNotEmpty(pciEoList) || CollectionUtils.isNotEmpty(projectCertificationInventoryEOList)){ + List endTimeList = new ArrayList<>(); + // 本次提交之前数据库里面存在的截止时间 + List oldEndTimeList = pciEoList.stream().map(ProjectCertificationInventoryEO::getEndTime).distinct().collect(Collectors.toList()); + endTimeList.addAll(oldEndTimeList); + // 当前要提交的数据截止时间 + List newEndTimeList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getEndTime).distinct().collect(Collectors.toList()); + endTimeList.addAll(newEndTimeList); + + endTimeList = endTimeList.stream().distinct().collect(Collectors.toList()); + Collections.sort(endTimeList, (d1, d2) -> d1.compareTo(d2)); // 根据时间顺序排序 + endTime = endTimeList.get(0); + } + + List processInfoDetailEOList = new ArrayList<>(); + List certificationEngineerList = Arrays.asList(certificationEngineer.split(",")); + // 给认证工程师分配任务 + for (String userId : certificationEngineerList) { + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(userId); + processInfoDetailEO.setTaskDefinitionKey(CertificationFlowNodeEnum.RZGCSSC.getKey()); + processInfoDetailEO.setCreateTime(new Date()); + processInfoDetailEO.setStatus(TaskStatusEnum.NOT_DONE.getValue()); + processInfoDetailEO.setProcessInfoId(projectLibraryBase.getId()); + processInfoDetailEO.setActiProcInstId(projectLibraryBase.getId()); + processInfoDetailEO.setFlowType(FlowTypeEnum.CERTIFICATION_LC.getValue()); + processInfoDetailEO.setEndTime(endTime); + processInfoDetailEOList.add(processInfoDetailEO); + } + // 数据更新为结果待审查 + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + processHistoryEOService.add(projectCertificationInventoryEO.getId(),CertificationFlowNodeEnum.TASK_HANDLING.getKey(),currentUser.getId(),null,null,projectCertificationInventoryEO.getDeliveryResult()); + + } + + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_DUTY_PERSON_SUBMIT_TASK.getValue()); + + List certificationEngineers = this.sysUserService.querySysUserListByIdList(certificationEngineerList); + + try { + this.updateBatchById(projectCertificationInventoryEOList); + + List certificationIdList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getId).distinct().collect(Collectors.toList()); + + // 将当前责任人的待办任务转为已办 + LambdaUpdateWrapper detailUpdateWrap = new LambdaUpdateWrapper<>(); + detailUpdateWrap.eq(ProcessInfoDetailEO::getProcessInfoId,projectLibraryBase.getId()); + detailUpdateWrap.eq(ProcessInfoDetailEO::getUserId,currentUser.getId()); + detailUpdateWrap.eq(ProcessInfoDetailEO::getTaskDefinitionKey,CertificationFlowNodeEnum.ZRRTJRW.getKey()); + detailUpdateWrap.in(ProcessInfoDetailEO::getProjectLawsInventoryId,certificationIdList); + detailUpdateWrap.set(ProcessInfoDetailEO::getStatus,TaskStatusEnum.HAVE_DONE.getValue()); + detailUpdateWrap.set(ProcessInfoDetailEO::getUpdateTime,new Date()); + detailUpdateWrap.set(ProcessInfoDetailEO::getUpdateBy,currentUser.getUsername()); + this.processInfoDetailEOService.update(detailUpdateWrap); + + // 给认证工程师分配待办中心的任务 认证工程师审查 + this.addProcessInfoDetailEO(processInfoDetailEOList,projectLibraryBase.getId(),CertificationFlowNodeEnum.RZGCSSC.getKey()); + this.sendMessageByTemplateId( + projectCertificationInventoryEOList, + TemplateInfoEnum2.CERTIFICATION_MESSAGE23.getValue(), + certificationEngineerList, + certificationEngineers, + endTime, + CertificationFlowNodeEnum.TASK_REVIEW.getKey() + ); + }catch (Exception ex){ + ex.printStackTrace(); + log.error("责任人-提交任务失败:" + ex.getMessage()); + throw new JeroBootException("提交任务失败!"); + } + + return Result.OK("提交任务成功!"); + } + + /** + * 责任人接受任务 + * @param json + * @return + */ + private Result dutyPersonAcceptTask(JSONObject json) { + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + List idList = Arrays.asList(ids.split(",")); + + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'任务待确认'的数据!"); + } + + ProjectLibraryBase projectLibraryBase = JSONObject.parseObject(JSONObject.toJSONString(json.get("projectLibraryBase")), ProjectLibraryBase.class); + String certificationEngineer = projectLibraryBase.getCertificationEngineer(); + if(StringUtils.isEmpty(certificationEngineer)){ + throw new JeroBootException("该项目中认证工程师为空,请先维护认证工程师!"); + } + + List processInfoDetailEOList = new ArrayList<>(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()); + + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(projectCertificationInventoryEO.getDutyPerson()); + processInfoDetailEO.setEndTime(projectCertificationInventoryEO.getEndTime()); + processInfoDetailEO.setProjectLawsInventoryId(projectCertificationInventoryEO.getId()); + processInfoDetailEOList.add(processInfoDetailEO); + processHistoryEOService.add(projectCertificationInventoryEO.getId(),CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(),currentUser.getId(),ReviewResultEnum.ACCEPTED.getValue(),null,null); + + } + + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_DUTY_PERSON_ACCEPT_TASK.getValue()); + + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryBase.getId(), PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + String hrefFeishu_CN_P = this.handlePhoneLink(projectLibraryBase.getId(),PRN_CN,CertificationFlowNodeEnum.TASK_HANDLING.getKey()); + + Map standNameAndItemName = this.platformProjectCertificationInventoryEOService.getStandNameAndItemName(projectCertificationInventoryEOList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + try { + List certificationIdList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getId).distinct().collect(Collectors.toList()); + // 将当前责任人的待办任务转为已办 + LambdaUpdateWrapper detailUpdateWrap = new LambdaUpdateWrapper<>(); + detailUpdateWrap.eq(ProcessInfoDetailEO::getProcessInfoId,projectLibraryBase.getId()); + detailUpdateWrap.eq(ProcessInfoDetailEO::getUserId,currentUser.getId()); + detailUpdateWrap.eq(ProcessInfoDetailEO::getTaskDefinitionKey,CertificationFlowNodeEnum.ZRRJSRW.getKey()); + detailUpdateWrap.in(ProcessInfoDetailEO::getProjectLawsInventoryId,certificationIdList); + detailUpdateWrap.set(ProcessInfoDetailEO::getStatus,TaskStatusEnum.HAVE_DONE.getValue()); + detailUpdateWrap.set(ProcessInfoDetailEO::getUpdateTime,new Date()); + detailUpdateWrap.set(ProcessInfoDetailEO::getUpdateBy,currentUser.getUsername()); + this.processInfoDetailEOService.update(detailUpdateWrap); + + // 给责任人分配待办中心的任务 (待提交) + this.addProcessInfoDetailEO(processInfoDetailEOList,projectLibraryBase.getId(),CertificationFlowNodeEnum.ZRRTJRW.getKey()); + + // 责任人接受任务,将数据的状态更新为 结果待提交。 + this.updateBatchById(projectCertificationInventoryEOList); + + + List certificationEngineerList = Arrays.asList(certificationEngineer.split(",")); + List certificationEngineers = this.sysUserService.querySysUserListByIdList(certificationEngineerList); + try { + for (String userId : certificationEngineerList) { + String thirdId = this.sysUserService.getUserThirdIdByUserId(certificationEngineers,userId); + + if(StringUtils.isNotEmpty(thirdId)){ + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + this.certificationInventoryEOListSortByEndTimeAsc(projectCertificationInventoryEOList); + Date endTime = projectCertificationInventoryEOList.get(0).getEndTime(); + + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE12.getValue()); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(endTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlCnPhone",hrefFeishu_CN_P); + templateVariableMap.put("operateUserName",currentUser.getUsername()); + + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } + } + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + }catch (Exception ex){ + ex.printStackTrace(); + log.error("责任人-接受任务失败:" + ex.getMessage()); + throw new JeroBootException("接受任务失败!"); + } + + return Result.OK("接受任务成功!"); + } + + /** + * 责任人拒绝任务 + * @param json + * @return + */ + private Result dutyPersonRejectTask(JSONObject json) { + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + String reasonForReturn = json.getString("reasonForReturn"); + + List idList = Arrays.asList(ids.split(",")); + + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'任务待确认'的数据!"); + } + + ProjectLibraryBase projectLibraryBase = JSONObject.parseObject(JSONObject.toJSONString(json.get("projectLibraryBase")), ProjectLibraryBase.class); + + // 给认证工程师分配待办中心的任务 + String certificationEngineer = projectLibraryBase.getCertificationEngineer(); + if(StringUtils.isEmpty(certificationEngineer)){ + throw new JeroBootException("该项目中认证工程师为空,请先维护认证工程师!"); + } + + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()); + projectCertificationInventoryEO.setReasonForReturn(reasonForReturn); + processHistoryEOService.add(projectCertificationInventoryEO.getId(),CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(),currentUser.getId(),ReviewResultEnum.REJECTED.getValue(),reasonForReturn,null); + + } + + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_DUTY_PERSON_REJECT_TASK.getValue()); + + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryBase.getId(), PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + String hrefFeishu_CN_P = (String) hrefFeishuMap.get("hrefFeishu_CN_P"); + + Map standNameAndItemName = this.platformProjectCertificationInventoryEOService.getStandNameAndItemName(projectCertificationInventoryEOList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + try { + List certificationIdList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getId).distinct().collect(Collectors.toList()); + // 将当前责任人的待办任务转为已办 + LambdaUpdateWrapper detailUpdateWrap = new LambdaUpdateWrapper<>(); + detailUpdateWrap.eq(ProcessInfoDetailEO::getProcessInfoId,projectLibraryBase.getId()); + detailUpdateWrap.eq(ProcessInfoDetailEO::getUserId,currentUser.getId()); + detailUpdateWrap.eq(ProcessInfoDetailEO::getTaskDefinitionKey,CertificationFlowNodeEnum.ZRRJSRW.getKey()); + detailUpdateWrap.in(ProcessInfoDetailEO::getProjectLawsInventoryId,certificationIdList); + detailUpdateWrap.set(ProcessInfoDetailEO::getStatus,TaskStatusEnum.HAVE_DONE.getValue()); + detailUpdateWrap.set(ProcessInfoDetailEO::getUpdateTime,new Date()); + detailUpdateWrap.set(ProcessInfoDetailEO::getUpdateBy,currentUser.getUsername()); + this.processInfoDetailEOService.update(detailUpdateWrap); + + this.certificationInventoryEOListSortByInventoryVerifyEndTimeAsc(projectCertificationInventoryEOList); + + List processInfoDetailEOList = new ArrayList<>(); + List certificationEngineerList = Arrays.asList(certificationEngineer.split(",")); + // 给认证工程师分配任务 + for (String userId : certificationEngineerList) { + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(userId); + processInfoDetailEO.setTaskDefinitionKey(CertificationFlowNodeEnum.RZGCSJSRW.getKey()); + processInfoDetailEO.setCreateTime(new Date()); + processInfoDetailEO.setStatus(TaskStatusEnum.NOT_DONE.getValue()); + processInfoDetailEO.setProcessInfoId(projectLibraryBase.getId()); + processInfoDetailEO.setActiProcInstId(projectLibraryBase.getId()); + processInfoDetailEO.setFlowType(FlowTypeEnum.CERTIFICATION_LC.getValue()); + processInfoDetailEO.setEndTime(projectCertificationInventoryEOList.get(0).getInventoryVerifyEndTime()); + processInfoDetailEOList.add(processInfoDetailEO); + } + + // 删除该项目数据的待办任务,key为 认证工程师接受任务的数据 + QueryWrapper deleteDetailWrap = new QueryWrapper<>(); + deleteDetailWrap.lambda().eq(ProcessInfoDetailEO::getProcessInfoId,projectLibraryBase.getId()); + deleteDetailWrap.lambda().eq(ProcessInfoDetailEO::getTaskDefinitionKey,CertificationFlowNodeEnum.RZGCSJSRW.getKey()); + deleteDetailWrap.lambda().eq(ProcessInfoDetailEO::getFlowType,FlowTypeEnum.CERTIFICATION_LC.getValue()); + this.processInfoDetailEOService.remove(deleteDetailWrap); + this.processInfoDetailEOService.saveBatch(processInfoDetailEOList); + + // 责任人接受任务,将数据的状态更新为 结果待提交。 + this.updateBatchById(projectCertificationInventoryEOList); + + List certificationEngineers = this.sysUserService.querySysUserListByIdList(certificationEngineerList); + try { + for (String userId : certificationEngineerList) { + String thirdId = this.sysUserService.getUserThirdIdByUserId(certificationEngineers,userId); + + if(StringUtils.isNotEmpty(thirdId)){ + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 +// this.certificationInventoryEOListSortByEndTimeAsc(projectCertificationInventoryEOList); + Date endTime = projectCertificationInventoryEOList.get(0).getInventoryVerifyEndTime(); + + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE11.getValue()); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(endTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlCnPhone",hrefFeishu_CN_P); + + templateVariableMap.put("operateUserName",currentUser.getUsername()); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } + } + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + }catch (Exception ex){ + ex.printStackTrace(); + log.error("责任人-拒绝任务失败:" + ex.getMessage()); + throw new JeroBootException("拒绝任务失败!"); + } + return Result.OK("拒绝任务成功!"); + } + + /** + * 认证工程师退回至studio任务 + * @param json + * @return + */ + private Result certificationReturnedStudioTask(JSONObject json) { + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + String reasonForReturn = json.getString("reasonForReturn"); + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + List idList = Arrays.asList(ids.split(",")); + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'清单待校核 或 责任人拒绝的数据'!"); + } + + ProjectLibraryBase projectLibraryBase = JSONObject.parseObject(JSONObject.toJSONString(json.get("projectLibraryBase")), ProjectLibraryBase.class); + if (StringUtils.isEmpty(projectLibraryBase.getStudioEngineer())) { + throw new JeroBootException("该项目的studio为空,请维护studio后再进行退回操作!"); + } + + List studioEngineerUserInfo = this.sysUserService.querySysUserListByIdList(Arrays.asList(projectLibraryBase.getStudioEngineer().split(","))); + + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryBase.getId(), PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + String hrefFeishu_CN_P = (String) hrefFeishuMap.get("hrefFeishu_CN_P"); + + // 给studio分配待办中心任务 + /*List processInfoDetailEOList = new ArrayList<>(); + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(projectLibraryBase.getStudioEngineer()); + processInfoDetailEOList.add(processInfoDetailEO); + this.addProcessInfoDetailEO(processInfoDetailEOList,projectLibraryBase.getId(),CertificationFlowNodeEnum.STUDIOFQ.getKey());*/ + + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + Collections.sort(projectCertificationInventoryEOList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue()); + } + + for (ProjectCertificationInventoryEO pciEo : projectCertificationInventoryEOList) { + pciEo.setReasonForReturn(reasonForReturn); + processHistoryEOService.add(pciEo.getId(),CertificationFlowNodeEnum.CHECKLIST_VERIFICATION.getKey(),currentUser.getId(),ReviewResultEnum.RETURNED.getValue(),reasonForReturn,null); + + } + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_RETURNED_STUDIO_TASK.getValue()); + + Map standNameAndItemName = this.getStandNameAndItemName(projectCertificationInventoryEOList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + try { + // 认证工程师退回任务到studio,将数据的状态更新为 认证退回 + this.updateBatchById(projectCertificationInventoryEOList); + + // 更新该项目认证流程中,认证工程师的任务状态。 + // 如果还有 清单待校核、责任人拒绝 状态的数据,不做操作,如果没有 将这个项目认证流程的所有认证工程师待办任务转为已办 + this.updateProcessInfoDetailStatus(projectLibraryBase,CertificationFlowNodeEnum.RZGCSJSRW.getKey(),flowStatusList); + + try { + String thirdId = this.sysUserService.getUserThirdIdByUserId(studioEngineerUserInfo,projectLibraryBase.getStudioEngineer()); + + if(StringUtils.isNotEmpty(thirdId)){ + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + /*Collections.sort(projectCertificationInventoryEOList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + Date endTime = projectCertificationInventoryEOList.get(0).getEndTime();*/ + this.certificationInventoryEOListSortByInventoryVerifyEndTimeAsc(projectCertificationInventoryEOList); + Date endTime = projectCertificationInventoryEOList.get(0).getInventoryVerifyEndTime(); + + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE3.getValue()); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(endTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlCnPhone",hrefFeishu_CN_P); + + templateVariableMap.put("certificationEngineer",currentUser.getUsername()); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + }catch (Exception ex){ + ex.printStackTrace(); + log.error("认证工程师-退回认证清单任务失败:" + ex.getMessage()); + throw new JeroBootException("退回任务失败!"); + } + + return Result.OK("退回任务成功!"); + } + + /** + * 认证工程师发起任务 + * @param json + * @return + */ + @Override + public Result certificationInitiatingTask(JSONObject json) { + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + String taskConfirmEndTimeStr = json.getString("taskConfirmEndTime"); + Date taskConfirmEndTime = DateUtils.str2Date(taskConfirmEndTimeStr, DateUtils.date_sdf.get()); + + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + List idList = Arrays.asList(ids.split(",")); + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'清单待校核 或 责任人拒绝的数据'!"); + } + + ProjectLibraryBase projectLibraryBase = JSONObject.parseObject(JSONObject.toJSONString(json.get("projectLibraryBase")), ProjectLibraryBase.class); + if (ObjectUtils.isEmpty(projectLibraryBase)) { + throw new JeroBootException("无法获取项目库信息"); + } + + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryBase.getId(), PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + //飞书手机跳转链接 + String hrefFeishu_CN_P = this.handlePhoneLink(projectLibraryBase.getId(),PRN_CN,CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey()); + + Map> certifycationInventoryListByDutyPersonMap = projectCertificationInventoryEOList.stream().collect(Collectors.groupingBy(ProjectCertificationInventoryEO::getDutyPerson)); + try { + // 给责任人分配待办中心的任务 + List processInfoDetailEOList = new ArrayList<>(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + projectCertificationInventoryEO.setFlowStatus(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()); + projectCertificationInventoryEO.setTaskConfirmEndTime(taskConfirmEndTime); + + ProcessInfoDetailEO processInfoDetailEO = new ProcessInfoDetailEO(); + processInfoDetailEO.setUserId(projectCertificationInventoryEO.getDutyPerson()); + processInfoDetailEO.setEndTime(taskConfirmEndTime); + processInfoDetailEO.setProjectLawsInventoryId(projectCertificationInventoryEO.getId()); + processInfoDetailEOList.add(processInfoDetailEO); + + processHistoryEOService.add(projectCertificationInventoryEO.getId(),CertificationFlowNodeEnum.CHECKLIST_VERIFICATION.getKey(),currentUser.getId(),null,null,null); + + } + + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_INITIATING_TASK.getValue()); + + this.addProcessInfoDetailEO(processInfoDetailEOList,projectLibraryBase.getId(),CertificationFlowNodeEnum.ZRRJSRW.getKey()); + + // 认证工程师发起任务,将数据的状态更新为 任务待确认。 + this.updateBatchById(projectCertificationInventoryEOList); + + // 获取当前项目下,认证清单,清单校核截止日期最早的一个,更新到流程明细表中,认证工程师接受任务节点的截止时间中 + this.updateProcessInfoDetailEndTime( + flowStatusList, + CertificationFlowNodeEnum.RZGCSJSRW.getKey(), + projectLibraryBase, + "inventory_verify_end_time", + idList + ); + + // 更新该项目认证流程中,认证工程师的任务状态。 + // 如果还有 清单待校核、责任人拒绝 状态的数据,不做操作,如果没有 将这个项目认证流程的所有认证工程师待办任务转为已办 + this.updateProcessInfoDetailStatus(projectLibraryBase,CertificationFlowNodeEnum.RZGCSJSRW.getKey(),flowStatusList); + + List dutyPersonIdList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList()); + List dutyPersonList = this.sysUserService.querySysUserListByIdList(dutyPersonIdList); + + for (Map.Entry> dataByDutyPersonMap : certifycationInventoryListByDutyPersonMap.entrySet()) { + String dutyPersonUserId = dataByDutyPersonMap.getKey(); + List dutyPersonDataList = dataByDutyPersonMap.getValue(); + if(CollectionUtils.isEmpty(dutyPersonDataList)){ + continue; + } + + Map standNameAndItemName = this.platformProjectCertificationInventoryEOService.getStandNameAndItemName(dutyPersonDataList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + try { + String thirdId = this.sysUserService.getUserThirdIdByUserId(dutyPersonList,dutyPersonUserId); + + if(StringUtils.isNotEmpty(thirdId)){ + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 +// this.certificationInventoryEOListSortByEndTimeAsc(projectCertificationInventoryEOList); +// Date endTime = projectCertificationInventoryEOList.get(0).getEndTime(); + + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE10.getValue()); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(taskConfirmEndTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlCnPhone",hrefFeishu_CN_P); + + templateVariableMap.put("certificationEngineer",currentUser.getUsername()); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + } + + }catch (Exception ex){ + ex.printStackTrace(); + log.error("认证工程师-发起认证清单任务失败:" + ex.getMessage()); + throw new JeroBootException("发起任务失败!"); + } + + return Result.OK("发起任务成功!"); + } + + @Override + public String handlePhoneLink(String id, String prn_cn, String key) { + String hrefFeishu_CN_P = backUrlPhone + + JumpLinkEnum.PRE_TASK_HANDING_PHONE.getLink() + "?isDisplay=false&projectLibraryId=" + id + + "&projectName=" + prn_cn + "&taskDefinitionKey=" + key + "&TaskKeyName="+CertificationFlowNodeEnum.getTextByValue(key, CutEnum.CN.getValue()); + ; + return URLUtil.encode(hrefFeishu_CN_P); + } + + /** + * 认证清单数据排序,根据截至时间顺序排序 + * @param projectCertificationInventoryEOList + */ + @Override + public void certificationInventoryEOListSortByEndTimeAsc(List projectCertificationInventoryEOList) { + Collections.sort(projectCertificationInventoryEOList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + } + + /** + * 认证清单数据排序,根据清单校核截至时间顺序排序 + * @param pciEoList + */ + @Override + public void certificationInventoryEOListSortByInventoryVerifyEndTimeAsc(List pciEoList) { + Collections.sort(pciEoList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getInventoryVerifyEndTime() != null && p2.getInventoryVerifyEndTime() != null){ + return p1.getInventoryVerifyEndTime().compareTo(p2.getInventoryVerifyEndTime()); + } + return 1; + } + }); + } + /** + * 认证清单数据排序,根据任务确认截至时间顺序排序 + * @param pciEoList + */ + @Override + public void certificationInventoryEOListSortByTaskConfirmEndTimeAsc(List pciEoList) { + Collections.sort(pciEoList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getTaskConfirmEndTime() != null && p2.getTaskConfirmEndTime() != null){ + return p1.getTaskConfirmEndTime().compareTo(p2.getTaskConfirmEndTime()); + } + return 1; + } + }); + } + + @Override + public List> getTaskToConfirmStatistics(List pciEoList) { + List> result = new ArrayList<>(); + + int notStartedCount = 0; + int toConfirmCount = 0; + int acceptedCount = 0; + int rejectedCount = 0; + if(CollectionUtils.isNotEmpty(pciEoList)){ + // 未发起 + notStartedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()) + ); + return flag; + }).count(); + // 待确认 + toConfirmCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + ); + return flag; + }).count(); + // 接受 + acceptedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ); + return flag; + }).count(); + // 拒绝 + rejectedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()) + ); + return flag; + }).count(); + } + Map notStartedMap = new HashMap<>(); + Map toConfirmMap = new HashMap<>(); + Map acceptedMap = new HashMap<>(); + Map rejectedMap = new HashMap<>(); + + notStartedMap.put("taskAffirmStatus",TaskAffirmStatusEnum.NOT_STARTED.getValue()); + notStartedMap.put("taskAffirmStatusCount",notStartedCount); + + toConfirmMap.put("taskAffirmStatus",TaskAffirmStatusEnum.LIST_TO_CONFIRM.getValue()); + toConfirmMap.put("taskAffirmStatusCount",toConfirmCount); + + acceptedMap.put("taskAffirmStatus",TaskAffirmStatusEnum.ACCEPTED.getValue()); + acceptedMap.put("taskAffirmStatusCount",acceptedCount); + + rejectedMap.put("taskAffirmStatus",TaskAffirmStatusEnum.REJECTED.getValue()); + rejectedMap.put("taskAffirmStatusCount",rejectedCount); + + result.add(notStartedMap); + result.add(toConfirmMap); + result.add(acceptedMap); + result.add(rejectedMap); + return result; + } + + @Override + public List> getPrehomoStatistice(List pciEoList) { + List> result = new ArrayList<>(); + + int notStartedCount = 0; + int toConfirmCount = 0; + int acceptedCount = 0; + int rejectedCount = 0; + if(CollectionUtils.isNotEmpty(pciEoList)){ + // 未发起 + notStartedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()) + ); + return flag; + }).count(); + // 待确认 + toConfirmCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()) + ); + return flag; + }).count(); + // 审查通过 + acceptedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()) + ); + return flag; + }).count(); + // 审查退回 + rejectedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ); + return flag; + }).count(); + } + Map notStartedMap = new HashMap<>(); + Map toConfirmMap = new HashMap<>(); + Map acceptedMap = new HashMap<>(); + Map rejectedMap = new HashMap<>(); + + notStartedMap.put("taskAffirmStatus",TaskAffirmStatusEnum.NOT_STARTED.getValue()); + notStartedMap.put("taskAffirmStatusCount",notStartedCount); + + toConfirmMap.put("taskAffirmStatus",TaskAffirmStatusEnum.LIST_TO_CONFIRM.getValue()); + toConfirmMap.put("taskAffirmStatusCount",toConfirmCount); + + acceptedMap.put("taskAffirmStatus",CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()); + acceptedMap.put("taskAffirmStatusCount",acceptedCount); + + rejectedMap.put("taskAffirmStatus",CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()); + rejectedMap.put("taskAffirmStatusCount",rejectedCount); + + result.add(notStartedMap); + result.add(toConfirmMap); + result.add(acceptedMap); + result.add(rejectedMap); + return result; + } + + @Override + public List> getAllCertificationProgressStatistics(List pciEoList) { + List> result = new ArrayList<>(); + + int notStartedCount = 0; + int inProgressCount = 0; + int testPassedCount = 0; + int testFailedCount = 0; + if(CollectionUtils.isNotEmpty(pciEoList)){ + // 未开始 + notStartedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.NOT_START.getValue()) + ); + return flag; + }).count(); + // 进行中 + inProgressCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.IN_PROGRESS.getValue()) + || StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_NOT_SUBMITTED.getValue()) + ); + return flag; + }).count(); + // 实验通过 + testPassedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.TEST_PASSED.getValue()) + || StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_SUBMITTED.getValue()) + || StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_HAS_BEEN_STORED.getValue()) + ); + return flag; + }).count(); + // 实验失败 + testFailedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.TEST_FAILED.getValue()) + ); + return flag; + }).count(); + } + Map notStartedMap = new HashMap<>(); + Map inProgressMap = new HashMap<>(); + Map testPassedMap = new HashMap<>(); + Map testFailedMap = new HashMap<>(); + + notStartedMap.put("certificationProgress",CertificationProgressEnum.NOT_START.getValue()); + notStartedMap.put("certificationProgressCount",notStartedCount); + + inProgressMap.put("certificationProgress",CertificationProgressEnum.IN_PROGRESS.getValue()); + inProgressMap.put("certificationProgressCount",inProgressCount); + + testPassedMap.put("certificationProgress",CertificationProgressEnum.TEST_PASSED.getValue()); + testPassedMap.put("certificationProgressCount",testPassedCount); + + testFailedMap.put("certificationProgress",CertificationProgressEnum.TEST_FAILED.getValue()); + testFailedMap.put("certificationProgressCount",testFailedCount); + + result.add(notStartedMap); + result.add(inProgressMap); + result.add(testPassedMap); + result.add(testFailedMap); + return result; + } + + @Override + public List> getCarCertificationProgressStatistics(List pciEoList) { + List> result = new ArrayList<>(); + + int notStartedCount = 0; + int inProgressCount = 0; + int testPassedCount = 0; + int testFailedCount = 0; + if(CollectionUtils.isNotEmpty(pciEoList)){ + // 未开始 + notStartedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.NOT_START.getValue()) + ); + return flag; + }).count(); + // 进行中 + inProgressCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.IN_PROGRESS.getValue()) + ); + return flag; + }).count(); + // 实验通过 + testPassedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.TEST_PASSED.getValue()) + ); + return flag; + }).count(); + // 实验失败 + testFailedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.TEST_FAILED.getValue()) + ); + return flag; + }).count(); + } + Map notStartedMap = new HashMap<>(); + Map inProgressMap = new HashMap<>(); + Map testPassedMap = new HashMap<>(); + Map testFailedMap = new HashMap<>(); + + notStartedMap.put("certificationProgress",CertificationProgressEnum.NOT_START.getValue()); + notStartedMap.put("certificationProgressCount",notStartedCount); + + inProgressMap.put("certificationProgress",CertificationProgressEnum.IN_PROGRESS.getValue()); + inProgressMap.put("certificationProgressCount",inProgressCount); + + testPassedMap.put("certificationProgress",CertificationProgressEnum.TEST_PASSED.getValue()); + testPassedMap.put("certificationProgressCount",testPassedCount); + + testFailedMap.put("certificationProgress",CertificationProgressEnum.TEST_FAILED.getValue()); + testFailedMap.put("certificationProgressCount",testFailedCount); + + result.add(notStartedMap); + result.add(inProgressMap); + result.add(testPassedMap); + result.add(testFailedMap); + return result; + } + + @Override + public List> getPartCertificationProgressStatistics(List pciEoList) { + List> result = new ArrayList<>(); + + int notSubmitCount = 0; + int reportSubmitCount = 0; + int storedCount = 0; + if(CollectionUtils.isNotEmpty(pciEoList)){ + // 部件报告未提交 + notSubmitCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_NOT_SUBMITTED.getValue()) + ); + return flag; + }).count(); + // 部件报告已提交 + reportSubmitCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_SUBMITTED.getValue()) + ); + return flag; + }).count(); + // 部件报告已入库 + storedCount = (int) pciEoList.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_HAS_BEEN_STORED.getValue()) + ); + return flag; + }).count(); + } + Map notSubmitMap = new HashMap<>(); + Map reportSubmitMap = new HashMap<>(); + Map storedMap = new HashMap<>(); + + notSubmitMap.put("certificationProgress",CertificationProgressEnum.COMPONENT_REPORT_NOT_SUBMITTED.getValue()); + notSubmitMap.put("certificationProgressCount",notSubmitCount); + + reportSubmitMap.put("certificationProgress",CertificationProgressEnum.COMPONENT_REPORT_SUBMITTED.getValue()); + reportSubmitMap.put("certificationProgressCount",reportSubmitCount); + + storedMap.put("certificationProgress",CertificationProgressEnum.COMPONENT_REPORT_HAS_BEEN_STORED.getValue()); + storedMap.put("certificationProgressCount",storedCount); + + result.add(notSubmitMap); + result.add(reportSubmitMap); + result.add(storedMap); + return result; + } + + @Override + public Result saveBatch(JSONObject json) { + Date now = new Date(); + if (!json.containsKey("dataList")) { + throw new JeroBootException("无法获取需要保存的数据,请检查!"); + } + JSONArray dataList = json.getJSONArray("dataList"); + List projectCertificationInventoryEOList = new ArrayList<>(); + ProjectCertificationInventoryEO projectCertificationInventoryEO = null; + //设置权限 先删后加 + List adds = new ArrayList<>(); + for (Object data : dataList) { + projectCertificationInventoryEO = JSONObject.parseObject(JSONObject.toJSONString(data),ProjectCertificationInventoryEO.class); + projectCertificationInventoryEOList.add(projectCertificationInventoryEO); + if(ObjectUtils.isNotEmpty(projectCertificationInventoryEO.getSdt())){ + setProjectCertificationInventoryPermission(projectCertificationInventoryEO.getSdt(), projectCertificationInventoryEO.getProjectLibraryId(), projectCertificationInventoryEO.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if(ObjectUtils.isNotEmpty(projectCertificationInventoryEO.getDutyPerson())){ + setProjectCertificationInventoryPermission(projectCertificationInventoryEO.getDutyPerson(), projectCertificationInventoryEO.getProjectLibraryId(), projectCertificationInventoryEO.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("无法获取需要保存的数据,请检查!"); + } + this.updateBatchById(projectCertificationInventoryEOList); + return Result.OK("保存成功!"); + } + + @Override + public Result resetFlow(JSONObject json) { + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行流程重置!"); + } + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + + String operatorType = json.getString("operatorType"); + + String projectLibraryId = json.getString("projectLibraryId"); + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectLibraryId); + if(ObjectUtils.isEmpty(projectLibraryBase)){ + throw new JeroBootException("无法获取项目库信息,项目库id为:" + projectLibraryId + " 请联系管理员!"); + } + + List certificationEngineerIdList = Arrays.asList(projectLibraryBase.getCertificationEngineer().split(",")); + List certificationEngineerList = this.sysUserService.querySysUserListByIdList(certificationEngineerIdList); + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryId, PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + String hrefFeishu_CN_P = (String) hrefFeishuMap.get("hrefFeishu_CN_P"); + + + List idList = Arrays.asList(ids.split(",")); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().ne(ProjectCertificationInventoryEO::getFlowStatus,CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + Collections.sort(projectCertificationInventoryEOList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + + Map standNameAndItemName = this.getStandNameAndItemName(projectCertificationInventoryEOList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + try { + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + // 把交付结果、截止日期清空,流程状态 设置为 清单待发布 + LambdaUpdateWrapper updateWrap = new LambdaUpdateWrapper<>(); + updateWrap.set(ProjectCertificationInventoryEO::getDeliveryResult,null); + // 流程重置,清空截止日期, 撤回不清空。 对应禅道问题:67048 + if(StringUtils.equals(operatorType,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_RESET.getValue())){ + updateWrap.set(ProjectCertificationInventoryEO::getEndTime,null); + } + + updateWrap.set(ProjectCertificationInventoryEO::getFlowStatus,CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()); + updateWrap.eq(ProjectCertificationInventoryEO::getId,projectCertificationInventoryEO.getId()); + this.update(updateWrap); + } + processHistoryEOService.deleteByPId(ids); + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,operatorType); + + // 处理待办中心相关数据 + // 更新该项目认证流程中,认证工程师的任务状态。 + // 认证工程师接受任务节点 + List rzgcsjsrwFlowStatusList = new ArrayList<>(); + rzgcsjsrwFlowStatusList.add(CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()); + rzgcsjsrwFlowStatusList.add(CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()); + this.updateProcessInfoDetailStatus(projectLibraryBase,CertificationFlowNodeEnum.RZGCSJSRW.getKey(),rzgcsjsrwFlowStatusList); + + // 认证工程师审查节点 如果还有 结果待审查 的数据,不做操作,如果没有 将这个项目认证流程的所有认证工程师待办任务转为已办 + List rzgcsscFlowStatusList = new ArrayList<>(); + rzgcsscFlowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()); + this.updateProcessInfoDetailStatus(projectLibraryBase,CertificationFlowNodeEnum.RZGCSSC.getKey(),rzgcsscFlowStatusList); + + // 删除其它用户的待办任务 + QueryWrapper detailRemoveWrap = new QueryWrapper<>(); + detailRemoveWrap.lambda().eq(ProcessInfoDetailEO::getProcessInfoId,projectLibraryBase.getId()); + detailRemoveWrap.lambda().eq(ProcessInfoDetailEO::getFlowType,FlowTypeEnum.CERTIFICATION_LC.getValue()); + detailRemoveWrap.lambda().in(ProcessInfoDetailEO::getProjectLawsInventoryId,idList); + this.processInfoDetailEOService.remove(detailRemoveWrap); + + try { + if(CollectionUtils.isNotEmpty(certificationEngineerList)){ + for (String certificationEngineerId : certificationEngineerIdList) { + String thirdId = this.sysUserService.getUserThirdIdByUserId(certificationEngineerList,certificationEngineerId); + + if(StringUtils.isNotEmpty(thirdId)){ + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + Collections.sort(projectCertificationInventoryEOList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + Date endTime = projectCertificationInventoryEOList.get(0).getEndTime(); + + JSONObject larkMesJson = new JSONObject(); + if(StringUtils.equals(operatorType,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_WITHDRAW.getValue())){ + this.certificationInventoryEOListSortByInventoryVerifyEndTimeAsc(projectCertificationInventoryEOList); + endTime = projectCertificationInventoryEOList.get(0).getInventoryVerifyEndTime(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE4.getValue()); + }else if(StringUtils.equals(operatorType,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_RESET.getValue())){ + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE5.getValue()); + } + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(endTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlCnPhone",hrefFeishu_CN_P); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } + } + } + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + + }catch (Exception ex){ + ex.printStackTrace(); + log.error("studio-流程重置失败:" + ex.getMessage()); + throw new JeroBootException("流程重置失败!"); + } + return Result.OK("流程重置成功!"); + } + + @Override + public Result transferTask(JSONObject json) { + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + + String projectLibraryId = json.getString("projectLibraryId"); + String transferUserId = json.getString("transferUserId"); + SysUser transferUserInfo = this.sysUserService.getById(transferUserId); + + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectLibraryId); + if(ObjectUtils.isEmpty(projectLibraryBase)){ + throw new JeroBootException("无法获取项目库信息,项目库id为:" + projectLibraryId + " 请联系管理员!"); + } + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + List idList = Arrays.asList(ids.split(",")); + + // 流程状态为 任务待确认、待提交、 审查退回 。 能转办 + List flowStatusList = new ArrayList<>(); + flowStatusList.add(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()); + flowStatusList.add(CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getDutyPerson,currentUser.getId()); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isEmpty(projectCertificationInventoryEOList)){ + throw new JeroBootException("至少选择一条数据流程状态为'任务待确认 或 结果待提交 或 审查退回'的数据进行转办操作!"); + } + + List projectCertificationInventoryLogEOList = new ArrayList<>(); + projectCertificationInventoryEOList.forEach(certificationInventory -> { + certificationInventory.setDutyPerson(transferUserId); + + String contentCn = "\"" + currentUser.getUsername() + "\"" +"将流程发送至" +"\""+ transferUserInfo.getUsername() + "\"办理" ; + String contentEn = "\"" + currentUser.getUsername() + "\"" +" sends the process to "+"\""+ transferUserInfo.getUsername() + "\" for handling" ; + ProjectCertificationInventoryLogEO projectCertificationInventoryLogEO = new ProjectCertificationInventoryLogEO(); + projectCertificationInventoryLogEO.setProjectCertificationInventoryId(certificationInventory.getId()); + projectCertificationInventoryLogEO.setContentCn(contentCn); + projectCertificationInventoryLogEO.setContentEn(contentEn); + projectCertificationInventoryLogEO.setOperatorType(OperatorTypeEnum.CERTIFICATION_INVENTORY_DUTY_PERSON_TRANSFER_TASK.getValue()); + projectCertificationInventoryLogEOList.add(projectCertificationInventoryLogEO); + if(certificationInventory.getFlowStatus().equals(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())){ + processHistoryEOService.add(certificationInventory.getId(),CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey(),currentUser.getId(),ReviewResultEnum.TRANSFER.getValue(),null,null); + }else{ + processHistoryEOService.add(certificationInventory.getId(),CertificationFlowNodeEnum.TASK_HANDLING.getKey(),currentUser.getId(),ReviewResultEnum.TRANSFER.getValue(),null,null); + } + }); + + if(CollectionUtils.isNotEmpty(projectCertificationInventoryLogEOList)){ + this.projectCertificationInventoryLogEOService.insertBatch(projectCertificationInventoryLogEOList); + } + + this.updateBatchById(projectCertificationInventoryEOList); + //设置权限 先删后加 + Date now = new Date(); + List adds = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci:projectCertificationInventoryEOList) { + if (ObjectUtils.isNotEmpty(pci.getSdt())) { + setProjectCertificationInventoryPermission(pci.getSdt(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(pci.getDutyPerson())) { + setProjectCertificationInventoryPermission(pci.getDutyPerson(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + + Collections.sort(projectCertificationInventoryEOList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + + QueryWrapper detailQueryWrap = new QueryWrapper<>(); + detailQueryWrap.lambda().eq(ProcessInfoDetailEO::getProcessInfoId,projectLibraryId); + detailQueryWrap.lambda().eq(ProcessInfoDetailEO::getUserId,currentUser.getId()); + detailQueryWrap.lambda().in(ProcessInfoDetailEO::getProjectLawsInventoryId,idList); + List processInfoDetailEOList = this.processInfoDetailEOService.list(detailQueryWrap); + if(CollectionUtils.isNotEmpty(processInfoDetailEOList)){ + processInfoDetailEOList.forEach(detail -> { + detail.setUserId(transferUserId); + }); + this.processInfoDetailEOService.updateBatchById(processInfoDetailEOList); + } + + List userIdList = Arrays.asList(transferUserId.split(",")); + List userInfoList = this.sysUserService.querySysUserListByIdList(userIdList); + this.sendMessageByTemplateId( + projectCertificationInventoryEOList, + TemplateInfoEnum2.CERTIFICATION_MESSAGE17.getValue(), + userIdList, + userInfoList, + projectCertificationInventoryEOList.get(0).getEndTime(), + CertificationFlowNodeEnum.TASK_HANDLING.getKey() + ); + + // 获取认证清单 - 飞书跳转链接 + // 2023-03-15 去掉此消息 + /*Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryBase.getId(), PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + + Map standNameAndItemName = this.getStandNameAndItemName(projectCertificationInventoryEOList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + SysUser sysUser = this.sysUserService.getBaseMapper().selectById(transferUserId); + if (StringUtils.isNotEmpty(sysUser.getThirdId())) { + try { + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE9.getValue()); + larkMesJson.put("userIds",sysUser.getThirdId()); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn", PRN_CN); + templateVariableMap.put("projectNameEn", PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator", projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime", DateUtils.formatDate(projectCertificationInventoryEOList.get(0).getEndTime())); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + }*/ + + return Result.OK("转办成功!"); + } + + @Override + public Result expediting(JSONObject json) { + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + + String projectLibraryId = json.getString("projectLibraryId"); + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectLibraryId); + String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文 + String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文 + if(ObjectUtils.isEmpty(projectLibraryBase)){ + throw new JeroBootException("无法获取项目库信息,项目库id为:" + projectLibraryId + " 请联系管理员!"); + } + + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + List idList = Arrays.asList(ids.split(",")); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,idList); +// queryWrapper.lambda().in(ProjectCertificationInventoryEO::getDutyPerson,currentUser.getId()); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isNotEmpty(projectCertificationInventoryEOList)){ + // 获取认证清单 - 飞书跳转链接 + Map hrefFeishuMap = this.getCertificationInventoryLinkHrefFeishu(projectLibraryId, PRN_CN, PRN_EN); + String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN"); + String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN"); + String hrefFeishu_CN_P = (String) hrefFeishuMap.get("hrefFeishu_CN_P"); + + /** + * studio催办:除了 清单待发布、审查通过、认证退回 的 催办当前办理人 + * 认证工程师催办:任务待确认、结果待提交、审查退回 的 催办当前办理人 + * 接口人催办:任务待确认 、结果待提交、审查退回 的 催办当前办理人 + */ + String operatorType = json.getString("operatorType"); + if(StringUtils.equals(operatorType,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_EXPEDITING.getValue())){ + // 结果待审查 + List toBeReviewedCiEoList = projectCertificationInventoryEOList.stream().filter(data -> { + return (StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue())); + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(toBeReviewedCiEoList)){ + String certificationEngineerIds = projectLibraryBase.getCertificationEngineer(); + if(StringUtils.isNotEmpty(certificationEngineerIds)){ + List certificationEngineerIdList = Arrays.asList(certificationEngineerIds.split(",")); + + List certificationEngineerList = this.sysUserService.querySysUserListByIdList(certificationEngineerIdList); + + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + Collections.sort(toBeReviewedCiEoList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + Date endTime = toBeReviewedCiEoList.get(0).getEndTime(); + + Map standNameAndItemName = this.getStandNameAndItemName(toBeReviewedCiEoList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + if(CollectionUtils.isNotEmpty(certificationEngineerList)){ + for (String certificationEngineerId : certificationEngineerIdList) { + String thirdId = this.sysUserService.getUserThirdIdByUserId(certificationEngineerList,certificationEngineerId); + + if(StringUtils.isNotEmpty(thirdId)){ + try { + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE1.getValue()); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(endTime)); + + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlEnPhone",hrefFeishu_CN_P); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + } + } + } + } + } + + // 清单待校核、责任人拒绝 + List toBeCheckedCiEoList = projectCertificationInventoryEOList.stream().filter(data -> { + return (StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()) + || StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue())); + }).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(toBeCheckedCiEoList)) { + String certificationEngineerIds = projectLibraryBase.getCertificationEngineer(); + if(StringUtils.isNotEmpty(certificationEngineerIds)){ + List certificationEngineerIdList = Arrays.asList(certificationEngineerIds.split(",")); + + List certificationEngineerList = this.sysUserService.querySysUserListByIdList(certificationEngineerIdList); + + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + Collections.sort(toBeCheckedCiEoList, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getInventoryVerifyEndTime() != null && p2.getInventoryVerifyEndTime() != null){ + return p1.getInventoryVerifyEndTime().compareTo(p2.getInventoryVerifyEndTime()); + } + return 1; + } + }); + Date inventoryVerifyEndTime = toBeCheckedCiEoList.get(0).getInventoryVerifyEndTime(); + + Map standNameAndItemName = this.getStandNameAndItemName(toBeCheckedCiEoList); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + if(CollectionUtils.isNotEmpty(certificationEngineerList)){ + for (String certificationEngineerId : certificationEngineerIdList) { + String thirdId = this.sysUserService.getUserThirdIdByUserId(certificationEngineerList,certificationEngineerId); + + if(StringUtils.isNotEmpty(thirdId)){ + try { + JSONObject larkMesJson = new JSONObject(); + larkMesJson.put("template_id", TemplateInfoEnum2.CERTIFICATION_MESSAGE1.getValue()); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(inventoryVerifyEndTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + templateVariableMap.put("viewBtnUrlEnPhone",hrefFeishu_CN_P); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + } + } + } + } + } + } + + List dutyPersonIdList = projectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList()); + List dutyPersonList = this.sysUserService.querySysUserListByIdList(dutyPersonIdList); + + Map> certifycationInventoryListByDutyPersonMap = projectCertificationInventoryEOList.stream().filter(data -> { + return (StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())); + }).collect(Collectors.groupingBy(ProjectCertificationInventoryEO::getDutyPerson)); + + if(!ObjectUtils.isEmpty(certifycationInventoryListByDutyPersonMap) && CollectionUtils.isNotEmpty(dutyPersonList)){ + for (Map.Entry> map : certifycationInventoryListByDutyPersonMap.entrySet()) { + String key = map.getKey(); + List userIdList = Arrays.asList(key.split(",")); + + // 任务待确认状态的数据:发送认证任务确认的催办消息 + List toBeConfirmedPciEoList = map.getValue().stream().filter(pciEo -> { + boolean flag = false; + if(StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())){ + flag = true; + } + return flag; + }).collect(Collectors.toList()); + this.certificationInventoryEOListSortByTaskConfirmEndTimeAsc(toBeConfirmedPciEoList); + if (CollectionUtils.isNotEmpty(toBeConfirmedPciEoList)) { + Date taskConfirmEndTime = toBeConfirmedPciEoList.get(0).getTaskConfirmEndTime(); + // 给责任人发消息 + this.sendMessageByTemplateId( + toBeConfirmedPciEoList, + TemplateInfoEnum2.CERTIFICATION_MESSAGE16.getValue(), + userIdList, + dutyPersonList, + taskConfirmEndTime, + CertificationFlowNodeEnum.TASK_RESPONSIBILITY_CONFIRMATION.getKey() + ); + } + + List toBeSubmitOrReturnPciEoList = map.getValue().stream().filter(pciEo -> { + boolean flag = false; + if(StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())){ + flag = true; + } + return flag; + }).collect(Collectors.toList()); + + if (CollectionUtils.isNotEmpty(toBeSubmitOrReturnPciEoList)) { + this.certificationInventoryEOListSortByTaskConfirmEndTimeAsc(toBeSubmitOrReturnPciEoList); + // 给责任人发消息 + this.sendMessageByTemplateId( + toBeSubmitOrReturnPciEoList, + TemplateInfoEnum2.CERTIFICATION_MESSAGE18.getValue(), + userIdList, + dutyPersonList, + toBeSubmitOrReturnPciEoList.get(0).getTaskConfirmEndTime(), + CertificationFlowNodeEnum.TASK_HANDLING.getKey() + ); + } + + /*// 待提交数据 单独发消息 + List toBeSubmitDataList = value.stream().filter(v -> { + boolean flag = false; + if(StringUtils.equals(v.getFlowStatus(),CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue())){ + flag = true; + } + return flag; + }).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(toBeSubmitDataList)) { + + this.sendMessageByTemplateId( + toBeSubmitDataList, + TemplateInfoEnum2.CERTIFICATION_MESSAGE18.getValue(), + userIdList, + dutyPersonList + ); + }*/ + + /*String thirdId = this.sysUserService.getUserThirdIdByUserId(dutyPersonList,key); + + if(StringUtils.isNotEmpty(thirdId)){ + // 过滤掉 待提交的数据,正常发消息 + value = value.stream().filter(v -> { + boolean flag = false; + if(!StringUtils.equals(v.getFlowStatus(),CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue())){ + flag = true; + } + return flag; + }).collect(Collectors.toList()); + + // 根据结束时间进行排序,获取最近的时间,发消息时使用。 + Collections.sort(value, new Comparator() { + @Override + public int compare(ProjectCertificationInventoryEO p1, ProjectCertificationInventoryEO p2) { + if(p1.getEndTime() != null && p2.getEndTime() != null){ + return p1.getEndTime().compareTo(p2.getEndTime()); + } + return 1; + } + }); + Map standNameAndItemName = this.getStandNameAndItemName(value); + String standName = (String) standNameAndItemName.get("standName"); + String itemName = (String) standNameAndItemName.get("itemName"); + + Date endTime = value.get(0).getEndTime(); + + try { + JSONObject larkMesJson = new JSONObject(); + + String templateId = TemplateInfoEnum2.CERTIFICATION_MESSAGE1.getValue(); + if(StringUtils.equals(operatorType,OperatorTypeEnum.CERTIFICATION_INVENTORY_CERTIFICATION_ENGINEER_EXPEDITING.getValue())){ + templateId = TemplateInfoEnum2.CERTIFICATION_MESSAGE16.getValue(); + } + + larkMesJson.put("template_id", templateId); + larkMesJson.put("userIds",thirdId); + + Map templateVariableMap = new HashMap<>(); + templateVariableMap.put("projectNameCn",PRN_CN); + templateVariableMap.put("projectNameEn",PRN_EN); + templateVariableMap.put("standName",standName); + templateVariableMap.put("itemName",itemName); + templateVariableMap.put("Initiator",projectLibraryBase.getStudioEngineerName()); + templateVariableMap.put("endTime",DateUtils.formatDate(endTime)); + templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN); + templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN); + + larkMesJson.put("templateVariableMap",templateVariableMap); + this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson); + } catch (Exception e) { + log.error("飞书消息推送失败"); + } + }*/ + } + } + } + + return Result.OK("催办成功!"); + } + + /** + * 获取标准编号和检验项目 发飞书消息使用 + * @param projectCertificationInventoryEOList + * @return + */ + @Override + public Map getStandNameAndItemName(List projectCertificationInventoryEOList){ + Map result = new HashMap<>(); + StringBuilder standNameSb = new StringBuilder(); + StringBuilder itemNameSb = new StringBuilder(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + if(StringUtils.isNotEmpty(projectCertificationInventoryEO.getInspectionItem())){ + itemNameSb.append(projectCertificationInventoryEO.getInspectionItem()).append(","); + } + if(StringUtils.isNotEmpty(projectCertificationInventoryEO.getSerialNumber())){ + standNameSb.append(projectCertificationInventoryEO.getSerialNumber()).append(","); + } + } + + String standName = ""; + if(StringUtils.isNotEmpty(standNameSb.toString())){ + standName = standNameSb.toString().substring(0,standNameSb.toString().length()-1); + } + String itemName = ""; + if(StringUtils.isNotEmpty(itemNameSb.toString())){ + itemName = itemNameSb.toString().substring(0,itemNameSb.toString().length()-1); + } + + result.put("standName",standName); + result.put("itemName",itemName); + return result; + } + + /** + * 获取认证清单飞书跳转链接 + * @param projectLibraryId + * @param PRN_CN + * @param PRN_EN + * @return + */ + @Override + public Map getCertificationInventoryLinkHrefFeishu(String projectLibraryId,String PRN_CN,String PRN_EN){ + Map result = new HashMap<>(); + + String hrefFeishu_CN = backUrl + + JumpLinkEnum.CERTIFICATION_INVENTORY_LINK.getLink() + + projectLibraryId + + JumpLinkEnum.CERTIFICATION_INVENTORY_LINK.getType() + + "&projectName=" + PRN_CN; + + //飞书跳转链接 + String hrefFeishu_EN = backUrl + + JumpLinkEnum.CERTIFICATION_INVENTORY_LINK.getLink() + + projectLibraryId + + JumpLinkEnum.CERTIFICATION_INVENTORY_LINK.getType() + + "&projectName=" + PRN_EN; + + //飞书手机跳转链接 + String hrefFeishu_CN_P = backUrlPhone + + JumpLinkEnum.TO_DO_CENTER_PHONE.getLink()+ "?keyWord=" + PRN_CN; + + + result.put("hrefFeishu_CN", URLUtil.encode(hrefFeishu_CN)); + result.put("hrefFeishu_EN",URLUtil.encode(hrefFeishu_EN)); + result.put("hrefFeishu_CN_P",URLUtil.encode(hrefFeishu_CN_P)); + return result; + } + + + @Override + public Result updateConfigItemBatch(JSONObject json) { + String ids = json.getString("ids"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("至少选择一条数据进行操作!"); + } + + String configItem = json.getString("configItem"); + if(StringUtils.isEmpty(ids)){ + throw new JeroBootException("请选择一个配置!"); + } + QueryWrapper queryWrap = new QueryWrapper<>(); + queryWrap.lambda().in(ProjectCertificationInventoryEO::getId,ids.split(",")); + List projectCertificationInventoryEOList = this.list(queryWrap); + projectCertificationInventoryEOList.forEach(certificationInventoryEO -> { + certificationInventoryEO.setConfigItem(configItem); + }); + + this.updateBatchById(projectCertificationInventoryEOList); + return Result.OK("修改配置成功!"); + } + + @Override + public Result callAdd(JSONObject json) { + String cut = json.getString("cut"); + List result = new ArrayList<>(); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + result.add("调取成功!"); + }else { + result.add("Successfully retrieved!"); + } + + String authDummyInventoryBaseId = json.getString("authDummyInventoryBaseId"); + if(StringUtils.isEmpty(authDummyInventoryBaseId)){ + throw new JeroBootException("请选择一个认证虚拟清单进行操作!"); + } + + String authDummyInventoryInfoIds = json.getString("authDummyInventoryInfoIds"); + if(StringUtils.isEmpty(authDummyInventoryInfoIds)){ + throw new JeroBootException("至少选择一条数据进行调取!"); + } + + String projectLibraryId = json.getString("projectLibraryId"); + + QueryWrapper authDummyInfoQueryWrap = new QueryWrapper<>(); + authDummyInfoQueryWrap.lambda().in(AuthDummyInventoryInfoEO::getId,authDummyInventoryInfoIds.split(",")); + List authDummyInventoryInfoEOList = this.authDummyInventoryInfoEOService.list(authDummyInfoQueryWrap); + + if(CollectionUtils.isNotEmpty(authDummyInventoryInfoEOList)){ + // 获取该项目相关人员名单信息,用于根据责任领域配置数据 自动设置责任人、接口人。 + QueryWrapper prpQueryWrap = new QueryWrapper<>(); + prpQueryWrap.lambda().eq(ProjectRelatedPersonnel::getProjectId,projectLibraryId); + List prpEoList = this.projectRelatedPersonnelService.list(prpQueryWrap); + + QueryWrapper lawsInventoryEOQueryWrap = new QueryWrapper<>(); + lawsInventoryEOQueryWrap.lambda().eq(ProjectLawsInventoryEO::getProjectLibraryId,projectLibraryId); + List projectLawsInventoryEOList = this.platformProjectLawsInventoryEOService.list(lawsInventoryEOQueryWrap); + + List projectCertificationInventoryEOList = new ArrayList<>(); + + List noSerialNumberList = new ArrayList<>(); + + for (AuthDummyInventoryInfoEO authDummyInventoryInfoEO : authDummyInventoryInfoEOList) { + if(CollectionUtils.isEmpty(projectLawsInventoryEOList)){ + break; + } + + // 根据选择调取的数据法规编号,跟当前项目中 法规清单数据法规编号对比,如果有,则加入,如果没有,则不加入。 + List lawsInventoryEOListTemp = projectLawsInventoryEOList.stream().filter(lawsInventoryEO -> { + boolean flag = false; + String adiSn = authDummyInventoryInfoEO.getSerialNumber(); + BussDocumentLibraryEO bl = iBussDocumentLibraryEOService.getBySerialNumber(adiSn); + if(ObjectUtils.isNotEmpty(bl)){ + if (StringUtils.equals(bl.getId(), lawsInventoryEO.getStandId())) { + flag = true; + } + } + + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(lawsInventoryEOListTemp)){ + ProjectCertificationInventoryEO projectCertificationInventoryEOTemp = new ProjectCertificationInventoryEO(); + BeanUtils.copyProperties(authDummyInventoryInfoEO,projectCertificationInventoryEOTemp); + + String dutyTerritory = projectCertificationInventoryEOTemp.getDutyTerritory(); + if(StringUtils.isNotEmpty(dutyTerritory)){ + if(CollectionUtils.isNotEmpty(prpEoList)){ + List prpEoListTemp = prpEoList.stream().filter(prpEo -> { + boolean flag = false; + if (StringUtils.equals(prpEo.getDutyTerritory(), dutyTerritory)) { + flag = true; + } + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(prpEoListTemp)){ + List engineeringInterfacePersonIdList = new ArrayList<>(); + ProjectRelatedPersonnel prpEo = prpEoListTemp.get(0); + if(StringUtils.isNotBlank(prpEo.getEngineeringInterfacePerson())){ + List engineeringInterfacePersonList = Arrays.asList(prpEo.getEngineeringInterfacePerson().split(",")); + engineeringInterfacePersonIdList.addAll(engineeringInterfacePersonList); + } + if(StringUtils.isNotBlank(prpEo.getEngineerAttSet())){ + List engineerAttSetList = Arrays.asList(prpEo.getEngineerAttSet().split(",")); + engineeringInterfacePersonIdList.addAll(engineerAttSetList); + } + if(StringUtils.isNotBlank(prpEo.getEngineerLawSet())){ + List engineerLawSetList = Arrays.asList(prpEo.getEngineerLawSet().split(",")); + engineeringInterfacePersonIdList.addAll(engineerLawSetList); + } + + engineeringInterfacePersonIdList = engineeringInterfacePersonIdList.stream().distinct().collect(Collectors.toList()); + if(CollectionUtils.isNotEmpty(engineeringInterfacePersonIdList) && engineeringInterfacePersonIdList.size() == 1){ + projectCertificationInventoryEOTemp.setSdt(engineeringInterfacePersonIdList.get(0)); + projectCertificationInventoryEOTemp.setDutyPerson(engineeringInterfacePersonIdList.get(0)); + } + } + } + } + + projectCertificationInventoryEOTemp.setId(UUID.randomUUID().toString().replace("-", "")); + projectCertificationInventoryEOTemp.setProjectLibraryId(projectLibraryId); + projectCertificationInventoryEOTemp.setFlowStatus(CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()); + projectCertificationInventoryEOTemp.setCreateTime(new Date()); + projectCertificationInventoryEOTemp.setUpdateTime(new Date()); + projectCertificationInventoryEOTemp.setCertificationProgress(CertificationProgressEnum.NOT_START.getValue()); + projectCertificationInventoryEOList.add(projectCertificationInventoryEOTemp); + }else { + noSerialNumberList.add(authDummyInventoryInfoEO.getSerialNumber()); + } + } + + + if(CollectionUtils.isNotEmpty(noSerialNumberList)){ + // 判断调取的数据中,是否有 在当前项目库法规清单中 没有的编号 + if (StringUtils.equals(cut, CutEnum.CN.getValue())) { + result.add("您所选的数据中包含当前项目中不包含的法规编号信息,已为您过滤添加。"); + }else { + result.add("The data you have selected contains regulatory number information that is not included in the current project, and has been filtered and added for you."); + } + } + +// List saveDataList = this.dataUniqueCheck(projectCertificationInventoryEOList, cut, result, projectLibraryId); + + this.saveBatch(projectCertificationInventoryEOList); + + // 设置历史log(修改历史) + this.saveProjectCertificationInventoryLog(projectCertificationInventoryEOList,OperatorTypeEnum.CERTIFICATION_INVENTORY_CALL_ADD.getValue()); + + Date now = new Date(); + //设置权限 先删后加 + List adds = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci: projectCertificationInventoryEOList) { + if (ObjectUtils.isNotEmpty(pci.getSdt())) { + setProjectCertificationInventoryPermission(pci.getSdt(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(pci.getDutyPerson())) { + setProjectCertificationInventoryPermission(pci.getDutyPerson(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + } + + return Result.OK(result); + } + + /** + * 数据导入 + * @param file + * @param projectCertificationInventoryEO + */ + @SneakyThrows + @Override + public void importData(MultipartFile file, ProjectCertificationInventoryEO projectCertificationInventoryEO) { + String title = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + title = "*类别,*检验项目,*配置项,*认证类型,*WVTA ID," + + "*标准编号,*责任领域,*工程接口人,*责任人," + + "交付物模板,*交付物类型,*截止日期,报告编号,产品型号,生产企业名称"; + }else { + title = "*Category,*Inspection Items,*Configuration Item,*Certification Type,*WVTA ID," + + "*Standard No,*Responsible Field,*Eng. Interface,*Assignee," + + "Deliverable Template,*Deliverable Type,*Due Date,Report No,Product Model,Name Of Manufacturer"; + } + + int pos = file.getOriginalFilename().lastIndexOf("."); + String str = file.getOriginalFilename().substring(pos + 1).toLowerCase(); + String filenameorg = file.getOriginalFilename().substring(0, pos); + //判断上传文件必须是zip + if (!str.equals("zip")) { + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("请上传zip格式的文件或rar格式的文件"); + }else{ + throw new JeroBootException("Please upload a zip file or rar file"); + } + + } + String path = uploadpath + File.separator + "modal" + File.separator + filenameorg + System.currentTimeMillis(); + File saveDirectory = new File(path); + if (!saveDirectory.isDirectory()) { + saveDirectory.mkdir(); + } + FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + File.separator + file.getOriginalFilename())); + //解压缩 + String zipEntryName = ""; + if (str.equals("zip")) { + zipEntryName = FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), path); + } + + + //判断压缩包下是否只有一个文件夹 + File fileTemp = new File(path); + int length = fileTemp.listFiles().length; + if (length > 2) { + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("压缩包中必须有且仅有一个文件夹,请重新上传"); + }else{ + throw new JeroBootException("There must be only one folder in the compressed package Please upload it again"); + } + + } + File fileNew = new File(zipEntryName); + List fileList = new ArrayList<>(); + for (File file1 : fileNew.listFiles()) { + if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx")) { + fileList.add(file1); + } + } + if (fileList.size() == 0) { + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("压缩包根目录下没有excel作为导入数据,请重新上传"); + }else{ + throw new JeroBootException("Excel does not exist in the root directory of the compressed package Please upload it again"); + } + + } else if (fileList.size() > 1) { + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("压缩包根目录下仅能存在一个excel为导入数据,请重新上传"); + }else{ + throw new JeroBootException("Only one Excel file can be imported in the compressed package root directory. Please upload data again"); + } + + } + + // 数据相关处理, + // 1.获取其中的Excel, + List excelfilelist = FileUnZip.readImpExcelFile(zipEntryName); + System.gc(); + if (excelfilelist.size() < 1) { + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("压缩包内没有上传Excel数据"); + }else{ + throw new JeroBootException("No Excel data is uploaded in the compressed package"); + } + + } else if (excelfilelist.size() > 1) { + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("压缩包内有多个Excel数据源"); + }else{ + throw new JeroBootException("There are multiple Excel data sources in the zip package"); + } + + } + List datas = new ArrayList<>(); + File excelFile = excelfilelist.get(0); + Workbook workbook = WorkbookFactory.create(excelFile); + List> dataList = new ArrayList<>(); + if (workbook != null) { + DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + Sheet sheet = workbook.getSheetAt(0); + if (sheet != null) { + StringBuilder headerSb = new StringBuilder(); + int rowNos = sheet.getLastRowNum();// 得到excel的总记录条数 + for (int i = 0; i <= rowNos; i++) { + Row row = sheet.getRow(i); + Row headerRow = sheet.getRow(i); + boolean isBlank = isRowEmpty(row); + String key = ""; + if (row != null && !isBlank) { + int columNos = headerRow.getLastCellNum();// 表头总共的列数 + Map rowList = new LinkedHashMap<>(); + for (int j = 0; j < columNos; j++) { + Cell cell = row.getCell(j); + Cell headerCell = headerRow.getCell(j); + if (cell != null) { + if (i == 0) { + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + headerSb.append(cell.getStringCellValue() + ","); + if(j == 15){ + break; + } + } else if(i > 1){ + List headList = Arrays.asList(headerSb.toString().split(",")); + String field =""; + if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) { + Date d = cell.getDateCellValue(); + field = fieldConvert(headList.get(j)); + rowList.put(field, df.format(d)); + } else { + field = fieldConvert(headList.get(j)); + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + String stringCellValue = cell.getStringCellValue(); + if (StringUtils.isNotBlank(stringCellValue)) { + String replace = stringCellValue.replace(",", ","); + rowList.put(field, replace); + } else { + rowList.put(field, ""); + } + } + } + } + } + if (i > 1) { + dataList.add(rowList); + } + } + } + if (dataList.size() == 0) { + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("请填写必填字段内容,带*的为必填"); + }else{ + throw new JeroBootException("Please fill in the required fields marked with *"); + } + + }else{ + //数据转换 JSON.parseObject(JSON.toJSONString(map), MyUser.class) + for (Map stringStringMap : dataList) { + ProjectCertificationInventoryEO projectCertificationInventoryEOTemp = JSON.parseObject(JSON.toJSONString(stringStringMap), ProjectCertificationInventoryEO.class); + projectCertificationInventoryEOTemp.setCut(projectCertificationInventoryEO.getCut()); + projectCertificationInventoryEOTemp.setProjectLibraryId(projectCertificationInventoryEO.getProjectLibraryId()); + projectCertificationInventoryEOTemp.setFlowStatus(CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()); + projectCertificationInventoryEOTemp.setCertificationProgress(CertificationProgressEnum.NOT_START.getValue()); + datas.add(projectCertificationInventoryEOTemp); + } + } + // 校验头部是否符合模板 + String substring = headerSb.toString(); + if (substring.endsWith(",") || substring.endsWith(",")){ + substring = headerSb.substring(0, headerSb.length() - 1); + } + + String excelHeader = substring.toString(); + if (!title.equals(excelHeader)) { + workbook.close(); + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("读取失败,请严格按照模板文件导入数据"); + }else{ + throw new JeroBootException("The data fails to be read. Import data strictly according to the template file"); + } + } + //必填项校验 + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + for(int k = 0 ; k categoryList = sysCategoryService.list(); + //普通数据字典 + List dictItemList = sysDictItemServiceImpl.selectItemsAll(); + importDatas(datas, dictItemList, zipEntryName,saveDirectory,projectCertificationInventoryEO,categoryList); +// String cut = projectCertificationInventoryEO.getCut(); +// importDisposeData(datas,cut); + //删除原上传文件 + FileUnZip.deleteDir(saveDirectory); + + } + + private void importDatas(List datas, + List dictItemList, String zipEntryName, + File saveDirectory, ProjectCertificationInventoryEO projectCertificationInventoryEOTemp, + List categoryList) { + List msgList = new ArrayList<>(); + //模板数据验证 + msgList = dataTemplateVerify(datas, dictItemList, zipEntryName, projectCertificationInventoryEOTemp, categoryList); + + if (msgList.size() > 0) { + //返回报错信息 + String html = ""; + for (String s : msgList) { + html += s + "
"; + } + FileUnZip.deleteDir(saveDirectory); + throw new JeroBootException(html); + }else { + if (datas.size() != 0) { + this.saveBatch(datas); + + this.saveProjectCertificationInventoryLog(datas,OperatorTypeEnum.CERTIFICATION_INVENTORY_IMPORT_ADD.getValue()); + + Date now = new Date(); + //设置权限 先删后加 + List adds = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci: datas) { + if (ObjectUtils.isNotEmpty(pci.getSdt())) { + setProjectCertificationInventoryPermission(pci.getSdt(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(pci.getDutyPerson())) { + setProjectCertificationInventoryPermission(pci.getDutyPerson(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + } + } + } + + //模板数据验证 + private List dataTemplateVerify(List datas, + List dictItemList, String zipEntryName, + ProjectCertificationInventoryEO projectCertificationInventoryEOTemp, + List categoryList) { + String dictId = sysCategoryMapper.getDictId("ren4_zheng4_-_jiao1_fu4_wu4_lei4_xing2"); + List collect = categoryList.stream().filter(e -> e.getSysDictId().equals(dictId)).collect(Collectors.toList()); + List treeNameList = new ArrayList<>(); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + treeNameList = collect.stream().map(SysCategory::getName).collect(Collectors.toList()); + }else{ + treeNameList = collect.stream().map(SysCategory::getEnName).collect(Collectors.toList()); + } + int i = 2; + List msgList = new ArrayList<>(); + String value = ""; + boolean flag = true; + +// List listUserName = new ArrayList<>(); +// listUserName = sysUserMapper.getListUserName(); +// listUserName = listUserName.stream().distinct().collect(Collectors.toList()); + + List userNameList = datas.stream().map(ProjectCertificationInventoryEO::getDutyPersonName).distinct().collect(Collectors.toList()); + List listUserName = this.sysUserService.querySysUserByUserNameList(userNameList); + + //编号验证 + verifySerialNumber(datas,projectCertificationInventoryEOTemp); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : datas) { + i++; + String errorMsg = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + errorMsg = "第" + i + "行:"; + }else{ + errorMsg = i + " line:"; + } + //类别 + String category = projectCertificationInventoryEO.getCategory(); + //检验项目 + String inspectionItem = projectCertificationInventoryEO.getInspectionItem(); + //配置项 + String configItem = projectCertificationInventoryEO.getConfigItem(); + //WVTA ID + String wvtaId = projectCertificationInventoryEO.getWvtaId(); + //标准编号 + String serialNumber = projectCertificationInventoryEO.getSerialNumber(); + //责任领域 + String dutyTerritory = projectCertificationInventoryEO.getDutyTerritoryName(); + //工程接口人engineeringInterfacePerson + String sdt = projectCertificationInventoryEO.getSdtName(); + //责任人 + String dutyPerson = projectCertificationInventoryEO.getDutyPersonName();; + //交付物类型 + String deliverableType = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + deliverableType = projectCertificationInventoryEO.getDeliverableTypeName(); + }else { + deliverableType = projectCertificationInventoryEO.getDeliverableTypeNameEn(); + } + + //截止时间 + String endTime = projectCertificationInventoryEO.getEndTimeStr(); + //报告编号 + String reportNumber = projectCertificationInventoryEO.getReportNumber(); + //产品型号 + String productModel = projectCertificationInventoryEO.getProductModel(); + //生产企业名称 + String productionEnterpriseName = projectCertificationInventoryEO.getProductionEnterpriseName(); + + //文件 + //交付物模板 + String deliverableTemplate = projectCertificationInventoryEO.getDeliverableTemplateName(); + + // 认证类型 + String attestationTypeName = projectCertificationInventoryEO.getAttestationTypeName(); + + + + + //编号必填 +// flag = must(projectCertificationInventoryEO, errorMsg, msgList, serialNumber, "编号", "Standard No"); + + + + //类别 + if(StringUtils.isNotBlank(category)){ + if(category.length() > 300){ + String message = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + message = errorMsg + "类别不能超过300个字符"; + }else{ + message = errorMsg + " The Category cannot contain more than 300 characters"; + } + msgList.add(message); + } + } + //检验项目 + if(StringUtils.isNotBlank(inspectionItem)){ + if(inspectionItem.length() > 300){ + String message = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + message = errorMsg + "检验项目不能超过300个字符"; + }else{ + message = errorMsg + " The InspectionItem cannot contain more than 300 characters"; + } + msgList.add(message); + } + } + //配置项 + if(StringUtils.isNotBlank(configItem)){ + if(configItem.length() > 300){ + String message = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + message = errorMsg + "配置项不能超过300个字符"; + }else{ + message = errorMsg + " The ConfigItem cannot contain more than 300 characters"; + } + msgList.add(message); + } + } + //WVTA ID + if(StringUtils.isNotBlank(wvtaId)){ + if(wvtaId.length() > 300){ + String message = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + message = errorMsg + "WVTA ID不能超过300个字符"; + }else{ + message = errorMsg + " The WVTA ID cannot contain more than 300 characters"; + } + msgList.add(message); + } + } + + //责任领域 + if(StringUtils.isNotBlank(dutyTerritory)){ + value = pullMore(dictItemList, projectCertificationInventoryEO, errorMsg, dutyTerritory,msgList,"责任领域","Responsible Field","duty_territory"); + if(StringUtils.isNotBlank(value)){ + projectCertificationInventoryEO.setDutyTerritory(value); + } + } + //工程接口人(责任领域下的工程接口人) + Map objectMap = iProjectRelatedPersonnelService.queryPersonByProjectId(projectCertificationInventoryEOTemp.getProjectLibraryId(), value); + + //工程接口人 + List> mapPersonList = (List>) objectMap.get("engineeringInterfacePersonList"); + + + String nameCn = ""; + String nameEn = ""; + //工程接口人 + if(StringUtils.isNotBlank(sdt)){ + nameCn = "工程接口人"; + nameEn = "Eng. Interface "; + //验证人员是否存在 + personnelVerify(projectCertificationInventoryEO, errorMsg, msgList, sdt, mapPersonList,nameCn,nameEn, com.jero.modules.project.enums.ProjectRoleEnum.ENGINEERING_INTERFACE_PERSON.getValue()); + } + + //责任人 + if(StringUtils.isNotBlank(dutyPerson)){ + nameCn = "责任人"; + nameEn = "Assignee"; + //验证人员是否存在 + personDutyPerson(projectCertificationInventoryEO, errorMsg, msgList, dutyPerson, listUserName,nameCn,nameEn); + } + + //交付物模板 + value = templateTransition(zipEntryName, projectCertificationInventoryEO, errorMsg, deliverableTemplate,msgList,"交付物模板","Deliverable Template"); + if(StringUtils.isNotBlank(value)){ + projectCertificationInventoryEO.setDeliverableTemplate(value); + } + + //交付物类型 + if(StringUtils.isNotEmpty(deliverableType)){ + value = tree(categoryList,treeNameList, projectCertificationInventoryEO, errorMsg, deliverableType,msgList,"交付物类型","Deliverable Type","deliverable_template"); + if(StringUtils.isNotBlank(value)){ + String treeId = getTreeId(categoryList, projectCertificationInventoryEOTemp, treeNameList, value); + projectCertificationInventoryEO.setDeliverableType(treeId); + } + } + + //截止时间 +// SimpleDateFormat sd = new SimpleDateFormat(); +// String endTimeStr = sd.format(endTime); + + flag = dateVerify(projectCertificationInventoryEO, errorMsg, endTime,msgList,"截止日期","Due Date"); + if(flag){ + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); + Date date = null; + try { + if(!endTime.contains("-")){ + endTime = DateUtils.coverDate(endTime); + } + date = sd.parse(endTime); + } catch (ParseException e) { + e.printStackTrace(); + } + projectCertificationInventoryEO.setEndTime(date); + } + + //报告编号 + if(StringUtils.isNotBlank(reportNumber)){ + if(reportNumber.length() > 200){ + String message = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + message = errorMsg + "报告编号不能超过200个字符"; + }else{ + message = errorMsg + " The Report No cannot contain more than 200 characters"; + } + msgList.add(message); + } + } + //产品型号 + if(StringUtils.isNotBlank(productModel)){ + if(productModel.length() > 200){ + String message = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + message = errorMsg + "产品型号不能超过200个字符"; + }else{ + message = errorMsg + " The Product Model cannot contain more than 200 characters"; + } + msgList.add(message); + } + } + //生产企业名称 + if(StringUtils.isNotBlank(productionEnterpriseName)){ + if(productionEnterpriseName.length() > 200){ + String message = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())){ + message = errorMsg + "生产企业名称不能超过200个字符"; + }else{ + message = errorMsg + " The Name Of Manufacturer cannot contain more than 200 characters"; + } + msgList.add(message); + } + } + + if (StringUtils.isNotEmpty(attestationTypeName)) { + value = pullMore(dictItemList, projectCertificationInventoryEO, errorMsg, attestationTypeName,msgList,"认证类型","Certification Type","ren4_zheng4_qing1_dan1_-_ren4_zheng4_lei4_xing2"); + if(StringUtils.isNotBlank(value)){ + projectCertificationInventoryEO.setAttestationType(value); + } + } + + } + return msgList; + } + //必填 + private boolean must(ProjectCertificationInventoryEO projectCertificationInventoryEO, String errorMsg, + List msgList, String serialNumber,String nameCn,String nameEn) { + int errorCount = 0; + if(StringUtils.isBlank(serialNumber)){ + errorCount ++; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn + "为必填项,不能为空, "; + }else{ + errorMsg += nameEn + "This parameter is mandatory and cannot be empty, "; + } + msgList.add(errorMsg); + } + if(errorCount == 0){ + return true; + }else{ + return false; + } + } + + private boolean dateVerify(ProjectCertificationInventoryEO projectCertificationInventoryEO, + String errorMsg, String field, List msgList, String nameCn, String nameEn) { + + //判断格式是否正确 + boolean flag = true; + if(ObjectUtils.isNotEmpty(field)){ +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); +// String format = sdf.format(field); + if (!DateUtils.isValidDate(field)) { + flag = false; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn + "格式不正确, 正确格式如:yyyy/m/d、yyyy-MM-dd、yyyy年MM月dd日"; + }else{ + errorMsg += nameEn + " Incorrect format correct format is:yyyy/m/d、yyyy-MM-dd、yyyy年MM月dd日"; + } + msgList.add(errorMsg); + }else{ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date now = new Date(); + String nowStr = sdf.format(now); +// String fieldStr = sdf.format(field); + Date now1 = null; + Date field1 = null; + try { + if(!field.contains("-")){ + field = DateUtils.coverDate(field); + } + now1 = sdf.parse(nowStr); + field1 = sdf.parse(field); + long day = now1.getTime()-field1.getTime(); + if(day>0){ + flag = false; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn + "不能导入今天之前的日期"; + }else{ + errorMsg += nameEn + " Cannot import dates before today"; + } + msgList.add(errorMsg); + } + } catch (ParseException e) { + e.printStackTrace(); + } + } + } + return flag; + } + + private String templateTransition(String zipEntryName, + ProjectCertificationInventoryEO projectCertificationInventoryEO, + String errorMsg, String deliverableTemplate, List msgList, + String nameCn, String nameEn) { + String value = ""; + if (StringUtils.isNotBlank(deliverableTemplate)) { + StringBuilder sb = new StringBuilder(); + for (String fileName : deliverableTemplate.split(",")) { + List nowFileList = new ArrayList<>(); + + nowFileList = FileUnZip.readFileByFilename(zipEntryName, fileName,projectCertificationInventoryEO.getCut(),errorMsg,msgList,nameCn,nameEn); + + if (nowFileList.size() == 0) { +// if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ +// errorMsg += "压缩包中没有" + fileName + "文件; "; +// }else{ +// errorMsg += " Not in the zip package" + fileName + "file; "; +// } +// msgList.add(errorMsg); + } else { + try { + FileInputStream input = new FileInputStream(nowFileList.get(0)); + MultipartFile multipartFile = + new MockMultipartFile(nowFileList.get(0).getName(), nowFileList.get(0).getName(), "text/plain", input); + //文件存入文件表 + OSSFile ossFile = iOSSFileService.uploadLocalOfCos(multipartFile, "", null,null); + if (ObjectUtils.isNotEmpty(ossFile)) { + sb.append(ossFile.getId() + ","); + } + } catch (IOException e) { + log.error("认证清单导入"+e.getMessage()); + } + } + } + if (StringUtils.isNotBlank(sb)) { + value = sb.substring(0, sb.length() - 1); + } + } + return value; + } + + private String getTreeId(List categoryList, + ProjectCertificationInventoryEO projectCertificationInventoryEOTemp, + List treeNameList, String value) { + StringBuilder sb = new StringBuilder(); + for (String valueTemp : value.split(",")) { + if (treeNameList.contains(valueTemp)) { + List sysCategoryList = new ArrayList<>(); + if (CutEnum.CN.getValue().equals(projectCertificationInventoryEOTemp.getCut())) { + sysCategoryList = categoryList.stream().filter(e -> e.getName().equals(valueTemp)).collect(Collectors.toList()); + } else { + sysCategoryList = categoryList.stream().filter(e -> e.getEnName().equals(valueTemp)).collect(Collectors.toList()); + } + if (sysCategoryList.size() != 0) { + sb.append(sysCategoryList.get(0).getId() + ","); + } + } + } + if (StringUtils.isNotBlank(sb)) { + String substring = sb.substring(0, sb.length() - 1); + return substring; + } + return null; + } + + private String tree(List categoryList, List nameList, + ProjectCertificationInventoryEO projectCertificationInventoryEO, + String errorMsg, String value, List msgList, + String nameCn, String nameEn, String dictCode) { + if (StringUtils.isNotBlank(value)) { + StringBuilder sb = new StringBuilder(); + for (String s : value.split(",")) { + if(!nameList.contains(s)){ + sb.append(s+","); + } + } + if(StringUtils.isNotBlank(sb)){ + String substring = sb.substring(0, sb.length() - 1); + if (CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())) { + errorMsg += nameCn + "中的" + substring + "与数据字典不匹配"; + } else { + errorMsg += nameEn + " " + substring + " does not match the data dictionary"; + } + msgList.add(errorMsg); + }else{ + StringBuilder sbTemp = new StringBuilder(); + for (String s : value.split(",")) { + List collect = new ArrayList<>(); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + collect = categoryList.stream().filter(e -> s.equals(e.getName())).collect(Collectors.toList()); + if(collect.size() != 0){ + sbTemp.append(collect.get(0).getName()+","); + } + }else{ + collect = categoryList.stream().filter(e -> s.equals(e.getEnName())).collect(Collectors.toList()); + if(collect.size() != 0){ + sbTemp.append(collect.get(0).getEnName()+","); + } + } + } + if(StringUtils.isNotBlank(sbTemp)){ + String substring = sbTemp.substring(0, sbTemp.length() - 1); + return substring; + } + } + } + return null; + } + private void personDutyPerson(ProjectCertificationInventoryEO projectCertificationInventoryEO, + String errorMsg, List msgList, String regulationOwnerId, + List listUserName ,String nameCn, String nameEn){ + //单选 + if(regulationOwnerId.contains(",")){ + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn + "导入只能填写一个用户名, "; + }else{ + errorMsg += "Only one user name can be entered for"+ nameEn +"import, "; + } + msgList.add(errorMsg); + } + + int count =0; + for(SysUser name : listUserName){ + if(StringUtils.isNotEmpty(name.getUsername())){ + if(name.getUsername().equals(regulationOwnerId)){ + count++; + String id = name.getId(); + projectCertificationInventoryEO.setDutyPerson(id); + break; + } + } + } + if(count==0){ + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn+regulationOwnerId+"与所有人员名单不匹配, "; + }else{ + errorMsg += nameEn+regulationOwnerId+"does not match a person with all person list, "; + } + msgList.add(errorMsg); + } + } + private void personnelVerify(ProjectCertificationInventoryEO projectCertificationInventoryEO, + String errorMsg, List msgList, String regulationOwnerId, + List> mapList, String nameCn, String nameEn, String fieldNumber) { + //单选 + if(regulationOwnerId.contains(",")){ + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn + "导入只能填写一个用户名"; + }else{ + errorMsg += "Only one user name can be entered for"+ nameEn +"import"; + } + msgList.add(errorMsg); + } + + if(mapList.size() != 0){ + int count = 0; + for (Map stringStringMap : mapList) { + String name = stringStringMap.get("name"); + if(regulationOwnerId.equals(name)){ + count ++; + if(com.jero.modules.project.enums.ProjectRoleEnum.ENGINEERING_INTERFACE_PERSON.getValue().equals(fieldNumber)){ + projectCertificationInventoryEO.setSdt(stringStringMap.get("value")); + } + break; + } + } + if(count == 0){ + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn+regulationOwnerId+"与相关人员名单中责任领域下的人员不匹配"; + }else{ + errorMsg += nameEn+regulationOwnerId+"does not match a person under the Responsible Field in the relevant person list"; + } + msgList.add(errorMsg); + } + }else{ + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + errorMsg += nameCn+regulationOwnerId+"与相关人员名单中责任领域下的人员不匹配"; + }else{ + errorMsg += nameEn+regulationOwnerId+"does not match a person under the Responsible Field in the relevant person list"; + } + msgList.add(errorMsg); + } + } + + private String pullMore(List dictItemList, ProjectCertificationInventoryEO projectCertificationInventoryEO, + String errorMsg, String value, List msgList, + String nameCn, String nameEn, String dictCode) { + List valueList = new ArrayList<>(); + if (StringUtils.isNotBlank(value)) { + List list = Arrays.asList(value.split(",")); + List sysDictItemList = new ArrayList<>(); + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + sysDictItemList = dictItemList.stream().filter(e ->dictCode.equals(e.getDictCode()) && list.contains(e.getItemText())).collect(Collectors.toList()); + }else{ + sysDictItemList = dictItemList.stream().filter(e ->dictCode.equals(e.getDictCode()) && list.contains(e.getEnName())).collect(Collectors.toList()); + } + + if(list.size() == sysDictItemList.size()){ + valueList = sysDictItemList.stream().map(SysDictItem::getItemValue).collect(Collectors.toList()); + + }else{ + //数据中有与数据字典不匹配的值 + List finalValueList = valueList; + List diffList = list.stream().filter(e -> !finalValueList.contains(e)).collect(Collectors.toList()); + if (CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())) { + errorMsg += nameCn + "中的" + StringUtils.join(diffList,",") + "与数据字典不匹配"; + } else { + errorMsg += nameEn + " " + StringUtils.join(diffList,",") + " does not match the data dictionary"; + } + msgList.add(errorMsg); + } + } + return StringUtils.join(valueList,","); + } + + + //编号验证 + private void verifySerialNumber(List datas, + ProjectCertificationInventoryEO projectCertificationInventoryEOTemp) { + + + List serialNumberList = datas.stream().map(ProjectCertificationInventoryEO::getSerialNumber).collect(Collectors.toList()); + //1. 验证标准号在文档库中是否存在 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.in(BussDocumentLibraryEO::getSerialNumber,serialNumberList); + List bussDocumentLibraryEOList = iBussDocumentLibraryEOService.list(wrapper); + //文档库中可能存在重复的标准号 + List serialNumberListTemp = bussDocumentLibraryEOList.stream().map(BussDocumentLibraryEO::getSerialNumber).distinct().collect(Collectors.toList()); + if(serialNumberList.size() != serialNumberListTemp.size()){ + //存在文档库没有的数据 + List collect = bussDocumentLibraryEOList.stream().map(BussDocumentLibraryEO::getSerialNumber).collect(Collectors.toList()); + List serialNumbers = serialNumberList.stream().filter(e -> !collect.contains(e)).collect(Collectors.toList()); + if(serialNumbers.size() > 0){ + if(CutEnum.CN.getValue().equals(datas.get(0).getCut())){ + throw new JeroBootException(StringUtils.join(serialNumbers,",")+"文档库中不存在,不能添加"); + }else{ + throw new JeroBootException(StringUtils.join(serialNumbers,",")+" does not exist in the document library and cannot be added"); + } + } + }else{ + //验证编号在法规清单中是否存在 + LambdaQueryWrapper lwrapper = new LambdaQueryWrapper<>(); + lwrapper.in(ProjectLawsInventoryEO::getSerialNumber,serialNumberList); + List projectLawsInventoryEOList = platformProjectLawsInventoryEOService.list(lwrapper); + List LawSerialNumberListTemp = projectLawsInventoryEOList.stream().map(ProjectLawsInventoryEO::getSerialNumber).distinct().collect(Collectors.toList()); + if(serialNumberList.size() != LawSerialNumberListTemp.size()){ + //存在法规清单中没有的数据 + List collect = projectLawsInventoryEOList.stream().map(ProjectLawsInventoryEO::getSerialNumber).collect(Collectors.toList()); + List serialNumbers = serialNumberList.stream().filter(e -> !collect.contains(e)).collect(Collectors.toList()); + if(serialNumbers.size() > 0){ + if(CutEnum.CN.getValue().equals(datas.get(0).getCut())){ + throw new JeroBootException(StringUtils.join(serialNumbers,",")+"法规清单中不存在,不能添加"); + }else{ + throw new JeroBootException(StringUtils.join(serialNumbers,",")+" does not exist in the project laws and cannot be added"); + } + } + } +// else{ +// for (ProjectCertificationInventoryEO projectCertificationInventoryEO : datas) { +// List collect = bussDocumentLibraryEOList.stream() +// .filter(e -> e.getSerialNumber().equals(projectCertificationInventoryEO.getSerialNumber())).collect(Collectors.toList()); +// projectCertificationInventoryEO.setBussDocumentLibraryId(collect.get(0).getId()); +// } +// } + } + + } + public static List copy(List list, + Class clazz) { + String oldOb = JSON.toJSONString(list); + return JSON.parseArray(oldOb, clazz); + } + + + /** + * 导出数据 + * @param response + * @param request + * @param projectCertificationInventoryEO + */ + @Override + public void exportData(HttpServletResponse response, HttpServletRequest request, ProjectCertificationInventoryEO projectCertificationInventoryEO) { + List dataList = new ArrayList<>(); + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(projectCertificationInventoryEO,request.getParameterMap()); + queryWrapper.in("project_library_id",projectCertificationInventoryEO.getProjectLibraryId()); + if(StringUtils.isNotBlank(projectCertificationInventoryEO.getIds())){ + queryWrapper.in("id",Arrays.asList(projectCertificationInventoryEO.getIds().split(","))); + } + queryWrapper.orderByDesc("create_time"); + //获取当前的projectId + String projectId = projectCertificationInventoryEO.getProjectLibraryId(); + //获取当前用户 + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + Map params = new HashMap<>(); + params.put("projectLibraryId",projectId); + params.put("userId",currentUser.getId()); + params.put("modelType",RoleRelModelTypeEnum.CERTIFICATION_INVENTORY.getValue()); + ProjectLibraryRoleRelEO projectLibraryRoleRelEO = projectLibraryRoleRelEOService.queryByProjectLibraryIdAndUserId(params); + String roleCode = projectLibraryRoleRelEO.getRoleCode(); + // 创建查询权限 + this.createQueryPermission(queryWrapper,roleCode); + //导出的数据 + dataList = this.list(queryWrapper); + //文件 + List fileInfos = getOssFiles(dataList); + //处理文件名称 + + String fileName = ""; + for (int i = 0; i < dataList.size(); i++) { + if(StringUtils.isNotEmpty(dataList.get(i).getDeliverableTemplate())){ + String deliverableTemplateName = template(fileInfos, dataList.get(i).getDeliverableTemplate()); + dataList.get(i).setDeliverableTemplateName(deliverableTemplateName); + } + } + String cut = projectCertificationInventoryEO.getCut(); + disposeData(dataList,cut); + List copy = copy(dataList,ProjectCertificationInventoryDutyEnginnerEO.class); + + + + OutputStream os = null; + try { + response.setContentType("application/force-download"); + Workbook workbook = new XSSFWorkbook(); + String path = uploadpath + "/tempZip"; + File fileTemp = new File(path); + if (fileTemp.exists()) { + fileTemp.delete(); + } + fileTemp.mkdirs(); + //文件 + exportFile(dataList,fileInfos); + + + for(int i =0 ;i copyEn = new ArrayList<>(); + for (ProjectCertificationInventoryDutyEnginnerEO projectCertificationInventoryDutyEnginnerEOTemp : copy) { + ProjectCertificationInventoryDutyEnginnerEOEn projectCertificationInventoryDutyEnginnerEOEn = new ProjectCertificationInventoryDutyEnginnerEOEn(); + BeanUtils.copyProperties(projectCertificationInventoryDutyEnginnerEOTemp,projectCertificationInventoryDutyEnginnerEOEn); + copyEn.add(projectCertificationInventoryDutyEnginnerEOEn); + } + workbook = ExcelExportUtil.exportExcel(exportParams, ProjectCertificationInventoryDutyEnginnerEOEn.class, copyEn); + }else{ + List dataListEn = new ArrayList<>(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEOTemp : dataList) { + ProjectCertificationInventoryEOEn projectCertificationInventoryEOEn = new ProjectCertificationInventoryEOEn(); + BeanUtils.copyProperties(projectCertificationInventoryEOTemp,projectCertificationInventoryEOEn); + dataListEn.add(projectCertificationInventoryEOEn); + } + //下拉选中英文转换 +// transition(dataListEn,projectCertificationInventoryEO); + workbook = ExcelExportUtil.exportExcel(exportParams, ProjectCertificationInventoryEOEn.class, dataListEn); + } + } + workbook.write(excelOS); + excelOS.flush(); + + ZipUtil.zip(path, path + ".zip"); + //文件 + FileInputStream fis = new FileInputStream(path + ".zip"); + os = response.getOutputStream(); + + int len = 0; + while ((len = fis.read()) != -1) { + os.write(len); + } + os.flush(); + fis.close(); + } catch (IOException e) { + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + throw new JeroBootException("下载文件失败"); + }else{ + throw new JeroBootException("Failed to download file"); + } + } finally { + IOUtils.closeQuietly(os); + File file = new File(uploadpath + "/tempZip"); + FileUtil.deleteContents(file); + } + + } + + private void exportFile(List dataList, List fileInfos) throws IOException{ + if(fileInfos.size() != 0){ + for(ProjectCertificationInventoryEO projectCertificationInventoryEO : dataList){ + String deliverableTemplate = projectCertificationInventoryEO.getDeliverableTemplate(); + String serialNumber = projectCertificationInventoryEO.getSerialNumber(); + String deliveryResult = projectCertificationInventoryEO.getDeliveryResult(); + if(StringUtils.isBlank(serialNumber)){ + continue; + } + List deliverableTemplateFileList = new ArrayList<>(); + List deliveryResultList = new ArrayList<>(); + List oSSFileList = new ArrayList<>(); + if(StringUtils.isNotBlank(deliverableTemplate)){ + deliverableTemplateFileList = fileInfos.stream().filter(e -> deliverableTemplate.contains(e.getId())).collect(Collectors.toList()); + oSSFileList.addAll(deliverableTemplateFileList); + } + if(StringUtils.isNotBlank(deliveryResult) && projectCertificationInventoryEO.getValueType().equals(SysCategoryValueTypeEnum.FILE.getValue())){ + deliveryResultList = fileInfos.stream().filter(e -> deliveryResult.contains(e.getId())).collect(Collectors.toList()); + oSSFileList.addAll(deliveryResultList); + + } + if(oSSFileList.size() != 0){ + if(serialNumber.contains("/")){ + serialNumber = serialNumber.replaceAll("/","-"); + } + String fileNowPath = uploadpath + "/tempZip/" + serialNumber; + File file = new File(fileNowPath); + if (file.exists()) { + file.delete(); + } + file.mkdirs(); + for (OSSFile ossFile : oSSFileList) { + String url = ossFile.getUrl(); + if(StringUtils.isNotBlank(url)){ + //判断文件是否存在 + boolean b = CosBootUtil.doesObjectExist(url); + if(b){ + InputStream download = CosBootUtil.download(url); + copyFile(download, fileNowPath + File.separator + ossFile.getFileName()); + } + } + } + } + } + + } + } + + private String template(List fileInfos, String value) { + StringBuilder sb = new StringBuilder(); + for (String s : value.split(",")) { + List collect = fileInfos.stream().filter(e -> s.equals(e.getId())).collect(Collectors.toList()); + if(collect.size() != 0){ + sb.append(collect.get(0).getFileName()+","); + } + } + String substring = ""; + if(StringUtils.isNotBlank(sb)){ + substring = sb.substring(0, sb.length() - 1); + } + return substring; + } + + private List getOssFiles(List dataList) { + List fileIdList = new ArrayList<>(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : dataList) { + if(StringUtils.isNotBlank(projectCertificationInventoryEO.getDeliverableTemplate())){ + fileIdList.add(projectCertificationInventoryEO.getDeliverableTemplate()); + } + if(StringUtils.isNotBlank(projectCertificationInventoryEO.getDeliveryResult())){ + fileIdList.add(projectCertificationInventoryEO.getDeliveryResult()); + } + } + //查询所有的文件 + List fileInfos = new ArrayList<>(); + if(fileIdList.size() != 0){ + fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ",")); + } + return fileInfos; + } + + private String pull(List sysDictItems, String field,String dictCode) { + if(StringUtils.isBlank(field)){ + return null; + } + StringBuilder sb = new StringBuilder(); + for (String s : field.split(",")) { + List collect = sysDictItems.stream().filter(e -> dictCode.equals(e.getDictCode()) && s.equals(e.getItemValue())).collect(Collectors.toList()); + if(collect.size() != 0){ + sb.append(collect.get(0).getEnName() + ","); + } + } + if(StringUtils.isNotBlank(sb)){ + String substring = sb.substring(0, sb.length() - 1); + return substring; + } + return null; + } + + + //判断row是否为空 空返回true + public boolean isRowEmpty(Row row) { + if (null == row) { + return true; + } + int firstCellNum = row.getFirstCellNum(); //第一个列位置 + int lastCellNum = row.getLastCellNum(); //最后一列位置 + int nullCellNum = 0; //空列数量 + for (int c = firstCellNum; c < lastCellNum; c++) { + Cell cell = row.getCell(c); + if (null == cell) { + nullCellNum++; + continue; + } + String value = ""; + switch (cell.getCellType()) { + case HSSFCell.CELL_TYPE_NUMERIC: // 数字 + //如果为时间格式的内容 + value = String.valueOf(cell.getNumericCellValue()); + break; + case HSSFCell.CELL_TYPE_STRING: // 字符串 + value = cell.getStringCellValue(); + break; + case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean + value = cell.getBooleanCellValue() + ""; + break; + case HSSFCell.CELL_TYPE_FORMULA: // 公式 + value = cell.getCellFormula() + ""; + break; + default: + break; + } + if (org.apache.commons.lang.StringUtils.isEmpty(value)) { + nullCellNum++; + } + } + //所有列都为空 + if (nullCellNum == (lastCellNum - firstCellNum)) { + return true; + } + return false; + } + + private String fieldConvert(String field){ + if (field == null) return null; + switch (field) { + case "*类别": return "category"; + case "*检验项目": return "inspectionItem"; + case "*配置项": return "configItem"; + case "*WVTA ID": return "wvtaId"; + case "*标准编号": return "serialNumber"; + case "*责任领域": return "dutyTerritoryName"; + case "*认证类型": return "attestationTypeName"; + case "*工程接口人": return "sdtName"; + case "*责任人": return "dutyPersonName"; + case "*交付物类型": return "deliverableTypeName"; + case "交付物模板": return "deliverableTemplateName"; + case "交付结果": return "deliveryResult"; + case "截止日期": return "endTime"; + case "*截止日期": return "endTimeStr"; + case "流程状态": return "flowStatus"; + case "报告编号": return "reportNumber"; + case "产品型号": return "productModel"; + case "生产企业名称": return "productionEnterpriseName"; + case "认证进度": return "certificationProgress"; + + case "*Category": return "category"; + case "*Inspection Items": return "inspectionItem"; + case "*Configuration Item": return "configItem"; + case "*Standard No": return "serialNumber"; + case "*Responsible Field": return "dutyTerritoryName"; + case "*Certification Type": return "attestationTypeName"; + case "*Eng. Interface": return "sdtName"; + case "*Assignee": return "dutyPersonName"; + case "*Deliverable Type": return "deliverableTypeNameEn"; + case "Deliverable Template": return "deliverableTemplateName"; + case "Deliverables Result": return "deliveryResult"; + case "Due Date": return "endTime"; + case "*Due Date": return "endTimeStr"; + case "Process Status": return "flowStatus"; + case "Report No": return "reportNumber"; + case "Product Model": return "productModel"; + case "Name Of Manufacturer": return "productionEnterpriseName"; + case "Homologation Progress": return "certificationProgress"; + + default: return null; + //"Deliverable Type,Deliverable Template,initiator,Assignee,Due Date," + + } + } + + /** + * 模板下载 + * @param projectCertificationInventoryEO + * @param response + * @param request + */ + @Override + public void exportTemplate(ProjectCertificationInventoryEO projectCertificationInventoryEO, HttpServletResponse response, HttpServletRequest request) { + OutputStream os = null; + HSSFWorkbook workbook = new HSSFWorkbook(); + String fileOriName = "认证清单导入模板.xls"; + String filePath = uploadpath + File.separator + fileOriName; + + try { + String title = ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + title = "*类别,*检验项目,*配置项,*认证类型,*WVTA ID," + + "*标准编号,*责任领域,*工程接口人,*责任人," + + "交付物模板,*交付物类型,*截止日期,报告编号,产品型号,生产企业名称"; + }else { + title = "*Category,*Inspection Items,*Configuration Item,*Certification Type,*WVTA ID," + + "*Standard No,*Responsible Field,*Eng. Interface,*Assignee," + + "Deliverable Template,*Deliverable Type,*Due Date,Report No,Product Model,Name Of Manufacturer"; + } + + List list = Arrays.asList(title.split(",")); + int index = 0; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + index = list.indexOf("生产企业名称") + 1; + }else{ + index = list.indexOf("Name Of Manufacturer") + 1; + } + + //创建临时文件夹 + File nowFile = new File(filePath); + if (nowFile.exists()) { + nowFile.delete(); + } + nowFile.mkdirs(); + HSSFSheet sheet = workbook.createSheet("认证清单导入模板"); + sheet.setDefaultColumnWidth(16);//列宽 + + HSSFCellStyle cellStyle = workbook.createCellStyle(); + cellStyle.setDataFormat((short) 49); + sheet.setDefaultColumnStyle(10,cellStyle); + +// cellStyle.setWrapText(true);//自动换行 +// cellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中 +// cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//水平居中 + + HSSFCellStyle cellStyleTemp = workbook.createCellStyle(); + cellStyleTemp.setWrapText(true);//自动换行 + + CellRangeAddress region = + new CellRangeAddress(1, 1, 0, 13); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列 + sheet.addMergedRegion(region); + String explain= ""; + if(CutEnum.CN.getValue().equals(projectCertificationInventoryEO.getCut())){ + explain = "填写说明\n" + + "1.导入数据从第三行开始\n" + + "2.所有带*号的字段必须填写\n"+ + "3.责任人,交付物类型,工程接口人,编号,责任领域,字段是单选属性,必须和系统中的对应字段选项相匹配\n" + + "4.类别,WVTA ID,检验项目,配置项,填写文本内容\n" + + "5.交付物模板字段为文件属性,填写时需要在本文件同级目录下以标准号为名称建立文件夹,并在文件夹下放置文件,假设在AAA标准号下放置了B.docx,则应填写AAA/B.docx"; + }else{ + explain = "Filling explanation\n" + + "1.Import data starts at the third line\n" + + "2.All fields marked with * must be filled in\n"+ + "3.Assignee,Deliverable Type,Eng. Interface,Standard No,Responsible Field,Fields are radio attributes that must match the corresponding field option in the system\n" + + "4.Category,WVTA ID,Configuration Item,Inspection Items,Fill in the text\n" + + "5.Deliverable Template,When filling in the field, you need to create a folder in the directory of the same level as the file with the name of the standard number and place the file in the folder. If b. docx is stored under the AAA standard number, enter AAA/B. docx"; + } + for(int i = 0; i < 2; i++){ + //表头 + Row row = sheet.createRow(i);//开始创建标题行 + String[] headerArr = title.split(","); + if(i == 0 ){ + for (int m = 0; m < headerArr.length; m++) { + if(m < index){ + row.createCell(m).setCellValue(headerArr[m]); + }else { + break; + } + } + }else { + short height = (short) (6 * 252); + row.setHeight((short) height); + Cell cell = row.createCell(0); + cell.setCellStyle(cellStyleTemp); + cell.setCellValue(new HSSFRichTextString(explain)); + } + } + response.setHeader("Content-Disposition", + "attachment; filename=\"" + fileOriName + ".xls"); + response.setContentType("application/force-download"); + response.flushBuffer(); + os = response.getOutputStream(); + workbook.write(os); + }catch (Exception e){ + e.printStackTrace(); + throw new JeroBootException("下载文件失败,请重试"); + }finally { + IOUtils.closeQuietly(os); + } + } + + + @Override + public Result citeDeliverable(JSONObject json) { + String cut = json.getString("cut"); + String resultMsg = ""; + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + resultMsg = "引用交付物成功!"; + }else { + resultMsg = "Successfully referenced deliverables!"; + } + + + String projectCertificationInventoryIds = json.getString("projectCertificationInventoryIds"); + if(StringUtils.isEmpty(projectCertificationInventoryIds)){ + throw new JeroBootException("请选择需要引用的认证清单数据!"); + } + String projectLibraryId = json.getString("projectLibraryId"); + + String citeProjectLibraryId = json.getString("citeProjectLibraryId"); + if(StringUtils.isEmpty(citeProjectLibraryId)){ + throw new JeroBootException("请选择引用的项目!"); + } + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(ProjectCertificationInventoryEO::getId,projectCertificationInventoryIds.split(",")); + List projectCertificationInventoryEOList = this.list(queryWrapper); + + if(CollectionUtils.isNotEmpty(projectCertificationInventoryEOList)){ + QueryWrapper citeQueryWrapper = new QueryWrapper<>(); + citeQueryWrapper.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,citeProjectLibraryId); + citeQueryWrapper.lambda().eq(ProjectCertificationInventoryEO::getFlowStatus,CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()); + List citeProjectCertificationInventoryEOList = this.baseMapper.selectList(citeQueryWrapper); + + if(CollectionUtils.isNotEmpty(citeProjectCertificationInventoryEOList)){ + + +// citeProjectCertificationInventoryEOList.stream().map(ProjectCertificationInventoryEO::getInspectionItem).distinct().collect(Collectors.joining(",")); +// return Result.OK("所选检验项目"+""+"暂未维护,需要进行手动填写。"); + //The review passed data in the selected reference project is empty, please reselect! + // 没有引用的数据 检验项目集合,给到前端进行展示。 + List noCiteInspectionItem = new ArrayList<>(); + for (ProjectCertificationInventoryEO projectCertificationInventoryEO : projectCertificationInventoryEOList) { + String deliveryResult = ""; + for (ProjectCertificationInventoryEO citeProjectCertificationInventoryEO : citeProjectCertificationInventoryEOList) { + // 匹配数据 类别、检验项目、配置项、标准编号、交付物类型完全一致,并且数据的状态为 审查完成 + boolean flag = ( + StringUtils.equals(projectCertificationInventoryEO.getCategory(),citeProjectCertificationInventoryEO.getCategory()) + && StringUtils.equals(projectCertificationInventoryEO.getInspectionItem(),citeProjectCertificationInventoryEO.getInspectionItem()) + && StringUtils.equals(projectCertificationInventoryEO.getConfigItem(),citeProjectCertificationInventoryEO.getConfigItem()) + && StringUtils.equals(projectCertificationInventoryEO.getSerialNumber(),citeProjectCertificationInventoryEO.getSerialNumber()) + && StringUtils.equals(projectCertificationInventoryEO.getDeliverableType(),citeProjectCertificationInventoryEO.getDeliverableType()) + ); + + if(flag){ + deliveryResult = citeProjectCertificationInventoryEO.getDeliveryResult(); + break; + } + } + if(StringUtils.isNotBlank(deliveryResult)){ + projectCertificationInventoryEO.setDeliveryResult(deliveryResult); + }else { + noCiteInspectionItem.add(projectCertificationInventoryEO.getInspectionItem() + "-" +projectCertificationInventoryEO.getConfigItem()); + } + } + + this.updateBatchById(projectCertificationInventoryEOList); + + // 如果有 (没有引用的数据 检验项目集合,给到前端进行展示。) + if(CollectionUtils.isNotEmpty(noCiteInspectionItem)){ + String noCiteInspectionItemStr = noCiteInspectionItem.stream().distinct().collect(Collectors.joining(",")); + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + resultMsg = "所选检验项目"+noCiteInspectionItemStr+"暂未维护,需要进行手动填写。"; + }else { + resultMsg = "The selected inspection characteristic "+noCiteInspectionItemStr+" is not currently maintained and needs to be manually filled in."; + } + } + }else { + // 如果引用的项目中没有审查完成的数据 ,提示用户。 + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + resultMsg = "所选引用项目中审查通过数据为空,请重新选择!"; + }else { + resultMsg = "The review passed data in the selected reference project is empty, please reselect!"; + } + } + } + + return Result.OK(resultMsg); + } + + private void setProjectCertificationInventoryPermission(String userId, String projectId,String certificationInventoryId,Date now, List adds, String belong) { + QueryWrapper del = new QueryWrapper<>(); + del.eq("project_id", projectId) + .eq("belong", belong) + .eq("description", PermissionDescriptionEnum.PROJECT_CERTIFICATION_INVENTORY.getValue() + certificationInventoryId); + projectUserPermissionService.remove(del); + + ProjectUserPermission permission = new ProjectUserPermission(); + permission.setProjectId(projectId); + permission.setUserId(userId); + permission.setBelong(belong); + permission.setDescription(PermissionDescriptionEnum.PROJECT_CERTIFICATION_INVENTORY.getValue() + certificationInventoryId); + permission.setCreateTime(now); + permission.setUpdateTime(now); + adds.add(permission); + } + + /** + * 保存认证清单修改历史 + * @param pciList + * @param operateType + */ + public void saveProjectCertificationInventoryLog(List pciList,String operateType){ + if(CollectionUtils.isNotEmpty(pciList)){ + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String projectLibraryId = pciList.get(0).getProjectLibraryId(); + ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectLibraryId); + if(ObjectUtils.isNotEmpty(projectLibraryBase)){ + List studioEngineerUserInfo = this.sysUserService.querySysUserListByIdList(Arrays.asList(projectLibraryBase.getStudioEngineer().split(","))); + + String certificationEngineerUserNames = ""; + if(StringUtils.isNotBlank(projectLibraryBase.getCertificationEngineer())){ + List certificationEngineerIdList = Arrays.asList(projectLibraryBase.getCertificationEngineer().split(",")); + List certificationEngineerList = this.sysUserService.querySysUserListByIdList(certificationEngineerIdList); + certificationEngineerUserNames = certificationEngineerList.stream().map(SysUser::getUsername).distinct().collect(Collectors.joining(",")); + } + + List pciLogEOList = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci : pciList) { + StringBuilder contentCnSb = new StringBuilder(); + StringBuilder contentEnSb = new StringBuilder(); + if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_ADD.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" 添加了 "); + contentCnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getSerialNumber()).append("\"").append(" "); + + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" added "); + contentEnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getSerialNumber()).append("\""); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_ISSUE.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("发布了认证清单"); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" has published a certification list"); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_REVIEW_RETURNED.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("审核退回"); + contentCnSb.append(",退回原因:\"").append(pci.getReasonForReturn()).append("\""); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" review and returned"); + contentEnSb.append(",Reason for return:\"").append(pci.getReasonForReturn()).append("\""); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_REVIEW_THROUGH.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("审核通过"); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" pass the audit"); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_DUTY_PERSON_SUBMIT_TASK.getValue())){ + if (StringUtils.equals(pci.getValueType(), SysCategoryValueTypeEnum.FILE.getValue())) { + String fileName = "N/A"; + if (StringUtils.isNotEmpty(pci.getDeliveryResult())) { + fileName = this.ossFileService.getFileInfos(pci.getDeliveryResult()).stream().map(OSSFile::getFileName).distinct().collect(Collectors.joining(",")); + } + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("提交了附件 ").append(fileName); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" submitted attachment ").append(fileName); + }else { + String deliveryResult = (StringUtils.isNotEmpty(pci.getDeliveryResult()) ? pci.getDeliveryResult() : "N/A"); + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("提交了交付结果为").append(deliveryResult); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" submitted a delivery result of ").append(deliveryResult); + } + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_DUTY_PERSON_ACCEPT_TASK.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("接受了任务信息"); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" accepts the task information"); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_DUTY_PERSON_REJECT_TASK.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("退回了任务信息"); + contentCnSb.append(",拒绝原因:\"").append(pci.getReasonForReturn()).append("\""); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" returned the task information"); + contentEnSb.append(",Reject for Reason:\"").append(pci.getReasonForReturn()).append("\""); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_RETURNED_STUDIO_TASK.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("拒绝,流程退回至") + .append("\"").append(studioEngineerUserInfo.get(0).getUsername()).append("\""); + contentCnSb.append(",退回原因:\"").append(pci.getReasonForReturn()).append("\""); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" refuses, and the process returns to ") + .append("\"").append(studioEngineerUserInfo.get(0).getUsername()).append("\""); + contentEnSb.append(",Reason for return:\"").append(pci.getReasonForReturn()).append("\""); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_INITIATING_TASK.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("发起了Pre-Homo流程"); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" initiates the Pre-Homo process"); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_RESET.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("操作了流程重置功能"); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" has operated the process reset function"); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_STUDIO_WITHDRAW.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("从").append("\"").append(certificationEngineerUserNames).append("\"撤回了流程"); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" withdrew the process from \"").append(certificationEngineerUserNames).append("\""); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_CALL_ADD.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" 添加了 "); + contentCnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getSerialNumber()).append("\"").append(" "); + + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" added "); + contentEnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getSerialNumber()).append("\""); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_IMPORT_ADD.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" 添加了 "); + contentCnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getSerialNumber()).append("\"").append(" "); + + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" added "); + contentEnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getSerialNumber()).append("\""); + } else if(StringUtils.equals(operateType,OperatorTypeEnum.CERTIFICATION_INVENTORY_ADD_CONFIG.getValue())){ + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" 添加了 "); + contentCnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentCnSb.append("\"").append(pci.getSerialNumber()).append("\"").append(" "); + + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" added "); + contentEnSb.append("\"").append(pci.getCategory()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getInspectionItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getConfigItem()).append("\"").append(" "); + contentEnSb.append("\"").append(pci.getSerialNumber()).append("\""); + } + + ProjectCertificationInventoryLogEO pciLogEO = new ProjectCertificationInventoryLogEO(); + pciLogEO.setProjectCertificationInventoryId(pci.getId()); + pciLogEO.setContentCn(contentCnSb.toString()); + pciLogEO.setContentEn(contentEnSb.toString()); + pciLogEO.setOperatorType(operateType); + pciLogEOList.add(pciLogEO); + } + + if(CollectionUtils.isNotEmpty(pciLogEOList)){ + this.projectCertificationInventoryLogEOService.insertBatch(pciLogEOList); + } + } + } + } + + /** + * 保存认证清单修改历史(编辑、批量设置专用) + * @param params + */ + public void saveProjectCertificationInventoryLog(Map params){ + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + List editBeforePciList = (List) params.get("editBeforePciList"); + List editAfterPciList = (List) params.get("editAfterPciList"); + String operatorType = (String) params.get("operatorType"); + + if(CollectionUtils.isNotEmpty(editBeforePciList) && CollectionUtils.isNotEmpty(editAfterPciList)){ + List categoryList = this.sysCategoryService.list(); + List sysDictItems = this.sysDictItemServiceImpl.getBaseMapper().selectItemsAll(); + + List beforeSdtUserIdList = editBeforePciList.stream().map(ProjectCertificationInventoryEO::getSdt).distinct().collect(Collectors.toList()); + List beforeDutyPersonUserIdList = editBeforePciList.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList()); + + List afterSdtUserIdList = editAfterPciList.stream().map(ProjectCertificationInventoryEO::getSdt).distinct().collect(Collectors.toList()); + List afterDutyPersonUserIdList = editAfterPciList.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList()); + List userIdList = new ArrayList<>(); + userIdList.addAll(beforeSdtUserIdList); + userIdList.addAll(beforeDutyPersonUserIdList); + userIdList.addAll(afterSdtUserIdList); + userIdList.addAll(afterDutyPersonUserIdList); + List userList = this.sysUserService.querySysUserListByIdList(userIdList); + + List beforeDeliverableTemplateIdList = editBeforePciList.stream().map(ProjectCertificationInventoryEO::getDeliverableTemplate).distinct().collect(Collectors.toList()); + List afterDeliverableTemplateIdList = editAfterPciList.stream().map(ProjectCertificationInventoryEO::getDeliverableTemplate).distinct().collect(Collectors.toList()); + List allDeliverableTemplateIdList = new ArrayList<>(); + allDeliverableTemplateIdList.addAll(beforeDeliverableTemplateIdList); + allDeliverableTemplateIdList.addAll(afterDeliverableTemplateIdList); + List allDeliverableTemplateList = this.ossFileService.getFileInfos(allDeliverableTemplateIdList.stream().distinct().collect(Collectors.joining(","))); + + List pciLogEOList = new ArrayList<>(); + + for (ProjectCertificationInventoryEO editAfterPciEo : editAfterPciList) { + List editBeforePciListTemp = editBeforePciList.stream().filter(editBeforePciEo -> { + boolean flag = false; + if (StringUtils.equals(editAfterPciEo.getId(), editBeforePciEo.getId())) { + flag = true; + } + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(editBeforePciListTemp)){ + boolean savePciLogFlag = false; + ProjectCertificationInventoryEO editBeforePciEo = editBeforePciListTemp.get(0); + + if(ObjectUtils.isNotEmpty(editBeforePciEo)){ + StringBuilder contentCnSb = new StringBuilder(); + contentCnSb.append("\"").append(currentUser.getUsername()).append("\"").append("将"); + StringBuilder contentEnSb = new StringBuilder(); + contentEnSb.append("\"").append(currentUser.getUsername()).append("\"").append(" changes the "); + + if(!StringUtils.equals(editBeforePciEo.getWvtaId(),editAfterPciEo.getWvtaId())){ + contentCnSb.append("\"").append("WVTA ID").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getWvtaId()) ? editBeforePciEo.getWvtaId() : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getWvtaId()) ? editAfterPciEo.getWvtaId() : "空") + .append(","); + + contentEnSb.append("\"").append("WVTA ID").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getWvtaId()) ? editBeforePciEo.getWvtaId() : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getWvtaId()) ? editAfterPciEo.getWvtaId() : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getCategory(),editAfterPciEo.getCategory())){ + contentCnSb.append("\"").append("类别").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getCategory()) ? editBeforePciEo.getCategory() : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getCategory()) ? editAfterPciEo.getCategory() : "空") + .append(","); + + contentEnSb.append("\"").append("Category").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getCategory()) ? editBeforePciEo.getCategory() : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getCategory()) ? editAfterPciEo.getCategory() : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getInspectionItem(),editAfterPciEo.getInspectionItem())){ + contentCnSb.append("\"").append("检验项目").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getInspectionItem()) ? editBeforePciEo.getInspectionItem() : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getInspectionItem()) ? editAfterPciEo.getInspectionItem() : "空") + .append(","); + + contentEnSb.append("\"").append("Inspection Items").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getInspectionItem()) ? editBeforePciEo.getInspectionItem() : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getInspectionItem()) ? editAfterPciEo.getInspectionItem() : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getConfigItem(),editAfterPciEo.getConfigItem())){ + contentCnSb.append("\"").append("配置项").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getConfigItem()) ? editBeforePciEo.getConfigItem() : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getConfigItem()) ? editAfterPciEo.getConfigItem() : "空") + .append(","); + + contentEnSb.append("\"").append("Configuration Item").append("\" ") + .append(StringUtils.isNotEmpty(editBeforePciEo.getConfigItem()) ? editBeforePciEo.getConfigItem() : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(editAfterPciEo.getConfigItem()) ? editAfterPciEo.getConfigItem() : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getDutyTerritory(),editAfterPciEo.getDutyTerritory())){ + String beforeDutyTerritoryNameCn = this.sysDictItemService.disposeShowDictItemValue( + sysDictItems, + editBeforePciEo.getDutyTerritory(), + CutEnum.CN.getValue(), + ProjectInventoryFieldEnum.DUTY_TERRITORY.getValue() + ); + String beforeDutyTerritoryNameEn = this.sysDictItemService.disposeShowDictItemValue( + sysDictItems, + editBeforePciEo.getDutyTerritory(), + CutEnum.EN.getValue(), + ProjectInventoryFieldEnum.DUTY_TERRITORY.getValue() + ); + + String afterDutyTerritoryNameCn = this.sysDictItemService.disposeShowDictItemValue( + sysDictItems, + editAfterPciEo.getDutyTerritory(), + CutEnum.CN.getValue(), + ProjectInventoryFieldEnum.DUTY_TERRITORY.getValue() + ); + String afterDutyTerritoryNameEn = this.sysDictItemService.disposeShowDictItemValue( + sysDictItems, + editAfterPciEo.getDutyTerritory(), + CutEnum.EN.getValue(), + ProjectInventoryFieldEnum.DUTY_TERRITORY.getValue() + ); + + contentCnSb.append("\"").append("责任领域").append("\" ") + .append(StringUtils.isNotEmpty(beforeDutyTerritoryNameCn) ? beforeDutyTerritoryNameCn : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(afterDutyTerritoryNameCn) ? afterDutyTerritoryNameCn : "空") + .append(","); + + contentEnSb.append("\"").append("Responsible Field").append("\" ") + .append(StringUtils.isNotEmpty(beforeDutyTerritoryNameEn) ? beforeDutyTerritoryNameEn : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(afterDutyTerritoryNameEn) ? afterDutyTerritoryNameEn : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getDeliverableType(),editAfterPciEo.getDeliverableType())){ + String beforeDeliverableTypeNameCn = this.getTreeName(CutEnum.CN.getValue(), categoryList, Arrays.asList(editBeforePciEo.getDeliverableType().split(","))); + String beforeDeliverableTypeNameEn = this.getTreeName(CutEnum.EN.getValue(), categoryList, Arrays.asList(editBeforePciEo.getDeliverableType().split(","))); + + String afterDeliverableTypeNameCn = this.getTreeName(CutEnum.CN.getValue(), categoryList, Arrays.asList(editAfterPciEo.getDeliverableType().split(","))); + String afterDeliverableTypeNameEn = this.getTreeName(CutEnum.EN.getValue(), categoryList, Arrays.asList(editAfterPciEo.getDeliverableType().split(","))); + + contentCnSb.append("\"").append("交付物类型").append("\" ") + .append(StringUtils.isNotEmpty(beforeDeliverableTypeNameCn) ? beforeDeliverableTypeNameCn : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(afterDeliverableTypeNameCn) ? afterDeliverableTypeNameCn : "空") + .append(","); + + contentEnSb.append("\"").append("Deliverable Type").append("\" ") + .append(StringUtils.isNotEmpty(beforeDeliverableTypeNameEn) ? beforeDeliverableTypeNameEn : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(afterDeliverableTypeNameEn) ? afterDeliverableTypeNameEn : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getDeliverableTemplate(),editAfterPciEo.getDeliverableTemplate())){ + String[] beforeDeliverableTemplateArr = StringUtils.isNotEmpty(editBeforePciEo.getDeliverableTemplate()) ? editBeforePciEo.getDeliverableTemplate().split(",") : null; + String[] afterDeliverableTemplateArr = StringUtils.isNotEmpty(editAfterPciEo.getDeliverableTemplate()) ? editAfterPciEo.getDeliverableTemplate().split(",") : null; + + String beforeDeliverableTemplateName = allDeliverableTemplateList.stream().filter(file -> { + boolean flag = false; + if(beforeDeliverableTemplateArr != null){ + for (String beforeDeliverableTemplate : beforeDeliverableTemplateArr) { + if(StringUtils.equals(file.getId(),beforeDeliverableTemplate)){ + flag = true; + } + } + } + return flag; + }).map(OSSFile::getFileName).collect(Collectors.joining(",")); + + String afterDeliverableTemplateName = allDeliverableTemplateList.stream().filter(file -> { + boolean flag = false; + if(afterDeliverableTemplateArr != null){ + for (String afterDeliverableTemplate : afterDeliverableTemplateArr) { + if(StringUtils.equals(file.getId(),afterDeliverableTemplate)){ + flag = true; + } + } + } + return flag; + }).map(OSSFile::getFileName).collect(Collectors.joining(",")); + + contentCnSb.append("\"").append("交付物模板").append("\" ") + .append(StringUtils.isNotEmpty(beforeDeliverableTemplateName) ? beforeDeliverableTemplateName : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(afterDeliverableTemplateName) ? afterDeliverableTemplateName : "空") + .append(","); + + contentEnSb.append("\"").append("Deliverable Template").append("\" ") + .append(StringUtils.isNotEmpty(beforeDeliverableTemplateName) ? beforeDeliverableTemplateName : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(afterDeliverableTemplateName) ? afterDeliverableTemplateName : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getSdt(),editAfterPciEo.getSdt())){ + String beforeSdtUserName = this.sysUserService.getUsernameByUserId(userList,editBeforePciEo.getSdt()); + String afterSdtUserName = this.sysUserService.getUsernameByUserId(userList,editAfterPciEo.getSdt()); + + contentCnSb.append("\"").append("工程接口人").append("\" ") + .append(StringUtils.isNotEmpty(beforeSdtUserName) ? beforeSdtUserName : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(afterSdtUserName) ? afterSdtUserName : "空") + .append(","); + + contentEnSb.append("\"").append("Eng. Interface").append("\" ") + .append(StringUtils.isNotEmpty(beforeSdtUserName) ? beforeSdtUserName : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(afterSdtUserName) ? afterSdtUserName : "null") + .append(","); + + savePciLogFlag = true; + } + String beforeEndTimeStr = ""; + if(editBeforePciEo.getEndTime() != null){ + beforeEndTimeStr = DateUtils.formatDate(editBeforePciEo.getEndTime()); + } + String afterEndTimeStr = ""; + if(editAfterPciEo.getEndTime() != null){ + afterEndTimeStr = DateUtils.formatDate(editAfterPciEo.getEndTime()); + } + if(!StringUtils.equals(beforeEndTimeStr,afterEndTimeStr)){ + contentCnSb.append("\"").append("截止日期").append("\" ") + .append(StringUtils.isNotEmpty(beforeEndTimeStr) ? beforeEndTimeStr : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(afterEndTimeStr) ? afterEndTimeStr : "空") + .append(","); + + contentEnSb.append("\"").append("Due Date").append("\" ") + .append(StringUtils.isNotEmpty(beforeEndTimeStr) ? beforeEndTimeStr : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(afterEndTimeStr) ? afterEndTimeStr : "null") + .append(","); + + savePciLogFlag = true; + } + if(!StringUtils.equals(editBeforePciEo.getDutyPerson(),editAfterPciEo.getDutyPerson())){ + String beforeDutyPersonUserName = this.sysUserService.getUsernameByUserId(userList,editBeforePciEo.getDutyPerson()); + String afterDutyPersonUserName = this.sysUserService.getUsernameByUserId(userList,editAfterPciEo.getDutyPerson()); + + contentCnSb.append("\"").append("责任人").append("\" ") + .append(StringUtils.isNotEmpty(beforeDutyPersonUserName) ? beforeDutyPersonUserName : "空") + .append(" 修改为 ") + .append(StringUtils.isNotEmpty(afterDutyPersonUserName) ? afterDutyPersonUserName : "空") + .append(","); + + contentEnSb.append("\"").append("Assignee").append("\" ") + .append(StringUtils.isNotEmpty(beforeDutyPersonUserName) ? beforeDutyPersonUserName : "null") + .append(" to ") + .append(StringUtils.isNotEmpty(afterDutyPersonUserName) ? afterDutyPersonUserName : "null") + .append(","); + + savePciLogFlag = true; + } + + if(savePciLogFlag){ + ProjectCertificationInventoryLogEO pciLogEO = new ProjectCertificationInventoryLogEO(); + pciLogEO.setProjectCertificationInventoryId(editAfterPciEo.getId()); + pciLogEO.setContentCn(contentCnSb.toString().substring(0,contentCnSb.toString().length()-1)); + pciLogEO.setContentEn(contentEnSb.toString().substring(0,contentEnSb.toString().length()-1)); + pciLogEO.setOperatorType(operatorType); + pciLogEOList.add(pciLogEO); + } + } + } + } + if(CollectionUtils.isNotEmpty(pciLogEOList)){ + this.projectCertificationInventoryLogEOService.insertBatch(pciLogEOList); + } + } + } + + + @Override + public Result addConfigByIds(JSONObject json) { + String ids = json.getString("ids"); + String configItem = json.getString("configItem"); + if (StringUtils.isEmpty(ids)) { + throw new JeroBootException("至少选择一条数据进行添加配置操作!"); + } + List addConfigPciEoList = new ArrayList<>(); + + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().in(ProjectCertificationInventoryEO::getId,Arrays.asList(ids.split(","))); + List pciEoList = this.list(pciQueryWrap); + + pciEoList.forEach(pciEo -> { + ProjectCertificationInventoryEO addConfigPciEo = new ProjectCertificationInventoryEO(); + BeanUtils.copyProperties(pciEo,addConfigPciEo); + addConfigPciEo.setId(UUID.randomUUID().toString().replace("-","")); + addConfigPciEo.setConfigItem(configItem); + addConfigPciEoList.add(addConfigPciEo); + }); + + if(CollectionUtils.isNotEmpty(addConfigPciEoList)){ + this.saveBatch(addConfigPciEoList); + + // 设置历史log(修改历史) + this.saveProjectCertificationInventoryLog(addConfigPciEoList,OperatorTypeEnum.CERTIFICATION_INVENTORY_ADD_CONFIG.getValue()); + + Date now = new Date(); + //设置权限 先删后加 + List adds = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci: addConfigPciEoList) { + if (ObjectUtils.isNotEmpty(pci.getSdt())) { + setProjectCertificationInventoryPermission(pci.getSdt(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_SDT.getValue()); + } + if (ObjectUtils.isNotEmpty(pci.getDutyPerson())) { + setProjectCertificationInventoryPermission(pci.getDutyPerson(), pci.getProjectLibraryId(), pci.getId(), now, adds, ProjectUserLocationEnum.PROJECT_CERTIFICATION_INVENTORY_DP.getValue()); + } + } + if (ObjectUtils.isNotEmpty(adds)) { + projectUserPermissionService.saveBatch(adds); + } + } + + return Result.OK("添加配置成功!"); + } + + @Override + public Map groupByFGRwqrStatus(List pciEos) { + Map result = new HashMap<>(); + Map projectScheduleExportMap = new HashMap<>(); + + double toBeReleasedCount = 0; + double toBeVerifiedCount = 0; + double toBeConfirmedCount = 0; + double acceptCount = 0; + double refuseCount = 0; + double count = 0; + // 计算百分比 + double percentage = 0; + String percentageStr = "0"; + if(CollectionUtils.isNotEmpty(pciEos)){ + List toBeReleased = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List toBeVerified = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List toBeConfirmed = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List accept = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List refuse = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + toBeReleasedCount = toBeReleased.size(); + toBeVerifiedCount = toBeVerified.size(); + toBeConfirmedCount = toBeConfirmed.size(); + acceptCount = accept.size(); + refuseCount = refuse.size(); + + count = toBeReleasedCount + toBeVerifiedCount + toBeConfirmedCount + acceptCount + refuseCount; + if(count <= 0){ + percentage = 0; + }else{ + // 计算百分比 + percentage = acceptCount / count * 100; + } + percentageStr = percentage != 0 ? df.format(percentage) : "0"; + } + + projectScheduleExportMap.put("toBeReleased",toBeReleasedCount); + projectScheduleExportMap.put("toBeVerified",toBeVerifiedCount); + projectScheduleExportMap.put("toBeConfirmed",toBeConfirmedCount); + projectScheduleExportMap.put("accept",acceptCount); + projectScheduleExportMap.put("refuse",refuseCount); + projectScheduleExportMap.put("percentage",percentageStr + percentSign); + result.put("projectScheduleExportMap",projectScheduleExportMap); + return result; + } + + @Override + public Map groupByPreHomoStatus(List pciEos) { + Map result = new HashMap<>(); + Map projectScheduleExportMap = new HashMap<>(); + + double notStartCount = 0; // 未发起 + double toBeSubmittedCount = 0; // 待提交 + double toBeReviewedCount = 0; // 待审查 + double acceptCount = 0; // 审查通过 + double refuseCount = 0; // 审查退回 + double taskTerminationCount = 0; // 任务终止 + double count = 0; + // 计算百分比 + double percentage = 0; + String percentageStr = "0"; + if(CollectionUtils.isNotEmpty(pciEos)){ + List notStart = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue()) + || StringUtils.equals(pciEo.getFlowStatus(),CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List toBeSubmitted = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List toBeReviewed = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List accept = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_PASS.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + List refuse = pciEos.stream().filter(pciEo -> { + boolean flag = ( + StringUtils.equals(pciEo.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + + notStartCount = notStart.size(); + toBeSubmittedCount = toBeSubmitted.size(); + toBeReviewedCount = toBeReviewed.size(); + acceptCount = accept.size(); + refuseCount = refuse.size(); + + count = notStartCount + toBeSubmittedCount + toBeReviewedCount + acceptCount + refuseCount; + if(count <= 0){ + percentage = 0; + }else{ + // 计算百分比 + percentage = acceptCount / count * 100; + } + percentageStr = percentage != 0 ? df.format(percentage) : "0"; + } + + projectScheduleExportMap.put("notStartCount",notStartCount); + projectScheduleExportMap.put("toBeSubmittedCount",toBeSubmittedCount); + projectScheduleExportMap.put("toBeReviewedCount",toBeReviewedCount); + projectScheduleExportMap.put("accept",acceptCount); + projectScheduleExportMap.put("refuse",refuseCount); + projectScheduleExportMap.put("percentage",percentageStr + percentSign); + result.put("projectScheduleExportMap",projectScheduleExportMap); + return result; + } + + @Override + public Map groupByCertificationProgress(List pciEos) { + Map result = new HashMap<>(); + Map projectScheduleExportMap = new HashMap<>(); + + double notStartCount = 0; // 待开始 + double inProgressCount = 0; // 进行中 + double testPassedCount = 0; // 实验通过 + double testFailedCount = 0; // 实验失败 + double notSubmitCount = 0; // 部件报告未上传 + double reportSubmitCount = 0; // 部件报告已上传 + double storedCount = 0; // 部件报告已入库 + double count = 0; + // 计算百分比 + double percentage = 0; + String percentageStr = "0"; + + if(CollectionUtils.isNotEmpty(pciEos)){ + // 未开始 + List notStartPciEoList = pciEos.stream().filter(data -> { + boolean flag = ( + StringUtils.equals(data.getCertificationProgress(),CertificationProgressEnum.NOT_START.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + notStartCount = (double) notStartPciEoList.size(); + + // 进行中 + List inProgressPciEoList = pciEos.stream().filter(data -> { + boolean flag = ( + StringUtils.equals(data.getCertificationProgress(),CertificationProgressEnum.IN_PROGRESS.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + inProgressCount = (double) inProgressPciEoList.size(); + + // 实验通过 + List testPassedPciEoList = pciEos.stream().filter(data -> { + boolean flag = ( + StringUtils.equals(data.getCertificationProgress(),CertificationProgressEnum.TEST_PASSED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + testPassedCount = (double) testPassedPciEoList.size(); + + // 实验失败 + List testFailedPciEoList = pciEos.stream().filter(data -> { + boolean flag = ( + StringUtils.equals(data.getCertificationProgress(),CertificationProgressEnum.TEST_FAILED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + testFailedCount = (double) testFailedPciEoList.size(); + + // 部件报告未提交 + List notSubmitPciEoList = pciEos.stream().filter(data -> { + boolean flag = ( + StringUtils.equals(data.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_NOT_SUBMITTED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + notSubmitCount = (double) notSubmitPciEoList.size(); + + // 部件报告已提交 + List reportSubmitPciEoList = pciEos.stream().filter(data -> { + boolean flag = ( + StringUtils.equals(data.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_SUBMITTED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + reportSubmitCount = (double) reportSubmitPciEoList.size(); + + // 部件报告已入库 + List storedPciEoList = pciEos.stream().filter(data -> { + boolean flag = ( + StringUtils.equals(data.getCertificationProgress(),CertificationProgressEnum.COMPONENT_REPORT_HAS_BEEN_STORED.getValue()) + ); + return flag; + }).collect(Collectors.toList()); + storedCount = (double) storedPciEoList.size(); + + count = notStartCount + inProgressCount + testPassedCount + testFailedCount + testFailedCount + notSubmitCount + reportSubmitCount + storedCount; + if(count<=0){ + percentage = 0; + }else { + // 计算百分比 + percentage = testPassedCount / count * 100; + } + percentageStr = percentage != 0 ? df.format(percentage) : "0"; + } + projectScheduleExportMap.put("notStartCount",notStartCount); + projectScheduleExportMap.put("inProgressCount",inProgressCount); + projectScheduleExportMap.put("testPassedCount",testPassedCount); + projectScheduleExportMap.put("testFailedCount",testFailedCount); + projectScheduleExportMap.put("notSubmitCount",notSubmitCount); + projectScheduleExportMap.put("reportSubmitCount",reportSubmitCount); + projectScheduleExportMap.put("storedCount",storedCount); + projectScheduleExportMap.put("count",count); + projectScheduleExportMap.put("percentage",percentageStr + percentSign); + result.put("projectScheduleExportMap",projectScheduleExportMap); + return result; + } + + @Override + public void syncProcessInfoDetailEndTime(Date newEndTime, List pciEoList) { + pciEoList = pciEoList.stream().filter(pciEo -> { + boolean flag = false; + if(null != newEndTime && !newEndTime.equals(pciEo.getEndTime())){ + flag = true; + } + return flag; + }).collect(Collectors.toList()); + + if(CollectionUtils.isNotEmpty(pciEoList)){ + List pciIdList = pciEoList.stream().map(ProjectCertificationInventoryEO::getId).distinct().collect(Collectors.toList()); + + QueryWrapper pidQueryWrap = new QueryWrapper<>(); + pidQueryWrap.lambda().eq(ProcessInfoDetailEO::getFlowType,FlowTypeEnum.CERTIFICATION_LC.getValue()); + pidQueryWrap.lambda().in(ProcessInfoDetailEO::getProjectLawsInventoryId,pciIdList); + List pidEoList = this.processInfoDetailEOService.list(pidQueryWrap); + + if(CollectionUtils.isNotEmpty(pidEoList)){ + List updatePidEoList = new ArrayList<>(); + for (ProjectCertificationInventoryEO pciEo : pciEoList) { + String pciEoId = pciEo.getId(); + String flowStatus = pciEo.getFlowStatus(); + // 如果该数据为 结果待提交或审查退回的时候 + if (StringUtils.equals(flowStatus,CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue()) + || StringUtils.equals(flowStatus,CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue()) ) { + List pidEoListTemp = pidEoList.stream().filter(pidEo -> { + boolean flag = ( + StringUtils.equals(pidEo.getProjectLawsInventoryId(),pciEoId) + && StringUtils.equals(pidEo.getStatus(),TaskStatusEnum.NOT_DONE.getValue()) + && StringUtils.equals(pidEo.getTaskDefinitionKey(),CertificationFlowNodeEnum.ZRRTJRW.getKey()) + ); + return flag; + }).collect(Collectors.toList()); + updatePidEoList.addAll(pidEoListTemp); + }else if(StringUtils.equals(flowStatus,CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue())){ + List pidEoListTemp = pidEoList.stream().filter(pidEo -> { + boolean flag = ( + StringUtils.equals(pidEo.getProjectLawsInventoryId(),pciEoId) + && StringUtils.equals(flowStatus,TaskStatusEnum.NOT_DONE.getValue()) + && StringUtils.equals(pidEo.getTaskDefinitionKey(),CertificationFlowNodeEnum.RZGCSSC.getKey()) + ); + return flag; + }).collect(Collectors.toList()); + updatePidEoList.addAll(pidEoListTemp); + } + } + + if(CollectionUtils.isNotEmpty(updatePidEoList)){ + updatePidEoList.forEach(pidEo -> pidEo.setEndTime(newEndTime)); + this.processInfoDetailEOService.updateBatchById(updatePidEoList); + } + } + } + } + + @Override + public Map>> queryDutyPersonByProjectId(Map params) { + Map>> result = new HashMap<>(); + String projectLibraryId = (String) params.get("projectLibraryId"); + if(StringUtils.isNotEmpty(projectLibraryId)) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ProjectCertificationInventoryEO::getProjectLibraryId, projectLibraryId); + List pciList = this.list(queryWrapper); + List dutyList = new ArrayList<>(); + List interfaceList = new ArrayList<>(); + for (ProjectCertificationInventoryEO pci : pciList) { + if(StringUtils.isNotEmpty(pci.getDutyPerson())){ + dutyList.add(pci.getDutyPerson()); + } + if(StringUtils.isNotEmpty(pci.getSdt())){ + interfaceList.add(pci.getSdt()); + } + } + if(CollectionUtils.isNotEmpty(dutyList)){ + List> resList = new ArrayList<>(); + List userList = this.sysUserService.querySysUserListByIdList(dutyList); + if(CollectionUtils.isNotEmpty(userList)){ + for (SysUser user : userList) { + Map userMap = new HashMap<>(); + userMap.put("id",user.getId()); + userMap.put("userName",user.getUsername()); + resList.add(userMap); + } + } + result.put("dutyList",resList); + } + + if(CollectionUtils.isNotEmpty(interfaceList)){ + List> resList = new ArrayList<>(); + List userList = this.sysUserService.querySysUserListByIdList(interfaceList); + if(CollectionUtils.isNotEmpty(userList)){ + for (SysUser user : userList) { + Map userMap = new HashMap<>(); + userMap.put("id",user.getId()); + userMap.put("userName",user.getUsername()); + resList.add(userMap); + } + } + result.put("interfaceList",resList); + } + } + return result; + } + + @Override + public List getUserDutyTerritoryList(Map params) { + List result = new ArrayList<>(); + String userId = (String) params.get("userId"); + String projectLibraryId = (String) params.get("projectLibraryId"); + List dutyTerritorySdiList = (List) params.get("dutyTerritorySdiList"); + + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,projectLibraryId); + pciQueryWrap.and(pciQuery -> { + pciQuery.lambda().eq(ProjectCertificationInventoryEO::getDutyPerson,userId) + .or().eq(ProjectCertificationInventoryEO::getSdt,userId); + }); + List pciEoList = this.list(pciQueryWrap); + + if(CollectionUtils.isNotEmpty(pciEoList)){ + List dutyTerritoryIdList = Arrays.asList( + pciEoList.stream().map(ProjectCertificationInventoryEO::getDutyTerritory).collect(Collectors.joining(",")).split(",") + ).stream().distinct().collect(Collectors.toList()); + + result = dutyTerritorySdiList.stream().filter(dutyTerritory -> { + boolean flag = false; + for (String dutyTerritoryId : dutyTerritoryIdList) { + if (StringUtils.equals(dutyTerritoryId, dutyTerritory.getItemValue())) { + flag = true; + break; + } + } + return flag; + }).collect(Collectors.toList()); + } + + return result; + } + + @Override + public void replacementUser(JSONObject json) { + //获取当前用户 + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String userId = json.getString("userId"); + String projectLibraryId = json.getString("projectLibraryId"); + List> replacementUserList = (List>) json.get("replacementUserList"); + + QueryWrapper pciQueryWrap = new QueryWrapper<>(); + pciQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId, projectLibraryId); + List pciEoList = this.list(pciQueryWrap); + + List updateEoList = new ArrayList<>(); + for (Map replacementUserMap : replacementUserList) { + String dutyTerritory = (String) replacementUserMap.get("dutyTerritory"); + String newUserId = (String) replacementUserMap.get("newUserId"); + if (StringUtils.isNotEmpty(newUserId)) { + for (ProjectCertificationInventoryEO pciEo : pciEoList) { + if (StringUtils.equals(pciEo.getDutyTerritory(), dutyTerritory)) { + if (StringUtils.equals(pciEo.getDutyPerson(), userId)) { + ProjectCertificationInventoryEO newPciEo = new ProjectCertificationInventoryEO(); + newPciEo.setId(pciEo.getId()); + newPciEo.setDutyPerson(newUserId); + +// QueryWrapper certificationQueryWrap = new QueryWrapper<>(); +// certificationQueryWrap.lambda().eq(ProjectCertificationInventoryEO::getId,pciEo.getId()); +// List oldPciEoList = this.list(certificationQueryWrap); + List oldPciEoList = pciEoList.stream().filter(p -> StringUtils.equals(p.getId(),pciEo.getId())).distinct().collect(Collectors.toList()); + // 编辑责任人处理逻辑 + this.editDutyPerson(newPciEo, oldPciEoList,currentUser); + + pciEo.setDutyPerson(newUserId); + } + if (StringUtils.equals(pciEo.getSdt(), userId)) { + pciEo.setSdt(newUserId); + } + updateEoList.add(pciEo); + } + } + } + } + + if (CollectionUtils.isNotEmpty(updateEoList)) { + this.updateBatchById(updateEoList); + } + } + + + /** + * 匹配相关人员 + * + * @param params + * @return + */ + @Override + public Result matchRelevantPeople(Map params) { + String projectLibraryId = (String) params.get("projectLibraryId");//项目id + + LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + int isProjectRole = this.checkUserRole(projectLibraryId, currentUser.getId()); + //验证用户是否是该项目的studio工程师,或者认证工程师,才能匹配相关人员 + if (isProjectRole == Integer.parseInt(com.jero.modules.project.enums.ProjectRoleEnum.STUDIO_ENGINEER.getValue()) + ||isProjectRole == Integer.parseInt(com.jero.modules.project.enums.ProjectRoleEnum.HOMOLOGATION_ENGINEER.getValue())) { + //获取当前项目中的相关人员信息 + QueryWrapper queryProjectPerson = new QueryWrapper<>(); + queryProjectPerson.lambda().eq(ProjectRelatedPersonnel::getProjectId, projectLibraryId); + List projectRelatedPersonnels = this.projectRelatedPersonnelMapper.selectList(queryProjectPerson); + + if (CollectionUtils.isNotEmpty(projectRelatedPersonnels)) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(ProjectCertificationInventoryEO::getProjectLibraryId,projectLibraryId); + List certificationInventoryEOs = this.list(queryWrapper); + List updateList = new ArrayList<>(); + for (ProjectCertificationInventoryEO certificationInventoryEO : certificationInventoryEOs) { + //只留下清单状态为 未发起、认证退回的认证清单。 + if(CertificationInventoryFlowStatusEnum.LIST_TO_BE_RELEASED.getValue().equals(certificationInventoryEO.getFlowStatus()) + ||CertificationInventoryFlowStatusEnum.CERTIFICATION_RETURNED.getValue().equals(certificationInventoryEO.getFlowStatus())){ + String dutyTerritory = certificationInventoryEO.getDutyTerritory(); + if (StringUtils.isNotEmpty(dutyTerritory)) { + List projectRelatedPersonnelTempList = projectRelatedPersonnels.stream().filter(relatedPersonnel -> { + boolean flag = false; + for (String duty : dutyTerritory.split(",")) { + if (StringUtils.equals(duty, relatedPersonnel.getDutyTerritory())) { + flag = true; + } + } + return flag; + }).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(projectRelatedPersonnelTempList)) { + List relatedPerson = new ArrayList<>(); + for (ProjectRelatedPersonnel prp : projectRelatedPersonnelTempList) { + String engineeringInterfacePerson = prp.getEngineeringInterfacePerson(); + if (StringUtils.isNotEmpty(engineeringInterfacePerson)) { + for (String eip : engineeringInterfacePerson.split(",")) { + if (StringUtils.isNotEmpty(eip)) { + relatedPerson.add(eip); + } + } + } + } + if (CollectionUtils.isNotEmpty(relatedPerson) && relatedPerson.size() == 1) { + certificationInventoryEO.setSdt(relatedPerson.get(0)); + certificationInventoryEO.setDutyPerson(relatedPerson.get(0)); + updateList.add(certificationInventoryEO); + } + } + } + } + } + if(CollectionUtils.isNotEmpty(updateList)) { + this.updateBatchById(updateList); + } + } else { + throw new JeroBootException("当前项目中,未找到相关维护人员信息"); + } + } else { + throw new JeroBootException("当前操作用户不是该项目的studio工程师或认证工程师,没有权限操作!"); + } + + //更新log +// LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); +// String username = sysUser.getUsername(); +// String contentLog = username + "带入了相关人员名单信息"; +// String enContentLog = username + " brought in the list information of relevant personnel."; +// projectLawsInventoryLogEOService.updateLog(contentLog, projectLibraryId, CutEnum.CN.getValue()); +// projectLawsInventoryLogEOService.updateLog(enContentLog, projectLibraryId, CutEnum.EN.getValue()); + + return new Result<>().success("带入成功!"); + } + + /** + * 验证用户在该项目中的角色 + * + * @param projectLibraryId 项目库id + * @param currentUserId 登录人id + * @return + */ + public int checkUserRole(String projectLibraryId, String currentUserId) { + int result = -1; + try { + QueryWrapper projectLibraryBaseQueryWrapper = new QueryWrapper<>(); + projectLibraryBaseQueryWrapper.lambda().eq(ProjectLibraryBase::getId, projectLibraryId); + projectLibraryBaseQueryWrapper.lambda().eq(ProjectLibraryBase::getStudioEngineer, currentUserId); + Integer projectLibrayBaseCount = projectLibraryBaseMapper.selectCount(projectLibraryBaseQueryWrapper); + if (projectLibrayBaseCount > 0) { + result = Integer.parseInt(com.jero.modules.project.enums.ProjectRoleEnum.STUDIO_ENGINEER.getValue()); + if(result == -1){ + result = Integer.parseInt(com.jero.modules.project.enums.ProjectRoleEnum.HOMOLOGATION_ENGINEER.getValue()); + } + } + } catch (Exception ex) { + log.error("验证用户在该项目中的角色失败:" + ex.getMessage()); + throw new JeroBootException("验证用户在该项目中的角色失败!"); + } + return result; + } + +}