| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.vci.ubcs.code.dao.CodeFixedValueDaoI; |
| | | import com.vci.ubcs.code.model.CodeFixedValueDO; |
| | | import com.vci.ubcs.code.service.CodeFixedValueServiceI; |
| | | 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.BeanUtilForVCI; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.starter.web.wrapper.VciQueryWrapperForDO; |
| | | import com.vci.web.pageModel.BatchCBO; |
| | | import com.vci.web.service.WebBoServiceI; |
| | | import com.vci.web.util.WebUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import com.vci.ubcs.code.dto.CodeFixedValueDTO; |
| | | import com.vci.ubcs.code.entity.CodeFixedValue; |
| | | import com.vci.ubcs.code.mapper.CodeFixedValueMapper; |
| | | import com.vci.ubcs.code.service.ICodeFixedValueService; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeFixedValueVO; |
| | | import com.vci.ubcs.code.wrapper.CodeFixedValueWrapper; |
| | | 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.MdmBtmTypeConstant; |
| | | import com.vci.ubcs.starter.web.util.BeanUtilForVCI; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.vci.ubcs.code.dto.CodeFixedValueDTO; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeFixedValueVO; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | 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.frameworkcore.constant.FrameWorkLangCodeConstant.*; |
| | | import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_LINKED_NOT_DELETE; |
| | | import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST; |
| | | |
| | | /** |
| | | * 固定码段的码值服务 |
| | | * @author weidy |
| | | * @author ludc |
| | | * @date 2022-01-24 |
| | | */ |
| | | @Service |
| | | public class CodeFixedValueServiceImpl implements CodeFixedValueServiceI { |
| | | public class CodeFixedValueServiceImpl extends ServiceImpl<CodeFixedValueMapper, CodeFixedValue> implements ICodeFixedValueService { |
| | | |
| | | /** |
| | | * 日志 |
| | | */ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | /** |
| | | * 数据操作层 |
| | | */ |
| | | @Resource |
| | | private CodeFixedValueMapper codeFixedValueMapper; |
| | | |
| | | /** |
| | | * 数据操作层 |
| | | */ |
| | | @Resource |
| | | private CodeFixedValueDaoI codeFixedValueMapper; |
| | | /** |
| | | * 对象的操作 |
| | | */ |
| | | @Resource |
| | | private RevisionModelUtil revisionModelUtil; |
| | | |
| | | /** |
| | | * 业务类型操作的服务 |
| | | */ |
| | | @Autowired |
| | | @Lazy |
| | | private WebBoServiceI boService; |
| | | /** |
| | | * 查询所有的固定码段的码值 |
| | | * @param codeFixedValueVO 查询条件 |
| | | * @param page 分页和排序 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public IPage<CodeFixedValueVO> gridCodeFixedValue(CodeFixedValueVO codeFixedValueVO,IPage<CodeFixedValueVO> page) throws VciBaseException{ |
| | | String secOid = codeFixedValueVO.getCodeFixedSecOid(); |
| | | if(StringUtils.isBlank(secOid)){ |
| | | return null; |
| | | } |
| | | List<CodeFixedValue> doList = codeFixedValueMapper.selectByPage(codeFixedValueVO,page); |
| | | return page.setRecords(CodeFixedValueWrapper.build().listVO(doList)); |
| | | } |
| | | |
| | | /** |
| | | * 对象的操作 |
| | | */ |
| | | @Autowired |
| | | private RevisionModelUtil revisionModelUtil; |
| | | /** |
| | | * 根据codeFixedSecOid查询码值 |
| | | * @param codeFixedSecOids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<CodeFixedValue> listFixedValueByCodeFixedSecOid(List<String> codeFixedSecOids){ |
| | | if(codeFixedSecOids.isEmpty()){ |
| | | return new ArrayList<CodeFixedValue>(); |
| | | } |
| | | /*List<CodeFixedValue> codeFixedValues = codeFixedValueMapper.selectList( |
| | | Wrappers.<CodeFixedValue>query().lambda() |
| | | .in(CodeFixedValue::getCodeFixedSecOid, codeFixedSecOids) |
| | | );*/ |
| | | List<CodeFixedValue> codeFixedValues = codeFixedValueMapper.selectByPageByCodeFixedSecOid(codeFixedSecOids, new Page<>(1, -1)); |
| | | return codeFixedValues; |
| | | } |
| | | |
| | | /** |
| | | * 根据关联固定码段主键删除码值 |
| | | * @param codeFixedSecOid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Boolean deleteFixedValueBySecOid(String codeFixedSecOid) { |
| | | LambdaQueryWrapper<CodeFixedValue> wrapper = Wrappers.<CodeFixedValue>query() |
| | | .lambda().eq(CodeFixedValue::getCodeFixedSecOid, codeFixedSecOid); |
| | | return codeFixedValueMapper.delete(wrapper)>0; |
| | | } |
| | | |
| | | /** |
| | | * 查询所有的固定码段的码值 |
| | | * @param conditionMap 查询条件 |
| | | * @param pageHelper 分页和排序 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public DataGrid<CodeFixedValueVO> gridCodeFixedValue(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{ |
| | | if (pageHelper == null) { |
| | | pageHelper = new PageHelper(-1); |
| | | } |
| | | pageHelper.addDefaultAsc("ordernum"); |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<>(); |
| | | } |
| | | String secOid = conditionMap.getOrDefault("codefixedsecoid", ""); |
| | | if(StringUtils.isBlank(secOid)){ |
| | | return new DataGrid<>(); |
| | | } |
| | | List<CodeFixedValueDO> doList = codeFixedValueMapper.selectByCondition(conditionMap,pageHelper); |
| | | DataGrid<CodeFixedValueVO> dataGrid=new DataGrid<CodeFixedValueVO>(); |
| | | if (!CollectionUtils.isEmpty(doList)) { |
| | | dataGrid.setData(codeFixedValueDO2VOs(doList)); |
| | | dataGrid.setTotal(VciBaseUtil.getInt(String.valueOf(codeFixedValueMapper.countByCondition(conditionMap)))); |
| | | } |
| | | return dataGrid; |
| | | } |
| | | /** |
| | | * 增加固定码段的码值 |
| | | * @param codeFixedValueDTO 固定码段的码值数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | public boolean addSave(CodeFixedValueDTO codeFixedValueDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeFixedValueDTO,"需要添加的数据对象"); |
| | | //将DTO转换为DO |
| | | CodeFixedValue codeFixedValueDO = new CodeFixedValue(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeFixedValueDTO,codeFixedValueDO); |
| | | //填充一些默认值 |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeFixedValueDO, MdmBtmTypeConstant.CODE_FIXED_VALUE); |
| | | Long count = this.codeFixedValueMapper.selectCount(Wrappers.<CodeFixedValue>query() |
| | | .lambda().eq(CodeFixedValue::getCodeFixedSecOid, codeFixedValueDO.getCodeFixedSecOid()) |
| | | )+1L; |
| | | codeFixedValueDO.setOrderNum(count.intValue()); |
| | | boolean resBoolean = this.codeFixedValueMapper.insert(codeFixedValueDO) > 0; |
| | | return resBoolean; |
| | | } |
| | | |
| | | /** |
| | | * 批量数据对象转换为显示对象 |
| | | * @param codeFixedValueDOs 数据对象列表 |
| | | * @return 显示对象 |
| | | * @throws VciBaseException 参数为空或者不存在的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public List<CodeFixedValueVO> codeFixedValueDO2VOs(Collection<CodeFixedValueDO> codeFixedValueDOs) throws VciBaseException{ |
| | | List<CodeFixedValueVO> voList = new ArrayList<CodeFixedValueVO>(); |
| | | if(!CollectionUtils.isEmpty(codeFixedValueDOs)){ |
| | | for(CodeFixedValueDO s: codeFixedValueDOs){ |
| | | CodeFixedValueVO vo = codeFixedValueDO2VO(s); |
| | | if(vo != null){ |
| | | voList.add(vo); |
| | | } |
| | | } |
| | | } |
| | | return voList; |
| | | } |
| | | /** |
| | | * 修改固定码段的码值 |
| | | * @param codeFixedValueDTO 固定码段的码值数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean editSave(CodeFixedValueDTO codeFixedValueDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeFixedValueDTO,"数据对象",codeFixedValueDTO.getOid(),"固定码段的码值主键"); |
| | | //将DTO转换为DO |
| | | CodeFixedValue codeFixedValueDO = selectByOid(codeFixedValueDTO.getOid()); |
| | | revisionModelUtil.copyFromDTOIgnore(codeFixedValueDTO,codeFixedValueDO); |
| | | //填充一些默认值 |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeFixedValueDO); |
| | | boolean resBoolean = codeFixedValueMapper.updateById(codeFixedValueDO) > 0; |
| | | return resBoolean; |
| | | } |
| | | |
| | | /** |
| | | * 数据对象转换为显示对象 |
| | | * @param codeFixedValueDO 数据对象 |
| | | * @return 显示对象 |
| | | * @throws VciBaseException 拷贝属性出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodeFixedValueVO codeFixedValueDO2VO(CodeFixedValueDO codeFixedValueDO) throws VciBaseException{ |
| | | CodeFixedValueVO vo = new CodeFixedValueVO(); |
| | | if(codeFixedValueDO != null){ |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeFixedValueDO,vo); |
| | | //如果有lcstatus的类的话 |
| | | /** |
| | | * 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除 |
| | | * @param codeFixedValueDTO 数据传输对象 |
| | | * @param codeFixedValueDO 数据库中的数据对象 |
| | | * @return success为true为可以删除,false表示有数据引用,obj为true表示有下级 |
| | | */ |
| | | private R checkIsCanDeleteForDO(CodeFixedValueDTO codeFixedValueDTO, CodeFixedValue codeFixedValueDO) { |
| | | //boService.checkTs(codeFixedValueDTO); |
| | | if(!checkIsLinked(codeFixedValueDO.getOid())) { |
| | | return R.status(true); |
| | | }else{ |
| | | return R.fail(DATA_LINKED_NOT_DELETE); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return vo; |
| | | } |
| | | /** |
| | | * 校验是否被引用 |
| | | * @param oid 主键 |
| | | * @throws VciBaseException 被引用的时候会抛出异常 |
| | | */ |
| | | private boolean checkIsLinked(String oid) throws VciBaseException{ |
| | | //TODO 添加需要校验引用的地方 |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 增加固定码段的码值 |
| | | * @param codeFixedValueDTO 固定码段的码值数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodeFixedValueVO addSave(CodeFixedValueDTO codeFixedValueDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeFixedValueDTO,"需要添加的数据对象"); |
| | | //将DTO转换为DO |
| | | CodeFixedValueDO codeFixedValueDO = new CodeFixedValueDO(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeFixedValueDTO,codeFixedValueDO); |
| | | codeFixedValueMapper.insert(codeFixedValueDO); |
| | | return codeFixedValueDO2VO(codeFixedValueDO); |
| | | } |
| | | /** |
| | | * 删除固定码段的码值 |
| | | * @param codeFixedValueDTO 固定码段的码值数据传输对象,oid和ts需要传输 |
| | | * @return 删除结果反馈::success:成功,fail:失败 |
| | | * @throws VciBaseException 参数为空,被引用时抛出异常 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R deleteCodeFixedValue(CodeFixedValueDTO codeFixedValueDTO) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(codeFixedValueDTO,"固定码段的码值数据对象",codeFixedValueDTO.getOid(),"固定码段的码值的主键"); |
| | | CodeFixedValue codeFixedValueDO = selectByOid(codeFixedValueDTO.getOid()); |
| | | R baseResult = checkIsCanDeleteForDO(codeFixedValueDTO,codeFixedValueDO); |
| | | if(!baseResult.isSuccess()) { |
| | | return baseResult; |
| | | } |
| | | //执行删除操作 |
| | | boolean resBoolean = codeFixedValueMapper.deleteById(codeFixedValueDO.getOid())>0; |
| | | return R.status(resBoolean); |
| | | } |
| | | |
| | | /** |
| | | * 修改固定码段的码值 |
| | | * @param codeFixedValueDTO 固定码段的码值数据传输对象 |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodeFixedValueVO editSave(CodeFixedValueDTO codeFixedValueDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeFixedValueDTO,"数据对象",codeFixedValueDTO.getOid(),"固定码段的码值主键"); |
| | | //将DTO转换为DO |
| | | CodeFixedValueDO codeFixedValueDO = selectByOid(codeFixedValueDTO.getOid()); |
| | | revisionModelUtil.copyFromDTOIgnore(codeFixedValueDTO,codeFixedValueDO); |
| | | codeFixedValueMapper.updateByPrimaryKey(codeFixedValueDO); |
| | | return codeFixedValueDO2VO(codeFixedValueDO); |
| | | } |
| | | /** |
| | | * 主键获取固定码段的码值 |
| | | * @param oid 主键 |
| | | * @return 固定码段的码值显示对象 |
| | | * @throws VciBaseException 参数为空,数据不存在时会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodeFixedValueVO getObjectByOid(String oid) throws VciBaseException{ |
| | | return CodeFixedValueWrapper.build().entityVO(selectByOid(oid)); |
| | | } |
| | | |
| | | /** |
| | | * 主键查询数据对象 |
| | | * @param oid 主键 |
| | | * @return 数据对象 |
| | | * @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常 |
| | | */ |
| | | private CodeFixedValue selectByOid(String oid) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(oid,"主键"); |
| | | CodeFixedValue codeFixedValueDO = codeFixedValueMapper.selectById(oid.trim()); |
| | | if(codeFixedValueDO == null || StringUtils.isBlank(codeFixedValueDO.getOid())){ |
| | | throw new VciBaseException(DATA_OID_NOT_EXIST); |
| | | } |
| | | return codeFixedValueDO; |
| | | } |
| | | |
| | | /** |
| | | * 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除 |
| | | * @param codeFixedValueDTO 数据传输对象 |
| | | * @param codeFixedValueDO 数据库中的数据对象 |
| | | * @return success为true为可以删除,false表示有数据引用,obj为true表示有下级 |
| | | */ |
| | | private BaseResult checkIsCanDeleteForDO(CodeFixedValueDTO codeFixedValueDTO, CodeFixedValueDO codeFixedValueDO) { |
| | | //boService.checkTs(codeFixedValueDTO); |
| | | if(!checkIsLinked(codeFixedValueDO.getOid())) { |
| | | return BaseResult.success(); |
| | | }else{ |
| | | return BaseResult.fail(DATA_LINKED_NOT_DELETE,new String[]{""}); |
| | | } |
| | | } |
| | | /** |
| | | * 主键批量获取固定码段的码值 |
| | | * @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个 |
| | | * @return 固定码段的码值显示对象 |
| | | * @throws VciBaseException 查询出现异常时会抛出 |
| | | */ |
| | | @Override |
| | | public Collection<CodeFixedValueVO> listCodeFixedValueByOids(Collection<String> oidCollections) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合"); |
| | | List<CodeFixedValue> codeFixedValueDOList = listCodeFixedValueDOByOidCollections(oidCollections); |
| | | return CodeFixedValueWrapper.build().listVO(codeFixedValueDOList); |
| | | } |
| | | |
| | | /** |
| | | * 校验是否被引用 |
| | | * @param oid 主键 |
| | | * @throws VciBaseException 被引用的时候会抛出异常 |
| | | */ |
| | | private boolean checkIsLinked(String oid) throws VciBaseException{ |
| | | //TODO 添加需要校验引用的地方 |
| | | return false; |
| | | } |
| | | /** |
| | | * 使用主键集合查询数据对象 |
| | | * @param oidCollections 主键的集合 |
| | | * @return 数据对象列表 |
| | | */ |
| | | private List<CodeFixedValue> listCodeFixedValueDOByOidCollections(Collection<String> oidCollections){ |
| | | List<CodeFixedValue> codeFixedValueDOList = new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(oidCollections)){ |
| | | Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); |
| | | for(Collection<String> oids: oidCollectionsList){ |
| | | List<CodeFixedValue> tempDOList = codeFixedValueMapper.selectBatchIds(oids); |
| | | if(!CollectionUtils.isEmpty(tempDOList)){ |
| | | codeFixedValueDOList.addAll(tempDOList); |
| | | } |
| | | } |
| | | } |
| | | return codeFixedValueDOList; |
| | | } |
| | | |
| | | /** |
| | | * 删除固定码段的码值 |
| | | * @param codeFixedValueDTO 固定码段的码值数据传输对象,oid和ts需要传输 |
| | | * @return 删除结果反馈::success:成功,fail:失败 |
| | | * @throws VciBaseException 参数为空,被引用时抛出异常 |
| | | */ |
| | | @Override |
| | | public BaseResult deleteCodeFixedValue(CodeFixedValueDTO codeFixedValueDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeFixedValueDTO,"固定码段的码值数据对象",codeFixedValueDTO.getOid(),"固定码段的码值的主键"); |
| | | CodeFixedValueDO codeFixedValueDO = selectByOid(codeFixedValueDTO.getOid()); |
| | | BaseResult baseResult = checkIsCanDeleteForDO(codeFixedValueDTO,codeFixedValueDO); |
| | | if(baseResult.isSuccess()) { |
| | | }else{ |
| | | return baseResult; |
| | | } |
| | | //执行删除操作 |
| | | BatchCBO batchCBO = codeFixedValueMapper.deleteByPrimaryKey(codeFixedValueDO.getOid()); |
| | | return (batchCBO!=null && batchCBO.getDeleteCbos() !=null &&batchCBO.getDeleteCbos().size() > 0)?BaseResult.successMsg(DELETE_SUCCESS):BaseResult.fail(DELETE_FAIL); |
| | | } |
| | | /** |
| | | * 参照固定码段的码值列表 |
| | | * @param codeFixedValueVO 查询条件 |
| | | * @param page 分页和排序 |
| | | * @return 固定码段的码值显示对象列表,生效的内容 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public IPage<CodeFixedValueVO> refDataGridCodeFixedValue(CodeFixedValueVO codeFixedValueVO,IPage<CodeFixedValueVO> page) throws VciBaseException{ |
| | | return gridCodeFixedValue(codeFixedValueVO,page); |
| | | } |
| | | |
| | | /** |
| | | * 主键获取固定码段的码值 |
| | | * @param oid 主键 |
| | | * @return 固定码段的码值显示对象 |
| | | * @throws VciBaseException 参数为空,数据不存在时会抛出异常 |
| | | */ |
| | | @Override |
| | | public CodeFixedValueVO getObjectByOid(String oid) throws VciBaseException{ |
| | | return codeFixedValueDO2VO(selectByOid(oid)); |
| | | } |
| | | /** |
| | | * 使用码段的主键获取固定码的码值 |
| | | * |
| | | * @param secOidCollection 码段的主键 |
| | | * @return 码值显示对象 |
| | | * @throws VciBaseException 查询的时候出现了错误会抛出异常 |
| | | */ |
| | | @Override |
| | | public Map<String, List<CodeFixedValueVO>> listCodeFixedValueBySecOids(Collection<String> secOidCollection) throws VciBaseException { |
| | | if(CollectionUtils.isEmpty(secOidCollection)){ |
| | | return new HashMap<>(); |
| | | } |
| | | List<CodeFixedValueVO> voList = new ArrayList<>(); |
| | | VciBaseUtil.switchCollectionForOracleIn(secOidCollection).forEach(secOids->{ |
| | | Query query = new Query(); |
| | | query.setDescs("orderNum"); |
| | | query.setSize(-1); |
| | | query.setCurrent(1); |
| | | List<CodeFixedValue> valueDOS = this.codeFixedValueMapper.selectByPageByCodeFixedSecOid(secOids,Condition.getPage(query)); |
| | | voList.addAll(CodeFixedValueWrapper.build().listVO(Optional.ofNullable(valueDOS).orElseGet(() -> new ArrayList<>()))); |
| | | }); |
| | | return voList.stream().collect(Collectors.groupingBy(CodeFixedValueVO::getCodeFixedSecOid)); |
| | | } |
| | | |
| | | /** |
| | | * 主键查询数据对象 |
| | | * @param oid 主键 |
| | | * @return 数据对象 |
| | | * @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常 |
| | | */ |
| | | private CodeFixedValueDO selectByOid(String oid) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(oid,"主键"); |
| | | CodeFixedValueDO codeFixedValueDO = codeFixedValueMapper.selectByPrimaryKey(oid.trim()); |
| | | if(codeFixedValueDO == null || StringUtils.isBlank(codeFixedValueDO.getOid())){ |
| | | throw new VciBaseException(DATA_OID_NOT_EXIST); |
| | | } |
| | | return codeFixedValueDO; |
| | | } |
| | | /** |
| | | * 批量添加固定码段的码值,如果保存的集合中不存在已在数据库中的码值则删除。主要是保存码值的序号 |
| | | * @param dtoList 固定码段的码值列表 |
| | | * @param codefixedsecoid 固定码段的主键 |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<CodeFixedValueVO> batchSave4Order(List<CodeFixedValueDTO> dtoList, String codefixedsecoid) { |
| | | VciBaseUtil.alertNotNull(codefixedsecoid,"固定码段主键"); |
| | | List<CodeFixedValue> doList = codeFixedValueMapper.selectList(Wrappers.<CodeFixedValue>query() |
| | | .lambda().eq(CodeFixedValue::getCodeFixedSecOid,codefixedsecoid) |
| | | ); |
| | | List<CodeFixedValue> updateList = new ArrayList<>(); |
| | | List<String> deleteOidList = new ArrayList<>(); |
| | | dtoList.forEach(dto -> { |
| | | if (StringUtils.isNotBlank(dto.getOid())){ |
| | | List<CodeFixedValue> valueDOList = doList.stream().filter(value -> { |
| | | return value.getOid().equals(dto.getOid()); |
| | | }).collect(Collectors.toList()); |
| | | valueDOList.forEach(valueDO -> { |
| | | valueDO.setId(dto.getId()); |
| | | valueDO.setName(dto.getName()); |
| | | valueDO.setOrderNum(dto.getOrderNum()); |
| | | updateList.add(valueDO); |
| | | }); |
| | | }else{ |
| | | throw new VciBaseException("固定码段主键不能为空"); |
| | | } |
| | | }); |
| | | if (doList.size() != dtoList.size()){ |
| | | List<String> oidList = dtoList.stream().map(CodeFixedValueDTO::getOid).collect(Collectors.toList()); |
| | | List<CodeFixedValue> deleteList = new ArrayList<>(); |
| | | for (CodeFixedValue value : doList) { |
| | | if (!oidList.contains(value.getOid())){ |
| | | deleteList.add(value); |
| | | } |
| | | } |
| | | deleteOidList = deleteList.stream().map(CodeFixedValue::getOid).collect(Collectors.toList()); |
| | | } |
| | | boolean resBooleanUpdate = this.updateBatchById(updateList); |
| | | if (!CollectionUtils.isEmpty(deleteOidList)) { |
| | | codeFixedValueMapper.deleteBatchIds(deleteOidList); |
| | | } |
| | | return R.status(resBooleanUpdate); |
| | | } |
| | | |
| | | /** |
| | | * 主键批量获取固定码段的码值 |
| | | * @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个 |
| | | * @return 固定码段的码值显示对象 |
| | | * @throws VciBaseException 查询出现异常时会抛出 |
| | | */ |
| | | @Override |
| | | public Collection<CodeFixedValueVO> listCodeFixedValueByOids(Collection<String> oidCollections) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合"); |
| | | List<CodeFixedValueDO> codeFixedValueDOList = listCodeFixedValueDOByOidCollections(oidCollections); |
| | | return codeFixedValueDO2VOs(codeFixedValueDOList); |
| | | } |
| | | /** |
| | | * 根据码段主键删除其存在的码值对象 |
| | | * @param codefixedsecoid 固定码段的主键 |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean batchDeleteBySecOid(String codefixedsecoid) { |
| | | VciBaseUtil.alertNotNull(codefixedsecoid,"固定码段主键"); |
| | | List<CodeFixedValue> doList = codeFixedValueMapper.selectList(Wrappers.<CodeFixedValue>query() |
| | | .lambda().eq(CodeFixedValue::getCodeFixedSecOid,codefixedsecoid) |
| | | ); |
| | | if(doList.isEmpty()){ |
| | | return false; |
| | | } |
| | | boolean resBoolean = codeFixedValueMapper.deleteBatchIds(doList.stream().map(CodeFixedValue::getOid).collect(Collectors.toList())) > 0; |
| | | return resBoolean; |
| | | } |
| | | |
| | | /** |
| | | * 使用主键集合查询数据对象 |
| | | * @param oidCollections 主键的集合 |
| | | * @return 数据对象列表 |
| | | */ |
| | | private List<CodeFixedValueDO> listCodeFixedValueDOByOidCollections(Collection<String> oidCollections){ |
| | | List<CodeFixedValueDO> codeFixedValueDOList = new ArrayList<CodeFixedValueDO>(); |
| | | if(!CollectionUtils.isEmpty(oidCollections)){ |
| | | Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); |
| | | for(Collection<String> oids: oidCollectionsList){ |
| | | List<CodeFixedValueDO> tempDOList = codeFixedValueMapper.selectByPrimaryKeyCollection(oids); |
| | | if(!CollectionUtils.isEmpty(tempDOList)){ |
| | | codeFixedValueDOList.addAll(tempDOList); |
| | | } |
| | | } |
| | | } |
| | | return codeFixedValueDOList; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 参照固定码段的码值列表 |
| | | * @param conditionMap 查询条件 |
| | | * @param pageHelper 分页和排序 |
| | | * @return 固定码段的码值显示对象列表,生效的内容 |
| | | * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public DataGrid<CodeFixedValueVO> refDataGridCodeFixedValue(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{ |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<String, String>(); |
| | | } |
| | | return gridCodeFixedValue(conditionMap,pageHelper); |
| | | } |
| | | |
| | | /** |
| | | * 使用码段的主键获取固定码的码值 |
| | | * |
| | | * @param secOidCollection 码段的主键 |
| | | * @return 码值显示对象 |
| | | * @throws VciBaseException 查询的时候出现了错误会抛出异常 |
| | | */ |
| | | @Override |
| | | public Map<String, List<CodeFixedValueVO>> listCodeFixedValueBySecOids(Collection<String> secOidCollection) throws VciBaseException { |
| | | if(CollectionUtils.isEmpty(secOidCollection)){ |
| | | return new HashMap<>(); |
| | | } |
| | | List<CodeFixedValueVO> voList = new ArrayList<>(); |
| | | VciBaseUtil.switchCollectionForOracleIn(secOidCollection).forEach(secOids->{ |
| | | Map<String,String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("codefixedsecoid", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(secOids.toArray(new String[0])) + ")"); |
| | | PageHelper pageHelper = new PageHelper(-1); |
| | | pageHelper.addDefaultAsc("ordernum"); |
| | | List<CodeFixedValueDO> valueDOS = codeFixedValueMapper.selectByCondition(conditionMap, pageHelper); |
| | | voList.addAll(codeFixedValueDO2VOs(Optional.ofNullable(valueDOS).orElseGet(() -> new ArrayList<>()))); |
| | | }); |
| | | return voList.stream().collect(Collectors.groupingBy(CodeFixedValueVO::getCodefixedsecoid)); |
| | | } |
| | | |
| | | /** |
| | | * 批量添加固定码段的码值,如果保存的集合中不存在已在数据库中的码值则删除。主要是保存码值的序号 |
| | | * @param dtoList 固定码段的码值列表 |
| | | * @param codefixedsecoid 固定码段的主键 |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | public BaseResult<CodeFixedValueVO> batchSave4Order(List<CodeFixedValueDTO> dtoList, String codefixedsecoid) { |
| | | VciBaseUtil.alertNotNull(codefixedsecoid,"固定码段主键"); |
| | | Map<String,String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("codefixedsecoid",codefixedsecoid); |
| | | VciQueryWrapperForDO wrapper = new VciQueryWrapperForDO(conditionMap,CodeFixedValueDO.class); |
| | | List<CodeFixedValueDO> doList = codeFixedValueMapper.selectByWrapper(wrapper); |
| | | List<CodeFixedValueDO> updateList = new ArrayList<>(); |
| | | List<String> deleteOidList = new ArrayList<>(); |
| | | dtoList.forEach(dto -> { |
| | | if (StringUtils.isNotBlank(dto.getOid())){ |
| | | List<CodeFixedValueDO> valueDOList = doList.stream().filter(value -> { |
| | | return value.getOid().equals(dto.getOid()); |
| | | }).collect(Collectors.toList()); |
| | | valueDOList.forEach(valueDO -> { |
| | | valueDO.setId(dto.getId()); |
| | | valueDO.setName(dto.getName()); |
| | | valueDO.setOrderNum(dto.getOrdernum()); |
| | | updateList.add(valueDO); |
| | | }); |
| | | }else{ |
| | | throw new VciBaseException("固定码段主键不能为空"); |
| | | } |
| | | }); |
| | | if (doList.size() != dtoList.size()){ |
| | | List<String> oidList = dtoList.stream().map(CodeFixedValueDTO::getOid).collect(Collectors.toList()); |
| | | List<CodeFixedValueDO> deleteList = new ArrayList<>(); |
| | | for (CodeFixedValueDO value : doList) { |
| | | if (!oidList.contains(value.getOid())){ |
| | | deleteList.add(value); |
| | | } |
| | | } |
| | | deleteOidList = deleteList.stream().map(CodeFixedValueDO::getOid).collect(Collectors.toList()); |
| | | } |
| | | WebUtil.setPersistence(false); |
| | | BatchCBO batchCBO = codeFixedValueMapper.batchUpdate(updateList); |
| | | if (!CollectionUtils.isEmpty(deleteOidList)) { |
| | | BatchCBO batchDeleteByOids = codeFixedValueMapper.batchDeleteByOids(deleteOidList); |
| | | batchCBO.setDeleteCbos(batchDeleteByOids.getDeleteCbos()); |
| | | } |
| | | WebUtil.setPersistence(true); |
| | | boService.persistenceBatch(batchCBO); |
| | | return BaseResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 根据码段主键删除其存在的码值对象 |
| | | * @param codefixedsecoid 固定码段的主键 |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | public BaseResult<CodeFixedValueVO> batchDeleteBySecOid(String codefixedsecoid) { |
| | | VciBaseUtil.alertNotNull(codefixedsecoid,"固定码段主键"); |
| | | Map<String,String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("codefixedvalueoid",codefixedsecoid); |
| | | VciQueryWrapperForDO wrapper = new VciQueryWrapperForDO(conditionMap,CodeFixedValueDO.class); |
| | | List<CodeFixedValueDO> doList = codeFixedValueMapper.selectByWrapper(wrapper); |
| | | codeFixedValueMapper.batchDeleteByOids(doList.stream().map(CodeFixedValueDO::getOid).collect(Collectors.toList())); |
| | | return BaseResult.success(); |
| | | } |
| | | } |
| | | |