Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/dev1.0' into dev1.0

# Conflicts:
#	src/main/resources/application-dev.yml
liuj 8 mēneši atpakaļ
vecāks
revīzija
9dc3bd7478

+ 2 - 0
src/main/java/com/sunxung/factoring/dict/impl/FileModuleDict.java

@@ -621,6 +621,8 @@ public class FileModuleDict extends Dict {
         /** 豁免事项跟进文件 **/
         EXEMPTION_MATTERS_FILE("exemption", "豁免事项跟进文件"),
 
+        CONTRACT_TEMPLATE_FILE("contractTemplateFile","合同模板文件" ),
+
         OTHER("other","其他");
 
         /**

+ 62 - 0
src/main/java/com/sunxung/factoring/entity/financing/contractTemplate/ContractTemplate.java

@@ -0,0 +1,62 @@
+package com.sunxung.factoring.entity.financing.contractTemplate;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.sunxung.factoring.entity.BaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
+
+/**
+ * <p>
+ * 合同模板
+ * </p>
+ *
+ * @author liutao
+ * @since 2024-03-04
+ */
+@TableName("contract_template")
+public class ContractTemplate extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 合同版本
+     */
+    @TableField("version")
+    private String version;
+
+    /**
+     * 合同名称
+     */
+    @TableField("name")
+    private String name;
+
+    /**
+     *  是否启用 0 否 1 是
+     */
+    private Integer visible;
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getVisible() {
+        return visible;
+    }
+
+    public void setVisible(Integer visible) {
+        this.visible = visible;
+    }
+
+}

+ 53 - 0
src/main/java/com/sunxung/factoring/entity/financing/contractTemplate/vo/SynchronizeFileVo.java

@@ -0,0 +1,53 @@
+package com.sunxung.factoring.entity.financing.contractTemplate.vo;
+
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * @author liutao
+ * @date 2024-3-4
+ */
+public class SynchronizeFileVo {
+
+    /**
+     * 合同名称
+     */
+    private String name;
+
+    /**
+     * 贸理通文件id
+     */
+    private Long file;
+
+    /**
+     * 文件类型
+     */
+    private String fileType;
+
+
+    public SynchronizeFileVo() {
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Long getFile() {
+        return file;
+    }
+
+    public void setFile(Long file) {
+        this.file = file;
+    }
+
+    public String getFileType() {
+        return fileType;
+    }
+
+    public void setFileType(String fileType) {
+        this.fileType = fileType;
+    }
+}

+ 36 - 0
src/main/java/com/sunxung/factoring/entity/financing/contractTemplate/vo/SynchronizeVo.java

@@ -0,0 +1,36 @@
+package com.sunxung.factoring.entity.financing.contractTemplate.vo;
+
+import java.util.List;
+
+/**
+ * @author liutao
+ * @date 2024-3-4
+ */
+public class SynchronizeVo {
+
+    /**
+     * 合同版本
+     */
+    private String versionNo;
+
+    /**
+     * 合同信息
+     */
+    private List<SynchronizeFileVo> synchronizeFileVos;
+
+    public String getVersionNo() {
+        return versionNo;
+    }
+
+    public void setVersionNo(String versionNo) {
+        this.versionNo = versionNo;
+    }
+
+    public List<SynchronizeFileVo> getSynchronizeFileVos() {
+        return synchronizeFileVos;
+    }
+
+    public void setSynchronizeFileVos(List<SynchronizeFileVo> synchronizeFileVos) {
+        this.synchronizeFileVos = synchronizeFileVos;
+    }
+}

+ 16 - 0
src/main/java/com/sunxung/factoring/mapper/financing/contractTemplate/ContractTemplateMapper.java

@@ -0,0 +1,16 @@
+package com.sunxung.factoring.mapper.financing.contractTemplate;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sunxung.factoring.entity.financing.contractTemplate.ContractTemplate;
+
+/**
+ * <p>
+ * 合同模板 Mapper 接口
+ * </p>
+ *
+ * @author liutao
+ * @since 2024-03-04
+ */
+public interface ContractTemplateMapper extends BaseMapper<ContractTemplate> {
+
+}

+ 18 - 0
src/main/java/com/sunxung/factoring/service/financing/contractTemplate/IContractTemplateService.java

@@ -0,0 +1,18 @@
+package com.sunxung.factoring.service.financing.contractTemplate;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.sunxung.factoring.entity.financing.contractTemplate.ContractTemplate;
+import com.sunxung.factoring.entity.financing.contractTemplate.vo.SynchronizeVo;
+
+/**
+ * <p>
+ * 合同模板 服务类
+ * </p>
+ *
+ * @author liutao
+ * @since 2024-03-04
+ */
+public interface IContractTemplateService extends IService<ContractTemplate> {
+
+    void SynchronizeContractTemplate(SynchronizeVo synchronizeVo);
+}

+ 129 - 0
src/main/java/com/sunxung/factoring/service/financing/contractTemplate/impl/ContractTemplateServiceImpl.java

@@ -0,0 +1,129 @@
+package com.sunxung.factoring.service.financing.contractTemplate.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sunxung.factoring.component.exception.BusinessException;
+import com.sunxung.factoring.component.util.CloseableHttpClientUtils;
+import com.sunxung.factoring.component.util.CodeUtil;
+import com.sunxung.factoring.component.util.CollectionUtil;
+import com.sunxung.factoring.component.util.FileUtil;
+import com.sunxung.factoring.dict.impl.FileModuleDict;
+import com.sunxung.factoring.entity.financing.contractTemplate.ContractTemplate;
+import com.sunxung.factoring.entity.financing.contractTemplate.vo.SynchronizeFileVo;
+import com.sunxung.factoring.entity.financing.contractTemplate.vo.SynchronizeVo;
+import com.sunxung.factoring.entity.sys.FileStorage;
+import com.sunxung.factoring.mapper.financing.contractTemplate.ContractTemplateMapper;
+import com.sunxung.factoring.service.financing.contractTemplate.IContractTemplateService;
+import com.sunxung.factoring.service.sys.FileStorageService;
+import com.sunxung.factoring.service.sys.ISysAttachmentRefService;
+import com.sunxung.factoring.service.sys.dto.AttachmentDto;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * <p>
+ * 合同模板 服务实现类
+ * </p>
+ *
+ * @author liutao
+ * @since 2024-03-04
+ */
+@Service
+public class ContractTemplateServiceImpl extends ServiceImpl<ContractTemplateMapper, ContractTemplate> implements IContractTemplateService {
+
+    @Autowired
+    private FileStorageService fileStorageService;
+
+    @Value("${sop.synchronizeDownloadFile}")
+    private String getFileUrl;
+
+    @Autowired
+    private ISysAttachmentRefService sysAttachmentRefService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void SynchronizeContractTemplate(SynchronizeVo synchronizeVo) {
+        String versionNo = synchronizeVo.getVersionNo();
+        Integer count = lambdaQuery().eq(ContractTemplate::getVersion, versionNo).count();
+        if (count != null && count > 0) {
+            throw new BusinessException(CodeUtil.FAIL, "该版本合同已经通不过,无需再同步!");
+        }
+        List<SynchronizeFileVo> synchronizeFileVos = synchronizeVo.getSynchronizeFileVos();
+
+        if (CollectionUtil.isNotEmpty(synchronizeFileVos)) {
+            lambdaUpdate().set(ContractTemplate::getVisible, 0).update();
+        } else {
+            throw new BusinessException(CodeUtil.FAIL, "该版本未获取到合同信息!");
+        }
+        for (SynchronizeFileVo synchronizeFileVo : synchronizeFileVos) {
+            //保存合同模板信息
+            ContractTemplate contractTemplate = new ContractTemplate();
+            contractTemplate.setVersion(versionNo);
+            String name = synchronizeFileVo.getName();
+            contractTemplate.setName(name);
+            contractTemplate.setVisible(1);
+            save(contractTemplate);
+            //从sop获取文件
+            String fileType = synchronizeFileVo.getFileType();
+            Long file = synchronizeFileVo.getFile();
+            FileModuleDict.ChildEnum childEnum = FileModuleDict.ChildEnum.CONTRACT_TEMPLATE_FILE;
+            String fileName = UUID.randomUUID().toString();
+            String localFilePath = FileUtil.getAbsolutePath(fileName, fileType, childEnum);
+            File destFile = new File(localFilePath);
+            if (!destFile.getParentFile().exists()) {
+                destFile.getParentFile().mkdirs();
+            }
+            getFileFromSop(file, destFile);
+            //新建FileStorage
+            FileStorage newFileStorage = new FileStorage(fileName, name + fileType, localFilePath, childEnum);
+            fileStorageService.add(newFileStorage);
+            List list = new ArrayList();
+            list.add(newFileStorage.getId());
+
+            AttachmentDto attachmentDto = AttachmentDto.builder()
+                    .setEntityId(contractTemplate.getId())
+                    .setChildEnum(FileModuleDict.ChildEnum.CONTRACT_TEMPLATE_FILE)
+                    .build();
+            sysAttachmentRefService.saveRef(list, attachmentDto);
+        }
+    }
+
+    private void getFileFromSop(Long file, File destFile) {
+        CloseableHttpClient httpclient = CloseableHttpClientUtils.getHttpClient();
+
+        HttpPost request = new HttpPost(getFileUrl + "?fileId=" + file);
+        HttpResponse response;
+        try {
+            response = httpclient.execute(request);
+            if (response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) {
+                InputStream input = response.getEntity().getContent();
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                IOUtils.copy(input, baos);
+                FileUtils.writeByteArrayToFile(destFile, baos.toByteArray());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}

+ 32 - 0
src/main/java/com/sunxung/factoring/web/financing/ContractTemplateController.java

@@ -0,0 +1,32 @@
+package com.sunxung.factoring.web.financing;
+
+import com.sunxung.factoring.entity.ResponseJson;
+import com.sunxung.factoring.entity.financing.contractTemplate.vo.SynchronizeVo;
+import com.sunxung.factoring.service.financing.contractTemplate.IContractTemplateService;
+import org.checkerframework.checker.units.qual.A;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.multipart.support.StandardServletMultipartResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+/**
+ * @author liutao
+ * @date 2024-3-4
+ */
+@RestController
+public class ContractTemplateController {
+
+    @Autowired
+    private IContractTemplateService contractTemplateService;
+
+    @RequestMapping("api/synchronize/contract/template")
+    public ResponseJson SynchronizeContractTemplate(SynchronizeVo synchronizeVo){
+        contractTemplateService.SynchronizeContractTemplate(synchronizeVo);
+        return new ResponseJson();
+    }
+}

+ 1 - 0
src/main/resources/application-dev.yml

@@ -133,6 +133,7 @@ sop:
   getBusinessByKeyWordUrl: http://192.168.3.6:8868/api/trade/findBusinessName
   getFlushUrl: http://192.168.3.6:8868/sys/customer/flushByTrade/url
   getEnterpriseInfoUrl: http://192.168.3.6:8868/sys/customer/getEnterpriseInfoByTrade
+  synchronizeDownloadFile: http://localhost:8868/synchronize/factoringContractTemplate/fileStorage/downloadFile
   synchronizeInformation: http://192.168.3.6:8868/sys/customer/synchronize/information
   getBusinessNoByTrade: http://192.168.3.6:8868/api/trade/quotaDisburseReport/getBusinessNoByTrade
 

+ 13 - 0
src/main/resources/data/update/v1.0/20231117liutao.sql

@@ -1307,3 +1307,16 @@ VALUES ( 149, 'button', '查看', 'viewSupplierInfo', 2, '供应商授信管理'
 INSERT INTO `t_permission`(`parentId`, `type`, `cname`, `ename`, `gradation`, `moduleName`, `url`, `icon`, `user_create`, `user_modified`, `gmt_create`, `gmt_modified`)
 VALUES (143, 'button', '查看', 'viewCreditResolution', 1, '授信决议管理', '/credit/resolution/viewCreditResolution', NULL, NULL, NULL,  now(), now());
 
+DROP TABLE IF EXISTS  `contract_template`;
+CREATE TABLE `contract_template` (
+                                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                                              `version` varchar(50) DEFAULT '' COMMENT '合同版本',
+                                              `name` varchar(200) DEFAULT '' COMMENT '合同名称',
+                                              `visible` tinyint(2) DEFAULT null COMMENT '是否启用',
+
+                                              `user_create` varchar(32) DEFAULT '' COMMENT '创建人',
+                                              `user_modified` varchar(32) DEFAULT '' COMMENT '修改人',
+                                              `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+                                              `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+                                              PRIMARY KEY (`id`)
+) COMMENT='合同模板';

+ 1 - 1
src/test/java/com/sunxung/factoring/generator/MpCodeGenerator.java

@@ -31,7 +31,7 @@ public class MpCodeGenerator {
     //author
     public static final String author = "liutao";
     //database
-    public static final String databaseUrl = "jdbc:mysql://192.168.3.6:3106/factoring_trade_v2_20230918?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true";
+    public static final String databaseUrl = "jdbc:mysql://192.168.3.6:3106/factoring_trade_v4?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true";
     public static final String driverName = "com.mysql.jdbc.Driver";
     public static final String userName = "root";
     public static final String password = "root";