|
|
@@ -1,17 +1,21 @@
|
|
|
package com.sckw.contract.service;
|
|
|
|
|
|
+import java.io.*;
|
|
|
+import java.net.URL;
|
|
|
import java.util.Date;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.sckw.contract.dao.KwcContractLogisticsMapper;
|
|
|
import com.sckw.contract.dubbo.RemoteContractServiceImpl;
|
|
|
+import com.sckw.contract.model.dto.req.EsignGetFlowReqDto;
|
|
|
import com.sckw.contract.model.dto.req.QueryListReqDto;
|
|
|
import com.sckw.contract.model.dto.res.QueryListResDto;
|
|
|
import com.sckw.contract.model.entity.KwcContractLogistics;
|
|
|
@@ -81,6 +85,10 @@ public class KwcContractLogisticsService {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = {})
|
|
|
public Long addCheckedContract(ContractLogisticsReqVo reqVo) {
|
|
|
+ LogisticsBaseInfoReqVo baseInfo = reqVo.getBaseInfo();
|
|
|
+ List<LogisticsGoodsInfoReqVo> goodsInfo = reqVo.getGoodsInfo();
|
|
|
+ //参数校验
|
|
|
+ checkParam(baseInfo, goodsInfo);
|
|
|
Long id = reqVo.getId();
|
|
|
//不为空时是修改
|
|
|
if (Objects.nonNull(id)) {
|
|
|
@@ -88,8 +96,6 @@ public class KwcContractLogisticsService {
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
- LogisticsBaseInfoReqVo baseInfo = reqVo.getBaseInfo();
|
|
|
- List<LogisticsGoodsInfoReqVo> goodsInfo = reqVo.getGoodsInfo();
|
|
|
//创建合同
|
|
|
KwcContractLogistics kwcContractLogistics = getKwcContractLogistics(baseInfo, goodsInfo, reqVo.getRemark(), reqVo.getPid());
|
|
|
long contactId = new IdWorker(1L).nextId();
|
|
|
@@ -108,6 +114,34 @@ public class KwcContractLogisticsService {
|
|
|
return contactId;
|
|
|
}
|
|
|
|
|
|
+ private void checkParam(LogisticsBaseInfoReqVo baseInfo, List<LogisticsGoodsInfoReqVo> goodsInfo) {
|
|
|
+ if(Objects.nonNull(baseInfo)) {
|
|
|
+ if(StringUtils.isNotBlank(baseInfo.getContractCode()) && baseInfo.getContractCode().length() > 20) {
|
|
|
+ throw new SystemException("合同编号超长!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(baseInfo.getContractName()) && baseInfo.getContractName().length() > 20) {
|
|
|
+ throw new SystemException("合同名称超长!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsInfo)) {
|
|
|
+ for (LogisticsGoodsInfoReqVo logisticsGoodsInfoReqVo : goodsInfo) {
|
|
|
+ if (StringUtils.isNotBlank(logisticsGoodsInfoReqVo.getGoodsName()) && logisticsGoodsInfoReqVo.getGoodsName().length() > 50) {
|
|
|
+ throw new SystemException("商品名称超长!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Objects.nonNull(logisticsGoodsInfoReqVo.getLoss()) && !RegularUtils.matchNumberWithFix(logisticsGoodsInfoReqVo.getLoss().toString(), 5, 2)) {
|
|
|
+ throw new SystemException("合理损耗超长!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Objects.nonNull(logisticsGoodsInfoReqVo.getDeficitPrice()) && !RegularUtils.matchNumberWithFix(logisticsGoodsInfoReqVo.getDeficitPrice().toString(), 5, 2)) {
|
|
|
+ throw new SystemException("扣亏货值超长!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public KwcContractLogistics getKwcContractLogistics(LogisticsBaseInfoReqVo baseInfo, List<LogisticsGoodsInfoReqVo> goodsInfo, String remark, Long pid) {
|
|
|
Date date = new Date();
|
|
|
KwcContractLogistics kwcContractLogistics = new KwcContractLogistics();
|
|
|
@@ -121,12 +155,11 @@ public class KwcContractLogisticsService {
|
|
|
kwcContractLogistics.setPerformedAmount(new BigDecimal("0"));
|
|
|
kwcContractLogistics.setContractPid(pid);
|
|
|
kwcContractLogistics.setRemark(remark);
|
|
|
+ kwcContractLogistics.setDelFlag(Global.NO);
|
|
|
kwcContractLogistics.setCreateBy(LoginUserHolder.getUserId());
|
|
|
kwcContractLogistics.setCreateTime(date);
|
|
|
kwcContractLogistics.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
kwcContractLogistics.setUpdateTime(date);
|
|
|
- kwcContractLogistics.setDelFlag(Global.NO);
|
|
|
-
|
|
|
BigDecimal amountTotal = new BigDecimal(Global.NUMERICAL_ZERO);
|
|
|
if (CollectionUtils.isNotEmpty(goodsInfo)) {
|
|
|
for (LogisticsGoodsInfoReqVo logisticsGoodsInfoReqVo : goodsInfo) {
|
|
|
@@ -146,7 +179,7 @@ public class KwcContractLogisticsService {
|
|
|
* @author: czh
|
|
|
* @date: 2023/7/14
|
|
|
*/
|
|
|
- public void supplement(ContractLogisticsReqVo reqVo) {
|
|
|
+ public void supplement(ContractLogisticsReqVo reqVo) throws SystemException {
|
|
|
Long id = reqVo.getPid();
|
|
|
KwcContractLogistics kwcContractLogistics = kwcContractLogisticsMapper.selectById(id);
|
|
|
if (Objects.isNull(kwcContractLogistics)) {
|
|
|
@@ -306,7 +339,7 @@ public class KwcContractLogisticsService {
|
|
|
* @date 2023/7/17
|
|
|
*/
|
|
|
@Transactional(rollbackFor = {})
|
|
|
- public Long submit(ContractLogisticsReqVo reqVo) {
|
|
|
+ public Long submit(ContractLogisticsReqVo reqVo) throws SystemException {
|
|
|
Long id = reqVo.getId();
|
|
|
//直接签约先存草稿再修改状态
|
|
|
if (Objects.isNull(id)) {
|
|
|
@@ -316,9 +349,72 @@ public class KwcContractLogisticsService {
|
|
|
}
|
|
|
update(reqVo);
|
|
|
changeToSubmit(id);
|
|
|
+
|
|
|
+ if (DictEnum.SIGNING_WAY_1.getValue().equals(String.valueOf(reqVo.getBaseInfo().getSigningWay()))) {
|
|
|
+ postToEsign(reqVo, id);
|
|
|
+ }
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
+ private void postToEsign(ContractLogisticsReqVo reqVo, Long id) {
|
|
|
+ EsignGetFlowReqDto esignGetFlowReqDto = new EsignGetFlowReqDto();
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(reqVo.getContractFile());
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(0);
|
|
|
+ String fileName = jsonObject.getString("name");
|
|
|
+ String url = jsonObject.getString("url");
|
|
|
+ File file = getFileByHttpURL(url, fileName);
|
|
|
+
|
|
|
+ Long carrierEntId = reqVo.getBaseInfo().getCarrierEntId();
|
|
|
+ Long checkedEntId = reqVo.getBaseInfo().getCheckedEntId();
|
|
|
+
|
|
|
+
|
|
|
+ esignGetFlowReqDto.setFile(file);
|
|
|
+ esignGetFlowReqDto.setSeqId(String.valueOf(id));
|
|
|
+ esignGetFlowReqDto.setSignFlowTitle(reqVo.getBaseInfo().getContractName());
|
|
|
+ esignGetFlowReqDto.setOrgFirstName("");
|
|
|
+ esignGetFlowReqDto.setPsnFirstAccount("");
|
|
|
+ esignGetFlowReqDto.setOrgSecondName("");
|
|
|
+ esignGetFlowReqDto.setPsnSecondAccount("");
|
|
|
+ Map<String, Object> map = BeanUtils.convertToMap(esignGetFlowReqDto);
|
|
|
+ String res = OkHttpUtils.doPostUploadFile("http://10.10.10.149:8840/v1/sign/getFlow", map);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static File getFileByHttpURL(String newUrl, String fileName){
|
|
|
+ String[] suffix = newUrl.split("/");
|
|
|
+ //得到最后一个分隔符后的名字
|
|
|
+ File file = null;
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try{
|
|
|
+ file = File.createTempFile("", fileName);
|
|
|
+ URL urlFile = new URL(newUrl);
|
|
|
+ inputStream = urlFile.openStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+
|
|
|
+ int bytesRead = 0;
|
|
|
+ byte[] buffer = new byte[8192];
|
|
|
+ while ((bytesRead=inputStream.read(buffer,0,8192))!=-1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ try {
|
|
|
+ if (null != outputStream) {
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+ if (null != inputStream) {
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return file;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @param id 合同id
|
|
|
* @desc: 更新合同为发起
|
|
|
@@ -350,13 +446,33 @@ public class KwcContractLogisticsService {
|
|
|
throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.CONTRACT_NOT_EXISTS);
|
|
|
}
|
|
|
|
|
|
- KwcContractLogistics param = getKwcContractLogistics(reqVo.getBaseInfo(), reqVo.getGoodsInfo(), reqVo.getRemark(), reqVo.getPid());
|
|
|
- param.setId(contractId);
|
|
|
- param.setSigningUrl(reqVo.getContractFile());
|
|
|
- param.setStatus(ContractStatusEnum.SAVE.getCode());
|
|
|
- param.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- param.setUpdateTime(date);
|
|
|
- if (kwcContractLogisticsMapper.updateById(param) <= 0) {
|
|
|
+ LogisticsBaseInfoReqVo baseInfo = reqVo.getBaseInfo();
|
|
|
+ kwcContractLogistics.setEntId(LoginUserHolder.getEntId());
|
|
|
+ kwcContractLogistics.setContractNo(baseInfo.getContractCode());
|
|
|
+ kwcContractLogistics.setName(baseInfo.getContractName());
|
|
|
+ kwcContractLogistics.setSigningWay(baseInfo.getSigningWay());
|
|
|
+ kwcContractLogistics.setCharging(baseInfo.getCharging());
|
|
|
+ kwcContractLogistics.setStartTime(baseInfo.getStartTime());
|
|
|
+ kwcContractLogistics.setEndTime(baseInfo.getEndTime());
|
|
|
+ kwcContractLogistics.setPerformedAmount(new BigDecimal("0"));
|
|
|
+ kwcContractLogistics.setContractPid(reqVo.getPid());
|
|
|
+ kwcContractLogistics.setRemark(reqVo.getRemark());
|
|
|
+
|
|
|
+ List<LogisticsGoodsInfoReqVo> goodsInfo = reqVo.getGoodsInfo();
|
|
|
+ BigDecimal amountTotal = new BigDecimal(Global.NUMERICAL_ZERO);
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsInfo)) {
|
|
|
+ for (LogisticsGoodsInfoReqVo logisticsGoodsInfoReqVo : goodsInfo) {
|
|
|
+ if (Objects.nonNull(logisticsGoodsInfoReqVo.getAmount())) {
|
|
|
+ amountTotal = amountTotal.add(logisticsGoodsInfoReqVo.getAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ kwcContractLogistics.setAmount(amountTotal);
|
|
|
+ kwcContractLogistics.setSigningUrl(reqVo.getContractFile());
|
|
|
+ kwcContractLogistics.setStatus(ContractStatusEnum.SAVE.getCode());
|
|
|
+ kwcContractLogistics.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwcContractLogistics.setUpdateTime(date);
|
|
|
+ if (kwcContractLogisticsMapper.updateById(kwcContractLogistics) <= 0) {
|
|
|
throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
}
|
|
|
|
|
|
@@ -520,7 +636,7 @@ public class KwcContractLogisticsService {
|
|
|
try {
|
|
|
EasyExcelUtil.writeSingleExcel("物流合同.xlsx", "sheet1", queryListResVos, QueryListResVo.class);
|
|
|
} catch (IOException e) {
|
|
|
- log.error("导出失败:", e);
|
|
|
+// log.error("导出失败:", e);
|
|
|
throw new SystemException(HttpStatus.CODE_10301, HttpStatus.MSG_014);
|
|
|
}
|
|
|
}
|