|
@@ -0,0 +1,130 @@
|
|
|
|
|
+package cn.iocoder.yudao.module.pms.service.qhse.jsa;
|
|
|
|
|
+
|
|
|
|
|
+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.jsa.vo.QhseJsaPageReqVO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.jsa.vo.QhseJsaSaveReqVO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.stat.DeptUtil;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.jsa.QhseJsaDO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotrhdailyreport.IotRhDailyReportMapper;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.jsa.QhseJsaMapper;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.service.qhse.ChineseLetterUtil;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+
|
|
|
|
|
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * QHSE_JSA工作安全分析 Service 实现类
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author 超级管理员
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+@Validated
|
|
|
|
|
+public class QhseJsaServiceImpl implements QhseJsaService {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private QhseJsaMapper qhseJsaMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DeptApi deptApi;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DeptUtil deptUtil;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotRhDailyReportMapper iotRhDailyReportMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Long createQhseJsa(QhseJsaSaveReqVO createReqVO) {
|
|
|
|
|
+ // 插入
|
|
|
|
|
+ QhseJsaDO qhseJsa = BeanUtils.toBean(createReqVO, QhseJsaDO.class);
|
|
|
|
|
+ qhseJsa.setDeleted(false);
|
|
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
|
|
+ if (Objects.nonNull(loginUserDeptId)) {
|
|
|
|
|
+ DeptRespDTO dept = deptApi.getDept(loginUserDeptId);
|
|
|
|
|
+ if (Objects.nonNull(dept)) {
|
|
|
|
|
+ qhseJsa.setDeptName(dept.getName());
|
|
|
|
|
+ //获取队伍代码大写
|
|
|
|
|
+ String convert = ChineseLetterUtil.convert(dept.getName());
|
|
|
|
|
+ //获取公司代码大写
|
|
|
|
|
+ String company = deptUtil.getCompanyCode(loginUserDeptId).toUpperCase();
|
|
|
|
|
+ //获取项目部代码大写
|
|
|
|
|
+ String jsaNo = getJSANo(loginUserDeptId);
|
|
|
|
|
+ if (StringUtils.isBlank(jsaNo)){throw new ServiceException(new ErrorCode(2,"获取项目部编号失败"));}
|
|
|
|
|
+ qhseJsa.setJsaNo(company+"-"+jsaNo+"-"+convert);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ qhseJsaMapper.insert(qhseJsa);
|
|
|
|
|
+ // 返回
|
|
|
|
|
+ return qhseJsa.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getJSANo(Long loginUserDeptId) {
|
|
|
|
|
+ String companyCode = deptUtil.getCompanyCode(loginUserDeptId);
|
|
|
|
|
+ if ("jt".equals(companyCode)) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ DeptRespDTO dept = deptApi.getDept(loginUserDeptId);
|
|
|
|
|
+ if (Objects.isNull(dept)) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ Long parentId = dept.getParentId();
|
|
|
|
|
+ if (Objects.isNull(parentId)) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ DeptRespDTO dept1 = deptApi.getDept(parentId);
|
|
|
|
|
+ if (Objects.isNull(dept1)) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ String name = dept1.getName();
|
|
|
|
|
+ if (name.contains("项目部")) {
|
|
|
|
|
+ companyCode = StringUtils.substringBeforeLast(name, "项目部");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ companyCode = ChineseLetterUtil.convert(name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return companyCode;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateQhseJsa(QhseJsaSaveReqVO updateReqVO) {
|
|
|
|
|
+ // 校验存在
|
|
|
|
|
+ validateQhseJsaExists(updateReqVO.getId());
|
|
|
|
|
+ // 更新
|
|
|
|
|
+ QhseJsaDO updateObj = BeanUtils.toBean(updateReqVO, QhseJsaDO.class);
|
|
|
|
|
+ qhseJsaMapper.updateById(updateObj);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void deleteQhseJsa(Long id) {
|
|
|
|
|
+ // 校验存在
|
|
|
|
|
+ validateQhseJsaExists(id);
|
|
|
|
|
+ // 删除
|
|
|
|
|
+ qhseJsaMapper.deleteById(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void validateQhseJsaExists(Long id) {
|
|
|
|
|
+ if (qhseJsaMapper.selectById(id) == null) {
|
|
|
|
|
+ throw exception(new ErrorCode(1,"不存在"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public QhseJsaDO getQhseJsa(Long id) {
|
|
|
|
|
+ return qhseJsaMapper.selectById(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public PageResult<QhseJsaDO> getQhseJsaPage(QhseJsaPageReqVO pageReqVO) {
|
|
|
|
|
+ return qhseJsaMapper.selectPage(pageReqVO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|