|
|
|
|
@@ -0,0 +1,352 @@
|
|
|
|
|
|
|
|
|
|
package com.yunzhupaas.cm.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.yunzhupaas.cm.entity.*;
|
|
|
|
|
import com.yunzhupaas.cm.mapper.ContractTempMapper;
|
|
|
|
|
import com.yunzhupaas.cm.service.*;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.yunzhupaas.cm.model.contracttemp.*;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.yunzhupaas.base.service.SuperServiceImpl;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import com.yunzhupaas.util.GeneraterSwapUtil;
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
import lombok.Cleanup;
|
|
|
|
|
import com.yunzhupaas.database.plugins.DynamicSourceGeneratorInterface;
|
|
|
|
|
import com.yunzhupaas.database.util.DynamicDataSourceUtil;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import com.yunzhupaas.i18n.util.I18nUtil;
|
|
|
|
|
import com.yunzhupaas.exception.DataException;
|
|
|
|
|
import com.yunzhupaas.constant.MsgCode;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.TableName;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import com.yunzhupaas.base.model.ColumnDataModel;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import com.yunzhupaas.model.QueryAllModel;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import com.yunzhupaas.util.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import com.yunzhupaas.base.UserInfo;
|
|
|
|
|
import com.yunzhupaas.permission.entity.UserEntity;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 合同模版管理
|
|
|
|
|
* 版本: V5.2.7
|
|
|
|
|
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
|
|
|
|
* 作者: 深圳市乐程软件有限公司
|
|
|
|
|
* 日期: 2026-05-21
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class ContractTempServiceImpl extends SuperServiceImpl<ContractTempMapper, ContractTempEntity> implements ContractTempService{
|
|
|
|
|
@Autowired
|
|
|
|
|
private GeneraterSwapUtil generaterSwapUtil;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserProvider userProvider;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ContractPrintingTempService contractPrintingTempService;
|
|
|
|
|
@Override
|
|
|
|
|
public List<ContractTempEntity> getList(ContractTempPagination contractTempPagination){
|
|
|
|
|
return getTypeList(contractTempPagination,contractTempPagination.getDataType());
|
|
|
|
|
}
|
|
|
|
|
/** 列表查询 */
|
|
|
|
|
@Override
|
|
|
|
|
public List<ContractTempEntity> getTypeList(ContractTempPagination contractTempPagination,String dataType){
|
|
|
|
|
String userId=userProvider.get().getUserId();
|
|
|
|
|
Map<String,Class> tableClassMap=new HashMap<>();
|
|
|
|
|
tableClassMap.put("cm_contract_temp",ContractTempEntity.class);
|
|
|
|
|
tableClassMap.put("cm_contract_printing_temp",ContractPrintingTempEntity.class);
|
|
|
|
|
|
|
|
|
|
MPJLambdaWrapper<ContractTempEntity> wrapper = JoinWrappers
|
|
|
|
|
.lambda("cm_contract_temp",ContractTempEntity.class)
|
|
|
|
|
.selectCollection(ContractPrintingTempEntity.class,ContractTempEntity::getContractPrintingTemp)
|
|
|
|
|
.leftJoin(ContractPrintingTempEntity.class,"cm_contract_printing_temp",ContractPrintingTempEntity::getContractTempId,ContractTempEntity::getContractTempCode)
|
|
|
|
|
.selectAll(ContractTempEntity.class);
|
|
|
|
|
MPJLambdaWrapper<ContractTempEntity> wrapper2 = JoinWrappers
|
|
|
|
|
.lambda("cm_contract_temp",ContractTempEntity.class)
|
|
|
|
|
.leftJoin(ContractPrintingTempEntity.class,"cm_contract_printing_temp",ContractPrintingTempEntity::getContractTempId,ContractTempEntity::getContractTempCode)
|
|
|
|
|
.distinct().select(ContractTempEntity::getContractTempId);
|
|
|
|
|
|
|
|
|
|
QueryAllModel queryAllModel = new QueryAllModel();
|
|
|
|
|
queryAllModel.setWrapper(wrapper);
|
|
|
|
|
queryAllModel.setClassMap(tableClassMap);
|
|
|
|
|
queryAllModel.setDbLink(ContractTempConstant.DBLINKID);
|
|
|
|
|
//数据过滤
|
|
|
|
|
boolean isPc = ServletUtil.getHeader("yunzhupaas-origin").equals("pc");
|
|
|
|
|
String columnData = !isPc ? ContractTempConstant.getAppColumnData() : ContractTempConstant.getColumnData();
|
|
|
|
|
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class);
|
|
|
|
|
String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList());
|
|
|
|
|
queryAllModel.setRuleJson(ruleJson);
|
|
|
|
|
//高级查询
|
|
|
|
|
boolean hasSuperQuery = true;
|
|
|
|
|
if (hasSuperQuery) {
|
|
|
|
|
queryAllModel.setSuperJson(contractTempPagination.getSuperQueryJson());
|
|
|
|
|
}
|
|
|
|
|
//数据权限
|
|
|
|
|
boolean pcPermission = false;
|
|
|
|
|
boolean appPermission = false;
|
|
|
|
|
if (isPc && pcPermission) {
|
|
|
|
|
queryAllModel.setModuleId(contractTempPagination.getMenuId());
|
|
|
|
|
}
|
|
|
|
|
if (!isPc && appPermission) {
|
|
|
|
|
queryAllModel.setModuleId(contractTempPagination.getMenuId());
|
|
|
|
|
}
|
|
|
|
|
//拼接复杂条件
|
|
|
|
|
wrapper = generaterSwapUtil.getConditionAllTable(queryAllModel);
|
|
|
|
|
if(wrapper == null) return new ArrayList<>();
|
|
|
|
|
queryAllModel.setWrapper(wrapper2);
|
|
|
|
|
wrapper2 = generaterSwapUtil.getConditionAllTable(queryAllModel);
|
|
|
|
|
//其他条件拼接
|
|
|
|
|
otherConditions(contractTempPagination, wrapper, isPc);
|
|
|
|
|
otherConditions(contractTempPagination, wrapper2, isPc);
|
|
|
|
|
|
|
|
|
|
if("0".equals(dataType)){
|
|
|
|
|
com.github.pagehelper.Page<Object> objects = PageHelper.startPage((int) contractTempPagination.getCurrentPage(), (int) contractTempPagination.getPageSize(), true);
|
|
|
|
|
List<ContractTempEntity> userIPage = this.selectJoinList(ContractTempEntity.class, wrapper2);
|
|
|
|
|
List<Object> collect = userIPage.stream().map(t -> t.getContractTempId()).collect(Collectors.toList());
|
|
|
|
|
if(CollectionUtils.isNotEmpty(collect)){
|
|
|
|
|
wrapper.in(ContractTempEntity::getContractTempId,collect);
|
|
|
|
|
}
|
|
|
|
|
List<ContractTempEntity> result = this.selectJoinList(ContractTempEntity.class, wrapper);
|
|
|
|
|
return contractTempPagination.setData(result,objects.getTotal());
|
|
|
|
|
}else{
|
|
|
|
|
List<ContractTempEntity> list = this.selectJoinList(ContractTempEntity.class, wrapper);
|
|
|
|
|
if("2".equals(dataType)){
|
|
|
|
|
List<Object> selectIds = Arrays.asList(contractTempPagination.getSelectIds());
|
|
|
|
|
return list.stream().filter(t -> selectIds.contains(t.getContractTempId())).collect(Collectors.toList());
|
|
|
|
|
}else{
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 其他条件拼接
|
|
|
|
|
*/
|
|
|
|
|
private void otherConditions(ContractTempPagination contractTempPagination, MPJLambdaWrapper<ContractTempEntity> wrapper, boolean isPc) {
|
|
|
|
|
String databaseName;
|
|
|
|
|
try {
|
|
|
|
|
@Cleanup Connection cnn = DynamicDataSourceUtil.getCurrentConnection();
|
|
|
|
|
databaseName = cnn.getMetaData().getDatabaseProductName().trim();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataException(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
wrapper.isNull(ContractTempEntity::getFlowId);
|
|
|
|
|
//关键词
|
|
|
|
|
if(ObjectUtil.isNotEmpty(contractTempPagination.getYunzhupaasKeyword())){
|
|
|
|
|
}
|
|
|
|
|
//普通查询
|
|
|
|
|
//排序
|
|
|
|
|
if(StringUtil.isEmpty(contractTempPagination.getSidx())){
|
|
|
|
|
wrapper.orderByDesc(ContractTempEntity::getContractTempId);
|
|
|
|
|
}else{
|
|
|
|
|
try {
|
|
|
|
|
String[] split = contractTempPagination.getSidx().split(",");
|
|
|
|
|
for(String sidx:split){
|
|
|
|
|
ContractTempEntity contractTempEntity = new ContractTempEntity();
|
|
|
|
|
String oderTableField = contractTempEntity.getClass().getAnnotation(TableName.class).value();
|
|
|
|
|
boolean descFlag = sidx.startsWith("-");
|
|
|
|
|
String sidxField = descFlag ? sidx.substring(1) : sidx;
|
|
|
|
|
try{
|
|
|
|
|
Field declaredField = contractTempEntity.getClass().getDeclaredField(sidxField);
|
|
|
|
|
declaredField.setAccessible(true);
|
|
|
|
|
sidxField = declaredField.getAnnotation(TableField.class).value();
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
}
|
|
|
|
|
String finalOderTableField = oderTableField;
|
|
|
|
|
String finalSidxField = sidxField;
|
|
|
|
|
Object select = wrapper.getSelectColumns().stream().filter(t -> Objects.equals(finalOderTableField, t.getTableAlias())
|
|
|
|
|
&& Objects.equals(finalSidxField, t.getColumn())).findFirst().orElse(null);
|
|
|
|
|
oderTableField = oderTableField + "." + sidxField;
|
|
|
|
|
if (select == null) {
|
|
|
|
|
wrapper.select(oderTableField);
|
|
|
|
|
}
|
|
|
|
|
if (descFlag) {
|
|
|
|
|
wrapper.orderByDesc(oderTableField);
|
|
|
|
|
} else {
|
|
|
|
|
wrapper.orderByAsc(oderTableField);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public ContractTempEntity getInfo(String contracttempid){
|
|
|
|
|
MPJLambdaWrapper<ContractTempEntity> wrapper = JoinWrappers
|
|
|
|
|
.lambda("cm_contract_temp",ContractTempEntity.class)
|
|
|
|
|
.selectCollection(ContractPrintingTempEntity.class,ContractTempEntity::getContractPrintingTemp)
|
|
|
|
|
.leftJoin(ContractPrintingTempEntity.class,"cm_contract_printing_temp",ContractPrintingTempEntity::getContractTempId,ContractTempEntity::getContractTempCode)
|
|
|
|
|
.selectAll(ContractTempEntity.class);
|
|
|
|
|
wrapper.and(
|
|
|
|
|
t->t.eq(ContractTempEntity::getContractTempId, contracttempid )
|
|
|
|
|
.or().eq(ContractTempEntity::getFlowTaskId, contracttempid)
|
|
|
|
|
);
|
|
|
|
|
return this.selectJoinOne(ContractTempEntity.class,wrapper);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void create(ContractTempEntity entity){
|
|
|
|
|
this.save(entity);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public boolean update(String contracttempid, ContractTempEntity entity){
|
|
|
|
|
return this.updateById(entity);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(ContractTempEntity entity){
|
|
|
|
|
if(entity!=null){
|
|
|
|
|
this.removeById(entity.getContractTempId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** 验证表单唯一字段,正则,非空 i-0新增-1修改*/
|
|
|
|
|
@Override
|
|
|
|
|
public String checkForm(ContractTempForm form,int i) {
|
|
|
|
|
boolean isUp =StringUtil.isNotEmpty(form.getContractTempId()) && !form.getContractTempId().equals("0");
|
|
|
|
|
Object id= null;
|
|
|
|
|
String countRecover = "";
|
|
|
|
|
String fieldTipName = "";
|
|
|
|
|
String canNotNull = I18nUtil.getMessageStr("sys.validate.textRequiredSuffix", "不能为空");
|
|
|
|
|
String canNotRepeated = I18nUtil.getMessageStr("EXIST103", "不能重复");
|
|
|
|
|
if (isUp){
|
|
|
|
|
id = form.getContractTempId();
|
|
|
|
|
}
|
|
|
|
|
//验证业务主键
|
|
|
|
|
String businessErr = checkBusinessKey(form, isUp ? id : null, null);
|
|
|
|
|
if (StringUtil.isNotEmpty(businessErr)) {
|
|
|
|
|
return businessErr;
|
|
|
|
|
}
|
|
|
|
|
//主表字段验证
|
|
|
|
|
fieldTipName = "合同模版编码";
|
|
|
|
|
if(StringUtil.isEmpty(form.getContractTempCode())){
|
|
|
|
|
return fieldTipName + canNotNull;
|
|
|
|
|
}
|
|
|
|
|
if(StringUtil.isNotEmpty(form.getContractTempCode())){
|
|
|
|
|
form.setContractTempCode(form.getContractTempCode().trim());
|
|
|
|
|
QueryWrapper<ContractTempEntity> contract_temp_codeWrapper=new QueryWrapper<>();
|
|
|
|
|
contract_temp_codeWrapper.lambda().eq(ContractTempEntity::getContractTempCode,form.getContractTempCode());
|
|
|
|
|
contract_temp_codeWrapper.lambda().isNull(ContractTempEntity::getFlowId);
|
|
|
|
|
if (isUp){
|
|
|
|
|
contract_temp_codeWrapper.lambda().ne(ContractTempEntity::getContractTempId, id);
|
|
|
|
|
}
|
|
|
|
|
if((int) this.count(contract_temp_codeWrapper)>0){
|
|
|
|
|
countRecover = fieldTipName + canNotRepeated;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fieldTipName = "合同模版名称";
|
|
|
|
|
if(StringUtil.isEmpty(form.getContractTempName())){
|
|
|
|
|
return fieldTipName + canNotNull;
|
|
|
|
|
}
|
|
|
|
|
fieldTipName = "备注";
|
|
|
|
|
fieldTipName = "框架合同";
|
|
|
|
|
fieldTipName = "清单合同";
|
|
|
|
|
fieldTipName = "启用产品清单";
|
|
|
|
|
fieldTipName = "启用材料清单";
|
|
|
|
|
fieldTipName = "启用人力清单";
|
|
|
|
|
fieldTipName = "启用资产清单";
|
|
|
|
|
fieldTipName = "启用任务清单";
|
|
|
|
|
fieldTipName = "合同类型";
|
|
|
|
|
fieldTipName = "启用在线打印";
|
|
|
|
|
fieldTipName = "我方签约类型";
|
|
|
|
|
fieldTipName = "乙方签约类型";
|
|
|
|
|
fieldTipName = "丙方签约类型";
|
|
|
|
|
//子表字段验证
|
|
|
|
|
if (form.getContractPrintingTempList()!=null){
|
|
|
|
|
|
|
|
|
|
fieldTipName = "打印模板"
|
|
|
|
|
+ "-" + "打印模版ID";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldTipName = "打印模板"
|
|
|
|
|
+ "-" + "是否启用";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return countRecover;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 验证业务主键
|
|
|
|
|
*/
|
|
|
|
|
private String checkBusinessKey(ContractTempForm form, Object id, List<String> flowIds){
|
|
|
|
|
QueryWrapper<ContractTempEntity> wrapper = new QueryWrapper<>();
|
|
|
|
|
//修改
|
|
|
|
|
if (id != null){
|
|
|
|
|
wrapper.lambda().ne(ContractTempEntity::getContractTempId, id);
|
|
|
|
|
}
|
|
|
|
|
//是否流程
|
|
|
|
|
if(flowIds == null){
|
|
|
|
|
wrapper.lambda().isNull(ContractTempEntity::getFlowId);
|
|
|
|
|
}else{
|
|
|
|
|
wrapper.lambda().in(ContractTempEntity::getFlowId, flowIds);
|
|
|
|
|
}
|
|
|
|
|
//合同模版编码字段判断
|
|
|
|
|
if(form.getContractTempCode() == null || form.getContractTempCode().toString().trim().isEmpty()){
|
|
|
|
|
wrapper.lambda().isNull(ContractTempEntity::getContractTempCode);
|
|
|
|
|
}else{
|
|
|
|
|
wrapper.lambda().eq(ContractTempEntity::getContractTempCode, form.getContractTempCode());
|
|
|
|
|
}
|
|
|
|
|
if((int) this.count(wrapper)>0){
|
|
|
|
|
return "数据已存在,请勿重复提交!";
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 新增修改数据(事务回滚)
|
|
|
|
|
* @param id
|
|
|
|
|
* @param contractTempForm
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void saveOrUpdate(ContractTempForm contractTempForm,String id, boolean isSave) throws Exception{
|
|
|
|
|
UserInfo userInfo=userProvider.get();
|
|
|
|
|
UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId());
|
|
|
|
|
contractTempForm = JsonUtil.getJsonToBean(
|
|
|
|
|
generaterSwapUtil.swapDatetime(ContractTempConstant.getFormData(),contractTempForm,ContractTempConstant.TABLERENAMES),ContractTempForm.class);
|
|
|
|
|
ContractTempEntity entity = JsonUtil.getJsonToBean(contractTempForm, ContractTempEntity.class);
|
|
|
|
|
String mainUuid = StringUtil.isEmpty(id) ? RandomUtil.uuId() : id;
|
|
|
|
|
if(isSave){
|
|
|
|
|
entity.setFlowTaskId(mainUuid);
|
|
|
|
|
entity.setContractTempId(mainUuid);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
boolean b = this.saveOrUpdate(entity);
|
|
|
|
|
ContractTempEntity info = this.getInfo(mainUuid);
|
|
|
|
|
if (info == null) throw new RuntimeException(MsgCode.FA001.get());
|
|
|
|
|
|
|
|
|
|
//ContractPrintingTemp子表数据新增修改
|
|
|
|
|
QueryWrapper<ContractPrintingTempEntity> ContractPrintingTempqueryWrapper = new QueryWrapper<>();
|
|
|
|
|
ContractPrintingTempqueryWrapper.lambda().eq(ContractPrintingTempEntity::getContractTempId, info.getContractTempCode());
|
|
|
|
|
if(!isSave && !CollectionUtils.isNotEmpty(contractTempForm.getContractPrintingTempList())){
|
|
|
|
|
contractPrintingTempService.remove(ContractPrintingTempqueryWrapper);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(contractTempForm.getContractPrintingTempList())){
|
|
|
|
|
List<ContractPrintingTempEntity> tablePrintingTemp = JsonUtil.getJsonToList(contractTempForm.getContractPrintingTempList(),ContractPrintingTempEntity.class);
|
|
|
|
|
//移除的数据
|
|
|
|
|
List<Object> childIds = tablePrintingTemp.stream().filter(t->t.getContractPrintingTempId()!=null).map(ContractPrintingTempEntity::getContractPrintingTempId).collect(Collectors.toList());
|
|
|
|
|
if(CollectionUtils.isNotEmpty(childIds)){
|
|
|
|
|
ContractPrintingTempqueryWrapper.lambda().notIn(ContractPrintingTempEntity::getContractPrintingTempId,childIds);
|
|
|
|
|
}
|
|
|
|
|
contractPrintingTempService.remove(ContractPrintingTempqueryWrapper);
|
|
|
|
|
for(ContractPrintingTempEntity entitys : tablePrintingTemp){
|
|
|
|
|
entitys.setContractTempId(entity.getContractTempCode());
|
|
|
|
|
if(entitys.getContractPrintingTempId()==null){
|
|
|
|
|
entitys.setContractPrintingTempId(RandomUtil.uuId());
|
|
|
|
|
}
|
|
|
|
|
contractPrintingTempService.saveOrUpdate(entitys);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|