/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package com.vci.ubcs.code.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.vci.ubcs.code.constant.MdmBtmTypeConstant;
|
import com.vci.ubcs.code.dto.CodeClstempattrDTO;
|
import com.vci.ubcs.code.entity.CodeClstempattrEntity;
|
import com.vci.ubcs.code.entity.CodeClstemplateEntity;
|
import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum;
|
import com.vci.ubcs.code.mapper.CodeClstempattrMapper;
|
import com.vci.ubcs.code.mapper.CodeClstemplateMapper;
|
import com.vci.ubcs.code.mapper.CodeOsbtmtypeattributeMapper;
|
import com.vci.ubcs.code.service.ICodeClstempattrService;
|
import com.vci.ubcs.code.service.ICodeTempphaseService;
|
import com.vci.ubcs.code.vo.CodeClstempattrVO;
|
import com.vci.ubcs.code.vo.CodeOsbtmtypeattributeVO;
|
import com.vci.ubcs.starter.exception.VciBaseException;
|
import com.vci.ubcs.starter.revision.service.RevisionModelUtil;
|
import com.vci.ubcs.starter.util.PatternUtil;
|
import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum;
|
import com.vci.ubcs.starter.web.pagemodel.*;
|
import com.vci.ubcs.starter.web.util.BeanUtilForVCI;
|
import com.vci.ubcs.starter.web.util.VciBaseUtil;
|
import com.vci.ubcs.starter.web.util.VciDateUtil;
|
import com.vci.ubcs.system.entity.DictBiz;
|
import com.vci.ubcs.system.feign.IDictBizClient;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.cglib.beans.BeanMap;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.*;
|
|
/**
|
* 编码库定义-模板属性 服务实现类
|
*
|
* @author yuxc
|
* @since 2023-04-19
|
*/
|
@Service
|
public class CodeClstempattrServiceImpl extends ServiceImpl<CodeClstempattrMapper, CodeClstempattrEntity> implements ICodeClstempattrService {
|
|
@Resource
|
CodeClstempattrMapper codeClstempattrMapper;
|
// @Resource
|
// ICodeTempphaseService codeTempphaseService;
|
@Resource
|
IDictBizClient iDictBizClient;
|
@Resource
|
CodeClstemplateMapper codeClstemplateMapper;
|
@Resource
|
CodeOsbtmtypeattributeMapper codeOsbtmtypeattributeMapper;
|
@Resource
|
ICodeTempphaseService codeTempphaseService;
|
|
/**
|
* 对象的操作
|
*/
|
@Autowired(required = false)
|
private RevisionModelUtil revisionModelUtil;
|
|
@Override
|
public IPage<CodeClstempattrVO> selectCodeClstempattrPage(IPage<CodeClstempattrVO> page, CodeClstempattrVO CodeClstempattr) {
|
return page.setRecords(baseMapper.selectCodeClstempattrPage(page, CodeClstempattr));
|
}
|
|
|
/**
|
* 使用模板的主键获取模板的属性--批量
|
*
|
* @param templateOidCollection 模板的主键
|
* @return 属性的信息
|
*/
|
@Override
|
public List<CodeClstempattrVO> listCodeClassifyTemplateAttrByTemplateOids(Collection<String> templateOidCollection) {
|
if(CollectionUtils.isEmpty(templateOidCollection)){
|
return new ArrayList<>();
|
}
|
List<CodeClstempattrEntity> attrDOList = new ArrayList<>();
|
VciBaseUtil.switchCollectionForOracleIn(templateOidCollection).stream().forEach(templateOids->{
|
// Map<String,String> conditionMap = new HashMap<>();
|
// conditionMap.put("classifytemplateoid", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(templateOids.toArray(new String[0])) + ")");
|
// PageHelper pageHelper = new PageHelper(-1);
|
// pageHelper.addDefaultAsc("orderNum");
|
List<CodeClstempattrEntity> attrDOS = baseMapper.selectByClassifytemplateoid(VciBaseUtil.toInSql(templateOids.toArray(new String[0])));
|
|
if(!CollectionUtils.isEmpty(attrDOS)){
|
attrDOList.addAll(attrDOS);
|
}
|
});
|
return codeClassifyTemplateAttrDO2VOs(attrDOList);
|
}
|
|
/**
|
* 批量数据对象转换为显示对象
|
* @param codeClassifyTemplateAttrDOs 数据对象列表
|
* @return 显示对象
|
*/
|
@Override
|
public List<CodeClstempattrVO> codeClassifyTemplateAttrDO2VOs(Collection<CodeClstempattrEntity> codeClassifyTemplateAttrDOs){
|
List<CodeClstempattrVO> voList = new ArrayList<CodeClstempattrVO>();
|
if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrDOs)){
|
for(CodeClstempattrEntity s: codeClassifyTemplateAttrDOs){
|
CodeClstempattrVO vo = codeClassifyTemplateAttrDO2VO(s);
|
if(vo != null){
|
voList.add(vo);
|
}
|
}
|
}
|
return voList;
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
* @param codeClassifyTemplateAttrDO 数据对象
|
* @return 显示对象
|
*/
|
@Override
|
public CodeClstempattrVO codeClassifyTemplateAttrDO2VO(CodeClstempattrEntity codeClassifyTemplateAttrDO){
|
CodeClstempattrVO vo = new CodeClstempattrVO();
|
if(codeClassifyTemplateAttrDO != null){
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDO,vo);
|
//如果有lcstatus的类的话
|
vo.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(vo.getAttributedatatype()));
|
}
|
return vo;
|
}
|
|
/**
|
* 查询所有的主题库分类的模板属性
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return 执行结果
|
*/
|
@Override
|
public DataGrid<CodeClstempattrVO> gridCodeClassifyTemplateAttr(Map<String, String> conditionMap, PageHelper pageHelper) {
|
DataGrid<CodeClstempattrVO> dataGrid=new DataGrid<CodeClstempattrVO>();
|
//没有传递参数,就不执行查询逻辑
|
if(conditionMap.size()==0){
|
dataGrid.setData(new ArrayList<>());
|
dataGrid.setTotal(0);
|
return dataGrid;
|
}
|
|
if (pageHelper == null) {
|
pageHelper = new PageHelper(-1);
|
}
|
pageHelper.addDefaultAsc("ordernum");
|
// IPage iPage = new IPage();
|
Query query = new Query();
|
query.setAscs("ordernum");
|
// query.setSize(100);
|
if(pageHelper.getLimit() != -1){
|
query.setSize(pageHelper.getLimit());
|
query.setCurrent(pageHelper.getPage());
|
}
|
// Condition.getPage(query)
|
CodeClstempattrVO codeClstempattrVO = new CodeClstempattrVO();
|
// BeanUtil.toBean(map,codeClstempattrVO);
|
// BeanUtil
|
BeanMap beanMap = BeanMap.create(codeClstempattrVO);
|
|
beanMap.putAll(conditionMap);
|
// Condition.getQueryWrapper(
|
IPage<CodeClstempattrEntity> doList = baseMapper.
|
selectPage(Condition.getPage(query), Condition.getQueryWrapper(codeClstempattrVO));
|
|
|
if (!CollectionUtils.isEmpty(doList.getRecords())) {
|
// CodeClstempattrEntity codeClstempattrEntity = new CodeClstempattrEntity();
|
// BeanUtils.copyProperties(conditionMap, codeClstempattrEntity);
|
// List<CodeClstempattrEntity> codeClstempattrEntities = new ArrayList<>();
|
// BeanUtils.copyProperties(doList,codeClstempattrEntities);
|
// codeClstempattrEntities.addAll(doList);
|
dataGrid.setData(codeClassifyTemplateAttrDO2VOs(doList.getRecords()));
|
dataGrid.setTotal(VciBaseUtil.getInt(String.valueOf(baseMapper.selectCount(Condition.getQueryWrapper(codeClstempattrVO)))));
|
}
|
return dataGrid;
|
}
|
|
/**
|
* 增加主题库分类的模板属性
|
* @param codeClassifyTemplateAttrDTO 主题库分类的模板属性数据传输对象
|
* @return 执行结果
|
*/
|
@Override
|
public CodeClstempattrVO addSave(CodeClstempattrDTO codeClassifyTemplateAttrDTO){
|
VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"需要添加的数据对象");
|
//将DTO转换为DO
|
CodeClstempattrEntity codeClassifyTemplateAttrDO = new CodeClstempattrEntity();
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO);
|
baseMapper.insert(codeClassifyTemplateAttrDO);
|
return codeClassifyTemplateAttrDO2VO(codeClassifyTemplateAttrDO);
|
}
|
|
|
/**
|
* 批量添加
|
* @param codeClassifyTemplateAttrDTOs 数据传输对象
|
* @return 保存后的显示对象
|
*/
|
@Override
|
@Transactional
|
public List<CodeClstempattrVO> batchAddSave(List<CodeClstempattrDTO> codeClassifyTemplateAttrDTOs) {
|
if(CollectionUtils.isEmpty(codeClassifyTemplateAttrDTOs)){
|
return new ArrayList<>();
|
}
|
|
//取所有属性的英文名称,第三个验证需要用到
|
Map<String,CodeClstempattrDTO> attrDTOMap =codeClassifyTemplateAttrDTOs.stream().collect(Collectors.toMap(s->s.getId().toLowerCase(Locale.ROOT), t->t));
|
|
//找属性中文名字重复
|
Map<String, Long> nameCountMap = codeClassifyTemplateAttrDTOs.stream().collect(Collectors.groupingBy(s -> s.getName(), Collectors.counting()));
|
List<String> repeatNameList = nameCountMap.keySet().stream().filter(s -> nameCountMap.get(s) > 1).collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(repeatNameList)){
|
throw new VciBaseException("模板属性中文名称【{0}】重复",new String[]{ repeatNameList.stream().collect(Collectors.joining(","))});
|
}
|
//找属性英文名字重复
|
Map<String, Long> idCountMap = codeClassifyTemplateAttrDTOs.stream().collect(Collectors.groupingBy(s -> s.getId().toLowerCase(Locale.ROOT), Collectors.counting()));
|
List<String> repeatIdList = idCountMap.keySet().stream().filter(s -> idCountMap.get(s) > 1).collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(repeatIdList)){
|
throw new VciBaseException("模板属性英文名称【{0}】重复",new String[]{ repeatIdList.stream().collect(Collectors.joining(","))});
|
}
|
|
//模板oid
|
String CLASSIFYTEMPLATEOID = null;
|
//转换
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDOInsert = new ArrayList<CodeClstempattrEntity>();
|
List<String> prefix = new ArrayList<>();
|
List<String> suffix = new ArrayList<>();
|
List<String> dateFormates = new ArrayList<>();
|
for (CodeClstempattrEntity codeClassifyTemplateAttrDTO:codeClassifyTemplateAttrDTOs){
|
VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"需要添加的数据对象");
|
//将DTO转换为DO
|
CodeClstempattrEntity codeClassifyTemplateAttrDO = new CodeClstempattrEntity();
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO);
|
codeClassifyTemplateAttrDOInsert.add(codeClassifyTemplateAttrDO);
|
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getPrefixvalue())){
|
prefix.add(codeClassifyTemplateAttrDO.getPrefixvalue());
|
}
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getSuffixvalue())){
|
suffix.add(codeClassifyTemplateAttrDO.getSuffixvalue());
|
}
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getCodedateformat())){
|
dateFormates.add(codeClassifyTemplateAttrDO.getCodedateformat());
|
}
|
//判断传过来的枚举注入是否是jsonArr格式
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getEnumstring())&&!checkKVArr(codeClassifyTemplateAttrDO.getEnumstring())){
|
throw new VciBaseException("{0}{1}属性的枚举注入数据格式错误!",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()});
|
}
|
//分类注入
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getClassifyinvokeattr())
|
&& !CodeLevelTypeEnum.MIN.getValue().equalsIgnoreCase(codeClassifyTemplateAttrDO.getClassifyinvokelevel())
|
&& VciBaseUtil.getInt(codeClassifyTemplateAttrDO.getClassifyinvokelevel()) < 0){
|
throw new VciBaseException("{0}{1}属性的是分类注入,但是注入层级不能小于0!",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()});
|
}
|
|
//判断传过来的参照配置是否是json格式
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getReferconfig())&&!checkKVObj(codeClassifyTemplateAttrDO.getReferconfig())){
|
throw new VciBaseException("{0}{1}属性的参照配置数据格式错误!",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()});
|
}
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getCodedateformat()) && !checkDateFormat(codeClassifyTemplateAttrDO.getCodedateformat())){
|
throw new VciBaseException("{0}{1}属性的时间格式不符合要求",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()});
|
}
|
//如果是组合规则,里面使用的属性不能缺失,也都得显示
|
String componentrule = codeClassifyTemplateAttrDTO.getComponentrule();
|
boolean isContainsDynamicParameter = PatternUtil.isContainsDynamicParameter(componentrule);
|
if(isContainsDynamicParameter){
|
List<String> userdAttrList = PatternUtil.getKeyListByContent(componentrule);//包含的所有${xxx}中的xxx
|
if(!CollectionUtils.isEmpty(userdAttrList)){
|
String unExistAttr = userdAttrList.stream().filter(s -> !attrDTOMap.containsKey(s.toLowerCase(Locale.ROOT))).collect(Collectors.joining(","));
|
if(StringUtils.isNotBlank(unExistAttr)){
|
throw new VciBaseException("{0}属性是组合规则,但是规则里包含的属性[{1}]在当前模板中不存在!",new String[]{codeClassifyTemplateAttrDO.getName(), unExistAttr});
|
}
|
//要看看表单是否显示
|
String unFormDisplayAttr = userdAttrList.stream().filter(s -> !VciBaseUtil.getBoolean(attrDTOMap.getOrDefault(s.toLowerCase(Locale.ROOT),
|
new CodeClstempattrDTO()).getFormdisplayflag())).collect(Collectors.joining(","));
|
if(StringUtils.isNotBlank(unFormDisplayAttr)){
|
throw new VciBaseException("{0}属性是组合规则,但是规则里包含的属性[{1}]在当前模板中没有设置 表单显示 ",new String[]{codeClassifyTemplateAttrDO.getName(),unFormDisplayAttr});
|
}
|
}
|
}
|
|
if(CLASSIFYTEMPLATEOID==null){
|
CLASSIFYTEMPLATEOID = codeClassifyTemplateAttrDTO.getClassifytemplateoid();
|
}
|
|
}
|
|
//执行数据保存操作
|
// WebUtil.setPersistence(false);//不执行保存
|
|
//先都删了
|
// VciQueryWrapperForDO deleteAttrWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class);
|
// deleteAttrWrapper.addQueryMap("CLASSIFYTEMPLATEOID",CLASSIFYTEMPLATEOID);
|
Map<String,Object> condition = new HashMap<>();
|
condition.put("CLASSIFYTEMPLATEOID",CLASSIFYTEMPLATEOID);
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDODelete = baseMapper.selectByMap(condition);
|
|
//oids
|
List<String> oids = new ArrayList<String>();
|
for (CodeClstempattrEntity codeClassifyTemplateAttrDO:codeClassifyTemplateAttrDODelete){
|
oids.add(codeClassifyTemplateAttrDO.getOid());
|
}
|
// BatchCBO batchCBOTemplateDelete = new BatchCBO();
|
if(!CollectionUtils.isEmpty(oids)){
|
baseMapper.deleteBatchIds(oids);
|
}
|
|
//再新增
|
if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrDOInsert)){
|
this.saveBatch(codeClassifyTemplateAttrDOInsert);
|
}
|
|
//调用阶段
|
if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrDOInsert)){
|
codeTempphaseService.codeTemplateAttrModifyTrigger(codeClassifyTemplateAttrDOInsert);
|
|
}
|
|
|
// SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo();
|
//处理可输可选的字符
|
if(!CollectionUtils.isEmpty(prefix)){
|
for (String s : prefix) {
|
DictBiz dictBiz = new DictBiz();
|
dictBiz.setCode(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR);
|
dictBiz.setDictKey(s);
|
dictBiz.setDictValue("prefix");
|
iDictBizClient.getCheck(dictBiz) ;
|
}
|
// .saveBySameNamespaceAndFlag(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR,"prefix",prefix,sessionInfo);
|
}
|
if(!CollectionUtils.isEmpty(suffix)){
|
for (String s : suffix) {
|
DictBiz dictBiz = new DictBiz();
|
dictBiz.setCode(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR);
|
dictBiz.setDictKey(s);
|
dictBiz.setDictValue("suffix");
|
iDictBizClient.getCheck(dictBiz) ;
|
}
|
// charService.saveBySameNamespaceAndFlag(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR,"suffix",suffix,sessionInfo);
|
}
|
if(!CollectionUtils.isEmpty(dateFormates)){
|
for (String s : dateFormates) {
|
DictBiz dictBiz = new DictBiz();
|
dictBiz.setCode(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR);
|
dictBiz.setDictKey(s);
|
dictBiz.setDictValue("dateFormates");
|
iDictBizClient.getCheck(dictBiz) ;
|
}
|
// charService.saveBySameNamespaceAndFlag(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR,"dateFormates",dateFormates,sessionInfo);
|
}
|
|
// WebUtil.setPersistence(true);//执行保存
|
// boService.persistenceBatch(batchCBOTemplateDelete);//一起执行保存
|
return codeClassifyTemplateAttrDO2VOs(codeClassifyTemplateAttrDOInsert);
|
}
|
|
public boolean checkKVArr(String kvString){
|
boolean isKV = true;
|
try {
|
JSONObject.parseArray(kvString, KeyValue.class);
|
}catch (Exception e){
|
isKV=false;
|
}
|
return isKV;
|
}
|
public boolean checkKVObj(String kvString){
|
boolean isKV = true;
|
try {
|
JSONObject.parseObject(kvString, UIFormReferVO.class);
|
}catch (Exception e){
|
isKV=false;
|
}
|
return isKV;
|
}
|
|
/**
|
* 校验时间格式
|
* @param dateFormat 时间格式
|
* @return true表示校验通过
|
*/
|
public boolean checkDateFormat(String dateFormat){
|
try{
|
VciDateUtil.date2Str(new Date(),dateFormat);
|
return true;
|
}catch (Throwable e){
|
return false;
|
}
|
}
|
|
|
/**
|
* 修改主题库分类的模板属性
|
* @param codeClassifyTemplateAttrDTO 主题库分类的模板属性数据传输对象
|
* @return 执行结果
|
* @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
|
*/
|
@Override
|
public R editSave(CodeClstempattrDTO codeClassifyTemplateAttrDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"数据对象",codeClassifyTemplateAttrDTO.getOid(),"主题库分类的模板属性主键");
|
|
//判断传过来的枚举注入是否是jsonArr格式
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDTO.getEnumstring())&&!checkKVArr(codeClassifyTemplateAttrDTO.getEnumstring())){
|
throw new VciBaseException("枚举注入数据格式错误!");
|
}
|
|
//判断传过来的参照配置是否是json格式
|
if(StringUtils.isNotBlank(codeClassifyTemplateAttrDTO.getReferbtmid())&&!checkKVObj(codeClassifyTemplateAttrDTO.getReferbtmid())){
|
throw new VciBaseException("枚举注入数据格式错误!");
|
}
|
|
|
//检查ts
|
CodeClstempattrEntity codeClassifyTemplateAttrDOCopyFromDTO = new CodeClstempattrEntity();
|
// BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDOCopyFromDTO);
|
// boolean tsBoolean = boService.checkTs(codeClassifyTemplateAttrDOCopyFromDTO);
|
|
//检查ts
|
// Map<String,Object> condition = new HashMap<>(2);
|
// condition.put("oid",codeClassifyTemplateAttrDTO.getOid());
|
// condition.put("ts",codeClassifyTemplateAttrDTO.getTs());
|
CodeClstempattrEntity detail = baseMapper.selectById(codeClassifyTemplateAttrDTO.getOid());
|
if(!detail.getTs().toString().equals(codeClassifyTemplateAttrDTO.getTs().toString())){//不是最新的不让改
|
return R.fail("当前数据不是最新,请刷新后再修改!");
|
}
|
|
//将DTO转换为DO
|
CodeClstempattrEntity codeClassifyTemplateAttrDO = baseMapper.selectById(codeClassifyTemplateAttrDTO.getOid());
|
revisionModelUtil.copyFromDTOIgnore(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO);
|
baseMapper.updateById(codeClassifyTemplateAttrDO);
|
return R.data(codeClassifyTemplateAttrDO2VO(codeClassifyTemplateAttrDO));
|
}
|
|
/**
|
* 删除主题库分类的模板属性
|
* @param codeClassifyTemplateAttrDTO 主题库分类的模板属性数据传输对象,oid和ts需要传输
|
* @return 删除结果反馈::success:成功,fail:失败
|
* @throws VciBaseException 参数为空,被引用时抛出异常
|
*/
|
@Override
|
public R deleteCodeClassifyTemplateAttr(CodeClstempattrDTO codeClassifyTemplateAttrDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"主题库分类的模板属性数据对象",codeClassifyTemplateAttrDTO.getOid(),"主题库分类的模板属性的主键");
|
CodeClstempattrEntity codeClassifyTemplateAttrDO = baseMapper.selectById(codeClassifyTemplateAttrDTO.getOid());
|
R baseResult = checkIsCanDeleteForDO(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO);
|
if(baseResult.isSuccess()) {
|
}else{
|
return baseResult;
|
}
|
//执行删除操作
|
int deleteNum = baseMapper.deleteById(codeClassifyTemplateAttrDO.getOid());
|
return deleteNum>0?R.success(DELETE_SUCCESS):R.fail(DELETE_FAIL);
|
}
|
|
/**
|
* 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除
|
* @param codeClassifyTemplateAttrDTO 数据传输对象
|
* @param codeClassifyTemplateAttrDO 数据库中的数据对象
|
* @return success为true为可以删除,false表示有数据引用,obj为true表示有下级
|
*/
|
private R checkIsCanDeleteForDO(CodeClstempattrDTO codeClassifyTemplateAttrDTO, CodeClstempattrEntity codeClassifyTemplateAttrDO) {
|
// boService.checkTs(codeClassifyTemplateAttrDO);
|
// Map<String,Object> condition = new HashMap<>(2);
|
// condition.put("oid",codeClassifyTemplateAttrDTO.getOid());
|
// condition.put("ts",codeClassifyTemplateAttrDTO.getTs());
|
CodeClstempattrEntity detail = baseMapper.selectById(codeClassifyTemplateAttrDTO.getOid());
|
// .selectOne(Condition.getQueryWrapper(condition,CodeClstempattrEntity.class));
|
|
if(!detail.getTs().toString().equals(codeClassifyTemplateAttrDTO.getTs().toString())){//不是最新的不让改
|
return R.fail("当前数据不是最新,请刷新后再修改!");
|
}
|
if(!checkIsLinked(codeClassifyTemplateAttrDO.getOid())) {
|
return R.success("可以删除!");
|
}else{
|
return R.fail(DATA_LINKED_NOT_DELETE);
|
}
|
}
|
|
/**
|
* 校验是否被引用
|
* @param oid 主键
|
* @throws VciBaseException 被引用的时候会抛出异常
|
*/
|
private boolean checkIsLinked(String oid) throws VciBaseException{
|
//TODO 添加需要校验引用的地方
|
return false;
|
}
|
|
/**
|
* 主键获取主题库分类的模板属性
|
* @param oid 主键
|
* @return 主题库分类的模板属性显示对象
|
* @throws VciBaseException 参数为空,数据不存在时会抛出异常
|
*/
|
@Override
|
public CodeClstempattrVO getObjectByOid(String oid) throws VciBaseException{
|
return codeClassifyTemplateAttrDO2VO(selectByOid(oid));
|
}
|
/**
|
* 主键查询数据对象
|
* @param oid 主键
|
* @return 数据对象
|
* @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常
|
*/
|
private CodeClstempattrEntity selectByOid(String oid) throws VciBaseException{
|
VciBaseUtil.alertNotNull(oid,"主键");
|
CodeClstempattrEntity codeClassifyTemplateAttrDO = baseMapper.selectById(oid.trim());
|
if(codeClassifyTemplateAttrDO == null || StringUtils.isBlank(codeClassifyTemplateAttrDO.getOid())){
|
throw new VciBaseException(DATA_OID_NOT_EXIST);
|
}
|
return codeClassifyTemplateAttrDO;
|
}
|
|
/**
|
* 主键批量获取主题库分类的模板属性
|
* @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个
|
* @return 主题库分类的模板属性显示对象
|
* @throws VciBaseException 查询出现异常时会抛出
|
*/
|
@Override
|
public Collection<CodeClstempattrVO> listCodeClassifyTemplateAttrByOids(Collection<String> oidCollections) {
|
VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合");
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDOList = listCodeClassifyTemplateAttrDOByOidCollections(oidCollections);
|
return codeClassifyTemplateAttrDO2VOs(codeClassifyTemplateAttrDOList);
|
}
|
|
/**
|
* 使用主键集合查询数据对象
|
* @param oidCollections 主键的集合
|
* @return 数据对象列表
|
*/
|
private List<CodeClstempattrEntity> listCodeClassifyTemplateAttrDOByOidCollections(Collection<String> oidCollections){
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDOList = new ArrayList<CodeClstempattrEntity>();
|
if(!CollectionUtils.isEmpty(oidCollections)){
|
Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections);
|
for(Collection<String> oids: oidCollectionsList){
|
List<CodeClstempattrEntity> tempDOList = baseMapper.selectBatchIds(oids);
|
if(!CollectionUtils.isEmpty(tempDOList)){
|
codeClassifyTemplateAttrDOList.addAll(tempDOList);
|
}
|
}
|
}
|
return codeClassifyTemplateAttrDOList;
|
}
|
|
/**
|
* 参照主题库分类的模板属性列表
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return 主题库分类的模板属性显示对象列表,生效的内容
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public DataGrid<CodeClstempattrVO> refDataGridCodeClassifyTemplateAttr(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{
|
if(conditionMap == null){
|
conditionMap = new HashMap<String, String>();
|
}
|
return gridCodeClassifyTemplateAttr(conditionMap,pageHelper);
|
}
|
|
/**
|
* 查询这个模板,业务类型下的所有未选择的属性
|
* @param baseQueryObject
|
* @return
|
*/
|
@Override
|
public DataGrid<CodeOsbtmtypeattributeVO> codeClassifyTemplateAttrByBtm(BaseQueryObject baseQueryObject){
|
if(baseQueryObject.getConditionMap() == null){
|
baseQueryObject.setConditionMap(new HashMap<>());
|
}
|
DataGrid<CodeOsbtmtypeattributeVO> dataGrid=new DataGrid<CodeOsbtmtypeattributeVO>();
|
//模板oid
|
String templateAttrOid = baseQueryObject.getConditionMap().get("oid");
|
String name = baseQueryObject.getConditionMap().getOrDefault("name","");
|
String id = baseQueryObject.getConditionMap().getOrDefault("id","");
|
|
//没有oid不执行逻辑
|
if(StringUtils.isBlank(templateAttrOid)){
|
dataGrid.setData(new ArrayList<>());
|
dataGrid.setTotal(0);
|
return dataGrid;
|
}
|
|
//查询模板对象
|
CodeClstemplateEntity codeClassifyTemplateDO = codeClstemplateMapper.selectById(templateAttrOid);
|
|
//这个业务类型下的所有属性
|
List<CodeOsbtmtypeattributeVO> boAttrs = (List<CodeOsbtmtypeattributeVO>) codeOsbtmtypeattributeMapper.selectById(codeClassifyTemplateDO.getBtmTypeId());// this.btmService.listAttributeByBtmId(codeClassifyTemplateDO.getBtmTypeId());
|
// codeOsbtmtypeattributeMapper.selectById(codeClassifyTemplateDO.getBtmTypeId());
|
// BeanUtils.copyProperties(codeOsbtmtypeattributeMapper.selectById(codeClassifyTemplateDO.getBtmTypeId()),boAttrs);
|
//把默认的属性也添加到boAttrs
|
if(boAttrs == null){
|
boAttrs = new ArrayList<>();
|
}
|
if(!false){
|
// List<CodeOsbtmtypeattributeVO> finalBoAttrs = boAttrs;
|
// attributeService.getDefaultAttributeVOs().stream().forEach(attr-> {
|
// CodeOsbtmtypeattributeVO attributeVO = new CodeOsbtmtypeattributeVO();
|
// BeanUtil.convert(attr, attributeVO);
|
// if ("id".equalsIgnoreCase(attributeVO.getId())) {
|
// attributeVO.setName("企业编码");
|
// }
|
// if ("name".equalsIgnoreCase(attributeVO.getId())) {
|
// attributeVO.setName("集团码");
|
// }
|
// attributeVO.setAttrDataType(attr.getAttributeDataType());
|
// attributeVO.setAttributeLength(attr.getAttrLength());
|
// attributeVO.setReferBtmTypeId(attr.getBtmTypeId());
|
// attributeVO.setReferBtmTypeName(attr.getBtmTypeName());
|
// finalBoAttrs.add(attributeVO);
|
// });
|
// boAttrs = finalBoAttrs;
|
Object o = null;
|
}
|
|
//这个模板下已经有的属性
|
// VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class);
|
// queryWrapper.addQueryMap("CLASSIFYTEMPLATEOID",templateAttrOid);
|
Map<String,Object> condition = new HashMap<>(1);
|
condition.put("CLASSIFYTEMPLATEOID",templateAttrOid);
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDOList = codeClstempattrMapper.selectByMap(condition);
|
|
List<String> btmOids = new ArrayList<String>();
|
for (CodeClstempattrEntity codeClassifyTemplateAttrDO:codeClassifyTemplateAttrDOList){
|
btmOids.add(codeClassifyTemplateAttrDO.getId());
|
}
|
|
//过滤掉已经存在的属性
|
List<CodeOsbtmtypeattributeVO> boAttrss = new ArrayList<CodeOsbtmtypeattributeVO>();
|
|
for (CodeOsbtmtypeattributeVO osBtmTypeAttributeVO:boAttrs){
|
if(!btmOids.contains(osBtmTypeAttributeVO.getId())){
|
//看看是不是有模糊查询
|
boolean inSearch = true;
|
if(StringUtils.isNotBlank(name) && !osBtmTypeAttributeVO.getName().contains(name.replace("*",""))){
|
inSearch = false;
|
}
|
if(StringUtils.isNotBlank(id) && !osBtmTypeAttributeVO.getId().contains(id.replace("*",""))){
|
inSearch = false;
|
}
|
if(inSearch) {
|
boAttrss.add(osBtmTypeAttributeVO);
|
}
|
}
|
}
|
dataGrid.setData(boAttrss);
|
dataGrid.setTotal(boAttrss.size());
|
return dataGrid;
|
}
|
|
|
|
/**
|
* 查询这个模板,业务类型下已选择的属性
|
* @param baseQueryObject
|
* @return
|
*/
|
@Override
|
public DataGrid<CodeOsbtmtypeattributeVO> codeClassifyTemplateAttrByBtmHave(BaseQueryObject baseQueryObject){
|
DataGrid<CodeOsbtmtypeattributeVO> dataGrid=new DataGrid<CodeOsbtmtypeattributeVO>();
|
//模板oid
|
String templateAttrOid = baseQueryObject.getConditionMap().get("oid");
|
|
//没有oid不执行逻辑
|
if(StringUtils.isBlank(templateAttrOid)){
|
dataGrid.setData(new ArrayList<>());
|
dataGrid.setTotal(0);
|
return dataGrid;
|
}
|
|
//查询模板对象
|
CodeClstemplateEntity codeClassifyTemplateDO = codeClstemplateMapper.selectById(templateAttrOid);
|
|
//这个业务类型下的所有属性
|
List<CodeOsbtmtypeattributeVO> boAttrs = (List<CodeOsbtmtypeattributeVO>) codeOsbtmtypeattributeMapper.selectById(codeClassifyTemplateDO.getBtmTypeId());//this.btmService.listAttributeByBtmIdHasDefault(codeClassifyTemplateDO.getBtmTypeId());
|
// codeOsbtmtypeattributeMapper.selectById(codeClassifyTemplateDO.getBtmTypeId());
|
// BeanUtils.copyProperties(codeOsbtmtypeattributeMapper.selectById(codeClassifyTemplateDO.getBtmTypeId()),boAttrs);
|
//这个模板下已经有的属性
|
//把默认的属性也添加到boAttrs
|
if(boAttrs == null){
|
boAttrs = new ArrayList<>();
|
}
|
// VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class);
|
// queryWrapper.addQueryMap("CLASSIFYTEMPLATEOID",templateAttrOid);
|
|
// Map<String,Object> condition = new HashMap<>(1);
|
// condition.put("CLASSIFYTEMPLATEOID",templateAttrOid);
|
|
QueryWrapper<CodeClstempattrEntity> wrapper=new QueryWrapper<>();
|
wrapper.eq("CLASSIFYTEMPLATEOID",templateAttrOid);
|
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDOList = codeClstempattrMapper.selectList(wrapper);
|
List<String> btmOids = new ArrayList<String>();
|
for (CodeClstempattrEntity codeClassifyTemplateAttrDO:codeClassifyTemplateAttrDOList){
|
btmOids.add(codeClassifyTemplateAttrDO.getId());
|
}
|
|
//过滤掉除了自身的别的属性
|
List<CodeOsbtmtypeattributeVO> boAttrss = new ArrayList<CodeOsbtmtypeattributeVO>();
|
|
for (CodeOsbtmtypeattributeVO osBtmTypeAttributeVO:boAttrs){
|
if(btmOids.contains(osBtmTypeAttributeVO.getId())){
|
boAttrss.add(osBtmTypeAttributeVO);
|
}
|
}
|
dataGrid.setData(boAttrss);
|
dataGrid.setTotal(boAttrss.size());
|
return dataGrid;
|
}
|
|
|
/**
|
* 同步到其他模板
|
* @param codeClassifyTemplateAttrDTO oid
|
* @return
|
*/
|
@Override
|
public R copyto(CodeClstempattrDTO codeClassifyTemplateAttrDTO) throws VciBaseException{
|
|
String templateAttrOid = codeClassifyTemplateAttrDTO.getOid();
|
|
//查询出来要复制的对象
|
CodeClstempattrEntity codeClassifyTemplateAttrDO = selectByOid(templateAttrOid);
|
String id = codeClassifyTemplateAttrDO.getId();//英文名称
|
String classfyTemplateOid = codeClassifyTemplateAttrDO.getClassifytemplateoid();
|
|
//查询其他id=id的模板属性
|
// VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class);
|
// queryWrapper.addQueryMap("id",id);
|
// Map<String,Object> condition = new HashMap<>(1);
|
// condition.put("id",id);
|
QueryWrapper<CodeClstempattrEntity> wrapper=new QueryWrapper<>();
|
wrapper.eq("id",id);
|
//所有id=id的模板属性
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDOList =codeClstempattrMapper.selectList(wrapper);
|
|
//要删除的模板属性的oids
|
List<String> deleteOids = new ArrayList<String>();
|
//要修改的模板属性对象
|
List<CodeClstempattrEntity> codeClassifyTemplateAttrDOListInsert = new ArrayList<CodeClstempattrEntity>();
|
for (CodeClstempattrEntity codeClassifyTemplateAttrDOi:codeClassifyTemplateAttrDOList){
|
String oid = codeClassifyTemplateAttrDOi.getOid();
|
String templateOldOid = codeClassifyTemplateAttrDOi.getClassifytemplateoid();
|
|
CodeClstempattrEntity codeClassifyTemplateAttrDOInsert = new CodeClstempattrEntity();
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDO,codeClassifyTemplateAttrDOInsert);
|
codeClassifyTemplateAttrDOInsert.setOid(oid);
|
codeClassifyTemplateAttrDOInsert.setClassifytemplateoid(templateOldOid);
|
codeClassifyTemplateAttrDOListInsert.add(codeClassifyTemplateAttrDOInsert);
|
|
deleteOids.add(codeClassifyTemplateAttrDOi.getOid());
|
}
|
|
// WebUtil.setPersistence(false);//不执行保存
|
|
//删除
|
// BatchCBO batchCBOTemplateAttrDelete = codeClassifyTemplateAttrDOissifyTemplateAttrMapper.batchDeleteByOids(deleteOids);
|
codeClstempattrMapper.deleteBatchIds(deleteOids);
|
//再新增
|
// BatchCBO batchCBOTemplateAttrInsert = codeClassifyTemplateAttrMapper.batchInsert(codeClassifyTemplateAttrDOListInsert);
|
// batchCBOTemplateAttrDelete.copyFromOther(batchCBOTemplateAttrInsert);
|
this.saveBatch(codeClassifyTemplateAttrDOListInsert);
|
|
// WebUtil.setPersistence(true);//执行保存
|
// boService.persistenceBatch(batchCBOTemplateAttrDelete);//一起执行保存
|
|
return R.success("操作成功!");
|
}
|
}
|