Browse Source

Merge branch 'master' into test

# Conflicts:
#	hx-sale/src/main/java/com/fjhx/sale/entity/contract/po/Contract.java
#	hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractService.java
yzc 1 year ago
parent
commit
e17c5df06f

+ 2 - 1
hx-sale/src/main/java/com/fjhx/sale/controller/intermediate/IntermediateContractController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.sale.entity.contract.vo.ContractPdfInfoVo;
 import com.fjhx.sale.entity.intermediate.dto.IntermediateContractDto;
 import com.fjhx.sale.entity.intermediate.dto.IntermediateContractSelectDto;
+import com.fjhx.sale.entity.intermediate.po.IntermediateContract;
 import com.fjhx.sale.entity.intermediate.vo.IntermediateContractVo;
 import com.fjhx.sale.service.intermediate.IntermediateContractService;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -67,7 +68,7 @@ public class IntermediateContractController {
      * 获取合中间同历史联系方式
      */
     @PostMapping("/getPrintInfo")
-    public ContractPdfInfoVo getPrintInfo(@RequestBody IntermediateContractDto dto) {
+    public IntermediateContract getPrintInfo(@RequestBody IntermediateContractDto dto) {
         return intermediateContractService.getPrintInfo(dto);
     }
 

+ 6 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/po/Contract.java

@@ -370,4 +370,10 @@ public class Contract extends BasePo {
      * 流程id
      */
     private Long flowId;
+
+    /**
+     * 创建时间英文
+     */
+    @TableField(exist = false)
+    private String createTimeEn;
 }

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/entity/intermediate/dto/IntermediateContractSelectDto.java

@@ -27,6 +27,6 @@ public class IntermediateContractSelectDto extends BaseSelectDto {
     /**
      * 是否创建
      */
-    private String isSet;
+    private Integer isSet;
 
 }

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/entity/intermediate/po/IntermediateContract.java

@@ -21,7 +21,7 @@ public class IntermediateContract extends BasePo {
     /**
      * 单证id
      */
-    private Long documentsId;
+    private String documentsIds;
 
     /**
      * 卖方公司ID

+ 3 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/intermediate/vo/IntermediateContractVo.java

@@ -5,6 +5,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Map;
 
 /**
  * 中间合同列表查询返回值实体
@@ -56,4 +57,6 @@ public class IntermediateContractVo extends IntermediateContract {
 
     private String opUserName;
 
+    private Map<String,Object> contractMap;
+
 }

+ 6 - 1
hx-sale/src/main/java/com/fjhx/sale/mapper/intermediate/IntermediateContractMapper.java

@@ -21,11 +21,16 @@ import java.util.List;
 public interface IntermediateContractMapper extends BaseMapper<IntermediateContract> {
 
     /**
-     * 中间合同分页
+     * 中间合同分页--未创建
      */
     Page<IntermediateContractVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<IntermediateContract> wrapper);
 
     /**
+     * 中间合同分页--已创建
+     */
+    Page<IntermediateContractVo> getPage2(@Param("page") Page<Object> page, @Param("ew") IWrapper<IntermediateContract> wrapper);
+
+    /**
      * 获取中间合同历史联系方式
      */
     List<IntermediateContractVo> contactList(@Param("ew") IWrapper<IntermediateContract> wrapper);

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractService.java

@@ -196,4 +196,13 @@ public interface ContractService extends BaseService<Contract> {
      * @return
      */
     Map<String, Object> getHeadCustomerStatistics(ContractSelectDto dto);
+
+    /**
+     * 中间合同打印PDF获取合同相关数据
+     * @param newContractId 最新一条单证合同ID
+     * @param contractIds 所有单证合同ID集合
+     * @return
+     */
+    Map<String,Object> getDocumentaryPdf(Long newContractId,List<Long> contractIds);
+
 }

+ 23 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -1728,4 +1728,27 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         }
         return map;
     }
+
+    @Override
+    public Map<String, Object> getDocumentaryPdf(Long newContractId, List<Long> contractIds) {
+        Map<String,Object> map = new HashMap<>();
+        if (ObjectUtil.isEmpty(newContractId)) {
+            throw new ServiceException("销售合同id不能为空");
+        }
+        Contract contract = getById(newContractId);
+        if (ObjectUtil.isEmpty(contract)) {
+            throw new ServiceException("没有找到销售合同");
+        }
+        contract.setCreateTimeEn(sdf.format(contract.getCreateTime()));
+        map.put("contract",contract);
+        //查询合同产品
+        List<ContractProduct> contractProductList = contractProductService.list(Wrappers.<ContractProduct>query().lambda().in(ContractProduct::getContractId,contractIds));
+        productInfoService.attributeAssign(contractProductList, ContractProduct::getProductId, (item, product) -> {
+            item.setProductCnName(product.getName());
+            item.setProductCode(product.getCode());
+            item.setProductUnit(product.getUnit());
+        });
+        map.put("contractProductList",contractProductList);
+        return map;
+    }
 }

+ 3 - 1
hx-sale/src/main/java/com/fjhx/sale/service/intermediate/IntermediateContractService.java

@@ -46,5 +46,7 @@ public interface IntermediateContractService extends BaseService<IntermediateCon
      *
      * @return
      */
-    ContractPdfInfoVo getPrintInfo(IntermediateContractDto dto);
+    IntermediateContract getPrintInfo(IntermediateContractDto dto);
+
+    String getAllIds();
 }

+ 57 - 48
hx-sale/src/main/java/com/fjhx/sale/service/intermediate/impl/IntermediateContractServiceImpl.java

@@ -19,11 +19,14 @@ import com.fjhx.sale.mapper.intermediate.IntermediateContractMapper;
 import com.fjhx.sale.service.contract.ContractService;
 import com.fjhx.sale.service.documents.DocumentsService;
 import com.fjhx.sale.service.intermediate.IntermediateContractService;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.common.utils.wrapper.SqlField;
 import com.ruoyi.system.utils.UserUtil;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Service;
 
 import java.util.Arrays;
@@ -54,25 +57,34 @@ public class IntermediateContractServiceImpl extends ServiceImpl<IntermediateCon
 
     @Override
     public Page<IntermediateContractVo> getPage(IntermediateContractSelectDto dto) {
+        if(ObjectUtil.isEmpty(dto.getIsSet())){
+            throw new ServiceException("参数异常");
+        }
         IWrapper<IntermediateContract> wrapper = getWrapper();
         //买方公司过滤
         wrapper.orderByDesc("d.create_time");
         wrapper.eq(StringUtils.isNotEmpty(dto.getKeyword()),"c.code", dto.getKeyword());
         wrapper.eq(ObjectUtil.isNotEmpty(dto.getBuyCorporationId()),"c.buy_corporation_id", dto.getBuyCorporationId());
         wrapper.eq(ObjectUtil.isNotEmpty(dto.getSellCorporationId()),"c.sell_corporation_id", dto.getSellCorporationId());
-        List<IntermediateContract> intermediateContracts = this.list(Wrappers.<IntermediateContract>query().lambda().select(IntermediateContract::getDocumentsId));
-        List<Long> ids = intermediateContracts.stream().map(IntermediateContract::getDocumentsId).collect(Collectors.toList());
-        wrapper.notIn("d.id",ids);
-        //卖方公司过滤
-        Page<IntermediateContractVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        Page<IntermediateContractVo> page;
+        if(dto.getIsSet()==1){//未创建
+            String ids = this.getAllIds();
+            wrapper.notIn("d.id",Arrays.asList(ids));
+            //卖方公司过滤
+            page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        }else{//已创建
+            wrapper.groupBy("t1.id");
+            page = this.baseMapper.getPage2(dto.getPage(), wrapper);
+        }
+
         List<IntermediateContractVo> records = page.getRecords();
         //赋值原买方公司名称 客户
-        customerService.attributeAssign(records, IntermediateContractVo::getOldBuyCorporationId, (item, customer) -> {
-            item.setOldBuyCorporationName(customer.getName());
+        customerService.attributeAssign(records, IntermediateContractVo::getBuyCorporationId, (item, customer) -> {
+            item.setBuyCorporationName(customer.getName());
         });
         //赋值原卖方公司名称 多公司
-        corporationService.attributeAssign(records, IntermediateContractVo::getOldSellCorporationId, (item, corporation) -> {
-            item.setOldSellCorporationName(corporation.getName());
+        corporationService.attributeAssign(records, IntermediateContractVo::getSellCorporationId, (item, corporation) -> {
+            item.setSellCorporationName(corporation.getName());
         });
 //        //赋值中间合同重新赋值过后的买方名称
 //        corporationService.attributeAssign(records, IntermediateContractVo::getBuyCorporationId, (item, corporation) -> {
@@ -97,8 +109,8 @@ public class IntermediateContractServiceImpl extends ServiceImpl<IntermediateCon
     @Override
     public void edit(IntermediateContractDto intermediateContractDto) {
         intermediateContractDto.setId(null);
-        Assert.notEmpty(intermediateContractDto.getDocumentsId(), "单证id不能为空");
-        IntermediateContract intermediateContract = this.getOne(q -> q.eq(IntermediateContract::getDocumentsId, intermediateContractDto.getDocumentsId()));
+        Assert.notEmpty(intermediateContractDto.getDocumentsIds(), "单证id不能为空");
+        IntermediateContract intermediateContract = this.getOne(q -> q.eq(IntermediateContract::getDocumentsIds, intermediateContractDto.getDocumentsIds()));
         if (ObjectUtil.isNotEmpty(intermediateContract)) {
             //编辑 赋值id
             intermediateContractDto.setId(intermediateContract.getId());
@@ -148,45 +160,42 @@ public class IntermediateContractServiceImpl extends ServiceImpl<IntermediateCon
      * @return
      */
     @Override
-    public ContractPdfInfoVo getPrintInfo(IntermediateContractDto dto) {
-        Assert.notEmpty(dto.getDocumentsId(), "单证id不能为空");
-        Documents documents = documentsService.getById(dto.getDocumentsId());
+    public IntermediateContract getPrintInfo(IntermediateContractDto dto) {
+        Assert.notEmpty(dto.getId(), "参数异常");
+        IntermediateContract in = this.getById(dto.getId());
+        IntermediateContractVo vo = new IntermediateContractVo();
+        BeanUtils.copyProperties(in,vo);
+        if(ObjectUtil.isEmpty(in)){
+            throw new ServiceException("合同不存在");
+        }
+        //赋值买方卖方公司名称
+        List<Long> corporationIds = Arrays.asList(in.getBuyCorporationId(), in.getSellCorporationId());
+        Map<Long, Corporation> corporationMap = corporationService.mapKEntity(Corporation::getId, q -> q.in(Corporation::getId, corporationIds));
+        Corporation buyCorporation = corporationMap.get(in.getBuyCorporationId());
+        Corporation sellCorporation = corporationMap.get(in.getSellCorporationId());
+        if (ObjectUtil.isNotEmpty(buyCorporation)) {
+            vo.setBuyCorporationName(buyCorporation.getName());
+        }
+        if (ObjectUtil.isNotEmpty(sellCorporation)) {
+            vo.setSellCorporationName(sellCorporation.getName());
+        }
+        //查询最新的一条单证信息
+        Documents documents = documentsService.getOne(Wrappers.<Documents>query().lambda().in(Documents::getId,Arrays.asList(in.getDocumentsIds().split(","))).orderByDesc(Documents::getCreateTime).last("limit 1"));
         Assert.notEmpty(documents, "查询不到单证信息");
-        ContractPdfInfoVo contractPdfInfo = contractService.getContractPdfInfo(documents.getContractId());
-        //重新赋值买卖方信息为中间合同信息
-        //获得多公司信息
-        IntermediateContract intermediateContract = getOne(q -> q.eq(IntermediateContract::getDocumentsId, documents.getId()));
-        if (ObjectUtil.isNotEmpty(intermediateContract)) {
-            List<Long> corporationIds = Arrays.asList(intermediateContract.getBuyCorporationId(), intermediateContract.getSellCorporationId());
-            Map<Long, Corporation> corporationMap = corporationService.mapKEntity(Corporation::getId, q -> q.in(Corporation::getId, corporationIds));
-
-            Corporation buyCorporation = corporationMap.get(intermediateContract.getBuyCorporationId());
-            //赋值买方信息
-            contractPdfInfo.setBuyContactNumber(intermediateContract.getBuyContactNumber());
-            contractPdfInfo.setBuyCorporationName(buyCorporation.getNameEn());
-            if (ObjectUtil.isNotEmpty(buyCorporation)) {
-                contractPdfInfo.setBuyContactName(intermediateContract.getBuyContactName());
-                //赋值买方国家省市详细地址信息
-                contractPdfInfo.setBuyCountryName(buyCorporation.getCountryEnStr());
-                contractPdfInfo.setBuyProvinceName(buyCorporation.getProvinceEnStr());
-                contractPdfInfo.setBuyCityName(buyCorporation.getCityEnStr());
-                contractPdfInfo.setBuyDetailedAddress(buyCorporation.getAddressEn());
-            }
+        List<Documents> documentsList = documentsService.list(Wrappers.<Documents>query().lambda().in(Documents::getId,Arrays.asList(in.getDocumentsIds().split(","))));
+        //查询合同
+        Map<String,Object> contractMap = contractService.getDocumentaryPdf(documents.getContractId(),documentsList.stream().map(Documents::getContractId).collect(Collectors.toList()));
+        vo.setContractMap(contractMap);
+        return vo;
+    }
 
-            Corporation sellCorporation = corporationMap.get(intermediateContract.getSellCorporationId());
-            //赋值卖方信息
-            contractPdfInfo.setSellContactNumber(intermediateContract.getSellContactName());
-            contractPdfInfo.setSellCorporationNameEn(intermediateContract.getSellContactNumber());
-            if (ObjectUtil.isNotEmpty(sellCorporation)) {
-                contractPdfInfo.setSellContactName(sellCorporation.getNameEn());
-                //赋值卖方国家省市详细地址信息
-                contractPdfInfo.setSellCountryName(sellCorporation.getCountryEnStr());
-                contractPdfInfo.setSellProvinceName(sellCorporation.getProvinceEnStr());
-                contractPdfInfo.setSellCityName(sellCorporation.getCityEnStr());
-                contractPdfInfo.setSellDetailedAddress(sellCorporation.getAddressEn());
-            }
-        }
-        return contractPdfInfo;
+    /**
+     * 获取所有单证ID
+     * @return
+     */
+    @Override
+    public String getAllIds() {
+        return baseMapper.getAllIds();
     }
 
 }

+ 16 - 3
hx-sale/src/main/resources/mapper/intermediate/IntermediateContractMapper.xml

@@ -6,13 +6,26 @@
             c.CODE,
             c.amount,
             c.currency,
-            c.sell_corporation_id oldSellCorporationId,
-            c.buy_corporation_id oldBuyCorporationId
+            c.sell_corporation_id,
+            c.buy_corporation_id
         FROM
             documents d
         LEFT JOIN contract c ON d.contract_id = c.id
             ${ew.customSqlSegment}
     </select>
+    <select id="getPage2" resultType="com.fjhx.sale.entity.intermediate.vo.IntermediateContractVo">
+        SELECT
+            t1.*,
+            MAX( d.create_time ) ,
+            d.id AS documentsId,
+            c.`code`AS `code`,
+            c.amount AS amount
+        FROM
+            intermediate_contract t1
+                JOIN documents d ON FIND_IN_SET( d.id, t1.documents_ids )
+                LEFT JOIN contract c ON d.contract_id = c.id
+        ${ew.customSqlSegment}
+    </select>
 
     <select id="contactList" resultType="com.fjhx.sale.entity.intermediate.vo.IntermediateContractVo">
         SELECT ic.sell_contact_name,
@@ -24,6 +37,6 @@
     </select>
 
     <select id="getAllIds" resultType="java.lang.String">
-        select GROUP_CONCAT(documents_id)AS ids FROM intermediate_contract
+        select GROUP_CONCAT(documents_ids)AS ids FROM intermediate_contract
     </select>
 </mapper>