| | |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | import com.by4cloud.platformx.business.entity.*; |
| | | import com.by4cloud.platformx.business.mapper.*; |
| | | import com.by4cloud.platformx.business.service.ContractService; |
| | | import com.by4cloud.platformx.business.utils.ContractNumberGenerator; |
| | | import com.by4cloud.platformx.business.utils.ItemGeneratorUtil; |
| | | import com.by4cloud.platformx.business.vo.ContractDetailVo; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | |
| | | private final RemoteDeptService remoteDeptService; |
| | | private final ContractDelayOutMapper contractDelayOutMapper; |
| | | private final ErpRequestRecordMapper erpRequestRecordMapper; |
| | | private final StringRedisTemplate redisTemplate; |
| | | |
| | | @Value("${erp.ymj}") |
| | | private String ymjErp; |
| | | |
| | | @Value("${erp.ymjToken}") |
| | | private String ymjToken; |
| | | |
| | | @Value("${erp.smj}") |
| | | private String smjErp; |
| | |
| | | Contract contract = BeanUtil.copyProperties(addDTO, Contract.class); |
| | | contract.setPartyBId(SecurityUtils.getUser().getCompId()); |
| | | contract.setPartyB(SecurityUtils.getUser().getCompName()); |
| | | contract.setContractNo(ContractNumberGenerator.generateContractNumber()); |
| | | |
| | | contract.setPaidAmount(new BigDecimal("0")); |
| | | contract.setBillingStatus("0"); |
| | | contract.setErpPushFlag("0"); |
| | |
| | | |
| | | } |
| | | } |
| | | List<Contract> contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo())); |
| | | while (ArrayUtil.isNotEmpty(contracts.toArray())) { |
| | | contract.setContractNo(ContractNumberGenerator.generateContractNumber()); |
| | | contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo())); |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)){ |
| | | contract.setContractNo(generateSMJContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",sgb)){ |
| | | contract.setContractNo(generateGYBContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",ymj)){ |
| | | contract.setContractNo(generateYMJContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",tfgs)){ |
| | | contract.setContractNo(generateTFContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",jxc)){ |
| | | contract.setContractNo(generateJXCContractNo()); |
| | | } |
| | | |
| | | baseMapper.insert(contract); |
| | | |
| | | if (ArrayUtil.isNotEmpty(addDTO.getContractSubjectMatter())) { |
| | |
| | | return R.failed("当前状态无法修改合同"); |
| | | } |
| | | Contract contract = BeanUtil.copyProperties(updateDTO, Contract.class); |
| | | contract.setContractNo(ContractNumberGenerator.generateContractNumber()); |
| | | contract.setBillingStatus("0"); |
| | | contract.setErpPushFlag("0"); |
| | | contract.setPaidAmount(new BigDecimal("0")); |
| | | List<Contract> contracts; |
| | | contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo())); |
| | | while (ArrayUtil.isNotEmpty(contracts.toArray())) { |
| | | contract.setContractNo(ContractNumberGenerator.generateContractNumber()); |
| | | contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo())); |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)){ |
| | | contract.setContractNo(generateSMJContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",sgb)){ |
| | | contract.setContractNo(generateGYBContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",ymj)){ |
| | | contract.setContractNo(generateYMJContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",tfgs)){ |
| | | contract.setContractNo(generateTFContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",jxc)){ |
| | | contract.setContractNo(generateJXCContractNo()); |
| | | } |
| | | if (ObjUtil.isNotNull(updateDTO.getDeliveryCycle())){ |
| | | contract.setExpirationDate(DateUtil.offsetDay(updateDTO.getSignDate(),updateDTO.getDeliveryCycle())); |
| | |
| | | request.put("details",subjectMatter); |
| | | } |
| | | log.info("一煤机合同推送erp入参:{}",request.toJSONString()); |
| | | String result = HttpUtil.post(ymjErp,request.toJSONString()); |
| | | log.info("一煤机合同推送erp回参:{}",result); |
| | | HttpResponse response = HttpRequest.post(ymjErp) |
| | | .header("token", ymjToken) // 添加认证头 |
| | | .header("Content-Type", "application/json") // 设置内容类型 |
| | | .body(request.toJSONString()) // 设置请求体 |
| | | .execute(); // 执行请求.post(ymjErp,request.toJSONString()); |
| | | log.info("一煤机合同推送erp回参:{}",response.body()); |
| | | //保存请求记录 |
| | | saveErpRequestRecord("ymj",request.toJSONString(),result); |
| | | saveErpRequestRecord("ymj",request.toJSONString(),response.body()); |
| | | //更新合同erp推送标识 |
| | | contract.setErpPushFlag("1"); |
| | | baseMapper.updateById(contract); |
| | |
| | | public R copyNewContract(Long id) { |
| | | Contract oldContract = baseMapper.selectById(id); |
| | | Contract newContract = BeanUtil.copyProperties(oldContract, Contract.class, "id", "createTime"); |
| | | newContract.setContractNo(ContractNumberGenerator.generateContractNumber()); |
| | | newContract.setPaidAmount(new BigDecimal("0")); |
| | | newContract.setBillingStatus("0"); |
| | | newContract.setErpPushFlag("0"); |
| | | newContract.setContractStatus(0); |
| | | List<Contract> contracts; |
| | | contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, newContract.getContractNo())); |
| | | while (ArrayUtil.isNotEmpty(contracts.toArray())) { |
| | | newContract.setContractNo(ContractNumberGenerator.generateContractNumber()); |
| | | contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, newContract.getContractNo())); |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)){ |
| | | newContract.setContractNo(generateSMJContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",sgb)){ |
| | | newContract.setContractNo(generateGYBContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",ymj)){ |
| | | newContract.setContractNo(generateYMJContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",tfgs)){ |
| | | newContract.setContractNo(generateTFContractNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",jxc)){ |
| | | newContract.setContractNo(generateJXCContractNo()); |
| | | } |
| | | baseMapper.insert(newContract); |
| | | List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, id)); |
| | |
| | | return R.failed("付款阶段比例异常"); |
| | | } |
| | | Contract contract = BeanUtil.copyProperties(addDTO, Contract.class); |
| | | contract.setErpContractNo(contract.getContractNo()); |
| | | contract.setPartyBId(SecurityUtils.getUser().getCompId()); |
| | | contract.setPartyB(SecurityUtils.getUser().getCompName()); |
| | | contract.setContractStatus(2); |
| | |
| | | if (ObjUtil.isNotNull(addDTO.getDeliveryCycle())){ |
| | | contract.setExpirationDate(DateUtil.offsetDay(addDTO.getSignDate(),addDTO.getDeliveryCycle())); |
| | | } |
| | | |
| | | contract.setContractNo(generateGYBContractNo()); |
| | | |
| | | if (!StrUtil.equals(addDTO.getContractCategory(), "water_house")){ |
| | | // 假设 list 是你的 List<ContractSubjectMatterAddDTO> |
| | | Optional<ContractSubjectMatterAddDTO> maxDateObj = addDTO.getContractSubjectMatter().stream() |
| | |
| | | return VALID_STAGES.equals(actualStageSet); |
| | | } |
| | | |
| | | /** |
| | | * 生成格式为: yyyyMMdd + 4位序列号 (例如: 20260629000001) |
| | | */ |
| | | public String generateSMJContractNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | | // 2. 构建 Redis Key,按天隔离,例如: order:no:20260629 |
| | | String key = "ZB-SMJ:" + dateStr; |
| | | |
| | | // 3. Redis 原子递增,设置过期时间为2天(防止Key堆积,同时覆盖跨天边界情况) |
| | | Long sequence = redisTemplate.opsForValue().increment(key, 1); |
| | | redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS); |
| | | |
| | | // 4. 格式化序列号,不足6位前补0 |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-SMJ-"+dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateYMJContractNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | | // 2. 构建 Redis Key,按天隔离,例如: order:no:20260629 |
| | | String key = "ZB-YMJ:" + dateStr; |
| | | |
| | | // 3. Redis 原子递增,设置过期时间为2天(防止Key堆积,同时覆盖跨天边界情况) |
| | | Long sequence = redisTemplate.opsForValue().increment(key, 1); |
| | | redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS); |
| | | |
| | | // 4. 格式化序列号,不足6位前补0 |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-YMJ-"+dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateJXCContractNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | | // 2. 构建 Redis Key,按天隔离,例如: order:no:20260629 |
| | | String key = "ZB-JXC:" + dateStr; |
| | | |
| | | // 3. Redis 原子递增,设置过期时间为2天(防止Key堆积,同时覆盖跨天边界情况) |
| | | Long sequence = redisTemplate.opsForValue().increment(key, 1); |
| | | redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS); |
| | | |
| | | // 4. 格式化序列号,不足6位前补0 |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-JXC-"+dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateTFContractNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | | // 2. 构建 Redis Key,按天隔离,例如: order:no:20260629 |
| | | String key = "ZB-TF:" + dateStr; |
| | | |
| | | // 3. Redis 原子递增,设置过期时间为2天(防止Key堆积,同时覆盖跨天边界情况) |
| | | Long sequence = redisTemplate.opsForValue().increment(key, 1); |
| | | redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS); |
| | | |
| | | // 4. 格式化序列号,不足6位前补0 |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-TF-"+dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateGYBContractNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | | // 2. 构建 Redis Key,按天隔离,例如: order:no:20260629 |
| | | String key = "ZB-GYB:" + dateStr; |
| | | |
| | | // 3. Redis 原子递增,设置过期时间为2天(防止Key堆积,同时覆盖跨天边界情况) |
| | | Long sequence = redisTemplate.opsForValue().increment(key, 1); |
| | | redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS); |
| | | |
| | | // 4. 格式化序列号,不足6位前补0 |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-GYB-"+dateStr + seqStr; |
| | | } |
| | | |
| | | } |