|
|
@@ -0,0 +1,126 @@
|
|
|
+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.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.system.api.dept.DeptApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
+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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * QHSE事故上报 Service 实现类
|
|
|
+ *
|
|
|
+ * @author 超级管理员
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class IotAccidentReportServiceImpl implements IotAccidentReportService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IotAccidentReportMapper iotAccidentReportMapper;
|
|
|
+ @Autowired
|
|
|
+ private DeptApi deptApi;
|
|
|
+ @Autowired
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+ @Autowired
|
|
|
+ private RoleApi roleApi;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long createIotAccidentReport(IotAccidentReportSaveReqVO createReqVO) {
|
|
|
+ // 插入
|
|
|
+ IotAccidentReportDO iotAccidentReport = BeanUtils.toBean(createReqVO, IotAccidentReportDO.class);
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
+ iotAccidentReport.setDeptId(loginUserDeptId);
|
|
|
+ DeptRespDTO dept = deptApi.getDept(loginUserDeptId);
|
|
|
+ if (Objects.nonNull(dept)){
|
|
|
+ iotAccidentReport.setDeptName(dept.getName());
|
|
|
+ }
|
|
|
+ //设置状态为上报中
|
|
|
+ iotAccidentReport.setStatus("reporting");
|
|
|
+ //查找上一级的项目主管
|
|
|
+ iotAccidentReport.setDeleted(false);
|
|
|
+ iotAccidentReport.setFlowStatus("2");
|
|
|
+ //获取当前部门的上一级部门也就是项目部的项目经理
|
|
|
+ Long parentId = dept.getParentId();
|
|
|
+ List<AdminUserRespDTO> parentDeptUsers = adminUserApi.getUserListByDeptIdsNew(Collections.singleton(parentId));
|
|
|
+ List<Long> projectUserIds = roleApi.getRoleUserIds("项目经理");
|
|
|
+ Set<Long> currentUserIds = parentDeptUsers.stream().map(AdminUserRespDTO::getId)
|
|
|
+ .filter(projectUserIds::contains)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ if (CollUtil.isEmpty(currentUserIds)){
|
|
|
+ throw new ServiceException(new ErrorCode(22,"未找到项目经理,无法完成事故上报"));
|
|
|
+ }
|
|
|
+ iotAccidentReport.setCurrentPerson(currentUserIds.stream().findFirst().get());
|
|
|
+ iotAccidentReportMapper.insert(iotAccidentReport);
|
|
|
+ //插入流程明细表
|
|
|
+ IotAccidentReportProcessDO processDO = new IotAccidentReportProcessDO();
|
|
|
+ processDO.setAccidentId(iotAccidentReport.getId());
|
|
|
+ String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname();
|
|
|
+ processDO.setOperator(loginUserNickname);
|
|
|
+ processDO.setDescription("发起事故事件上报");
|
|
|
+ processDO.setNodeName("发起人");
|
|
|
+ processDO.setCreateTime(LocalDateTime.now());
|
|
|
+ processDO.setStatus("提交上报");
|
|
|
+ // 返回
|
|
|
+ return iotAccidentReport.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateIotAccidentReport(IotAccidentReportSaveReqVO updateReqVO) {
|
|
|
+ // 校验存在
|
|
|
+ validateIotAccidentReportExists(updateReqVO.getId());
|
|
|
+ // 更新
|
|
|
+ IotAccidentReportDO updateObj = BeanUtils.toBean(updateReqVO, IotAccidentReportDO.class);
|
|
|
+ iotAccidentReportMapper.updateById(updateObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteIotAccidentReport(Long id) {
|
|
|
+ // 校验存在
|
|
|
+ validateIotAccidentReportExists(id);
|
|
|
+ // 删除
|
|
|
+ iotAccidentReportMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateIotAccidentReportExists(Long id) {
|
|
|
+ if (iotAccidentReportMapper.selectById(id) == null) {
|
|
|
+ throw exception(new ErrorCode(11,"不存在"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IotAccidentReportDO getIotAccidentReport(Long id) {
|
|
|
+ return iotAccidentReportMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<IotAccidentReportDO> getIotAccidentReportPage(IotAccidentReportPageReqVO pageReqVO) {
|
|
|
+ return iotAccidentReportMapper.selectPage(pageReqVO);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|