package com.gkhy.safePlatform.specialWork.service.impl;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.query.PageQuery;
|
import com.gkhy.safePlatform.commons.utils.StringUtils;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleItemStand;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleItemStandDO;
|
import com.gkhy.safePlatform.specialWork.enums.RuleItemStandStatusEnum;
|
import com.gkhy.safePlatform.specialWork.enums.WorkStandTypeEnum;
|
import com.gkhy.safePlatform.specialWork.model.update.EntityStatusBatchUO;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.ApprovalRuleStandAddReqDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.ApprovalRuleStandModReqDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.DeleteForm;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleItemStandPageRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleStandListRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.query.ApprovalRuleStandListQuery;
|
import com.gkhy.safePlatform.specialWork.model.query.ApprovalRuleStandPageQuery;
|
import com.gkhy.safePlatform.specialWork.model.query.db.ApprovalRuleStandListDBQuery;
|
import com.gkhy.safePlatform.specialWork.model.query.db.ApprovalRuleStandPageDBQuery;
|
import com.gkhy.safePlatform.specialWork.service.RuleStandService;
|
import com.gkhy.safePlatform.specialWork.service.baseService.ApprovalRuleStandService;
|
import com.gkhy.safePlatform.specialWork.service.baseService.ApprovalRuleUnitItemService;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
@Service("ruleStandService")
|
public class RuleStandServiceImpl implements RuleStandService {
|
|
@DubboReference(check = false)
|
private AccountDepartmentService accountDepartmentService;
|
@Autowired
|
private ApprovalRuleStandService approvalRuleStandService;
|
@Autowired
|
private ApprovalRuleUnitItemService approvalRuleUnitItemService;
|
|
|
@Override
|
public void saveRuleStand(ContextCacheUser currentUser, ApprovalRuleStandAddReqDTO addReqDTO) {
|
;
|
if (addReqDTO.getRuleStandType() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (StringUtils.isBlank(addReqDTO.getTitle())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "标题为空");
|
}
|
WorkStandTypeEnum standTypeEnum = WorkStandTypeEnum.parse(addReqDTO.getRuleStandType());
|
if (standTypeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "标准类型参数不合法");
|
}
|
|
// 1.保存审批项标准
|
ApprovalRuleItemStand itemStandEntity = new ApprovalRuleItemStand();
|
// itemStandEntity.setDepId(addReqDTO.getDepId());
|
itemStandEntity.setType(addReqDTO.getRuleStandType());
|
// itemStandEntity.setEid(addReqDTO.getEid());
|
itemStandEntity.setMaxVal(addReqDTO.getMaxVal());
|
itemStandEntity.setMaxValMatchPattern(addReqDTO.getMaxValMatchPattern());
|
itemStandEntity.setMinVal(addReqDTO.getMinVal());
|
itemStandEntity.setMinValMatchPattern(addReqDTO.getMinValMatchPattern());
|
itemStandEntity.setTitle(addReqDTO.getTitle());
|
itemStandEntity.setInfo(addReqDTO.getInfo());
|
itemStandEntity.setCreateUid(currentUser.getUid());
|
itemStandEntity.setCreateUname(currentUser.getRealName());
|
itemStandEntity.setGmtCreate(LocalDateTime.now());
|
itemStandEntity.setStatus(RuleItemStandStatusEnum.VALID.getCode());
|
approvalRuleStandService.saveRuleStand(itemStandEntity);
|
}
|
|
@Override
|
public void updateRuleStand(ContextCacheUser currentUser, ApprovalRuleStandModReqDTO modReqDTO) {
|
;
|
if (modReqDTO.getRuleStandType() == null ||
|
modReqDTO.getRuleStandId() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (StringUtils.isBlank(modReqDTO.getTitle())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "标题为空");
|
}
|
WorkStandTypeEnum standTypeEnum = WorkStandTypeEnum.parse(modReqDTO.getRuleStandType());
|
if (standTypeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "标准类型参数不合法");
|
}
|
ApprovalRuleItemStandDO ruleStandDO = approvalRuleStandService.getRuleStandDOById(modReqDTO.getRuleStandId());
|
if (ruleStandDO == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "审批标准不存在");
|
}
|
if (!ruleStandDO.getStatus().equals(RuleItemStandStatusEnum.VALID.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "审批标准不存在");
|
}
|
|
if (!WorkStandTypeEnum.checkWorkStandType(modReqDTO.getRuleStandType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "标准类型参数不合法");
|
}
|
// 更新
|
ApprovalRuleItemStand itemStandEntity = new ApprovalRuleItemStand();
|
itemStandEntity.setId(modReqDTO.getRuleStandId());
|
// itemStandEntity.setDepId(modReqDTO.getDepId());
|
itemStandEntity.setTitle(modReqDTO.getTitle());
|
itemStandEntity.setMinVal(modReqDTO.getMinVal());
|
itemStandEntity.setMinValMatchPattern(modReqDTO.getMinValMatchPattern());
|
itemStandEntity.setMaxVal(modReqDTO.getMaxVal());
|
itemStandEntity.setMaxValMatchPattern(modReqDTO.getMaxValMatchPattern());
|
itemStandEntity.setType(modReqDTO.getRuleStandType());
|
itemStandEntity.setInfo(modReqDTO.getInfo());
|
itemStandEntity.setGmtModified(LocalDateTime.now());
|
itemStandEntity.setModifiedUid(currentUser.getUid());
|
itemStandEntity.setModifiedUname(currentUser.getRealName());
|
approvalRuleStandService.updateRuleStand(itemStandEntity);
|
}
|
|
@Override
|
public List<ApprovalRuleStandListRespDTO> listRuleStand(ContextCacheUser currentUser,ApprovalRuleStandListQuery query) {
|
;
|
// 查询对象
|
ApprovalRuleStandListDBQuery dbQuery = new ApprovalRuleStandListDBQuery();
|
dbQuery.setRuleStandType(query.getRuleStandType());
|
dbQuery.setStatus(RuleItemStandStatusEnum.VALID.getCode());
|
dbQuery.setTitle(query.getTitle());
|
// 执行
|
List<ApprovalRuleItemStandDO> dbData = approvalRuleStandService.listRuleStandDO(dbQuery);
|
List<ApprovalRuleStandListRespDTO> respDTOs = new ArrayList<>(dbData.size());
|
ApprovalRuleStandListRespDTO respDTO;
|
RuleItemStandStatusEnum itemStandStatusEnum;
|
WorkStandTypeEnum standTypeEnum;
|
if (dbData.size() > 0) {
|
for (ApprovalRuleItemStandDO ruleItemStandDO : dbData) {
|
respDTO = new ApprovalRuleStandListRespDTO();
|
respDTO.setTitle(ruleItemStandDO.getTitle());
|
respDTO.setRuleStandId(ruleItemStandDO.getId());
|
respDTO.setTitle(ruleItemStandDO.getTitle());
|
respDTO.setMaxVal(ruleItemStandDO.getMaxVal());
|
respDTO.setMaxValMatchPattern(ruleItemStandDO.getMaxValMatchPattern());
|
respDTO.setMinVal(ruleItemStandDO.getMinVal());
|
respDTO.setMinValMatchPattern(ruleItemStandDO.getMinValMatchPattern());
|
respDTO.setRuleStandType(ruleItemStandDO.getType());
|
respDTO.setStatus(ruleItemStandDO.getStatus());
|
respDTO.setInfo(ruleItemStandDO.getInfo());
|
standTypeEnum = WorkStandTypeEnum.parse(ruleItemStandDO.getType());
|
if (standTypeEnum != null) {
|
respDTO.setRuleStandTypeDesc(standTypeEnum.getDesc());
|
}
|
itemStandStatusEnum = RuleItemStandStatusEnum.parse(ruleItemStandDO.getStatus());
|
if (itemStandStatusEnum != null) {
|
respDTO.setStatusDesc(itemStandStatusEnum.getValue());
|
}
|
respDTOs.add(respDTO);
|
}
|
}
|
return respDTOs;
|
}
|
|
@Override
|
public SearchResultVO<List<ApprovalRuleItemStandPageRespDTO>> listRuleStandByPage(ContextCacheUser currentUser, PageQuery<ApprovalRuleStandPageQuery> query) {
|
;
|
// 查询对象
|
ApprovalRuleStandPageDBQuery dbQuery = new ApprovalRuleStandPageDBQuery();
|
dbQuery.setStatus(RuleItemStandStatusEnum.VALID.getCode());
|
if (query.getSearchParams() != null) {
|
dbQuery.setTitle(query.getSearchParams().getTitle());
|
dbQuery.setRuleStandType(query.getSearchParams().getRuleStandType());
|
}
|
// 分页对象
|
Page<ApprovalRuleItemStand> page = new Page<>(query.getPageIndex(), query.getPageSize());
|
List<ApprovalRuleItemStand> dbData = approvalRuleStandService.listRuleStandByPage(page, dbQuery);
|
List<ApprovalRuleItemStandPageRespDTO> respDTOs = new ArrayList<>(dbData.size());
|
ApprovalRuleItemStandPageRespDTO respDTO;
|
RuleItemStandStatusEnum itemStandStatusEnum;
|
WorkStandTypeEnum standTypeEnum;
|
if (dbData.size() > 0) {
|
for (ApprovalRuleItemStand ruleItemStandDO : dbData) {
|
respDTO = new ApprovalRuleItemStandPageRespDTO();
|
respDTO.setRuleStandId(ruleItemStandDO.getId());
|
respDTO.setMaxVal(ruleItemStandDO.getMaxVal());
|
respDTO.setMaxValMatchPattern(ruleItemStandDO.getMaxValMatchPattern());
|
respDTO.setMinVal(ruleItemStandDO.getMinVal());
|
respDTO.setMinValMatchPattern(ruleItemStandDO.getMinValMatchPattern());
|
respDTO.setRuleStandType(ruleItemStandDO.getType());
|
respDTO.setTitle(ruleItemStandDO.getTitle());
|
respDTO.setInfo(ruleItemStandDO.getInfo());
|
respDTO.setStatus(ruleItemStandDO.getStatus());
|
respDTO.setCreateUid(ruleItemStandDO.getCreateUid());
|
respDTO.setCreateUname(ruleItemStandDO.getCreateUname());
|
respDTO.setGmtCreate(ruleItemStandDO.getGmtCreate());
|
respDTO.setModifiedUid(ruleItemStandDO.getModifiedUid());
|
respDTO.setModifiedUname(ruleItemStandDO.getModifiedUname());
|
respDTO.setGmtModified(ruleItemStandDO.getGmtModified());
|
standTypeEnum = WorkStandTypeEnum.parse(ruleItemStandDO.getType());
|
if (standTypeEnum != null) {
|
respDTO.setRuleStandTypeDesc(standTypeEnum.getDesc());
|
}
|
itemStandStatusEnum = RuleItemStandStatusEnum.parse(ruleItemStandDO.getStatus());
|
if (itemStandStatusEnum != null) {
|
respDTO.setStatusDesc(itemStandStatusEnum.getValue());
|
}
|
respDTOs.add(respDTO);
|
}
|
}
|
|
return new SearchResultVO<>(
|
true,page.getCurrent(),
|
page.getSize(),
|
page.getPages(),
|
page.getTotal(),
|
respDTOs,
|
ResultCodes.OK);
|
}
|
|
@Override
|
public void deleteRuleStand(ContextCacheUser currentUser, DeleteForm deleteForm) {
|
;
|
if (deleteForm.getIds() == null || deleteForm.getIds().size() == 0) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (deleteForm.getIds().size() > 10) {
|
throw new BusinessException(ResultCodes.SERVER_DEL_OVER_SIZE);
|
}
|
ApprovalRuleItemStandDO ruleItemStandDO;
|
long count;
|
for (Long ruleStandId : deleteForm.getIds()) {
|
ruleItemStandDO = approvalRuleStandService.getRuleStandDOById(ruleStandId);
|
if (ruleItemStandDO == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"审批项标准不存在");
|
}
|
if (!ruleItemStandDO.getStatus().equals(RuleItemStandStatusEnum.VALID.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID,"审批项标准不存在");
|
}
|
// 是否被审批项占用
|
count = approvalRuleUnitItemService.countByRuleStandId(ruleStandId);
|
if (count > 0) {
|
throw new AusinessException(E.DATA_BING_RELATION, "审批项关联,无法删除");
|
}
|
}
|
EntityStatusBatchUO batchDeleteObj = new EntityStatusBatchUO();
|
batchDeleteObj.setIds(deleteForm.getIds());
|
batchDeleteObj.setModifiedUname(currentUser.getRealName());
|
batchDeleteObj.setGmtModified(LocalDateTime.now());
|
batchDeleteObj.setModifiedUid(currentUser.getUid());
|
batchDeleteObj.setStatus(RuleItemStandStatusEnum.ABANDONED.getCode());
|
approvalRuleStandService.deleteBatch(batchDeleteObj);
|
}
|
}
|