| | |
| | | /* |
| | | * 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.vci.ubcs.code.constant.MdmBtmTypeConstant; |
| | | import com.vci.ubcs.code.dao.CodePhaseAttrDaoI; |
| | | import com.vci.ubcs.code.model.CodePhaseAttrDO; |
| | | import com.vci.ubcs.code.service.CodePhaseAttrServiceI; |
| | | import com.vci.starter.revision.service.RevisionModelUtil; |
| | | import com.vci.starter.web.constant.QueryOptionConstant; |
| | | 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.dto.CodePhaseAttrDTO; |
| | | 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.entity.CodePhaseAttr; |
| | | import com.vci.ubcs.code.mapper.CodePhaseAttrMapper; |
| | | import com.vci.ubcs.code.service.ICodePhaseAttrService; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodePhaseAttrVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | 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 |
| | | * 编码库定义-模板阶段-属性 服务实现类 |
| | | * |
| | | * @author yuxc |
| | | * @since 2023-04-20 |
| | | */ |
| | | @Service |
| | | public class CodePhaseAttrServiceImpl implements CodePhaseAttrServiceI { |
| | | public class CodePhaseAttrServiceImpl extends ServiceImpl<CodePhaseAttrMapper, CodePhaseAttr> implements ICodePhaseAttrService { |
| | | |
| | | /** |
| | | * 日志 |
| | | */ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | @Override |
| | | public IPage<CodePhaseAttrVO> selectCodePhaseattrPage(IPage<CodePhaseAttrVO> page, CodePhaseAttrVO codePhaseAttr) { |
| | | return page.setRecords(baseMapper.selectCodePhaseattrPage(page, codePhaseAttr)); |
| | | } |
| | | |
| | | /** |
| | | * 数据操作层 |
| | | */ |
| | | @Resource |
| | | private CodePhaseAttrDaoI codePhaseAttrMapper; |
| | | |
| | | /** |
| | | * 业务类型操作的服务 |
| | | */ |
| | | @Autowired |
| | | @Lazy |
| | | private WebBoServiceI boService; |
| | | |
| | | /** |
| | | * 对象的操作 |
| | | */ |
| | | @Autowired |
| | | private RevisionModelUtil revisionModelUtil; |
| | | /** |
| | | * 使用模板主键和阶段编号获取包含的属性 |
| | | * |
| | | * @param templateOid 模板的编号 |
| | | * @param phaseId 阶段的编号 |
| | | * @return 属性的英文名称 |
| | | */ |
| | | @Override |
| | | public List<String> listAttrByTemplateOidAndPhaseId(String templateOid, String phaseId) { |
| | | if(StringUtils.isBlank(templateOid)|| StringUtils.isBlank(phaseId)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | QueryWrapper<CodePhaseAttr> wrapper = new QueryWrapper(); |
| | | wrapper.inSql("codephaseoid","select oid from pl_code_tempphase where codeClassifyTemplateOid ='" + templateOid + "' and lower(name) ='" + phaseId.trim().toLowerCase(Locale.ROOT) + "'"); |
| | | // Map<String,String> conditionMap = new HashMap<>(); |
| | | // conditionMap.put("codephaseoid", QueryOptionConstant.IN + "(select oid from pl_code_tempphase where codeClassifyTemplateOid ='" + templateOid + "' and lower(name) ='" + phaseId.trim().toLowerCase(Locale.ROOT) + "')"); |
| | | // PageHelper pageHelper = new PageHelper(-1); |
| | | List<CodePhaseAttr> attrDOS = baseMapper.selectList(wrapper); |
| | | return CollectionUtils.isEmpty(attrDOS)?new ArrayList<>():attrDOS.stream().map(CodePhaseAttr::getId).collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询所有的阶段的属性 |
| | | * @param conditionMap 查询条件 |
| | | * @param pageHelper 分页和排序 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public DataGrid<CodePhaseAttrVO> gridCodePhaseAttr(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{ |
| | | if (pageHelper == null) { |
| | | pageHelper = new PageHelper(-1); |
| | | } |
| | | pageHelper.addDefaultDesc("createTime"); |
| | | List<CodePhaseAttrDO> doList = codePhaseAttrMapper.selectByCondition(conditionMap,pageHelper); |
| | | DataGrid<CodePhaseAttrVO> dataGrid=new DataGrid<CodePhaseAttrVO>(); |
| | | if (!CollectionUtils.isEmpty(doList)) { |
| | | dataGrid.setData(codePhaseAttrDO2VOs(doList)); |
| | | dataGrid.setTotal(VciBaseUtil.getInt(String.valueOf(codePhaseAttrMapper.countByCondition(conditionMap)))); |
| | | } |
| | | return dataGrid; |
| | | } |
| | | |
| | | /** |
| | | * 批量数据对象转换为显示对象 |
| | | * @param codePhaseAttrDOs 数据对象列表 |
| | | * @return 显示对象 |
| | | * @throws VciBaseException 参数为空或者不存在的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public List<CodePhaseAttrVO> codePhaseAttrDO2VOs(Collection<CodePhaseAttrDO> codePhaseAttrDOs) throws VciBaseException{ |
| | | List<CodePhaseAttrVO> voList = new ArrayList<CodePhaseAttrVO>(); |
| | | if(!CollectionUtils.isEmpty(codePhaseAttrDOs)){ |
| | | for(CodePhaseAttrDO s: codePhaseAttrDOs){ |
| | | CodePhaseAttrVO vo = codePhaseAttrDO2VO(s); |
| | | if(vo != null){ |
| | | voList.add(vo); |
| | | } |
| | | } |
| | | } |
| | | return voList; |
| | | } |
| | | |
| | | /** |
| | | * 数据对象转换为显示对象 |
| | | * @param codePhaseAttrDO 数据对象 |
| | | * @return 显示对象 |
| | | * @throws VciBaseException 拷贝属性出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodePhaseAttrVO codePhaseAttrDO2VO(CodePhaseAttrDO codePhaseAttrDO) throws VciBaseException{ |
| | | CodePhaseAttrVO vo = new CodePhaseAttrVO(); |
| | | if(codePhaseAttrDO != null){ |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codePhaseAttrDO,vo); |
| | | //如果有lcstatus的类的话 |
| | | } |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | | * 增加阶段的属性 |
| | | * @param codePhaseAttrDTO 阶段的属性数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodePhaseAttrVO addSave(CodePhaseAttrDTO codePhaseAttrDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codePhaseAttrDTO,"需要添加的数据对象"); |
| | | //将DTO转换为DO |
| | | CodePhaseAttrDO codePhaseAttrDO = new CodePhaseAttrDO(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codePhaseAttrDTO,codePhaseAttrDO); |
| | | codePhaseAttrMapper.insert(codePhaseAttrDO); |
| | | return codePhaseAttrDO2VO(codePhaseAttrDO); |
| | | } |
| | | |
| | | /** |
| | | * 修改阶段的属性 |
| | | * @param codePhaseAttrDTO 阶段的属性数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodePhaseAttrVO editSave(CodePhaseAttrDTO codePhaseAttrDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codePhaseAttrDTO,"数据对象",codePhaseAttrDTO.getOid(),"阶段的属性主键"); |
| | | //将DTO转换为DO |
| | | CodePhaseAttrDO codePhaseAttrDO = selectByOid(codePhaseAttrDTO.getOid()); |
| | | revisionModelUtil.copyFromDTOIgnore(codePhaseAttrDTO,codePhaseAttrDO); |
| | | codePhaseAttrMapper.updateByPrimaryKey(codePhaseAttrDO); |
| | | return codePhaseAttrDO2VO(codePhaseAttrDO); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除 |
| | | * @param codePhaseAttrDTO 数据传输对象 |
| | | * @param codePhaseAttrDO 数据库中的数据对象 |
| | | * @return success为true为可以删除,false表示有数据引用,obj为true表示有下级 |
| | | */ |
| | | private BaseResult checkIsCanDeleteForDO(CodePhaseAttrDTO codePhaseAttrDTO, CodePhaseAttrDO codePhaseAttrDO) { |
| | | CodePhaseAttrDO tsDO = new CodePhaseAttrDO(); |
| | | BeanUtil.convert(codePhaseAttrDTO,tsDO); |
| | | boService.checkTs(tsDO); |
| | | if(!checkIsLinked(codePhaseAttrDO.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 codePhaseAttrDTO 阶段的属性数据传输对象,oid和ts需要传输 |
| | | * @return 删除结果反馈::success:成功,fail:失败 |
| | | * @throws VciBaseException 参数为空,被引用时抛出异常 |
| | | */ |
| | | @Override |
| | | public BaseResult deleteCodePhaseAttr(CodePhaseAttrDTO codePhaseAttrDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codePhaseAttrDTO,"阶段的属性数据对象",codePhaseAttrDTO.getOid(),"阶段的属性的主键"); |
| | | CodePhaseAttrDO codePhaseAttrDO = selectByOid(codePhaseAttrDTO.getOid()); |
| | | BaseResult baseResult = checkIsCanDeleteForDO(codePhaseAttrDTO,codePhaseAttrDO); |
| | | if(baseResult.isSuccess()) { |
| | | }else{ |
| | | return baseResult; |
| | | } |
| | | //执行删除操作 |
| | | BatchCBO batchCBO = codePhaseAttrMapper.deleteByPrimaryKey(codePhaseAttrDO.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 CodePhaseAttrVO getObjectByOid(String oid) throws VciBaseException{ |
| | | return codePhaseAttrDO2VO(selectByOid(oid)); |
| | | } |
| | | |
| | | /** |
| | | * 主键查询数据对象 |
| | | * @param oid 主键 |
| | | * @return 数据对象 |
| | | * @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常 |
| | | */ |
| | | private CodePhaseAttrDO selectByOid(String oid) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(oid,"主键"); |
| | | CodePhaseAttrDO codePhaseAttrDO = codePhaseAttrMapper.selectByPrimaryKey(oid.trim()); |
| | | if(codePhaseAttrDO == null || StringUtils.isBlank(codePhaseAttrDO.getOid())){ |
| | | throw new VciBaseException(DATA_OID_NOT_EXIST); |
| | | } |
| | | return codePhaseAttrDO; |
| | | } |
| | | |
| | | /** |
| | | * 主键批量获取阶段的属性 |
| | | * @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个 |
| | | * @return 阶段的属性显示对象 |
| | | * @throws VciBaseException 查询出现异常时会抛出 |
| | | */ |
| | | @Override |
| | | public Collection<CodePhaseAttrVO> listCodePhaseAttrByOids(Collection<String> oidCollections) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合"); |
| | | List<CodePhaseAttrDO> codePhaseAttrDOList = listCodePhaseAttrDOByOidCollections(oidCollections); |
| | | return codePhaseAttrDO2VOs(codePhaseAttrDOList); |
| | | } |
| | | |
| | | /** |
| | | * 使用主键集合查询数据对象 |
| | | * @param oidCollections 主键的集合 |
| | | * @return 数据对象列表 |
| | | */ |
| | | private List<CodePhaseAttrDO> listCodePhaseAttrDOByOidCollections(Collection<String> oidCollections){ |
| | | List<CodePhaseAttrDO> codePhaseAttrDOList = new ArrayList<CodePhaseAttrDO>(); |
| | | if(!CollectionUtils.isEmpty(oidCollections)){ |
| | | Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); |
| | | for(Collection<String> oids: oidCollectionsList){ |
| | | List<CodePhaseAttrDO> tempDOList = codePhaseAttrMapper.selectByPrimaryKeyCollection(oids); |
| | | if(!CollectionUtils.isEmpty(tempDOList)){ |
| | | codePhaseAttrDOList.addAll(tempDOList); |
| | | } |
| | | } |
| | | } |
| | | return codePhaseAttrDOList; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 参照阶段的属性列表 |
| | | * @param conditionMap 查询条件 |
| | | * @param pageHelper 分页和排序 |
| | | * @return 阶段的属性显示对象列表,生效的内容 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public DataGrid<CodePhaseAttrVO> refDataGridCodePhaseAttr(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{ |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<String, String>(); |
| | | } |
| | | return gridCodePhaseAttr(conditionMap,pageHelper); |
| | | } |
| | | |
| | | /** |
| | | * 使用模板主键和阶段编号获取包含的属性 |
| | | * |
| | | * @param templateOid 模板的编号 |
| | | * @param phaseId 阶段的编号 |
| | | * @return 属性的英文名称 |
| | | */ |
| | | @Override |
| | | public List<String> listAttrByTemplateOidAndPhaseId(String templateOid, String phaseId) { |
| | | if(StringUtils.isBlank(templateOid)|| StringUtils.isBlank(phaseId)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | Map<String,String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("codephaseoid", QueryOptionConstant.IN + "(select oid from "+ |
| | | VciBaseUtil.getTableName(MdmBtmTypeConstant.CODE_TEMPLATE_PHASE) + |
| | | " where codeClassifyTemplateOid ='" + templateOid + "' and lower(name) ='" + phaseId.trim().toLowerCase(Locale.ROOT) + "')"); |
| | | PageHelper pageHelper = new PageHelper(-1); |
| | | List<CodePhaseAttrDO> attrDOS = codePhaseAttrMapper.selectByCondition(conditionMap, pageHelper); |
| | | return CollectionUtils.isEmpty(attrDOS)?new ArrayList<>():attrDOS.stream().map(CodePhaseAttrDO::getId).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |