| | |
| | | */ |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.alibaba.cloud.commons.lang.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vci.ubcs.code.entity.CodeClstempattrEntity; |
| | | import com.vci.ubcs.code.entity.CodePhaseattrEntity; |
| | | import com.vci.ubcs.code.entity.CodeTempphaseEntity; |
| | | import com.vci.ubcs.code.mapper.CodePhaseattrMapper; |
| | | import com.vci.ubcs.code.mapper.CodeTempphaseMapper; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.vci.ubcs.code.service.ICodeTempphaseService; |
| | | import com.vci.ubcs.code.vo.CodeTempphaseVO; |
| | | import com.vci.ubcs.code.constant.MdmBtmTypeConstant; |
| | | import com.vci.ubcs.code.dto.CodeTemplatePhaseDTO; |
| | | import com.vci.ubcs.code.entity.*; |
| | | import com.vci.ubcs.code.mapper.CodePhaseAttrMapper; |
| | | import com.vci.ubcs.code.mapper.CodeTemplatePhaseMapper; |
| | | import com.vci.ubcs.code.mapper.CommonsMapper; |
| | | import com.vci.ubcs.code.service.ICodeClassifyTemplateAttrService; |
| | | import com.vci.ubcs.code.service.ICodePhaseAttrService; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeClassifyTemplateAttrVO; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeTemplatePhaseVO; |
| | | import com.vci.ubcs.code.wrapper.CodeTemplatePhaseWapper; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | import com.vci.ubcs.starter.revision.service.RevisionModelUtil; |
| | | import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; |
| | | import com.vci.ubcs.starter.util.MybatisParameterUtil; |
| | | import com.vci.ubcs.starter.web.pagemodel.PageHelper; |
| | | import com.vci.ubcs.starter.web.util.BeanUtil; |
| | | import com.vci.ubcs.starter.web.util.BeanUtilForVCI; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | 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 java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.*; |
| | | |
| | | /** |
| | | * 编码库定义-模板阶段 服务实现类 |
| | |
| | | * @since 2023-04-20 |
| | | */ |
| | | @Service |
| | | public class CodeTempphaseServiceImpl extends ServiceImpl<CodeTempphaseMapper, CodeTempphaseEntity> implements ICodeTempphaseService { |
| | | |
| | | public class CodeTempphaseServiceImpl extends ServiceImpl<CodeTemplatePhaseMapper, CodeTemplatePhase> implements ICodeTempphaseService { |
| | | |
| | | @Autowired(required = false) |
| | | private CodePhaseattrMapper codePhaseattrMapper; |
| | | @Autowired(required = false) |
| | | private CodePhaseattrServiceImpl codePhaseattrServiceImpl; |
| | | private CodePhaseAttrMapper codePhaseAttrMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private CodeTemplatePhaseMapper codeTemplatePhaseMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private CommonsMapper commonsMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private ICodePhaseAttrService codePhaseattrService; |
| | | |
| | | /** |
| | | * 对象的操作 |
| | | */ |
| | | @Autowired(required = false) |
| | | private RevisionModelUtil revisionModelUtil; |
| | | |
| | | /** |
| | | * 模板属性的服务 |
| | | */ |
| | | @Autowired |
| | | private ICodeClassifyTemplateAttrService tempAttrService; |
| | | |
| | | /** |
| | | * 查询所有的模板阶段 |
| | | * @param conditionMap 查询条件 |
| | | * @param pageHelper 分页和排序 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public IPage<CodeTempphaseVO> selectCodeTempphasePage(IPage<CodeTempphaseVO> page, CodeTempphaseVO CodeTempphase) { |
| | | return page.setRecords(baseMapper.selectCodeTempphasePage(page, CodeTempphase)); |
| | | public IPage<CodeTemplatePhaseVO> gridCodeTemplatePhase(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException { |
| | | Query query = new Query(); |
| | | if (pageHelper == null) { |
| | | query.setSize(-1); |
| | | }else { |
| | | query.setSize(pageHelper.getLimit()); |
| | | query.setCurrent(pageHelper.getPage()); |
| | | } |
| | | query.setDescs("CREATETIME"); |
| | | CodeTemplatePhase codeTemplatePhase = new CodeTemplatePhase(); |
| | | BeanMap beanMap = BeanMap.create(codeTemplatePhase); |
| | | beanMap.putAll(conditionMap); |
| | | IPage<CodeTemplatePhase> doList = codeTemplatePhaseMapper.selectPage(Condition.getPage(query), Condition.getQueryWrapper(codeTemplatePhase)); |
| | | IPage<CodeTemplatePhaseVO> voList = new Page<>(); |
| | | if (!CollectionUtils.isEmpty(doList.getRecords())) { |
| | | CodeTemplatePhaseWapper.build().pageVO(doList); |
| | | } |
| | | return voList; |
| | | } |
| | | |
| | | /** |
| | | * 批量数据对象转换为显示对象 |
| | | * @param codeTemplatePhaseEntityDOS 数据对象列表 |
| | | * @return 显示对象 |
| | | * @throws VciBaseException 参数为空或者不存在的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public List<CodeTemplatePhaseVO> codeTemplatePhaseDO2VOs(Collection<CodeTemplatePhase> codeTemplatePhaseEntityDOS) throws VciBaseException{ |
| | | List<CodeTemplatePhaseVO> voList = new ArrayList<CodeTemplatePhaseVO>(); |
| | | if(!CollectionUtils.isEmpty(codeTemplatePhaseEntityDOS)){ |
| | | for(CodeTemplatePhase s: codeTemplatePhaseEntityDOS){ |
| | | CodeTemplatePhaseVO vo = codeTemplatePhaseDO2VO(s); |
| | | if(vo != null){ |
| | | voList.add(vo); |
| | | } |
| | | } |
| | | } |
| | | return voList; |
| | | } |
| | | |
| | | /** |
| | | * 数据对象转换为显示对象 |
| | | * @param codeTemplatePhaseEntityDO 数据对象 |
| | | * @return 显示对象 |
| | | * @throws VciBaseException 拷贝属性出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodeTemplatePhaseVO codeTemplatePhaseDO2VO(CodeTemplatePhase codeTemplatePhaseEntityDO) throws VciBaseException{ |
| | | CodeTemplatePhaseVO vo = new CodeTemplatePhaseVO(); |
| | | if(codeTemplatePhaseEntityDO != null){ |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeTemplatePhaseEntityDO,vo); |
| | | //如果有lcstatus的类的话 |
| | | } |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | |
| | | int updateCount = 0; |
| | | Map<String,Object> condition = new HashMap<>(1); |
| | | condition.put("codeclassifytemplateoid",templateOid); |
| | | List<CodeTempphaseEntity> codeTempphaseEntities = baseMapper.selectByMap(condition); |
| | | List<CodeTemplatePhase> codeTempphaseEntities = baseMapper.selectByMap(condition); |
| | | if(!CollectionUtils.isEmpty(codeTempphaseEntities)) { |
| | | updateCount += baseMapper.deleteBatchIds(codeTempphaseEntities.stream().map(CodeTempphaseEntity::getOid).collect(Collectors.toList())); |
| | | // batchCBO.copyFromOther(codeTemplatePhaseMapper.batchDeleteByOids(templatePhaseDOS.stream().map(CodeTemplatePhaseDO::getOid).collect(Collectors.toList()))); |
| | | // conditionMap.put("codePhaseOid", QueryOptionConstant.IN + "(select oid from " + getPhaseTable() + " where codeClassifyTemplateOid='" + classifyTemplateOid + "')"); |
| | | List<CodePhaseattrEntity> phaseAttrDOS = codePhaseattrMapper.selectByPhasea(templateOid); |
| | | updateCount += baseMapper.deleteBatchIds(codeTempphaseEntities.stream().map(CodeTemplatePhase::getOid).collect(Collectors.toList())); |
| | | //batchCBO.copyFromOther(codeTemplatePhaseMapper.batchDeleteByOids(templatePhaseDOS.stream().map(CodeTemplatePhaseDO::getOid).collect(Collectors.toList()))); |
| | | //conditionMap.put("codePhaseOid", QueryOptionConstant.IN + "(select oid from " + getPhaseTable() + " where codeClassifyTemplateOid='" + classifyTemplateOid + "')"); |
| | | List<CodePhaseAttr> phaseAttrDOS = codePhaseAttrMapper.selectByPhasea(templateOid); |
| | | if(!CollectionUtils.isEmpty(phaseAttrDOS)){ |
| | | updateCount += codePhaseattrMapper.deleteBatchIds(phaseAttrDOS.stream().map(CodePhaseattrEntity::getOid).collect(Collectors.toList())); |
| | | updateCount += codePhaseAttrMapper.deleteBatchIds(phaseAttrDOS.stream().map(CodePhaseAttr::getOid).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | return updateCount; |
| | | } |
| | | |
| | | /** |
| | | * 模板修改触发功能 |
| | | * @param attrDOList 属性的数据对象 |
| | | * @return 受影响的数据 |
| | | */ |
| | | @Override |
| | | public List<CodeClstempattrEntity> codeTemplateAttrModifyTrigger(List<CodeClstempattrEntity> attrDOList){ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public List<CodeClassifyTemplateAttr> codeTemplateAttrModifyTrigger(List<CodeClassifyTemplateAttr> attrDOList){ |
| | | //属性修改的时候,需要同步修改对应属性的名称 |
| | | // BatchCBO batchCBO = new BatchCBO(); |
| | | List<CodePhaseattrEntity> phaseAttrDOS =codePhaseattrMapper.listLinkAttrDOByTemplateAttrDOS(VciBaseUtil.toInSql(attrDOList.stream() |
| | | .map(CodeClstempattrEntity::getId).collect(Collectors.toList()).toArray(new String[0])),attrDOList.get(0).getClassifytemplateoid()); |
| | | //BatchCBO batchCBO = new BatchCBO(); |
| | | List<CodePhaseAttr> phaseAttrDOS =codePhaseAttrMapper.listLinkAttrDOByTemplateAttrDOS(VciBaseUtil.toInSql(attrDOList.stream() |
| | | .map(CodeClassifyTemplateAttr::getId).collect(Collectors.toList()).toArray(new String[0])),attrDOList.get(0).getClassifyTemplateOid()); |
| | | boolean resSavePhaseAttr = false; |
| | | if(!CollectionUtils.isEmpty(phaseAttrDOS)){ |
| | | //说明有属性,我们去替换一下 |
| | | Map<String, CodeClstempattrEntity> attrDOMap = attrDOList.stream().collect(Collectors.toMap(s -> s.getId(), t -> t)); |
| | | Map<String, CodeClassifyTemplateAttr> attrDOMap = attrDOList.stream().collect(Collectors.toMap(s -> s.getId(), t -> t)); |
| | | phaseAttrDOS.stream().forEach(phaseAttrDO->{ |
| | | if(attrDOMap.containsKey(phaseAttrDO.getId())){ |
| | | CodeClstempattrEntity attrDO = attrDOMap.get(phaseAttrDO.getId()); |
| | | CodeClassifyTemplateAttr attrDO = attrDOMap.get(phaseAttrDO.getId()); |
| | | phaseAttrDO.setId(attrDO.getId()); |
| | | phaseAttrDO.setName(attrDO.getName()); |
| | | phaseAttrDO.setAttributegroup(attrDO.getAttributegroup()); |
| | | phaseAttrDO.setAttributeGroup(attrDO.getAttributeGroup()); |
| | | } |
| | | }); |
| | | // codePhaseattrMapper. |
| | | codePhaseattrServiceImpl.saveBatch(phaseAttrDOS); |
| | | // BatchCBO updateCBO = |
| | | // codePhaseAttrMapper.batchUpdate(phaseAttrDOS); |
| | | // batchCBO.copyFromOther(updateCBO); |
| | | resSavePhaseAttr = codePhaseattrService.saveBatch(phaseAttrDOS); |
| | | //BatchCBO updateCBO = |
| | | //codePhaseAttrMapper.batchUpdate(phaseAttrDOS); |
| | | //batchCBO.copyFromOther(updateCBO); |
| | | } |
| | | return attrDOList; |
| | | return resSavePhaseAttr ? attrDOList:null; |
| | | } |
| | | |
| | | /** |
| | | * 增加模板阶段 |
| | | * @param codeTemplatePhaseDTO 模板阶段数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public CodeTemplatePhaseVO addSave(CodeTemplatePhaseDTO codeTemplatePhaseDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeTemplatePhaseDTO,"需要添加的数据对象",codeTemplatePhaseDTO.getAttributes(),"包含的属性"); |
| | | //将DTO转换为DO |
| | | CodeTemplatePhase codeTemplatePhaseDO = new CodeTemplatePhase(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeTemplatePhaseDTO, codeTemplatePhaseDO); |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeTemplatePhaseDO,MdmBtmTypeConstant.CODE_TEMPLATE_PHASE); |
| | | //WebUtil.setPersistence(false); |
| | | boolean resInsertTempPhase = codeTemplatePhaseMapper.insert(codeTemplatePhaseDO) > 0; |
| | | List<CodePhaseAttr> attrDOList = new ArrayList<>(); |
| | | CodeTemplatePhase finalCodeTemplatePhaseDO = codeTemplatePhaseDO; |
| | | codeTemplatePhaseDTO.getAttributes().stream().forEach(attrDTO->{ |
| | | CodePhaseAttr attrDO = new CodePhaseAttr(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(attrDTO,attrDO); |
| | | attrDO.setOid(VciBaseUtil.getPk()); |
| | | attrDO.setCodePhaseOid(finalCodeTemplatePhaseDO.getOid()); |
| | | attrDOList.add(attrDO); |
| | | }); |
| | | boolean resPhaseAttr = codePhaseattrService.saveOrUpdateBatch(attrDOList); |
| | | //WebUtil.setPersistence(true); |
| | | return resInsertTempPhase && resPhaseAttr ? codeTemplatePhaseDO2VO(codeTemplatePhaseDO):null; |
| | | } |
| | | |
| | | /** |
| | | * 修改模板阶段 |
| | | * @param codeTemplatePhaseDTO 模板阶段数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public CodeTemplatePhaseVO editSave(CodeTemplatePhaseDTO codeTemplatePhaseDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeTemplatePhaseDTO,"数据对象",codeTemplatePhaseDTO.getOid(),"模板阶段主键",codeTemplatePhaseDTO.getAttributes(),"包含的属性"); |
| | | //将DTO转换为DO |
| | | CodeTemplatePhase codeTemplatePhaseEntityDO = selectByOid(codeTemplatePhaseDTO.getOid()); |
| | | revisionModelUtil.copyFromDTOIgnore(codeTemplatePhaseDTO, codeTemplatePhaseEntityDO); |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeTemplatePhaseEntityDO); |
| | | //WebUtil.setPersistence(false); |
| | | codeTemplatePhaseMapper.updateById(codeTemplatePhaseEntityDO); |
| | | //把以前的删除 |
| | | List<CodePhaseAttr> phaseAttrDOS = listPhaseAttrDOByPhaseOid(codeTemplatePhaseEntityDO.getOid()); |
| | | if(!CollectionUtils.isEmpty(phaseAttrDOS)){ |
| | | codePhaseAttrMapper.deleteBatchIds(phaseAttrDOS.stream().map(CodePhaseAttr::getOid).collect(Collectors.toList())); |
| | | } |
| | | List<CodePhaseAttr> attrDOList = new ArrayList<>(); |
| | | |
| | | codeTemplatePhaseDTO.getAttributes().stream().forEach(attrDTO->{ |
| | | CodePhaseAttr attrDO = new CodePhaseAttr(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(attrDTO,attrDO); |
| | | attrDO.setOid(VciBaseUtil.getPk()); |
| | | attrDO.setCodePhaseOid(codeTemplatePhaseEntityDO.getOid()); |
| | | attrDOList.add(attrDO); |
| | | }); |
| | | codePhaseattrService.saveBatch(attrDOList); |
| | | //WebUtil.setPersistence(true); |
| | | return codeTemplatePhaseDO2VO(codeTemplatePhaseEntityDO); |
| | | } |
| | | |
| | | /** |
| | | * 模板属性删除的时候触发 |
| | | * @param attrDOList 属性的数据对象 |
| | | * @return 受影响的数据 |
| | | */ |
| | | @Override |
| | | public R codeTemplateAttrDeleteTrigger(List<CodeClassifyTemplateAttr> attrDOList){ |
| | | List<CodePhaseAttr> phaseAttrDOS =listLinkAttrDOByTemplateAttrDOS(attrDOList); |
| | | boolean resDeletePhaseAttr = false; |
| | | if(!CollectionUtils.isEmpty(phaseAttrDOS)){ |
| | | //属性被删除的时候,阶段里面也一样要被删除 |
| | | resDeletePhaseAttr = codePhaseAttrMapper.deleteBatchIds(phaseAttrDOS.stream().map(CodePhaseAttr::getOid).collect(Collectors.toList())) > 0; |
| | | } |
| | | return R.status(resDeletePhaseAttr); |
| | | } |
| | | |
| | | /** |
| | | * 删除模板阶段 |
| | | * @param codeTemplatePhaseDTO 模板阶段数据传输对象,oid和ts需要传输 |
| | | * @return 删除结果反馈::success:成功,fail:失败 |
| | | * @throws VciBaseException 参数为空,被引用时抛出异常 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R deleteCodeTemplatePhase(CodeTemplatePhaseDTO codeTemplatePhaseDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeTemplatePhaseDTO,"模板阶段数据对象",codeTemplatePhaseDTO.getOid(),"模板阶段的主键"); |
| | | CodeTemplatePhase codeTemplatePhaseEntityDO = selectByOid(codeTemplatePhaseDTO.getOid()); |
| | | R baseResult = checkIsCanDeleteForDO(codeTemplatePhaseDTO, codeTemplatePhaseEntityDO); |
| | | if(baseResult.isSuccess()) { |
| | | }else{ |
| | | return baseResult; |
| | | } |
| | | //执行删除操作 |
| | | //WebUtil.setPersistence(false); |
| | | boolean batchCBO = codeTemplatePhaseMapper.deleteById(codeTemplatePhaseEntityDO.getOid())>0; |
| | | //需要删除属性 |
| | | List<CodePhaseAttr> phaseAttrDOS = listPhaseAttrDOByPhaseOid(codeTemplatePhaseEntityDO.getOid()); |
| | | boolean deleteCBO = false; |
| | | if(!CollectionUtils.isEmpty(phaseAttrDOS)) { |
| | | deleteCBO = codePhaseAttrMapper.deleteBatchIds(phaseAttrDOS.stream().map(CodePhaseAttr::getOid).collect(Collectors.toList()))>0; |
| | | } |
| | | //WebUtil.setPersistence(true); |
| | | return (batchCBO || deleteCBO)?R.success(DELETE_SUCCESS):R.fail(DELETE_FAIL); |
| | | } |
| | | |
| | | /** |
| | | * 主键获取模板阶段 |
| | | * @param oid 主键 |
| | | * @return 模板阶段显示对象 |
| | | * @throws VciBaseException 参数为空,数据不存在时会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodeTemplatePhaseVO getObjectByOid(String oid) throws VciBaseException{ |
| | | return codeTemplatePhaseDO2VO(selectByOid(oid)); |
| | | } |
| | | |
| | | /** |
| | | * 主键批量获取模板阶段 |
| | | * @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个 |
| | | * @return 模板阶段显示对象 |
| | | * @throws VciBaseException 查询出现异常时会抛出 |
| | | */ |
| | | @Override |
| | | public Collection<CodeTemplatePhaseVO> listCodeTemplatePhaseByOids(Collection<String> oidCollections) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合"); |
| | | List<CodeTemplatePhase> codeTemplatePhaseEntityDOList = listCodeTemplatePhaseDOByOidCollections(oidCollections); |
| | | return CodeTemplatePhaseWapper.build().listVO(codeTemplatePhaseEntityDOList); |
| | | } |
| | | |
| | | /** |
| | | * 参照模板阶段列表 |
| | | * @param conditionMap 查询条件 |
| | | * @param pageHelper 分页和排序 |
| | | * @return 模板阶段显示对象列表,生效的内容 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public IPage<CodeTemplatePhaseVO> refDataGridCodeTemplatePhase(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{ |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<>(); |
| | | } |
| | | return gridCodeTemplatePhase(conditionMap,pageHelper); |
| | | } |
| | | |
| | | /** |
| | | * 阶段不包含的属性 |
| | | * |
| | | * @param conditionMap 查询对象,必须要有模板的主键(classifyTemplateOid),否则不能确定属性 |
| | | * @param pageHelper 分页对象 |
| | | * @return 属性的信息 |
| | | */ |
| | | @Override |
| | | public IPage<CodeClassifyTemplateAttrVO> gridUnUsedAttribute(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException { |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<String, String>(); |
| | | } |
| | | if(!conditionMap.containsKey("classifyTemplateOid")){ |
| | | throw new VciBaseException("没有模板的主键"); |
| | | } |
| | | //需要判断阶段的主键是否存在 |
| | | String codePhaseOid = conditionMap.getOrDefault("codePhaseOid", null); |
| | | MPJLambdaWrapper<CodeClassifyTemplateAttr> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(CodeClassifyTemplateAttr.class) |
| | | .selectAs(CodeClassifyTemplate::getName,CodeClassifyTemplateAttr::getClassifyTemplateOidName) |
| | | .leftJoin(CodeClassifyTemplate.class, CodeClassifyTemplate::getOid, CodeClassifyTemplateAttr::getClassifyTemplateOid) |
| | | .eq(CodeClassifyTemplateAttr::getClassifyTemplateOid,conditionMap.getOrDefault("classifyTemplateOid",null)); |
| | | if(StringUtils.isNotBlank(codePhaseOid)){ |
| | | //排除阶段上使用的 |
| | | conditionMap.remove("codePhaseOid"); |
| | | List<String> ids = commonsMapper.selectById("(select id from " + getPhaseAttrTable() + " where codePhaseOid ='" + codePhaseOid + "')"); |
| | | if(ids.size()<1000){ |
| | | queryWrapper = queryWrapper.notIn(CodeClassifyTemplateAttr::getId, ids); |
| | | }else { |
| | | queryWrapper = MybatisParameterUtil.cutNotInParameter(queryWrapper,CodeClassifyTemplateAttr::getId,ids); |
| | | } |
| | | //conditionMap.put("id", QueryOptionConstant.NOTIN + ids); |
| | | } |
| | | return tempAttrService.gridCodeClassifyTemplateAttr(queryWrapper,pageHelper); |
| | | } |
| | | |
| | | /** |
| | | * 阶段包含的属性 |
| | | * |
| | | * @param conditionMap 查询对象,必须要阶段的主键(codePhaseOid) |
| | | * @param pageHelper 分页对象 |
| | | * @return 属性的信息 |
| | | */ |
| | | @Override |
| | | public IPage<CodeClassifyTemplateAttrVO> gridUsedAttribute(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException { |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<String, String>(); |
| | | } |
| | | String codePhaseOid = conditionMap.getOrDefault("codePhaseOid", null); |
| | | if(StringUtils.isBlank(codePhaseOid)){ |
| | | return new Page<>(); |
| | | } |
| | | conditionMap.remove("codePhaseOid"); |
| | | CodeTemplatePhase phaseDO = selectByOid(codePhaseOid); |
| | | List<String> ids = commonsMapper.selectById("(select id from " + getPhaseAttrTable() + " where codePhaseOid ='" +codePhaseOid + "')"); |
| | | //这儿是个连表查询语句 |
| | | MPJLambdaWrapper<CodeClassifyTemplateAttr> mpjLambdaWrapper = new MPJLambdaWrapper<>(); |
| | | mpjLambdaWrapper.selectAll(CodeClassifyTemplateAttr.class) |
| | | .selectAs(CodeClassifyTemplate::getName,CodeClassifyTemplateAttr::getClassifyTemplateOidName) |
| | | .leftJoin(CodeClassifyTemplate.class, CodeClassifyTemplate::getOid, CodeClassifyTemplateAttr::getClassifyTemplateOid) |
| | | .eq(CodeClassifyTemplateAttr::getClassifyTemplateOid,phaseDO.getCodeClassifyTemplateOid()); |
| | | if(ids.size()<1000){ |
| | | mpjLambdaWrapper = mpjLambdaWrapper.in(CodeClassifyTemplateAttr::getId, ids); |
| | | }else { |
| | | mpjLambdaWrapper = MybatisParameterUtil.cutInParameter(mpjLambdaWrapper,CodeClassifyTemplateAttr::getId,ids); |
| | | } |
| | | return tempAttrService.gridCodeClassifyTemplateAttr(mpjLambdaWrapper,pageHelper); |
| | | } |
| | | |
| | | /** |
| | | * 阶段属性的表名 |
| | | * @return 表名 |
| | | */ |
| | | private String getPhaseAttrTable(){ |
| | | /**以前VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY在启动时初始化值为true所以拼接出来的表名是正确的, |
| | | 现在因为搬过来没有被赋值为true所以表名拿到的是错误的这儿暂时写死 |
| | | **/ |
| | | //return VciBaseUtil.getTableName(MdmBtmTypeConstant.CODE_PHASE_ATTR_TABLENAME); |
| | | return "pl_"+MdmBtmTypeConstant.CODE_PHASE_ATTR_TABLENAME; |
| | | } |
| | | |
| | | /** |
| | | * 阶段的表名 |
| | | * @return 表名 |
| | | */ |
| | | private String getPhaseTable(){ |
| | | //return VciBaseUtil.getTableName(MdmBtmTypeConstant.CODE_TEMPLATE_PHASE); |
| | | return "pl_"+MdmBtmTypeConstant.CODE_TEMPLATE_PHASE; |
| | | } |
| | | |
| | | /** |
| | | * 使用主键集合查询数据对象 |
| | | * @param oidCollections 主键的集合 |
| | | * @return 数据对象列表 |
| | | */ |
| | | private List<CodeTemplatePhase> listCodeTemplatePhaseDOByOidCollections(Collection<String> oidCollections){ |
| | | List<CodeTemplatePhase> codeTemplatePhaseEntityDOList = new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(oidCollections)){ |
| | | Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); |
| | | for(Collection<String> oids: oidCollectionsList){ |
| | | List<CodeTemplatePhase> tempDOList = codeTemplatePhaseMapper.selectBatchIds(oids); |
| | | if(!CollectionUtils.isEmpty(tempDOList)){ |
| | | codeTemplatePhaseEntityDOList.addAll(tempDOList); |
| | | } |
| | | } |
| | | } |
| | | return codeTemplatePhaseEntityDOList; |
| | | } |
| | | |
| | | /** |
| | | * 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除 |
| | | * @param codeTemplatePhaseDTO 数据传输对象 |
| | | * @param codeTemplatePhaseEntityDO 数据库中的数据对象 |
| | | * @return success为true为可以删除,false表示有数据引用,obj为true表示有下级 |
| | | */ |
| | | private R checkIsCanDeleteForDO(CodeTemplatePhaseDTO codeTemplatePhaseDTO, CodeTemplatePhase codeTemplatePhaseEntityDO) { |
| | | CodeTemplatePhase tsDO = new CodeTemplatePhase(); |
| | | BeanUtil.convert(codeTemplatePhaseDTO,tsDO); |
| | | if (!checkTs(tsDO,codeTemplatePhaseEntityDO)) { |
| | | return R.fail(TS_NOT_PROCESS); |
| | | } |
| | | if(!checkIsLinked(codeTemplatePhaseEntityDO.getOid())) { |
| | | return R.success("succcess"); |
| | | }else{ |
| | | return R.fail(DATA_LINKED_NOT_DELETE); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查ts |
| | | * @param codeTempphaseDO |
| | | * @return |
| | | */ |
| | | private boolean checkTs(CodeTemplatePhase tempDO, CodeTemplatePhase codeTempphaseDO){ |
| | | Date dbTs = codeTempphaseDO.getTs(); |
| | | Date currentTs = tempDO.getTs(); |
| | | if(currentTs == null ? dbTs == null:currentTs.compareTo(dbTs)==0){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 校验是否被引用 |
| | | * @param oid 主键 |
| | | * @throws VciBaseException 被引用的时候会抛出异常 |
| | | */ |
| | | private boolean checkIsLinked(String oid) throws VciBaseException{ |
| | | //TODO 添加需要校验引用的地方 |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 使用阶段主键获取包含的属性 |
| | | * @param codePhaseOid 阶段的主键 |
| | | * @return 包含属性的数据对象 |
| | | */ |
| | | private List<CodePhaseAttr> listPhaseAttrDOByPhaseOid(String codePhaseOid){ |
| | | if(StringUtils.isBlank(codePhaseOid)||StringUtils.isEmpty(codePhaseOid)){ |
| | | return null; |
| | | } |
| | | List<CodePhaseAttr> phaseAttrDOS = codePhaseAttrMapper.selectByPhasea(codePhaseOid); |
| | | return phaseAttrDOS; |
| | | } |
| | | |
| | | /** |
| | | * 使用模板的属性获取阶段中包含的属性内容 |
| | | * @param attrDOList 属性的数据对象 |
| | | * @return 阶段里的属性数据对象 |
| | | */ |
| | | private List<CodePhaseAttr> listLinkAttrDOByTemplateAttrDOS(List<CodeClassifyTemplateAttr> attrDOList){ |
| | | if(!CollectionUtils.isEmpty(attrDOList)) { |
| | | //查询这个模板里包含的所有阶段的这些属性 |
| | | //因为oracle里表的字段不能超过1000个,所以我们这里默认属性个数是小于1000的; |
| | | List<String> oids = commonsMapper.selectById("select oid from " + getPhaseTable() + " where codeClassifyTemplateOid='" + attrDOList.get(0).getClassifyTemplateOid() + "'"); |
| | | LambdaQueryWrapper<CodePhaseAttr> queryWrapper = new LambdaQueryWrapper<>(); |
| | | if(oids.size()<1000){ |
| | | queryWrapper.in(CodePhaseAttr::getCodePhaseOid,oids); |
| | | }else { |
| | | MybatisParameterUtil.cutInParameter(queryWrapper,CodePhaseAttr::getCodePhaseOid,oids); |
| | | } |
| | | if(attrDOList.size()<1000){ |
| | | queryWrapper.in(CodePhaseAttr::getId,VciBaseUtil.toInSql(attrDOList.stream().map(CodeClassifyTemplateAttr::getId).collect(Collectors.toList()).toArray(new String[0]))); |
| | | }else { |
| | | MybatisParameterUtil.cutInParameter(queryWrapper,CodePhaseAttr::getId,attrDOList.stream().map(CodeClassifyTemplateAttr::getId).collect(Collectors.toList())); |
| | | } |
| | | //conditionMap.put("codePhaseOid", QueryOptionConstant.IN + "(select oid from " + getPhaseTable() + " where codeClassifyTemplateOid='" + attrDOList.get(0).getClassifyTemplateOid() + "')"); |
| | | //conditionMap.put("id", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(attrDOList.stream().map(CodeClassifyTemplateAttr::getId).collect(Collectors.toList()).toArray(new String[0])) + ")"); |
| | | return codePhaseAttrMapper.selectList(queryWrapper); |
| | | }else{ |
| | | return new ArrayList<>(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 主键查询数据对象 |
| | | * @param oid 主键 |
| | | * @return 数据对象 |
| | | * @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常 |
| | | */ |
| | | private CodeTemplatePhase selectByOid(String oid) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(oid,"主键"); |
| | | CodeTemplatePhase codeTemplatePhaseEntityDO = codeTemplatePhaseMapper.selectById(oid.trim()); |
| | | if(codeTemplatePhaseEntityDO == null || StringUtils.isBlank(codeTemplatePhaseEntityDO.getOid())){ |
| | | throw new VciBaseException(DATA_OID_NOT_EXIST); |
| | | } |
| | | return codeTemplatePhaseEntityDO; |
| | | } |
| | | |
| | | } |