package com.vci.ubcs.omd.service.impl; import com.alibaba.cloud.commons.lang.StringUtils; import com.alibaba.nacos.api.exception.NacosException; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.vci.ubcs.omd.constant.OmdBtmTypeConstant; import com.vci.ubcs.omd.repeater.DomainRepeater; import com.vci.ubcs.omd.service.IOmdBtmTypeAttributeService; import com.vci.ubcs.omd.wrapper.OmdBtmTypeWrapper; import com.vci.ubcs.starter.web.constant.OmdRegExpConstant; import com.vci.ubcs.omd.dto.OmdBtmTypeDTO; import com.vci.ubcs.omd.dto.OmdBtmTypeLinkAttributesDTO; import com.vci.ubcs.omd.entity.OmdBtmType; import com.vci.ubcs.omd.entity.OmdBtmTypeAttribute; import com.vci.ubcs.omd.entity.OsModifyAttributeInfoDO; import com.vci.ubcs.omd.mapper.OmdBtmTypeMapper; import com.vci.ubcs.omd.service.IOmdBtmTypeService; import com.vci.ubcs.omd.vo.OmdBtmTypeVO; import com.vci.ubcs.omd.vo.OmdBtmTypeAttributeVO; import com.vci.ubcs.omd.vo.OsLinkTypeVO; import com.vci.ubcs.starter.exception.VciBaseException; import com.vci.ubcs.starter.web.util.VciBaseUtil; import com.vci.ubcs.starter.web.util.VciDateUtil; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Service; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import javax.validation.constraints.NotEmpty; import java.util.*; /** * Description: 业务类型服务的实现类 * * @author LiHang * @date 2023/4/23 */ @Service public class OmdBtmTypeServiceImpl extends ServiceImpl implements IOmdBtmTypeService { /** * 事务管理 */ @Autowired private DataSourceTransactionManager dataSourceTransactionManager; /** * 业务类型关联属性服务 */ @Autowired private IOmdBtmTypeAttributeService btmTypeAttributeService; @Autowired private DomainRepeater domainRepeater; /** * 设置平台本身的业务类型 * * @param platformBtmType 平台本身的业务类型 */ @Override public void setPlatformBtmType(Collection platformBtmType) { } /** * 根据主键获取业务类型 * * @param pkBtmType 业务类型主键 * @return 业务类型,如果不存在会返回null * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public OmdBtmTypeVO getBtmTypeByOid(String pkBtmType) throws ServiceException { Func.requireNotNull(pkBtmType,"业务类型主键不能为空"); OmdBtmTypeVO btmTypeVO = OmdBtmTypeWrapper.build().entityVO(baseMapper.selectOne(Wrappers.query().lambda().eq(OmdBtmType::getOid, pkBtmType))); btmTypeVO.setAttributes(btmTypeAttributeService.getAttributeByBtmTypeOid(pkBtmType)); return btmTypeVO; } /** * 根据主键批量获取业务类型 * * @param pkBtmTypes 业务类型主键,用逗号分隔 * @return 业务类型列表,如果有不存在的不会返回,全部不存在的则返回空列表 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public List listBtmTypeByOids(String pkBtmTypes) throws ServiceException { return null; } /** * 批量根据主键获取业务类型 * * @param pkBtmTypeCollection 业务类型主键集合 * @return 业务类型列表,如果有不存在的不会返回,全部不存在的则返回空列表 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public List listBtmTypeByOidCollection(Collection pkBtmTypeCollection) throws ServiceException { return null; } /** * 根据英文名称获取业务类型 * * @param id 英文名称 * @return 业务类型,如果不存在会返回null * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public OmdBtmTypeVO getBtmTypeById(String id) throws ServiceException { return null; } /** * 根据英文名称批量获取业务类型 * * @param ids 英文名称,使用逗号分隔 * @return 业务类型列表,如果有不存在的不会返回,全部不存在的则返回空列表 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public List listBtmTypeByIds(String ids) throws ServiceException { return null; } /** * 根据英文名称集合批量获取业务类型 * * @param idCollection 英文名称集合 * @return 业务类型列表,如果有不存在的不会返回,全部不存在的则返回空列表 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public List listBtmTypeByIdCollection(Collection idCollection) throws ServiceException { return null; } /** * 根据英文名称集合批量获取业务类型的数据对象 * * @param idCollection 英文名称集合 * @return 业务类型列表,如果有不存在的不会返回,全部不存在的则返回空列表 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public List listBtmTypeDOByIdCollection(Collection idCollection) throws ServiceException { return null; } /** * 根据主键集合批量获取业务类型的数据对象 * * @param oidCollection 主键 * @return 业务类型列表,如果有不存在的不会返回,全部不存在的则返回空列表 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public List listBtmTypeDOByOidCollection(Collection oidCollection) throws ServiceException { return null; } /** * 根据业务类型主键获取中文名称 * * @param oid 业务类型主键,多个使用逗号分隔 * @return 中文名称,如果不存在会返回null;多个会以逗号分隔 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public String getNameByOid(String oid) throws ServiceException { return null; } /** * 根据业务类型英文名称获取中文名称 * * @param id 业务类型英文名称 * @return 中文名称,如果不存在会返回null;多个会以逗号分隔 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public String getNameById(String id) throws ServiceException { return null; } /** * 根据业务类型主键获取关联的所有属性对象 * * @param oid 业务类型主键 * @return 所有的属性对象,包括系统属性 * @throws ServiceException 业务类型不存在,参数为空或查询出错时会抛出错误 */ @Override public List listHasAttributesByOid(String oid) throws ServiceException { return null; } /** * 根据业务类型英文名称获取关联的所有属性对象 * * @param id 业务类型英文名称 * @return 所有的属性对象,包括系统内置属性 * @throws ServiceException 业务类型不存在,参数为空或者查询出错时会抛出异常 */ @Override public List listHasAttributeById(String id) throws ServiceException { return null; } /** * 根据业务类型主键获取关联的所有属性对象 * * @param oidCollection 业务类型主键集合 * @return 所有的属性对象,包括系统内置属性,key是业务类型主键,value是包含的属性 * @throws ServiceException 业务类型不存在,参数为空或者查询出错时会抛出异常 */ @Override public Map> batchListHasAttributesByOidCollection(Collection oidCollection) throws ServiceException { return null; } /** * 根据业务类型英文名称获取关联的所有属性对象 * * @param idCollection 业务类型英文名称集合 * @return 所有的属性对象,包括系统内置属性,key是业务类型主键,value是包含的属性 * @throws ServiceException 业务类型不存在,参数为空或者查询出错时会抛出异常 */ @Override public Map> batchListHasAttributesByIdCollection(Collection idCollection) throws ServiceException { return null; } /** * 获取使用业务类型的链接类型 * * @param pkBtmType 业务类型主键 * @return 引用的链接类型 * @throws ServiceException 参数为空或者查询出错时会抛出异常 */ @Override public List listLinkTypeForUsedBtmType(String pkBtmType) throws ServiceException { return null; } /** * 校验业务类型是否被引用 * * @param pkBtmType 业务类型的主键 * @return true表示被引用, false表示没有被引用 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public boolean checkBtmTypeUsed(String pkBtmType) throws ServiceException { return false; } /** * 校验业务类型是否被引用 * * @param oidCollection 业务类型的主键集合 * @return true表示被引用, false表示没有被引用 * @throws ServiceException 参数为空或者查询出错时会抛出错误 */ @Override public boolean checkBtmTypeUseds(Collection oidCollection) throws ServiceException { return false; } /** * 添加业务类型 * * @param btmTypeDTO 业务类型数据传输对象 * @param autoCreateTable 是否自动创建表格 * @return 添加后的业务类型 * @throws ServiceException 添加出错的时候会抛出异常 */ @Override public OmdBtmTypeDTO addSave(OmdBtmTypeDTO btmTypeDTO, boolean autoCreateTable) throws ServiceException { TransactionStatus transaction = null; DefaultTransactionDefinition def = null; if (autoCreateTable) { def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); // 事物隔离级别,开启新事务,这样会比较安全些。 transaction = dataSourceTransactionManager.getTransaction(def); // 获得事务状态 } OmdBtmType btmTypeDO = new OmdBtmType(); try { VciBaseUtil.alertNotNull(btmTypeDTO, "要添加的业务类型", btmTypeDTO.getId(), "业务类型的英文名称", btmTypeDTO.getName(), "业务类型中文名称"); if (btmTypeDTO.isViewFlag() && (StringUtils.isBlank(btmTypeDTO.getViewCreateSql()) || StringUtils.isBlank(btmTypeDTO.getTableName()))) { throw new VciBaseException("如果当前是业务类型是视图的时候,请必须输入视图的创建语句和视图名称"); } if (!btmTypeDTO.isViewFlag()) { VciBaseUtil.alertCollectionNotNull("属性", btmTypeDTO.getAttributesDTOList()); } if (!btmTypeDTO.getId().matches(OmdRegExpConstant.LETTER)) { throw new VciBaseException("业务类型英文名称只能是纯英文,目前为{0}", new Object[]{btmTypeDTO.getId()}); } if (btmTypeDTO.getId().length() > 24) { throw new VciBaseException("业务类型英文名称不能超过18,目前长度为{0}", new Object[]{btmTypeDTO.getId().length()}); } List btmTypeDOList = listBtmTypeDOByIdCollection(VciBaseUtil.str2List(btmTypeDTO.getId())); if (!CollectionUtils.isEmpty(btmTypeDOList) && btmTypeDOList.size() > 0) { OmdBtmType existBtmType = btmTypeDOList.get(0); throw new VciBaseException("业务类型英文名称已经存在(不区分大小写),这个英文名称对应的中文名称为{0},创建人{1},创建时间{2}" , new Object[]{existBtmType.getName(), existBtmType.getCreator(), VciDateUtil.date2Str(existBtmType.getCreateTime(), VciDateUtil.DateFormat)}); } /* //检查使用的版本规则是否存在 if (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) { if (revisionRuleServiceI.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) { throw new VciBaseException("版本规则{0}[{1}]在系统中不存在,请先查证", new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()}); } } //检查使用的生命周期是否存在 if (StringUtils.isNotBlank(btmTypeDTO.getLifeCycleId()) && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btmTypeDTO.getLifeCycleId())) { if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getLifeCycleId())) { throw new VciBaseException("生命周期{0}[{1}]在系统中不存在,请先查证", new Object[]{btmTypeDTO.getLifeCycleId(), btmTypeDTO.getLifeCycleName()}); } } if (StringUtils.isNotBlank(btmTypeDTO.getSubLifeCycleId())) { if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getSubLifeCycleId())) { throw new VciBaseException("备用生命周期{0}[{1}]中其中有某些在系统中不存在,请先查证", new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()}); } } */ if (StringUtils.isBlank(btmTypeDTO.getOid())) { btmTypeDTO.setOid(VciBaseUtil.getPk()); } BeanUtil.copy(btmTypeDTO, btmTypeDO); String creator = AuthUtil.getUserAccount(); Date now = new Date(); btmTypeDO.setCreator(creator); btmTypeDO.setCreateTime(now); btmTypeDO.setOwner(creator); btmTypeDO.setBtmname(OmdBtmTypeConstant.OMD_BTMTYPE); btmTypeDO.setTs(now); if (StringUtils.isBlank(btmTypeDO.getTableName())) { btmTypeDO.setTableName(getTableName(btmTypeDO.getId())); } //处理属性 addAttributeForBtm(btmTypeDTO, creator, now); baseMapper.insert(btmTypeDO); if (autoCreateTable) { dataSourceTransactionManager.commit(transaction); } } catch (ServiceException e) { if (autoCreateTable) { dataSourceTransactionManager.rollback(transaction); } throw e; } catch (Throwable e) { if (autoCreateTable) { dataSourceTransactionManager.rollback(transaction); } throw e; } if (autoCreateTable) { OmdBtmTypeVO btmTypeVO = OmdBtmTypeWrapper.build().entityVO(btmTypeDO); btmTypeVO.setAttributes(listHasAttributesByOid(btmTypeDO.getOid())); checkTableSame(btmTypeVO); } return btmTypeDTO; } /** * 检查业务类型的属性是否和数据库中相同 * * @param btmTypeVO 业务类型的显示对象 */ private void checkTableSame(OmdBtmTypeVO btmTypeVO) { /*List btmTypeVOList = new ArrayList<>(); btmTypeVOList.add(btmTypeVO); List modifyAttributeInfoDOList = ddlServiceI.checkDifferent(btmTypeVOList, null); try { modifyAttributeServiceI.batchAddSave(modifyAttributeInfoDOList); } catch (Throwable e) { if (logger.isErrorEnabled()) { logger.error("保存【修改属性】数据", e); } } ddlServiceI.reflexDifferent(modifyAttributeInfoDOList); modifyAttributeServiceI.finishModify(modifyAttributeInfoDOList);*/ } /** * 添加属性到业务类型中 * * @param btmTypeDTO 业务类型的数据传输对象 * @param creator 创建人 * @param now 当前时间 */ private void addAttributeForBtm(OmdBtmTypeDTO btmTypeDTO, String creator, Date now) throws VciBaseException{ List attributesDTOList = btmTypeDTO.getAttributesDTOList(); btmTypeAttributeService.checkAndInsert(btmTypeDTO.getOid(),attributesDTOList,creator,now); } /** * 修改业务类型 * * @param btmTypeDTO 业务类型数据传输对象 * @param autoEditTable 是否自动更新表格 * @return 修改后的业务类型 * @throws ServiceException 修改出错的时候会抛出异常 */ @Override public OmdBtmTypeDTO editSave(OmdBtmTypeDTO btmTypeDTO, boolean autoEditTable) throws ServiceException { return null; } /** * 删除业务类型 * * @param btmTypeVO 业务类型显示对象 * @param autoDeleteTable 自动删除表格 * @throws ServiceException 如果业务类型被引用,或者删除出错时会抛出异常 */ @Override public void delete(OmdBtmTypeVO btmTypeVO, boolean autoDeleteTable) throws ServiceException { } /** * 批量删除业务类型 * * @param btmTypeVOList 要删除的业务类型显示对象列表 * @param autoDeleteTable 自动删除表格 * @throws ServiceException 如果业务类型被引用,或者删除出错时会抛出异常 */ @Override public void batchDelete(List btmTypeVOList, boolean autoDeleteTable) throws ServiceException { } /** * 检查业务类型与数据库表是否一致 * * @param pkBtmType 业务类型主键 * @return 不同的属性信息 * @throws ServiceException 参数为空或者查询出错时会抛出异常 */ @Override public List checkDbTableSame(String pkBtmType) throws ServiceException { return null; } /** * 获取数据库表,支持业务类型和视图 * * @param id 业务类型的名称 * @return 数据库表的名称 * @throws ServiceException 参数为空的时候会抛出异常 */ @Override public String getTableName(String id) throws ServiceException { return null; } /** * 将业务类型使用的属性的传输对象转换为数据对象 * * @param attributesDTO 属性的数据传输对象 * @param pkBtmType 业务类型的主键 * @param creator 创建人 * @param now 当前时间 * @return 属性的数据对象 */ @Override public OmdBtmTypeAttribute btmTypeAttributeDTO2DO(OmdBtmTypeLinkAttributesDTO attributesDTO, String pkBtmType, String creator, Date now) { return null; } /** * 业务类型的属性显示对象转换为数据对象 * * @param thisBtmTypeHasAttributeVOList 业务类型属性显示对象 * @return 数据对象 */ @Override public List btmTypeAttributeVO2DO(List thisBtmTypeHasAttributeVOList) { return null; } /** * 批量将业务类型的数据对象转换为显示对象 * * @param attributeDOList 属性的数据对象列表 * @return 属性的显示对象列表 */ @Override public List batchBtmTypeAttributeDO2VO(List attributeDOList) { return null; } /** * 批量将业务类型的数据对象转换为显示对象 * * @param attributesDO 属性的数据对象 * @return 属性的显示对象列表 */ @Override public OmdBtmTypeAttributeVO btmTypeAttributeDO2VO(OmdBtmTypeAttribute attributesDO) { return null; } /** * 获取业务类型的指定属性 * * @param id 链接类型的英文名称 * @param attributeIdCollection 属性的集合,如果为空则获取全部 * @return 属性的显示对象 */ @Override public List listAttributeDOByIdsForBtm(String id, Collection attributeIdCollection) { return null; } /** * 根据业务类型的编号获取属性 * * @param id 业务类型的编号 * @return 属性的显示对象 */ @Override public List listAttributeByBtmTypeId(String id) { return null; } /** * 根据业务类型的主键获取属性 * * @param oid 业务类型的主键 * @return 属性的显示对象 */ @Override public List listAttributeByBtmTypeOid(String oid) { return null; } /** * 批量根据业务类型编号或者主键获取包含的属性 * * @param oidsOrIds 主键或者编号集合 * @param queryById 是否使用编号查询 * @return key是业务类型的主键或者编号,值是包含的属性的信息 * @throws ServiceException 参数为空或者查询出错会抛出异常 */ @Override public List batchListAttributeByBtmType(Collection oidsOrIds, boolean queryById) throws ServiceException { return null; } /** * 新增或修改业务类型 * * @param btmTypeDTO 业务类型页面传输对象 * @return 执行结果 */ @Override public boolean submit(OmdBtmTypeDTO btmTypeDTO) { //addSave(btmTypeDTO,false); try { Object result = domainRepeater.submitBtmType(btmTypeDTO.getDomain(), Objects.requireNonNull(BeanUtil.copy(btmTypeDTO, OmdBtmTypeVO.class))); if (result instanceof R){ R r = (R) result; if (r.isSuccess()){ return true; }else { return false; } } } catch (NacosException e) { throw new RuntimeException(e); } return true; } @Override public boolean deleteLogic(@NotEmpty List ids) { return false; } @Override public boolean changeStatus(@NotEmpty List ids, Integer status) { return false; } }