package com.vci.ubcs.code.service.impl;
|
|
import com.vci.ubcs.code.dao.CodeKeyAttrRepeatRuleDaoI;
|
import com.vci.ubcs.code.model.CodeKeyAttrRepeatRuleDO;
|
import com.vci.ubcs.code.service.CodeKeyAttrRepeatRuleServiceI;
|
import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus;
|
import com.vci.starter.revision.service.RevisionModelUtil;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.BaseResult;
|
import com.vci.starter.web.pagemodel.DataGrid;
|
import com.vci.starter.web.pagemodel.PageHelper;
|
import com.vci.starter.web.util.BeanUtil;
|
import com.vci.starter.web.util.BeanUtilForVCI;
|
import com.vci.starter.web.util.VciBaseUtil;
|
import com.vci.web.pageModel.BatchCBO;
|
import com.vci.web.service.WebBoServiceI;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
|
import com.vci.ubcs.code.dto.CodeKeyAttrRepeatRuleDTO;
|
import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO;
|
import com.vci.ubcs.code.vo.pagemodel.CodeKeyAttrRepeatRuleVO;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
import static com.vci.frameworkcore.constant.FrameWorkLangCodeConstant.*;
|
|
/**
|
* 关键数据查重规则服务
|
* @author weidy
|
* @date 2022-01-24
|
*/
|
@Service
|
public class CodeKeyAttrRepeatRuleServiceImpl implements CodeKeyAttrRepeatRuleServiceI {
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 数据操作层
|
*/
|
@Resource
|
private CodeKeyAttrRepeatRuleDaoI codeKeyAttrRepeatRuleMapper;
|
|
/**
|
* 业务类型操作的服务
|
*/
|
@Autowired
|
@Lazy
|
private WebBoServiceI boService;
|
|
/**
|
* 对象的操作
|
*/
|
@Autowired
|
private RevisionModelUtil revisionModelUtil;
|
|
|
/**
|
* 查询所有的关键数据查重规则
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return 执行结果
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public DataGrid<CodeKeyAttrRepeatRuleVO> gridCodeKeyAttrRepeatRule(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{
|
if (pageHelper == null) {
|
pageHelper = new PageHelper(-1);
|
}
|
pageHelper.addDefaultDesc("createTime");
|
List<CodeKeyAttrRepeatRuleDO> doList = codeKeyAttrRepeatRuleMapper.selectByCondition(conditionMap,pageHelper);
|
DataGrid<CodeKeyAttrRepeatRuleVO> dataGrid=new DataGrid<CodeKeyAttrRepeatRuleVO>();
|
if (!CollectionUtils.isEmpty(doList)) {
|
dataGrid.setData(codeKeyAttrRepeatRuleDO2VOs(doList));
|
dataGrid.setTotal(VciBaseUtil.getInt(String.valueOf(codeKeyAttrRepeatRuleMapper.countByCondition(conditionMap))));
|
}
|
return dataGrid;
|
}
|
|
/**
|
* 批量数据对象转换为显示对象
|
* @param codeKeyAttrRepeatRuleDOs 数据对象列表
|
* @return 显示对象
|
* @throws VciBaseException 参数为空或者不存在的时候会抛出异常
|
*/
|
@Override
|
public List<CodeKeyAttrRepeatRuleVO> codeKeyAttrRepeatRuleDO2VOs(Collection<CodeKeyAttrRepeatRuleDO> codeKeyAttrRepeatRuleDOs) throws VciBaseException{
|
List<CodeKeyAttrRepeatRuleVO> voList = new ArrayList<CodeKeyAttrRepeatRuleVO>();
|
if(!CollectionUtils.isEmpty(codeKeyAttrRepeatRuleDOs)){
|
for(CodeKeyAttrRepeatRuleDO s: codeKeyAttrRepeatRuleDOs){
|
CodeKeyAttrRepeatRuleVO vo = codeKeyAttrRepeatRuleDO2VO(s);
|
if(vo != null){
|
voList.add(vo);
|
}
|
}
|
}
|
return voList;
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
* @param codeKeyAttrRepeatRuleDO 数据对象
|
* @return 显示对象
|
* @throws VciBaseException 拷贝属性出错的时候会抛出异常
|
*/
|
@Override
|
public CodeKeyAttrRepeatRuleVO codeKeyAttrRepeatRuleDO2VO(CodeKeyAttrRepeatRuleDO codeKeyAttrRepeatRuleDO) throws VciBaseException{
|
CodeKeyAttrRepeatRuleVO vo = new CodeKeyAttrRepeatRuleVO();
|
if(codeKeyAttrRepeatRuleDO != null) {
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeKeyAttrRepeatRuleDO, vo);
|
//如果有lcstatus的类的话
|
vo.setLcStatusText(FrameworkDataLCStatus.getTextByValue(vo.getLcStatus()));
|
}
|
return vo;
|
}
|
|
/**
|
* 增加关键数据查重规则
|
* @param codeKeyAttrRepeatRuleDTO 关键数据查重规则数据传输对象
|
* @return 执行结果
|
* @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
|
*/
|
@Override
|
public CodeKeyAttrRepeatRuleVO addSave(CodeKeyAttrRepeatRuleDTO codeKeyAttrRepeatRuleDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeKeyAttrRepeatRuleDTO,"需要添加的数据对象");
|
//将DTO转换为DO
|
CodeKeyAttrRepeatRuleDO codeKeyAttrRepeatRuleDO = new CodeKeyAttrRepeatRuleDO();
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeKeyAttrRepeatRuleDTO,codeKeyAttrRepeatRuleDO);
|
codeKeyAttrRepeatRuleMapper.insert(codeKeyAttrRepeatRuleDO);
|
return codeKeyAttrRepeatRuleDO2VO(codeKeyAttrRepeatRuleDO);
|
}
|
|
/**
|
* 修改关键数据查重规则
|
* @param codeKeyAttrRepeatRuleDTO 关键数据查重规则数据传输对象
|
* @return 执行结果
|
* @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
|
*/
|
@Override
|
public CodeKeyAttrRepeatRuleVO editSave(CodeKeyAttrRepeatRuleDTO codeKeyAttrRepeatRuleDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeKeyAttrRepeatRuleDTO,"数据对象",codeKeyAttrRepeatRuleDTO.getOid(),"关键数据查重规则主键");
|
//将DTO转换为DO
|
CodeKeyAttrRepeatRuleDO codeKeyAttrRepeatRuleDO = selectByOid(codeKeyAttrRepeatRuleDTO.getOid());
|
revisionModelUtil.copyFromDTOIgnore(codeKeyAttrRepeatRuleDTO,codeKeyAttrRepeatRuleDO);
|
codeKeyAttrRepeatRuleMapper.updateByPrimaryKey(codeKeyAttrRepeatRuleDO);
|
return codeKeyAttrRepeatRuleDO2VO(codeKeyAttrRepeatRuleDO);
|
}
|
|
|
/**
|
* 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除
|
* @param codeKeyAttrRepeatRuleDTO 数据传输对象
|
* @param codeKeyAttrRepeatRuleDO 数据库中的数据对象
|
* @return success为true为可以删除,false表示有数据引用,obj为true表示有下级
|
*/
|
private BaseResult checkIsCanDeleteForDO(CodeKeyAttrRepeatRuleDTO codeKeyAttrRepeatRuleDTO, CodeKeyAttrRepeatRuleDO codeKeyAttrRepeatRuleDO) {
|
CodeKeyAttrRepeatRuleDO repeatRuleDO = new CodeKeyAttrRepeatRuleDO();
|
BeanUtil.convert(codeKeyAttrRepeatRuleDTO,repeatRuleDO);
|
boService.checkTs(repeatRuleDO);
|
if(!checkIsLinked(codeKeyAttrRepeatRuleDO.getOid())) {
|
return BaseResult.success();
|
}else{
|
return BaseResult.fail(DATA_LINKED_NOT_DELETE,new String[]{""});
|
}
|
}
|
|
/**
|
* 校验是否被引用
|
* @param oid 主键
|
* @throws VciBaseException 被引用的时候会抛出异常
|
*/
|
private boolean checkIsLinked(String oid) throws VciBaseException{
|
//TODO 添加需要校验引用的地方
|
return false;
|
}
|
|
/**
|
* 删除关键数据查重规则
|
* @param codeKeyAttrRepeatRuleDTO 关键数据查重规则数据传输对象,oid和ts需要传输
|
* @return 删除结果反馈::success:成功,fail:失败
|
* @throws VciBaseException 参数为空,被引用时抛出异常
|
*/
|
@Override
|
public BaseResult deleteCodeKeyAttrRepeatRule(CodeKeyAttrRepeatRuleDTO codeKeyAttrRepeatRuleDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeKeyAttrRepeatRuleDTO,"关键数据查重规则数据对象",codeKeyAttrRepeatRuleDTO.getOid(),"关键数据查重规则的主键");
|
CodeKeyAttrRepeatRuleDO codeKeyAttrRepeatRuleDO = selectByOid(codeKeyAttrRepeatRuleDTO.getOid());
|
BaseResult baseResult = checkIsCanDeleteForDO(codeKeyAttrRepeatRuleDTO,codeKeyAttrRepeatRuleDO);
|
if(baseResult.isSuccess()) {
|
}else{
|
return baseResult;
|
}
|
//执行删除操作
|
BatchCBO batchCBO = codeKeyAttrRepeatRuleMapper.deleteByPrimaryKey(codeKeyAttrRepeatRuleDO.getOid());
|
return (batchCBO!=null && batchCBO.getDeleteCbos() !=null &&batchCBO.getDeleteCbos().size() > 0)?BaseResult.successMsg(DELETE_SUCCESS):BaseResult.fail(DELETE_FAIL);
|
}
|
|
/**
|
* 主键获取关键数据查重规则
|
* @param oid 主键
|
* @return 关键数据查重规则显示对象
|
* @throws VciBaseException 参数为空,数据不存在时会抛出异常
|
*/
|
@Override
|
public CodeKeyAttrRepeatRuleVO getObjectByOid(String oid) throws VciBaseException{
|
return codeKeyAttrRepeatRuleDO2VO(selectByOid(oid));
|
}
|
|
/**
|
* 主键查询数据对象
|
* @param oid 主键
|
* @return 数据对象
|
* @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常
|
*/
|
private CodeKeyAttrRepeatRuleDO selectByOid(String oid) throws VciBaseException{
|
VciBaseUtil.alertNotNull(oid,"主键");
|
CodeKeyAttrRepeatRuleDO codeKeyAttrRepeatRuleDO = codeKeyAttrRepeatRuleMapper.selectByPrimaryKey(oid.trim());
|
if(codeKeyAttrRepeatRuleDO == null || StringUtils.isBlank(codeKeyAttrRepeatRuleDO.getOid())){
|
throw new VciBaseException(DATA_OID_NOT_EXIST);
|
}
|
return codeKeyAttrRepeatRuleDO;
|
}
|
|
/**
|
* 主键批量获取关键数据查重规则
|
* @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个
|
* @return 关键数据查重规则显示对象
|
* @throws VciBaseException 查询出现异常时会抛出
|
*/
|
@Override
|
public Collection<CodeKeyAttrRepeatRuleVO> listCodeKeyAttrRepeatRuleByOids(Collection<String> oidCollections) throws VciBaseException{
|
VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合");
|
List<CodeKeyAttrRepeatRuleDO> codeKeyAttrRepeatRuleDOList = listCodeKeyAttrRepeatRuleDOByOidCollections(oidCollections);
|
return codeKeyAttrRepeatRuleDO2VOs(codeKeyAttrRepeatRuleDOList);
|
}
|
|
/**
|
* 编号批量获取关键数据查重规则
|
*
|
* @param idCollections 编号集合
|
* @return 关键数据查重规则显示对象
|
*/
|
@Override
|
public Collection<CodeKeyAttrRepeatRuleVO> listCodeKeyAttrRepeatRuleByIds(List<String> idCollections) {
|
List<CodeKeyAttrRepeatRuleDO> codeKeyAttrRepeatRuleDOList = listCodeKeyAttrRepeatRuleDOByIdCollections(idCollections);
|
return codeKeyAttrRepeatRuleDO2VOs(codeKeyAttrRepeatRuleDOList);
|
}
|
|
/**
|
* 使用主键集合查询数据对象
|
* @param idCollections 编号的集合
|
* @return 数据对象列表
|
*/
|
private List<CodeKeyAttrRepeatRuleDO> listCodeKeyAttrRepeatRuleDOByIdCollections(Collection<String> idCollections){
|
List<CodeKeyAttrRepeatRuleDO> codeKeyAttrRepeatRuleDOList = new ArrayList<CodeKeyAttrRepeatRuleDO>();
|
if(!CollectionUtils.isEmpty(idCollections)){
|
Collection<Collection<String>> idCollectionsList = VciBaseUtil.switchCollectionForOracleIn(idCollections);
|
for(Collection<String> ids: idCollectionsList){
|
List<CodeKeyAttrRepeatRuleDO> tempDOList = codeKeyAttrRepeatRuleMapper.selectByIdCollection(ids);
|
if(!CollectionUtils.isEmpty(tempDOList)){
|
codeKeyAttrRepeatRuleDOList.addAll(tempDOList);
|
}
|
}
|
}
|
return codeKeyAttrRepeatRuleDOList;
|
}
|
|
/**
|
* 使用主键集合查询数据对象
|
* @param oidCollections 主键的集合
|
* @return 数据对象列表
|
*/
|
private List<CodeKeyAttrRepeatRuleDO> listCodeKeyAttrRepeatRuleDOByOidCollections(Collection<String> oidCollections){
|
List<CodeKeyAttrRepeatRuleDO> codeKeyAttrRepeatRuleDOList = new ArrayList<CodeKeyAttrRepeatRuleDO>();
|
if(!CollectionUtils.isEmpty(oidCollections)){
|
Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections);
|
for(Collection<String> oids: oidCollectionsList){
|
List<CodeKeyAttrRepeatRuleDO> tempDOList = codeKeyAttrRepeatRuleMapper.selectByPrimaryKeyCollection(oids);
|
if(!CollectionUtils.isEmpty(tempDOList)){
|
codeKeyAttrRepeatRuleDOList.addAll(tempDOList);
|
}
|
}
|
}
|
return codeKeyAttrRepeatRuleDOList;
|
}
|
|
|
|
/**
|
* 参照关键数据查重规则列表
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return 关键数据查重规则显示对象列表,生效的内容
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public DataGrid<CodeKeyAttrRepeatRuleVO> refDataGridCodeKeyAttrRepeatRule(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{
|
if(conditionMap == null){
|
conditionMap = new HashMap<String, String>();
|
}
|
return gridCodeKeyAttrRepeatRule(conditionMap,pageHelper);
|
}
|
|
/**
|
* 使用分类的全部信息来获取关键属性判断规则的内容
|
*
|
* @param classifyFullInfo 主题库分类的全部信息
|
* @return 规则的显示对象
|
*/
|
@Override
|
public CodeKeyAttrRepeatRuleVO getRuleByClassifyFullInfo(CodeClassifyFullInfoBO classifyFullInfo) {
|
VciBaseUtil.alertNotNull(classifyFullInfo,"主题库分类的信息");
|
String keyAttrRuleOid = classifyFullInfo.getCurrentClassifyVO().getCodekeyattrrepeatoid();
|
if(StringUtils.isBlank(keyAttrRuleOid)){
|
//我们根据上级的分类,按照层级倒序排列
|
if(!CollectionUtils.isEmpty(classifyFullInfo.getParentClassifyVOs())){
|
//有上级分类的情况下才去查询
|
List<CodeClassifyVO> sortedClassifyVO = classifyFullInfo.getParentClassifyVOs().stream().sorted(((o1, o2) -> o1.getDataLevel().compareTo(o2.getDataLevel()))).collect(Collectors.toList());
|
for(int i = sortedClassifyVO.size() -1;i>=0;i--){
|
CodeClassifyVO record = sortedClassifyVO.get(i);
|
if(StringUtils.isNotBlank(record.getCodekeyattrrepeatoid())){
|
keyAttrRuleOid = record.getCodekeyattrrepeatoid();
|
break;
|
}
|
}
|
}
|
}
|
if(StringUtils.isNotBlank(keyAttrRuleOid)){
|
return getObjectByOid(keyAttrRuleOid);
|
}
|
//关键属性的规则可以为空,为空的时候就代表不控制,
|
return null;
|
}
|
}
|