package com.gkhy.safePlatform.specialWork.service.impl;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
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.SearchResultVO;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleItemStandDO;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleUnitItem;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleUnitItemDO;
|
import com.gkhy.safePlatform.specialWork.enums.RuleItemStandStatusEnum;
|
import com.gkhy.safePlatform.specialWork.enums.RuleItemStatusEnum;
|
import com.gkhy.safePlatform.specialWork.enums.RuleItemTypeEnum;
|
import com.gkhy.safePlatform.specialWork.enums.WorkStandTypeEnum;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleStandListRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.update.EntityStatusBatchUO;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.ApprovalRuleItemAddReqDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.ApprovalRuleItemModReqDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.DeleteForm;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleUnitItemListRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleUnitItemPageRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.query.ApprovalRuleItemPageQuery;
|
import com.gkhy.safePlatform.specialWork.model.query.ApprovalRuleItemQuery;
|
import com.gkhy.safePlatform.specialWork.model.query.db.ApprovalRuleItemDBQuery;
|
import com.gkhy.safePlatform.specialWork.model.query.db.ApprovalRuleItemPageDBQuery;
|
import com.gkhy.safePlatform.specialWork.service.RuleItemService;
|
import com.gkhy.safePlatform.specialWork.service.baseService.ApprovalRuleStandService;
|
import com.gkhy.safePlatform.specialWork.service.baseService.ApprovalRuleUnitItemService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service("ruleItemService")
|
public class RuleItemServiceImpl implements RuleItemService {
|
|
@Autowired
|
private ApprovalRuleUnitItemService approvalRuleUnitItemService;
|
|
@Autowired
|
private ApprovalRuleStandService approvalRuleStandService;
|
|
@Override
|
public void saveRuleItem(ContextCacheUser currentUser, ApprovalRuleItemAddReqDTO addReqDTO) {
|
;
|
if (addReqDTO.getItemStandId() == null || addReqDTO.getItemType() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (StringUtils.isBlank(addReqDTO.getItemName())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "填报项名称不可为空");
|
}
|
// 填报类型判断
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(addReqDTO.getItemType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "填报项类型校验非法");
|
}
|
// 判断填报项标准是否存在
|
ApprovalRuleItemStandDO ruleItemStand = approvalRuleStandService.getRuleStandDOById(addReqDTO.getItemStandId());
|
if (ruleItemStand == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "填报项标准不存在");
|
}
|
if (!ruleItemStand.getStatus().equals(RuleItemStandStatusEnum.VALID.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "填报项标准不存在");
|
}
|
// 1.新增审批项
|
ApprovalRuleUnitItem itemEntity = new ApprovalRuleUnitItem();
|
itemEntity.setItemName(addReqDTO.getItemName().trim());
|
itemEntity.setType(addReqDTO.getItemType());
|
itemEntity.setStandId(addReqDTO.getItemStandId());
|
itemEntity.setGmtCreate(LocalDateTime.now());
|
itemEntity.setCreateUid(currentUser.getUid());
|
itemEntity.setCreateUname(currentUser.getRealName());
|
itemEntity.setStatus(RuleItemStatusEnum.VALID.getCode());
|
approvalRuleUnitItemService.saveRuleItem(itemEntity);
|
}
|
|
@Override
|
public void updateRuleItem(ContextCacheUser currentUser, ApprovalRuleItemModReqDTO modReqDTO) {
|
;
|
if (modReqDTO.getItemId() == null ||
|
modReqDTO.getItemType() == null ||
|
modReqDTO.getItemStandId() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (StringUtils.isBlank(modReqDTO.getItemName())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "填报项名称不可为空");
|
}
|
// 填报类型判断
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(modReqDTO.getItemType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "填报项类型校验非法");
|
}
|
ApprovalRuleUnitItemDO item = approvalRuleUnitItemService.getApprovalRuleUnitItemDOById(modReqDTO.getItemId());
|
if (item == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "填报项不存在");
|
}
|
if (!item.getStatus().equals(RuleItemStatusEnum.VALID.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "填报项不存在");
|
}
|
// 判断填报项标准是否存在
|
ApprovalRuleItemStandDO ruleItemStand = approvalRuleStandService.getRuleStandDOById(modReqDTO.getItemStandId());
|
if (ruleItemStand == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "填报项标准不存在");
|
}
|
if (!ruleItemStand.getStatus().equals(RuleItemStandStatusEnum.VALID.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "填报项标准不存在");
|
}
|
|
// 1.更新审批项
|
ApprovalRuleUnitItem itemEntity = new ApprovalRuleUnitItem();
|
itemEntity.setId(modReqDTO.getItemId());
|
itemEntity.setItemName(modReqDTO.getItemName());
|
itemEntity.setType(modReqDTO.getItemType());
|
itemEntity.setGmtModified(LocalDateTime.now());
|
itemEntity.setModifiedUname(currentUser.getRealName());
|
itemEntity.setModifiedUid(currentUser.getUid());
|
approvalRuleUnitItemService.updateRuleItem(itemEntity);
|
}
|
|
@Override
|
public void deleteRuleItem(ContextCacheUser currentUser, DeleteForm deleteForm) {
|
;
|
if (deleteForm.getIds() == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
if (deleteForm.getIds().size() > 10) {
|
throw new BusinessException(ResultCodes.SERVER_DEL_OVER_SIZE);
|
}
|
// 1.id合法
|
for (Long ruleItemId : deleteForm.getIds()) {
|
ApprovalRuleUnitItemDO ruleUnitItemDO = approvalRuleUnitItemService.getApprovalRuleUnitItemDOById(ruleItemId);
|
if (ruleUnitItemDO == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "填报项不存在");
|
}
|
if (!ruleUnitItemDO.getStatus().equals(RuleItemStatusEnum.VALID.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "填报项不存在");
|
}
|
// 2.todo 是否被占用
|
}
|
EntityStatusBatchUO entityBatchDeleteObject = new EntityStatusBatchUO();
|
entityBatchDeleteObject.setIds(deleteForm.getIds());
|
entityBatchDeleteObject.setModifiedUid(currentUser.getUid());
|
entityBatchDeleteObject.setModifiedUname(currentUser.getRealName());
|
entityBatchDeleteObject.setGmtModified(LocalDateTime.now());
|
approvalRuleUnitItemService.deleteBatch(entityBatchDeleteObject);
|
|
}
|
|
@Override
|
public SearchResultVO<List<ApprovalRuleUnitItemPageRespDTO>> listRuleItemByPage(ContextCacheUser currentUser, PageQuery<ApprovalRuleItemPageQuery> pageQuery) {
|
;
|
// 查询对象
|
ApprovalRuleItemPageDBQuery dbQuery = new ApprovalRuleItemPageDBQuery();
|
if (pageQuery.getSearchParams() != null) {
|
dbQuery.setItemName(pageQuery.getSearchParams().getItemName());
|
dbQuery.setItemStandId(pageQuery.getSearchParams().getItemStandId());
|
dbQuery.setItemType(pageQuery.getSearchParams().getItemType());
|
dbQuery.setStatus(RuleItemStatusEnum.VALID.getCode());
|
}
|
// 分页对象
|
Page<ApprovalRuleUnitItem> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
|
List<ApprovalRuleUnitItem> dbData = approvalRuleUnitItemService.listRuleItemByPage(page, dbQuery);
|
|
List<ApprovalRuleUnitItemPageRespDTO> respDTOs = new ArrayList<>(dbData.size());
|
ApprovalRuleUnitItemPageRespDTO respDTO;
|
RuleItemTypeEnum itemTypeEnum;
|
RuleItemStatusEnum statusEnum;
|
RuleItemStandStatusEnum standStatusEnum;
|
WorkStandTypeEnum standTypeEnum;
|
ApprovalRuleItemStandDO ruleStandDO;
|
Map<Long, ApprovalRuleStandListRespDTO> standPool = null;
|
if (pageQuery.getSearchParams().isContainItemStandEnable()) {
|
standPool = new HashMap<>();
|
}
|
if (dbData.size() > 0) {
|
for (ApprovalRuleUnitItem item : dbData) {
|
respDTO = new ApprovalRuleUnitItemPageRespDTO();
|
respDTO.setItemId(item.getId());
|
respDTO.setItemName(item.getItemName());
|
respDTO.setItemStandId(item.getStandId());
|
respDTO.setRuleId(item.getRuleId());
|
respDTO.setStepId(item.getStepId());
|
respDTO.setUnitId(item.getUnitId());
|
respDTO.setCreateUid(item.getCreateUid());
|
respDTO.setCreateUname(item.getCreateUname());
|
respDTO.setGmtCreate(item.getGmtCreate());
|
respDTO.setModifiedUid(item.getModifiedUid());
|
respDTO.setModifiedUname(item.getModifiedUname());
|
respDTO.setGmtModified(item.getGmtModified());
|
respDTO.setItemType(item.getType());
|
respDTO.setStatus(item.getStatus());
|
itemTypeEnum = RuleItemTypeEnum.parse(item.getType());
|
if (itemTypeEnum != null) {
|
respDTO.setItemTypeDesc(itemTypeEnum.getValue());
|
}
|
statusEnum = RuleItemStatusEnum.parse(item.getStatus());
|
if (statusEnum != null) {
|
respDTO.setStatusDesc(statusEnum.getValue());
|
}
|
|
// 是否包含审批项标准
|
if (pageQuery.getSearchParams().isContainItemStandEnable()) {
|
assert standPool != null;
|
if (item.getStandId() != null) {
|
if (!standPool.containsKey(item.getStandId())) {
|
ruleStandDO = approvalRuleStandService.getRuleStandDOById(item.getStandId());
|
if (ruleStandDO != null && ruleStandDO.getStatus().equals(RuleItemStatusEnum.VALID.getCode())) {
|
ApprovalRuleStandListRespDTO standListRespDTO = new ApprovalRuleStandListRespDTO();
|
standListRespDTO.setRuleStandId(ruleStandDO.getId());
|
standListRespDTO.setRuleStandType(ruleStandDO.getType());
|
standListRespDTO.setTitle(ruleStandDO.getTitle());
|
standListRespDTO.setMinVal(ruleStandDO.getMinVal());
|
standListRespDTO.setMinValMatchPattern(ruleStandDO.getMinValMatchPattern());
|
standListRespDTO.setMaxVal(ruleStandDO.getMaxVal());
|
standListRespDTO.setMaxValMatchPattern(ruleStandDO.getMaxValMatchPattern());
|
standListRespDTO.setStatus(ruleStandDO.getStatus());
|
standStatusEnum = RuleItemStandStatusEnum.parse(ruleStandDO.getStatus());
|
if (standStatusEnum != null) {
|
standListRespDTO.setStatusDesc(standStatusEnum.getValue());
|
}
|
standTypeEnum = WorkStandTypeEnum.parse(ruleStandDO.getType());
|
if (standTypeEnum != null) {
|
standListRespDTO.setRuleStandTypeDesc(standTypeEnum.getDesc());
|
}
|
standPool.put(item.getStandId(), standListRespDTO);
|
}
|
respDTO.setItemStand(standPool.get(item.getStandId()));
|
|
}
|
}
|
}
|
|
|
respDTOs.add(respDTO);
|
}
|
}
|
|
return new SearchResultVO<>(
|
true,
|
page.getCurrent(),
|
page.getSize(),
|
page.getPages(),
|
page.getTotal(),
|
respDTOs,
|
ResultCodes.OK);
|
}
|
|
@Override
|
public List<ApprovalRuleUnitItemListRespDTO> listRuleItem(ContextCacheUser currentUser, ApprovalRuleItemQuery query) {
|
;
|
ApprovalRuleItemDBQuery dbQuery = new ApprovalRuleItemDBQuery();
|
dbQuery.setItemName(query.getItemName());
|
dbQuery.setItemStandId(query.getItemStandId());
|
dbQuery.setItemType(query.getItemType());
|
dbQuery.setStatus(RuleItemStatusEnum.VALID.getCode());
|
// db查询
|
List<ApprovalRuleUnitItemDO> dbData = approvalRuleUnitItemService.listRuleItem(dbQuery);
|
List<ApprovalRuleUnitItemListRespDTO> respDTOs = new ArrayList<>(dbData.size());
|
ApprovalRuleUnitItemListRespDTO respDTO;
|
RuleItemTypeEnum itemTypeEnum;
|
RuleItemStatusEnum statusEnum;
|
RuleItemStandStatusEnum standStatusEnum;
|
WorkStandTypeEnum standTypeEnum;
|
ApprovalRuleItemStandDO ruleStandDO;
|
Map<Long, ApprovalRuleStandListRespDTO> standPool = null;
|
if (query.isContainItemStandEnable()) {
|
standPool = new HashMap<>();
|
}
|
if (dbData.size() > 0) {
|
for (ApprovalRuleUnitItemDO itemDO : dbData) {
|
respDTO = new ApprovalRuleUnitItemListRespDTO();
|
respDTO.setItemId(itemDO.getId());
|
respDTO.setItemName(itemDO.getItemName());
|
respDTO.setItemStandId(itemDO.getStandId());
|
respDTO.setRuleId(itemDO.getRuleId());
|
respDTO.setStepId(itemDO.getStepId());
|
respDTO.setUnitId(itemDO.getUnitId());
|
respDTO.setItemType(itemDO.getType());
|
respDTO.setStatus(itemDO.getStatus());
|
itemTypeEnum = RuleItemTypeEnum.parse(itemDO.getType());
|
if (itemTypeEnum != null) {
|
respDTO.setItemTypeDesc(itemTypeEnum.getValue());
|
}
|
statusEnum = RuleItemStatusEnum.parse(itemDO.getStatus());
|
if (statusEnum != null) {
|
respDTO.setStatusDesc(statusEnum.getValue());
|
}
|
|
// 是否包含审批项标准
|
if (query.isContainItemStandEnable()) {
|
assert standPool != null;
|
if (itemDO.getStandId() != null) {
|
if (!standPool.containsKey(itemDO.getStandId())) {
|
ruleStandDO = approvalRuleStandService.getRuleStandDOById(itemDO.getStandId());
|
if (ruleStandDO != null && ruleStandDO.getStatus().equals(RuleItemStatusEnum.VALID.getCode())) {
|
ApprovalRuleStandListRespDTO standListRespDTO = new ApprovalRuleStandListRespDTO();
|
standListRespDTO.setRuleStandId(ruleStandDO.getId());
|
standListRespDTO.setRuleStandType(ruleStandDO.getType());
|
standListRespDTO.setTitle(ruleStandDO.getTitle());
|
standListRespDTO.setMinVal(ruleStandDO.getMinVal());
|
standListRespDTO.setMinValMatchPattern(ruleStandDO.getMinValMatchPattern());
|
standListRespDTO.setMaxVal(ruleStandDO.getMaxVal());
|
standListRespDTO.setMaxValMatchPattern(ruleStandDO.getMaxValMatchPattern());
|
standListRespDTO.setStatus(ruleStandDO.getStatus());
|
standStatusEnum = RuleItemStandStatusEnum.parse(ruleStandDO.getStatus());
|
if (standStatusEnum != null) {
|
standListRespDTO.setStatusDesc(standStatusEnum.getValue());
|
}
|
standTypeEnum = WorkStandTypeEnum.parse(ruleStandDO.getType());
|
if (standTypeEnum != null) {
|
standListRespDTO.setRuleStandTypeDesc(standTypeEnum.getDesc());
|
}
|
standPool.put(itemDO.getStandId(), standListRespDTO);
|
}
|
respDTO.setItemStand(standPool.get(itemDO.getStandId()));
|
|
}
|
}
|
}
|
|
|
|
respDTOs.add(respDTO);
|
}
|
}
|
return respDTOs;
|
}
|
|
|
}
|