package com.gkhy.safePlatform.specialWork.service.baseService.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.utils.StringUtils;
|
import com.gkhy.safePlatform.specialWork.entity.WorkApprovalUnitInfo;
|
import com.gkhy.safePlatform.specialWork.enums.WorkApprovalUnitResultEnum;
|
import com.gkhy.safePlatform.specialWork.repository.WorkApprovalUnitInfoRepository;
|
import com.gkhy.safePlatform.specialWork.service.baseService.WorkApprovalUnitInfoService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
@Service("workApprovalUnitInfoService")
|
public class WorkApprovalUnitInfoServiceImpl extends ServiceImpl<WorkApprovalUnitInfoRepository, WorkApprovalUnitInfo> implements WorkApprovalUnitInfoService {
|
|
@Autowired
|
private WorkApprovalUnitInfoRepository workApprovalUnitInfoRepository;
|
|
@Override
|
public void saveBatchRuleUnit(List<WorkApprovalUnitInfo> workApprovalUnitInfos) {
|
if (workApprovalUnitInfos == null || workApprovalUnitInfos.size() == 0) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
int i = workApprovalUnitInfoRepository.insertBatch(workApprovalUnitInfos);
|
if (i != workApprovalUnitInfos.size()) {
|
throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
|
}
|
}
|
|
@Override
|
public List<WorkApprovalUnitInfo> listApprovalRuleUnitByWorkApplyId(Long workApplyId) {
|
if (workApplyId == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
return workApprovalUnitInfoRepository.listApprovalRuleUnitByWorkApplyId(workApplyId);
|
}
|
|
@Override
|
public WorkApprovalUnitInfo getWorkApprovalUnitByStepIdAndUid(Long stepId, Long approvalUid) {
|
if (stepId == null || approvalUid == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
List<WorkApprovalUnitInfo> workApprovalUnitInfos = workApprovalUnitInfoRepository.listWorkApprovalUnitByStepIdAndUid(stepId, approvalUid);
|
if (workApprovalUnitInfos.size() == 0) {
|
return null;
|
}
|
if (workApprovalUnitInfos.size() > 1) {
|
throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED);
|
}
|
return workApprovalUnitInfos.get(0);
|
}
|
|
@Override
|
public void updateStatusById(Long unitId, WorkApprovalUnitResultEnum resultStatus) {
|
if (unitId == null || resultStatus == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
int i = workApprovalUnitInfoRepository.updateStatusById(unitId, resultStatus.getResult());
|
if (i == 0) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
|
}
|
if (i > 1) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
|
}
|
}
|
|
@Override
|
public List<WorkApprovalUnitInfo> listApprovalRuleUnitByStepId(Long stepId) {
|
if (stepId == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
return workApprovalUnitInfoRepository.listApprovalRuleUnitByStepId(stepId);
|
}
|
|
@Override
|
public void updateStatusByStepId(Long stepId, WorkApprovalUnitResultEnum result) {
|
if (stepId == null || result == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
// 不考虑数量
|
workApprovalUnitInfoRepository.updateStatusByStepId(stepId, result.getResult());
|
}
|
|
@Override
|
public void updateStatusByIds(List<Long> unitIds, WorkApprovalUnitResultEnum result) {
|
if (unitIds == null || unitIds.size() == 0 || result == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
int i = workApprovalUnitInfoRepository.updateStatusByIds(unitIds, result.getResult());
|
if (i == 0) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
|
}
|
if (i != unitIds.size()) {
|
throw new BusinessException(ResultCodes.SERVER_BATCH_UPDATE_ERROR);
|
}
|
}
|
|
@Override
|
public void updateStatusAndFillContentById(Long unitId, String unitFillContent, WorkApprovalUnitResultEnum result) {
|
if (unitId == null || StringUtils.isBlank(unitFillContent) || result == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
int i = workApprovalUnitInfoRepository.updateStatusAndFillContentById(unitId, unitFillContent, result.getResult());
|
if (i == 0) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
|
}
|
if (i != 1) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
|
}
|
}
|
|
@Override
|
public void batchUpdateStatusByIds(List<Long> unitIds, WorkApprovalUnitResultEnum result) {
|
if (unitIds == null || unitIds.size() == 0 || result == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
int i = workApprovalUnitInfoRepository.batchUpdateStatusByIds(unitIds, result.getResult());
|
if (i != unitIds.size()) {
|
throw new BusinessException(ResultCodes.SERVER_BATCH_UPDATE_ERROR);
|
}
|
|
}
|
}
|