|
|
@@ -3,33 +3,37 @@ package cn.iocoder.yudao.module.pms.service.qhse.accident;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.accident.vo.IotAccidentReportPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.accident.vo.IotAccidentReportSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.accident.IotAccidentReportDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.accident.IotAccidentReportProcessDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.qhse.accident.IotAccidentReportMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.accident.IotAccidentReportProcessMapper;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.PostApi;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
|
/**
|
|
|
@@ -49,6 +53,104 @@ public class IotAccidentReportServiceImpl implements IotAccidentReportService {
|
|
|
private AdminUserApi adminUserApi;
|
|
|
@Autowired
|
|
|
private RoleApi roleApi;
|
|
|
+ @Autowired
|
|
|
+ private DeptService deptService;
|
|
|
+ @Autowired
|
|
|
+ private PostApi postApi;
|
|
|
+ @Autowired
|
|
|
+ private IotAccidentReportProcessMapper iotAccidentReportProcessMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void approvalAccident(Long id, String suggestion) {
|
|
|
+ IotAccidentReportDO iotAccidentReportDO = iotAccidentReportMapper.selectById(id);
|
|
|
+ assert Objects.nonNull(iotAccidentReportDO);
|
|
|
+ IotAccidentReportProcessDO processDO = new IotAccidentReportProcessDO();
|
|
|
+ processDO.setAccidentId(id);
|
|
|
+ processDO.setOperator(SecurityFrameworkUtils.getLoginUserNickname());
|
|
|
+ processDO.setDescription(suggestion);
|
|
|
+ processDO.setStatus("上报");
|
|
|
+ processDO.setDeleted(false);
|
|
|
+ Set<Long> deptIds = getDeptIdCompany(iotAccidentReportDO.getDeptId());
|
|
|
+ List<AdminUserRespDTO> users = adminUserApi.getUserListByDeptIdsNew(deptIds);
|
|
|
+ if ("2".equals(iotAccidentReportDO.getFlowStatus())) {//项目经理操作的
|
|
|
+ processDO.setNodeName("项目经理");
|
|
|
+ iotAccidentReportDO.setFlowStatus("3");
|
|
|
+ PostRespDTO bz = postApi.getPostByName("QHSE部长");
|
|
|
+ Long postId = bz.getId();
|
|
|
+ users.stream().filter(e -> e.getPostIds().contains(postId)).findFirst().ifPresent(f ->{
|
|
|
+ //设置当前操作人为QHSE部长
|
|
|
+ iotAccidentReportDO.setCurrentPerson(Collections.singleton(f.getId()));
|
|
|
+ });
|
|
|
+ } else if ("3".equals(iotAccidentReportDO.getFlowStatus())){//QHSE部长操作的
|
|
|
+ processDO.setNodeName("公司QHSE部长");
|
|
|
+ iotAccidentReportDO.setFlowStatus("4");
|
|
|
+ PostRespDTO bz = postApi.getPostByName("总经理");
|
|
|
+ Long postId = bz.getId();
|
|
|
+ boolean b = users.stream().anyMatch(e -> e.getPostIds().contains(postId));
|
|
|
+ if (!b) {
|
|
|
+ throw new ServiceException(new ErrorCode(1,"未找到总经理岗位"));
|
|
|
+ }
|
|
|
+ users.stream().filter(e -> e.getPostIds().contains(postId)).findFirst().ifPresent(f->{
|
|
|
+ iotAccidentReportDO.setCurrentPerson(ImmutableSet.of(f.getId(), 873L));
|
|
|
+ });
|
|
|
+ } else if ("4".equals(iotAccidentReportDO.getFlowStatus())) {//总经理或者集团QHSE副总监操作的
|
|
|
+ Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
+ if (Objects.nonNull(loginUserId) && loginUserId==873L) {//如果集团QHSE副总监
|
|
|
+ processDO.setNodeName("集团QHSE副总监");
|
|
|
+ } else {
|
|
|
+ processDO.setNodeName("总经理");
|
|
|
+ }
|
|
|
+ iotAccidentReportDO.setFlowStatus("5");
|
|
|
+ iotAccidentReportDO.setStatus("finished");
|
|
|
+ PostRespDTO zz = postApi.getPostByName("总裁");
|
|
|
+ Long postId = zz.getId();
|
|
|
+ List<AdminUserRespDTO> allUser = adminUserApi.getUserListByPostIdsNoPermission(Collections.singleton(postId));
|
|
|
+ if (CollUtil.isEmpty(allUser)){
|
|
|
+ throw new ServiceException(new ErrorCode(2,"未找到审批岗位"));
|
|
|
+ }
|
|
|
+ allUser.stream().filter(e -> e.getPostIds().contains(postId)).findFirst().ifPresent(f ->{
|
|
|
+ iotAccidentReportDO.setCurrentPerson(ImmutableSet.of(f.getId()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ iotAccidentReportProcessMapper.insert(processDO);
|
|
|
+ iotAccidentReportMapper.updateById(iotAccidentReportDO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Set<Long> getDeptIdCompany(Long deviceDept) {
|
|
|
+ List<DeptRespDTO> rhdept = deptApi.getDeptByNamePermission("瑞恒兴域");
|
|
|
+ Set<Long> rhDeptIds = Collections.emptySet();
|
|
|
+ if (CollUtil.isNotEmpty(rhdept)) {
|
|
|
+ Long deptId = rhdept.get(0).getId();
|
|
|
+ rhDeptIds = deptService.getChildDeptIdListFromCache(deptId);
|
|
|
+ rhDeptIds.add(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DeptRespDTO> rddept = deptApi.getDeptByNamePermission("四川瑞都");
|
|
|
+ Set<Long> rdDeptIds = Collections.emptySet();
|
|
|
+ if (CollUtil.isNotEmpty(rddept)) {
|
|
|
+ Long deptId = rddept.get(0).getId();
|
|
|
+ rdDeptIds = deptService.getChildDeptIdListFromCache(deptId);
|
|
|
+ rdDeptIds.add(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DeptRespDTO> rydept = deptApi.getDeptByNamePermission("瑞鹰国际");
|
|
|
+ Set<Long> ryDeptIds = Collections.emptySet();
|
|
|
+ if (CollUtil.isNotEmpty(rydept)) {
|
|
|
+ Long deptId = rydept.get(0).getId();
|
|
|
+ ryDeptIds = deptService.getChildDeptIdListFromCache(deptId);
|
|
|
+ ryDeptIds.add(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rhDeptIds.contains(deviceDept)) {
|
|
|
+ return rhDeptIds;
|
|
|
+ } else if (rdDeptIds.contains(deviceDept)) {
|
|
|
+ return rdDeptIds;
|
|
|
+ } else {
|
|
|
+ return ryDeptIds;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public Long createIotAccidentReport(IotAccidentReportSaveReqVO createReqVO) {
|
|
|
@@ -75,7 +177,7 @@ public class IotAccidentReportServiceImpl implements IotAccidentReportService {
|
|
|
if (CollUtil.isEmpty(currentUserIds)){
|
|
|
throw new ServiceException(new ErrorCode(22,"未找到项目经理,无法完成事故上报"));
|
|
|
}
|
|
|
- iotAccidentReport.setCurrentPerson(currentUserIds.stream().findFirst().get());
|
|
|
+ iotAccidentReport.setCurrentPerson(Collections.singleton(currentUserIds.stream().findFirst().get()));
|
|
|
iotAccidentReportMapper.insert(iotAccidentReport);
|
|
|
//插入流程明细表
|
|
|
IotAccidentReportProcessDO processDO = new IotAccidentReportProcessDO();
|
|
|
@@ -84,8 +186,10 @@ public class IotAccidentReportServiceImpl implements IotAccidentReportService {
|
|
|
processDO.setOperator(loginUserNickname);
|
|
|
processDO.setDescription("发起事故事件上报");
|
|
|
processDO.setNodeName("发起人");
|
|
|
+ processDO.setDeleted(false);
|
|
|
processDO.setCreateTime(LocalDateTime.now());
|
|
|
processDO.setStatus("提交上报");
|
|
|
+ iotAccidentReportProcessMapper.insert(processDO);
|
|
|
// 返回
|
|
|
return iotAccidentReport.getId();
|
|
|
}
|
|
|
@@ -123,4 +227,8 @@ public class IotAccidentReportServiceImpl implements IotAccidentReportService {
|
|
|
return iotAccidentReportMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public PageResult<IotAccidentReportDO> getIotAccidentReportApprovalPage(IotAccidentReportPageReqVO pageReqVO) {
|
|
|
+ return iotAccidentReportMapper.selectApprovalPage(pageReqVO);
|
|
|
+ }
|
|
|
}
|