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.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.core.JsonParser;
|
import com.vci.ubcs.code.constant.MdmBtmTypeConstant;
|
import com.vci.ubcs.code.dto.CodeClassifyProcessTempDTO;
|
import com.vci.ubcs.code.entity.CodeClassifyProcessTemp;
|
import com.vci.ubcs.code.mapper.CodeClassifyProcessTempMapper;
|
import com.vci.ubcs.code.service.ICodeClassifyProcessTempService;
|
import com.vci.ubcs.code.vo.pagemodel.CodeClassifyProcessTempVO;
|
import com.vci.ubcs.code.wrapper.CodeClassifyProcessTempWrapper;
|
import com.vci.ubcs.common.utils.PageDO2PageVO;
|
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.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 javax.annotation.Resource;
|
import java.sql.Wrapper;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.*;
|
import static com.vci.ubcs.code.constant.MdmBtmTypeConstant.CODE_CLASSIFY_PROCESS_TEMPLATE;
|
|
/**
|
* 分类使用的流程模板服务接口
|
*
|
* @author ludc
|
* @date 2023/5/5
|
*/
|
@Service
|
public class CodeClassifyProcessTempServiceImpl extends ServiceImpl<CodeClassifyProcessTempMapper, CodeClassifyProcessTemp> implements ICodeClassifyProcessTempService {
|
|
/**
|
* 数据操作层
|
*/
|
@Resource
|
private CodeClassifyProcessTempMapper codeClassifyProcessTempMapper;
|
|
/**
|
* 对象的操作
|
*/
|
@Autowired
|
private RevisionModelUtil revisionModelUtil;
|
|
/**
|
* 查询所有的分类使用的流程模板
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return 执行结果
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public IPage<CodeClassifyProcessTempVO> gridCodeClassifyProcessTemp(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException {
|
Query query = new Query();
|
if (pageHelper == null) {
|
//pageHelper = new PageHelper(-1);
|
query.setSize(-1);
|
}else {
|
query.setSize(pageHelper.getLimit());
|
query.setCurrent(pageHelper.getPage());
|
}
|
query.setDescs("createTime");
|
CodeClassifyProcessTemp codeClassifyProcessTemp = new CodeClassifyProcessTemp();
|
BeanMap beanMap = BeanMap.create(codeClassifyProcessTemp);
|
beanMap.putAll(conditionMap);
|
IPage<CodeClassifyProcessTemp> doList = codeClassifyProcessTempMapper.selectPage(Condition.getPage(query), Condition.getQueryWrapper(codeClassifyProcessTemp));
|
IPage<CodeClassifyProcessTempVO> voList = new Page<>();
|
//DataGrid<CodeClassifyProcessTempVO> dataGrid=new DataGrid<>();
|
if (!CollectionUtils.isEmpty(doList.getRecords())) {
|
voList = CodeClassifyProcessTempWrapper.build().pageVO(doList);
|
}
|
return voList;
|
}
|
|
/**
|
* 批量数据对象转换为显示对象
|
* @param codeClassifyProcessTempDOs 数据对象列表
|
* @return 显示对象
|
* @throws VciBaseException 参数为空或者不存在的时候会抛出异常
|
*/
|
@Override
|
public List<CodeClassifyProcessTempVO> codeClassifyProcessTempDO2VOs(Collection<CodeClassifyProcessTemp> codeClassifyProcessTempDOs) throws VciBaseException{
|
List<CodeClassifyProcessTempVO> voList = new ArrayList<CodeClassifyProcessTempVO>();
|
if(!CollectionUtils.isEmpty(codeClassifyProcessTempDOs)){
|
codeClassifyProcessTempDOs.forEach(temp -> {
|
CodeClassifyProcessTempVO tempVO = codeClassifyProcessTempDO2VO(temp);
|
BeanUtilForVCI.copyPropertiesIgnoreCase(temp,tempVO);
|
voList.add(tempVO);
|
});
|
}
|
return voList;
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
* @param codeClassifyProcessTempDO 数据对象
|
* @return 显示对象
|
* @throws VciBaseException 拷贝属性出错的时候会抛出异常
|
*/
|
@Override
|
public CodeClassifyProcessTempVO codeClassifyProcessTempDO2VO(CodeClassifyProcessTemp codeClassifyProcessTempDO) throws VciBaseException{
|
CodeClassifyProcessTempVO vo = new CodeClassifyProcessTempVO();
|
if(codeClassifyProcessTempDO != null){
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyProcessTempDO,vo);
|
//如果有lcstatus的类的话
|
//处理关联的模板属性
|
|
}
|
return vo;
|
}
|
|
/**
|
* 增加分类使用的流程模板
|
* @param codeClassifyProcessTempDTO 分类使用的流程模板数据传输对象
|
* @return 执行结果
|
* @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public CodeClassifyProcessTempVO addSave(CodeClassifyProcessTempDTO codeClassifyProcessTempDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeClassifyProcessTempDTO,"需要添加的数据对象",codeClassifyProcessTempDTO.getProcessVersion(),"流程模板的版本号",codeClassifyProcessTempDTO.getCodeProcessUse(),"模板流程的用途");
|
if (StringUtils.isBlank(codeClassifyProcessTempDTO.getCodeProcessUse())){
|
throw new VciBaseException("模板流程用途不能为空");
|
}
|
Long count = countProcessTemplate(codeClassifyProcessTempDTO);
|
if(count > 0){
|
throw new VciBaseException("已存在相同的流程模板");
|
}
|
//将DTO转换为DO
|
CodeClassifyProcessTemp codeClassifyProcessTempDO = new CodeClassifyProcessTemp();
|
BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyProcessTempDTO,codeClassifyProcessTempDO);
|
DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeClassifyProcessTempDO, MdmBtmTypeConstant.CODE_CLASSIFY_PROCESS_TEMPLATE);
|
codeClassifyProcessTempMapper.insert(codeClassifyProcessTempDO);
|
//因为业务类型本身没有控制版本,所有强制给版本revisionValue设置值,平台也会变成空。。。。
|
//版本号不能使用默认的属性
|
return CodeClassifyProcessTempWrapper.build().entityVO(codeClassifyProcessTempDO);
|
}
|
|
/**
|
* 修改分类使用的流程模板
|
* @param codeClassifyProcessTempDTO 分类使用的流程模板数据传输对象
|
* @return 执行结果
|
* @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public CodeClassifyProcessTempVO editSave(CodeClassifyProcessTempDTO codeClassifyProcessTempDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeClassifyProcessTempDTO,"数据对象",codeClassifyProcessTempDTO.getOid(),"分类使用的流程模板主键",codeClassifyProcessTempDTO.getProcessVersion(),"流程模板的版本号",codeClassifyProcessTempDTO.getName(),"流程模板的名称");
|
//将DTO转换为DO
|
CodeClassifyProcessTemp codeClassifyProcessTempDO = selectByOid(codeClassifyProcessTempDTO.getOid());
|
revisionModelUtil.copyFromDTOIgnore(codeClassifyProcessTempDTO,codeClassifyProcessTempDO);
|
DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeClassifyProcessTempDO);
|
codeClassifyProcessTempMapper.updateById(codeClassifyProcessTempDO);
|
return CodeClassifyProcessTempWrapper.build().entityVO(codeClassifyProcessTempDO);
|
}
|
|
/**
|
* 删除分类使用的流程模板
|
* @param codeClassifyProcessTempDTO 分类使用的流程模板数据传输对象,oid和ts需要传输
|
* @return 删除结果反馈::success:成功,fail:失败
|
* @throws VciBaseException 参数为空,被引用时抛出异常
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R deleteCodeClassifyProcessTemp(CodeClassifyProcessTempDTO codeClassifyProcessTempDTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(codeClassifyProcessTempDTO,"分类使用的流程模板数据对象",codeClassifyProcessTempDTO.getOid(),"分类使用的流程模板的主键");
|
CodeClassifyProcessTemp codeClassifyProcessTempDO = selectByOid(codeClassifyProcessTempDTO.getOid());
|
R baseResult = checkIsCanDeleteForDO(codeClassifyProcessTempDTO,codeClassifyProcessTempDO);
|
if(baseResult.isSuccess()) {
|
}else{
|
return baseResult;
|
}
|
//执行删除操作
|
boolean batchCBO = codeClassifyProcessTempMapper.deleteById(codeClassifyProcessTempDO.getOid()) > 0;
|
return batchCBO?R.success(DELETE_SUCCESS):R.fail(DELETE_FAIL);
|
}
|
|
/**
|
* 主键获取分类使用的流程模板
|
* @param oid 主键
|
* @return 分类使用的流程模板显示对象
|
* @throws VciBaseException 参数为空,数据不存在时会抛出异常
|
*/
|
@Override
|
public CodeClassifyProcessTempVO getObjectByOid(String oid) throws VciBaseException{
|
return CodeClassifyProcessTempWrapper.build().entityVO((selectByOid(oid)));
|
}
|
|
/**
|
* 主键批量获取分类使用的流程模板
|
* @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个
|
* @return 分类使用的流程模板显示对象
|
* @throws VciBaseException 查询出现异常时会抛出
|
*/
|
@Override
|
public Collection<CodeClassifyProcessTempVO> listCodeClassifyProcessTempByOids(Collection<String> oidCollections) throws VciBaseException{
|
VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合");
|
List<CodeClassifyProcessTemp> codeClassifyProcessTempDOList = listCodeClassifyProcessTempDOByOidCollections(oidCollections);
|
return CodeClassifyProcessTempWrapper.build().listVO(codeClassifyProcessTempDOList);
|
}
|
|
/**
|
* 参照分类使用的流程模板列表
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return 分类使用的流程模板显示对象列表,生效的内容
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public IPage<CodeClassifyProcessTempVO> refDataGridCodeClassifyProcessTemp(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{
|
if(conditionMap == null){
|
conditionMap = new HashMap<String, String>();
|
}
|
return gridCodeClassifyProcessTemp(conditionMap,pageHelper);
|
|
}
|
|
/**
|
* 获取流程的模板的信息
|
*
|
* @param codeTemplateOid 模板的主键
|
* @param processUse 用途
|
* @return 模板的信息
|
*/
|
@Override
|
public List<CodeClassifyProcessTempVO> listProcessTemplate(String codeTemplateOid, String processUse) {
|
if(StringUtils.isBlank(codeTemplateOid) || StringUtils.isBlank(processUse)){
|
return new ArrayList<>();
|
}
|
Map<String,String> conditionMap =new HashMap<>();
|
conditionMap.put("classifyTemplateOid",codeTemplateOid);
|
conditionMap.put("codeprocessuse",processUse);
|
LambdaQueryWrapper<CodeClassifyProcessTemp> wrapper = Wrappers.<CodeClassifyProcessTemp>query()
|
.lambda().eq(CodeClassifyProcessTemp::getClassifyTemplateOid, codeTemplateOid)
|
.eq(CodeClassifyProcessTemp::getCodeProcessUse, processUse);
|
return CodeClassifyProcessTempWrapper.build().listVO(codeClassifyProcessTempMapper.selectList(wrapper));
|
}
|
|
/**
|
* 使用查询封装器来查询
|
* @param queryWrapper 查询封装器
|
* @return 数据对象
|
*/
|
@Override
|
public List<CodeClassifyProcessTempVO> selectByWrapper(LambdaQueryWrapper<CodeClassifyProcessTemp> queryWrapper) {
|
List<CodeClassifyProcessTemp> codeClassifyProcessTempDOList= codeClassifyProcessTempMapper.selectList(queryWrapper);
|
return CodeClassifyProcessTempWrapper.build().listVO(codeClassifyProcessTempDOList);
|
}
|
|
/**
|
* 使用主键集合查询数据对象
|
* @param oidCollections 主键的集合
|
* @return 数据对象列表
|
*/
|
private List<CodeClassifyProcessTemp> listCodeClassifyProcessTempDOByOidCollections(Collection<String> oidCollections){
|
List<CodeClassifyProcessTemp> codeClassifyProcessTempDOList = new ArrayList<CodeClassifyProcessTemp>();
|
if(!CollectionUtils.isEmpty(oidCollections)){
|
Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections);
|
for(Collection<String> oids: oidCollectionsList){
|
//List<CodeClassifyProcessTemp> tempDOList = codeClassifyProcessTempMapper.selectByPrimaryKeyCollection(oids);
|
List<CodeClassifyProcessTemp> tempDOList = codeClassifyProcessTempMapper.selectBatchIds(oids);
|
if(!CollectionUtils.isEmpty(tempDOList)){
|
codeClassifyProcessTempDOList.addAll(tempDOList);
|
}
|
}
|
}
|
return codeClassifyProcessTempDOList;
|
}
|
|
/**
|
* 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除
|
* @param codeClassifyProcessTempDTO 数据传输对象
|
* @param codeClassifyProcessTempDO 数据库中的数据对象
|
* @return success为true为可以删除,false表示有数据引用,obj为true表示有下级
|
*/
|
private R checkIsCanDeleteForDO(CodeClassifyProcessTempDTO codeClassifyProcessTempDTO, CodeClassifyProcessTemp codeClassifyProcessTempDO) {
|
CodeClassifyProcessTemp tempDO = new CodeClassifyProcessTemp();
|
BeanUtil.convert(codeClassifyProcessTempDTO,tempDO);
|
if (!checkTs(tempDO,codeClassifyProcessTempDO)) {
|
return R.fail(TS_NOT_PROCESS);
|
}
|
if(!checkIsLinked(codeClassifyProcessTempDO.getOid())) {
|
return R.success("success");
|
}else{
|
return R.fail(DATA_LINKED_NOT_DELETE);
|
}
|
}
|
|
/**
|
* 检查ts
|
* @param tempDO
|
* @return
|
*/
|
private boolean checkTs(CodeClassifyProcessTemp tempDO, CodeClassifyProcessTemp codeClassifyProcessTempDO){
|
Date dbTs = codeClassifyProcessTempDO.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 oid 主键
|
* @return 数据对象
|
* @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常
|
*/
|
private CodeClassifyProcessTemp selectByOid(String oid) throws VciBaseException{
|
VciBaseUtil.alertNotNull(oid,"主键");
|
CodeClassifyProcessTemp codeClassifyProcessTempDO = codeClassifyProcessTempMapper.selectById(oid.trim());
|
if(codeClassifyProcessTempDO == null || StringUtils.isBlank(codeClassifyProcessTempDO.getOid())){
|
throw new VciBaseException(DATA_OID_NOT_EXIST);
|
}
|
return codeClassifyProcessTempDO;
|
}
|
|
/**
|
* 获取流程模板是否已经存在了
|
* @param codeClassifyProcessTempDTO 数据传输对象
|
* @return 个数
|
*/
|
private Long countProcessTemplate(CodeClassifyProcessTempDTO codeClassifyProcessTempDTO) {
|
String templateName = codeClassifyProcessTempDTO.getName();
|
if (StringUtils.isBlank(templateName)){
|
throw new VciBaseException("模板流程名称不能为空");
|
}
|
LambdaQueryWrapper<CodeClassifyProcessTemp> wrapper = Wrappers.<CodeClassifyProcessTemp>query()
|
.lambda().eq(CodeClassifyProcessTemp::getCodeProcessUse, codeClassifyProcessTempDTO.getCodeProcessUse())
|
.eq(CodeClassifyProcessTemp::getClassifyTemplateOid, codeClassifyProcessTempDTO.getClassifyTemplateOid())
|
.eq(CodeClassifyProcessTemp::getId, codeClassifyProcessTempDTO.getId());
|
Long count = codeClassifyProcessTempMapper.selectCount(wrapper);
|
return count;
|
}
|
|
}
|