Просмотр исходного кода

Merge remote-tracking branch 'origin/dev' into dev

xucaiqin 2 лет назад
Родитель
Сommit
b585e03b3e

+ 2 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEntCertificateDao.java

@@ -66,4 +66,6 @@ public interface KwsEntCertificateDao {
      * @date: 2023/6/30
      * @date: 2023/6/30
      */
      */
     List<KwsEntCertificate> findByEntType(@Param(value = "entId") Long entId, @Param(value = "type") Integer type);
     List<KwsEntCertificate> findByEntType(@Param(value = "entId") Long entId, @Param(value = "type") Integer type);
+
+    List<KwsEntCertificate> findPrevious(@Param(value = "entId") Long entId, @Param(value = "type") Integer type);
 }
 }

+ 2 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/res/EntDetailResVo.java

@@ -146,4 +146,6 @@ public class EntDetailResVo implements Serializable {
      * 主营业务
      * 主营业务
      */
      */
     private String business;
     private String business;
+
+    private boolean valid;
 }
 }

+ 55 - 12
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsEnterpriseService.java

@@ -429,17 +429,20 @@ public class KwsEnterpriseService {
         List<KwsEntCertificate> kwsEntCertificates = new ArrayList<>();
         List<KwsEntCertificate> kwsEntCertificates = new ArrayList<>();
         for (KwsEntCertificate kwsEntCertificate : kwsEntCertificateList) {
         for (KwsEntCertificate kwsEntCertificate : kwsEntCertificateList) {
             //先把旧的作废
             //先把旧的作废
-            List<KwsEntCertificate> previous = kwsEntCertificateDao.findByEntType(kwsEntCertificate.getEntId(), kwsEntCertificate.getType());
-            previous = previous.stream().filter(item -> !item.getId().equals(kwsEntCertificate.getId())).toList();
-            if (!CollectionUtils.isEmpty(previous)) {
-                for (KwsEntCertificate kwsEntCertificate1 : previous) {
-                    kwsEntCertificate1.setDelFlag(Global.YES);
-                    kwsEntCertificateDao.update(kwsEntCertificate1);
+            if (status.equals(ApprovalEnum.OK.getCode())) {
+                List<KwsEntCertificate> previous = kwsEntCertificateDao.findPrevious(kwsEntCertificate.getEntId(), kwsEntCertificate.getType());
+                if (CollectionUtils.isNotEmpty(previous)) {
+                    for (KwsEntCertificate kwsEntCertificate1 : previous) {
+                        kwsEntCertificate1.setDelFlag(Global.YES);
+                        kwsEntCertificateDao.update(kwsEntCertificate1);
+                    }
                 }
                 }
             }
             }
 
 
-            kwsEntCertificate.setStatus(ApprovalEnum.OK.getCode() == status ? Global.NO : Global.YES);
-            kwsEntCertificateDao.update(kwsEntCertificate);
+            if (kwsEntCertificate.getStatus().equals(ApprovalEnum.PROCESS.getCode())) {
+                kwsEntCertificate.setStatus(status.equals(ApprovalEnum.OK.getCode()) ? Global.NO : Global.YES);
+                kwsEntCertificateDao.update(kwsEntCertificate);
+            }
 
 
             entId = kwsEntCertificate.getEntId();
             entId = kwsEntCertificate.getEntId();
             kwsEntCertificates.add(kwsEntCertificate);
             kwsEntCertificates.add(kwsEntCertificate);
@@ -458,6 +461,7 @@ public class KwsEnterpriseService {
         KwsEntCheckTrack kwsEntCheckTrack = new KwsEntCheckTrack();
         KwsEntCheckTrack kwsEntCheckTrack = new KwsEntCheckTrack();
         kwsEntCheckTrack.setEntId(entId);
         kwsEntCheckTrack.setEntId(entId);
         kwsEntCheckTrack.setRemark(reqVo.getRemark());
         kwsEntCheckTrack.setRemark(reqVo.getRemark());
+        kwsEntCheckTrack.setStatus(status.equals(ApprovalEnum.OK.getCode()) ? Global.NO : Global.YES);
         if (kwsEntCheckTrackDao.insert(kwsEntCheckTrack) <= 0) {
         if (kwsEntCheckTrackDao.insert(kwsEntCheckTrack) <= 0) {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
         }
         }
@@ -560,13 +564,45 @@ public class KwsEnterpriseService {
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ENTCERTIFICATES_NOT_EXISTS);
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ENTCERTIFICATES_NOT_EXISTS);
         }
         }
 
 
-        kwsEntCertificates = kwsEntCertificates.stream().filter(item -> item.getStatus().equals(Global.NO)).toList();
-        if (CollectionUtils.isEmpty(kwsEntCertificates)) {
-            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ENTCERTIFICATES_NOT_EXISTS);
+        KwsEnterprise kwsEnterprise = kwsEnterpriseDao.selectByKey(entId);
+        List<KwsEntCertificate> finalList = new ArrayList<>();
+        if (kwsEnterprise.getApproval().equals(ApprovalEnum.PROCESS.getCode()) || kwsEnterprise.getApproval().equals(ApprovalEnum.REFRESH.getCode())) {
+            finalList = kwsEntCertificates.stream().filter(item -> item.getStatus().equals(ApprovalEnum.PROCESS.getCode())).toList();
+        }
+
+
+        if (kwsEnterprise.getApproval().equals(ApprovalEnum.OK.getCode())) {
+            finalList = kwsEntCertificates.stream().filter(item -> item.getStatus().equals(Global.NO)).toList();
+        }
+
+        if (kwsEnterprise.getApproval().equals(ApprovalEnum.PASS.getCode())) {
+            List<KwsEntCheckTrack> list = kwsEntCheckTrackDao.findList(entId);
+            if (list.stream().anyMatch(item -> item.getStatus().equals(Global.NO))) {
+                //通过了一次
+                finalList = kwsEntCertificates.stream().filter(item -> item.getStatus().equals(Global.NO)).toList();
+            } else {
+                //未通过过,按时间倒序取最后一次驳回
+                finalList = kwsEntCertificates.stream().filter(item -> item.getStatus().equals(Global.YES)).collect(Collectors.toList());
+                if (CollectionUtils.isNotEmpty(finalList)) {
+                    Map<Integer, List<KwsEntCertificate>> collect = finalList.stream().collect(Collectors.groupingBy(KwsEntCertificate::getType));
+                    for (Integer type : collect.keySet()) {
+                        List<KwsEntCertificate> kwsEntCertificates1 = collect.get(type);
+                        if (CollectionUtils.isNotEmpty(kwsEntCertificates1)) {
+                            List<KwsEntCertificate> collect1 = kwsEntCertificates1.stream().sorted(Comparator.comparing(KwsEntCertificate::getUpdateTime).reversed()).collect(Collectors.toList());
+                            finalList.add(collect1.get(0));
+                        }
+                    }
+                }
+            }
         }
         }
+
+        if (CollectionUtils.isEmpty(finalList)) {
+            return Collections.emptyList();
+        }
+
         /*拼装返参*/
         /*拼装返参*/
         List<CertificateResVo> list = new ArrayList<>();
         List<CertificateResVo> list = new ArrayList<>();
-        kwsEntCertificates.forEach(item -> {
+        finalList.forEach(item -> {
             CertificateResVo certificateResVo = new CertificateResVo();
             CertificateResVo certificateResVo = new CertificateResVo();
             certificateResVo.setTypeName(Objects.requireNonNull(CertificateTypeEnum.getName(item.getType())).getName());
             certificateResVo.setTypeName(Objects.requireNonNull(CertificateTypeEnum.getName(item.getType())).getName());
             BeanUtils.copyProperties(item, certificateResVo);
             BeanUtils.copyProperties(item, certificateResVo);
@@ -810,6 +846,13 @@ public class KwsEnterpriseService {
         if (CollectionUtils.isNotEmpty(listByEntIds)) {
         if (CollectionUtils.isNotEmpty(listByEntIds)) {
             entDetailResVo.setEntTypes(String.join(Global.COMMA, listByEntIds.stream().map(KwsEntType::getType).map(String::valueOf).distinct().toList()));
             entDetailResVo.setEntTypes(String.join(Global.COMMA, listByEntIds.stream().map(KwsEntType::getType).map(String::valueOf).distinct().toList()));
         }
         }
+
+        List<KwsEntCheckTrack> list = kwsEntCheckTrackDao.findList(id);
+        if (CollectionUtils.isNotEmpty(list)) {
+            entDetailResVo.setValid(list.stream().anyMatch(item -> item.getStatus().equals(Global.NO)));
+        } else {
+            entDetailResVo.setValid(false);
+        }
         return entDetailResVo;
         return entDetailResVo;
     }
     }
 
 

+ 4 - 0
sckw-modules/sckw-system/src/main/resources/mapper/KwsEntCertificateDao.xml

@@ -38,6 +38,10 @@
     select a.* from kws_ent_certificate a where a.ent_id = #{entId} and a.type = #{type} and a.del_flag = 0 and a.status = 0
     select a.* from kws_ent_certificate a where a.ent_id = #{entId} and a.type = #{type} and a.del_flag = 0 and a.status = 0
   </select>
   </select>
 
 
+  <select id="findPrevious" resultType="com.sckw.system.model.KwsEntCertificate">
+    select a.* from kws_ent_certificate a where a.ent_id = #{entId} and a.type = #{type} and a.del_flag = 0 and a.status in (0, 1)
+  </select>
+
   <insert id="insert" parameterType="com.sckw.system.model.KwsEntCertificate">
   <insert id="insert" parameterType="com.sckw.system.model.KwsEntCertificate">
     insert into kws_ent_certificate
     insert into kws_ent_certificate
     <trim prefix="(" suffix=")" suffixOverrides=",">
     <trim prefix="(" suffix=")" suffixOverrides=",">

+ 16 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/dao/KwtWaybillOrderMapper.java

@@ -5,6 +5,7 @@ import com.sckw.mongo.model.TableTops;
 import com.sckw.transport.model.KwtWaybillOrder;
 import com.sckw.transport.model.KwtWaybillOrder;
 import com.sckw.transport.model.dto.OrderCarDTO;
 import com.sckw.transport.model.dto.OrderCarDTO;
 import com.sckw.transport.model.dto.WayBillDetailDTO;
 import com.sckw.transport.model.dto.WayBillDetailDTO;
+import com.sckw.transport.model.dto.WaybillAmountDTO;
 import com.sckw.transport.model.vo.WaybillCountVo;
 import com.sckw.transport.model.vo.WaybillCountVo;
 import com.sckw.transport.model.vo.WaybillOrderDriverVo;
 import com.sckw.transport.model.vo.WaybillOrderDriverVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
@@ -162,6 +163,21 @@ public interface KwtWaybillOrderMapper extends BaseMapper<KwtWaybillOrder> {
             @Param("endDate") String endDate
             @Param("endDate") String endDate
     );
     );
 
 
+    /**
+     * 按装卸量统计运单
+     * @param entId 企业ID
+     * @param statuses 查询状态
+     * @return
+     */
+    List<WaybillAmountDTO> selectWaybillOrdersByStatus(
+            @Param("entId") Long entId,
+            @Param("statuses") List<Long> statuses,
+            @Param("keyword") String keyword,
+            @Param("startDate") String startDate,
+            @Param("endDate") String endDate
+    );
+
+
     String getMaxOrderNo(@Param("lOrderNo") String lOrderNo);
     String getMaxOrderNo(@Param("lOrderNo") String lOrderNo);
 
 
     /**
     /**

+ 39 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/dto/WaybillAmountDTO.java

@@ -0,0 +1,39 @@
+package com.sckw.transport.model.dto;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @author JC
+ * @version 1.0
+ * @desc TODO
+ * @date 2023/09/22 08:50:14
+ **/
+@Data
+public class WaybillAmountDTO {
+    /**
+     * 实装量
+     */
+    private BigDecimal loadAmount;
+
+    /**
+     * 实卸量
+     */
+    private BigDecimal unloadAmount;
+
+    /**
+     * 货损量
+     */
+    private BigDecimal deficitAmount;
+
+    /**
+     * 允许货损量
+     */
+    private BigDecimal loss;
+
+    /**
+     * 货损量计算单位
+     */
+    private String lossUnit;
+}

+ 25 - 2
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/CommonService.java

@@ -804,6 +804,25 @@ public class CommonService {
      * @date 2023/7/27
      * @date 2023/7/27
      **/
      **/
     public BigDecimal deficitPrice(BigDecimal loadAmount, BigDecimal deficitAmount, BigDecimal loss, String lossUnit) {
     public BigDecimal deficitPrice(BigDecimal loadAmount, BigDecimal deficitAmount, BigDecimal loss, String lossUnit) {
+        //亏吨<=0
+//        if (deficitAmount.compareTo(new BigDecimal(Global.AMOUNT)) <= 0) {
+//            return new BigDecimal(Global.AMOUNT);
+//        }
+//        //承运订单亏吨扣款=(承运订单亏吨量 -(承运订单装货量 * 承运订单合理损耗))* 扣亏货值
+//        loss = loss == null ? new BigDecimal(Global.AMOUNT) : loss;
+//        if (loss.doubleValue() > 0 && StringUtils.isNotBlank(lossUnit)) {
+//            if (lossUnit.equals(String.valueOf(TaxRateTypeEnum.PERCENT.getCode()))) {
+//                loss = loss.divide(new BigDecimal(TaxRateTypeEnum.PERCENT.getValue()));
+//            }
+//            if (lossUnit.equals(String.valueOf(TaxRateTypeEnum.MILLIMETER.getCode()))) {
+//                loss = loss.divide(new BigDecimal(TaxRateTypeEnum.MILLIMETER.getValue()));
+//            }
+//        }
+//        //扣亏量
+//        BigDecimal deficitPrice = deficitAmount.subtract(loadAmount.multiply(loss).setScale(4, RoundingMode.HALF_UP));
+//        return deficitPrice;
+
+
         //亏吨<=0
         //亏吨<=0
         if (deficitAmount.compareTo(new BigDecimal(Global.AMOUNT)) <= 0) {
         if (deficitAmount.compareTo(new BigDecimal(Global.AMOUNT)) <= 0) {
             return new BigDecimal(Global.AMOUNT);
             return new BigDecimal(Global.AMOUNT);
@@ -818,8 +837,12 @@ public class CommonService {
                 loss = loss.divide(new BigDecimal(TaxRateTypeEnum.MILLIMETER.getValue()));
                 loss = loss.divide(new BigDecimal(TaxRateTypeEnum.MILLIMETER.getValue()));
             }
             }
         }
         }
-        //扣亏量
-        BigDecimal deficitPrice = deficitAmount.subtract(loadAmount.multiply(loss).setScale(4, RoundingMode.HALF_UP));
+        //扣亏量=亏吨量-合理损耗值【要求大于0,如果小于0则扣亏货量取0】
+        BigDecimal deficitPrice = deficitAmount.subtract(loadAmount.multiply(loss).setScale(2, RoundingMode.HALF_UP));
+        log.error("[ddd] {}", deficitPrice);
+        if (deficitPrice.doubleValue() <= 0) {
+            return new BigDecimal(Global.AMOUNT);
+        }
         return deficitPrice;
         return deficitPrice;
     }
     }
 }
 }

+ 35 - 5
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/WaybillManagementService.java

@@ -22,10 +22,7 @@ import com.sckw.system.api.model.dto.res.SysDictResDto;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
 import com.sckw.transport.dao.*;
 import com.sckw.transport.dao.*;
 import com.sckw.transport.model.*;
 import com.sckw.transport.model.*;
-import com.sckw.transport.model.dto.AddressDropListDTO;
-import com.sckw.transport.model.dto.WayBillDetailDTO;
-import com.sckw.transport.model.dto.WaybillListAppDTO;
-import com.sckw.transport.model.dto.WaybillOrderDTO;
+import com.sckw.transport.model.dto.*;
 import com.sckw.transport.model.vo.*;
 import com.sckw.transport.model.vo.*;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.dubbo.config.annotation.DubboReference;
@@ -960,13 +957,46 @@ public class WaybillManagementService {
      */
      */
     public HttpResult waybillAmountStatistic(WaybillListAppDTO query) {
     public HttpResult waybillAmountStatistic(WaybillListAppDTO query) {
         List<Long> _statuses = getWallBillStatues(query.getStatus());
         List<Long> _statuses = getWallBillStatues(query.getStatus());
-        Map<String, Object> amount = kwtWaybillOrderMapper.selectWaybillOrderAmountByStatus(
+        List<WaybillAmountDTO> wOrders = kwtWaybillOrderMapper.selectWaybillOrdersByStatus(
                 LoginUserHolder.getEntId(),
                 LoginUserHolder.getEntId(),
                 _statuses,
                 _statuses,
                 query.getKeyword(),
                 query.getKeyword(),
                 StringUtils.isBlank(query.getStartDate()) ? null : query.getStartDate().concat(" 00:00:00"),
                 StringUtils.isBlank(query.getStartDate()) ? null : query.getStartDate().concat(" 00:00:00"),
                 StringUtils.isBlank(query.getEndDate()) ? null : query.getEndDate().concat(" 23:59:59")
                 StringUtils.isBlank(query.getEndDate()) ? null : query.getEndDate().concat(" 23:59:59")
         );
         );
+        Map<String, String> amount = new HashMap<>();
+        // 总计条数
+        BigDecimal loadAmount = new BigDecimal(Global.AMOUNT);
+        BigDecimal unloadAmount = new BigDecimal(Global.AMOUNT);
+        BigDecimal lossAmount = new BigDecimal(Global.AMOUNT);
+        BigDecimal deficitRealAmount = new BigDecimal(Global.AMOUNT);
+        if(CollectionUtils.isNotEmpty(wOrders)) {
+            for (WaybillAmountDTO wOrder:wOrders) {
+                loadAmount = loadAmount.add(wOrder.getLoadAmount() == null ? new BigDecimal(Global.AMOUNT) : wOrder.getLoadAmount());
+                unloadAmount = unloadAmount.add(wOrder.getUnloadAmount() == null ? new BigDecimal(Global.AMOUNT) : wOrder.getUnloadAmount());
+                lossAmount = lossAmount.add(wOrder.getDeficitAmount() == null ? new BigDecimal(Global.AMOUNT) : wOrder.getDeficitAmount());
+                if(wOrder.getLoadAmount() != null
+                        && wOrder.getUnloadAmount() != null
+                        && wOrder.getDeficitAmount() != null
+                ) {
+                    BigDecimal realDeficitAMount = commonService.deficitPrice(
+                            wOrder.getLoadAmount(),
+                            wOrder.getDeficitAmount(),
+                            wOrder.getLoss(),
+                            wOrder.getLossUnit()
+                    );
+                    deficitRealAmount = deficitRealAmount.add(realDeficitAMount);
+                }
+            }
+        }
+        // 总计装货量
+        amount.put("loadAmount",  String.valueOf(loadAmount));
+        // 总计卸货量
+        amount.put("unloadAmount",  String.valueOf(unloadAmount));
+        // 总计货损量
+        amount.put("lossAmount",  String.valueOf(lossAmount));
+        // 总计扣亏量
+        amount.put("deficitRealAmount",  String.valueOf(deficitRealAmount));
         return HttpResult.ok(amount);
         return HttpResult.ok(amount);
     }
     }
 
 

+ 32 - 0
sckw-modules/sckw-transport/src/main/resources/mapper/KwtWaybillOrderMapper.xml

@@ -564,6 +564,38 @@
         </if>
         </if>
     </select>
     </select>
 
 
+    <select id="selectWaybillOrdersByStatus" resultType="com.sckw.transport.model.dto.WaybillAmountDTO">
+        SELECT
+        wo.load_amount as loadAmount,
+        wo.unload_amount as unloadAmount,
+        wo.deficit_amount as DeficitAmount,
+        lo.loss as loss,
+        lo.loss_unit as lossUnit
+        FROM
+        kwt_waybill_order AS wo
+        LEFT JOIN kwt_logistics_order AS lo
+        ON lo.id = wo.l_order_id
+        WHERE wo.ent_id = #{entId}
+        AND wo.del_flag = 0
+        <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
+            AND wo.create_time BETWEEN #{startDate} AND #{endDate}
+        </if>
+        <if test="keyword != null and keyword != ''">
+            AND (
+            wo.w_order_no LIKE concat('%',#{keyword},'%')
+            OR wo.truck_no LIKE concat('%',#{keyword},'%')
+            OR wo.driver_name LIKE concat('%',#{keyword},'%')
+            OR wo.driver_phone LIKE concat('%',#{keyword},'%')
+            )
+        </if>
+        <if test="statuses != null and statuses.size() > 0">
+            AND wo.status IN
+            <foreach collection="statuses" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+
     <select id="getMaxOrderNo" resultType="java.lang.String">
     <select id="getMaxOrderNo" resultType="java.lang.String">
         SELECT w_order_no FROM `kwt_waybill_order`  WHERE w_order_no LIKE concat(#{lOrderNo},'%') ORDER BY w_order_no DESC LIMIT 1
         SELECT w_order_no FROM `kwt_waybill_order`  WHERE w_order_no LIKE concat(#{lOrderNo},'%') ORDER BY w_order_no DESC LIMIT 1
     </select>
     </select>