Răsfoiți Sursa

机具回收接口优化

mac 2 ani în urmă
părinte
comite
2547ecf35c

+ 4 - 0
kxs-common/kxs-common-core/src/main/java/com/kxs/common/core/constant/CommonConstants.java

@@ -102,6 +102,10 @@ public interface CommonConstants {
 	 * KXS提现订单号前缀
 	 */
 	String KXS_WAREHOUSE_APPLY_PREFIX = "FC";
+	/**
+	 * 机具回收订单
+	 */
+	String KXS_MACHINE_RE_PREFIX = "JJHS";
 
 	/**
 	 * K2最低交易基数

+ 7 - 0
kxs-product/kxs-product-api/src/main/java/com/kxs/product/api/dto/kxsapp/machine/RecycleMachineQuery.java

@@ -3,6 +3,8 @@ package com.kxs.product.api.dto.kxsapp.machine;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
+import java.time.LocalDateTime;
+
 
 /**
  * 仓库库存机具列表-dto
@@ -33,5 +35,10 @@ public class RecycleMachineQuery {
     @Schema(description = "sn")
     private String posSn;
 
+    /**
+     * 循环结束时间
+     */
+    private LocalDateTime endDay;
+
 
 }

+ 4 - 4
kxs-product/kxs-product-api/src/main/java/com/kxs/product/api/model/KxsMachine.java

@@ -207,15 +207,15 @@ public class KxsMachine extends Model<KxsMachine> implements Serializable {
 
 
     /**
-     * 状态 0在库 1出库
+     * 状态 -1坏机 0在库 1出库
      */
-    @Schema(description = "状态 0在库 1出库 2已退回 3可回收 4回收中 5已回收 6已预发")
+    @Schema(description = "状态 -1坏机 0在库 1出库")
     private Integer status;
 
     /**
-     * 回收状态 待回收=1 待确认=2 已确认=3 已驳回=4 已撤回=-1
+     * 回收状态 0正常 1可回收
      */
-    @Schema(description = "回收状态 待回收=1 待确认=2 已确认=3 已驳回=4 已撤回=-1")
+    @Schema(description = "回收状态 0正常 1可回收 ")
     private Integer returnStatus;
 
 

+ 5 - 4
kxs-product/kxs-product-biz/src/main/java/com/kxs/product/biz/mapper/KxsMachineMapper.java

@@ -116,13 +116,14 @@ public interface KxsMachineMapper extends BaseMapper<KxsMachine> {
      * @param userId 用户id
      * @return 机具可回收列表
      */
-    List<RecycleBrandListVO> recycleBrandList(Long userId);
+    List<RecycleBrandListVO> recycleBrandList(@Param("userId") Long userId, @Param("endDay") LocalDateTime endDay);
 
     /**
      * 查询激活和绑定时间在指定区间的机具
-     * @param param
-     * @param brandId
-     * @return
+     *
+     * @param param   参数
+     * @param brandId 品牌标识
+     * @return {@link Integer}
      */
     Integer getActivityMachineByIdAndTime(@Param("param")GetActivityMachineByIdAndTimeDTO param,@Param("brandId") Long brandId);
 

+ 8 - 1
kxs-product/kxs-product-biz/src/main/java/com/kxs/product/biz/service/impl/KxsMachineServiceImpl.java

@@ -35,6 +35,7 @@ import com.kxs.store.api.dto.admin.machine.WarehouseSearchDTO;
 import com.kxs.store.api.feign.RemoteKxsStoreService;
 import com.kxs.store.api.feign.RemoteKxsWarehouseService;
 import com.kxs.system.api.feign.RemoteOldService;
+import com.kxs.system.api.util.ParamResolver;
 import com.kxs.system.api.vo.kxsapp.RecycleBrandListVO;
 import com.kxs.user.api.dto.admin.user.UserSearchDTO;
 import com.kxs.user.api.feign.RemoteKxsUserService;
@@ -231,6 +232,9 @@ public class KxsMachineServiceImpl extends ServiceImpl<KxsMachineMapper, KxsMach
 
         Long userId = SecurityUtils.getUser().getId();
         param.setUserId(userId.intValue());
+        Integer reDayCount = ParamResolver.getInteger("MACHINE_RE_DAY_COUNT", 15);
+        LocalDateTime endDay = LocalDate.now().minusDays(reDayCount).atStartOfDay();
+        param.setEndDay(endDay);
 
         return baseMapper.recyclePageList(page, param);
     }
@@ -329,7 +333,10 @@ public class KxsMachineServiceImpl extends ServiceImpl<KxsMachineMapper, KxsMach
     @Override
     public Object recycleBrandList() {
         Long userId = SecurityUtils.getUser().getId();
-        return baseMapper.recycleBrandList(userId);
+        Integer reDayCount = ParamResolver.getInteger("MACHINE_RE_DAY_COUNT", 15);
+        LocalDateTime endDay = LocalDate.now().minusDays(reDayCount).atStartOfDay();
+
+        return  baseMapper.recycleBrandList(userId, endDay);
     }
 
     @Override

+ 20 - 18
kxs-product/kxs-product-biz/src/main/resources/mapper/KxsMachineMapper.xml

@@ -141,8 +141,10 @@
     <select id="recyclePageList" resultType="com.kxs.product.api.vo.kxsapp.machine.MachineRecycleListVO">
         select recycle_end_time, pos_sn, brand_id from kxs_machine
         where del_flag = 0
-          and status = 3
-          and user_id = #{query.userId}
+        and bind_status = 0
+        and is_act = 0
+        and recycle_end_time &lt; #{query.endDay}
+        and user_id = #{query.userId}
         <if test="query.posSn != null and query.posSn != ''">
             and pos_sn like concat('%', #{query.posSn}, '%')
         </if>
@@ -157,8 +159,7 @@
         select a.id, a.user_id, a.pos_sn, a.brand_id, a.recycle_end_time
         from kxs_machine a
                  left join kxs_machine_deduct b on a.pos_sn = b.pos_sn
-        where
-          b.pos_sn is null
+        where b.pos_sn is null
           and a.del_flag = 0
           and a.user_id = #{query.userId}
           and a.status = #{query.status}
@@ -169,26 +170,27 @@
         select a.id, a.pos_sn, recycle_end_time
         from kxs_machine a
                  left join kxs_machine_deduct b on a.pos_sn = b.pos_sn
-        where
-          b.pos_sn is null
+        where b.pos_sn is null
           and a.del_flag = 0
           and a.status = 1
           and a.user_id > 0
           and a.bind_status = 0
           and a.recycle_end_time &lt; #{endDay}
-          order by recycle_end_time desc
-          limit 1000
+        order by recycle_end_time desc limit 1000
     </select>
     <select id="recycleBrandList" resultType="com.kxs.system.api.vo.kxsapp.RecycleBrandListVO">
-        select DISTINCT kb.id,kb.name from kxs_machine km
-        left join  kxs_brand kb on km.brand_id = kb.id
+        select DISTINCT kb.id, kb.name
+        from kxs_machine km
+                 left join kxs_brand kb on km.brand_id = kb.id
         where km.del_flag = 0
-        and km.status = 3
-        and km.user_id = #{query.userId}
+          and km.is_act = 0
+          and km.bind_status = 0
+          and km.recycle_end_time &lt; #{endDay}
+          and km.user_id = #{userId}
     </select>
     <select id="getActivityMachineByIdAndTime" resultType="java.lang.Integer">
         select
-            count(id) as number
+        count(id) as number
         from kxs_machine
         where del_flag != 1
         and bind_time between #{param.startTime} and #{param.endTime}
@@ -204,9 +206,9 @@
 
     <select id="machinePage" resultMap="KxsMachineMap">
         SELECT
-            km.*
+        km.*
         FROM
-            kxs_machine km
+        kxs_machine km
         <where>
             and km.del_flag = 0
             <if test="query.posSn != null and query.posSn != ''">
@@ -241,19 +243,19 @@
             <if test="query.bindTime != null and query.bindTime.length > 1">
                 and (
                 DATE_FORMAT(km.bind_time,'%Y-%m-%d') >= DATE_FORMAT(#{query.bindTime.[0]},'%Y-%m-%d') and
-                DATE_FORMAT(#{query.bindTime.[1]},'%Y-%m-%d')  >= DATE_FORMAT(km.bind_time,'%Y-%m-%d')
+                DATE_FORMAT(#{query.bindTime.[1]},'%Y-%m-%d') >= DATE_FORMAT(km.bind_time,'%Y-%m-%d')
                 )
             </if>
             <if test="query.actTime != null and query.actTime.length > 1">
                 and (
                 DATE_FORMAT(km.act_time,'%Y-%m-%d') >= DATE_FORMAT(#{query.actTime.[0]},'%Y-%m-%d') and
-                DATE_FORMAT(#{query.actTime.[1]},'%Y-%m-%d')  >= DATE_FORMAT(km.act_time,'%Y-%m-%d')
+                DATE_FORMAT(#{query.actTime.[1]},'%Y-%m-%d') >= DATE_FORMAT(km.act_time,'%Y-%m-%d')
                 )
             </if>
             <if test="query.deliveryTime != null and query.deliveryTime.length > 1">
                 and (
                 DATE_FORMAT(km.delivery_time,'%Y-%m-%d') >= DATE_FORMAT(#{query.deliveryTime.[0]},'%Y-%m-%d') and
-                DATE_FORMAT(#{query.deliveryTime.[1]},'%Y-%m-%d')  >= DATE_FORMAT(km.delivery_time,'%Y-%m-%d')
+                DATE_FORMAT(#{query.deliveryTime.[1]},'%Y-%m-%d') >= DATE_FORMAT(km.delivery_time,'%Y-%m-%d')
                 )
             </if>
         </where>

+ 0 - 1
kxs-store/kxs-store-api/src/main/java/com/kxs/store/api/model/KxsMachineRecycle.java

@@ -53,7 +53,6 @@ public class KxsMachineRecycle extends Model<KxsMachineRecycle> implements Seria
      * 删除标记,0未删除,1已删除
      */
     @Schema(description = "删除标记,0未删除,1已删除")
-    @TableLogic
     private String delFlag;
 
 

+ 0 - 1
kxs-store/kxs-store-api/src/main/java/com/kxs/store/api/model/KxsMachineRecycleInfo.java

@@ -60,7 +60,6 @@ public class KxsMachineRecycleInfo extends Model<KxsMachineRecycleInfo> implemen
      * 删除标记,0未删除,1已删除
      */
     @Schema(description = "删除标记,0未删除,1已删除")
-    @TableLogic
     private String delFlag;
 
 

+ 1 - 1
kxs-store/kxs-store-api/src/main/java/com/kxs/store/api/vo/kxsapp/storeRecycle/RecycleInfoVO.java

@@ -23,7 +23,7 @@ public class RecycleInfoVO implements Serializable {
     /**
      * 状态 0未确认 1已确认 2已驳回态
      */
-    @Schema(description = "状态 0未确认 1已确认 2已驳回")
+    @Schema(description = "状态 0未确认 1已确认 2已驳回 3已取消")
     private Integer confirmStatus;
 
     /**

+ 21 - 41
kxs-store/kxs-store-biz/src/main/java/com/kxs/store/biz/service/impl/KxsMachineRecycleServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.kxs.common.core.constant.CommonConstants;
 import com.kxs.common.core.constant.SecurityConstants;
 import com.kxs.common.core.constant.enums.ErrorTypeEnum;
 import com.kxs.common.core.constant.enums.MachineTypeEnum;
@@ -114,7 +115,7 @@ public class KxsMachineRecycleServiceImpl extends ServiceImpl<KxsMachineRecycleM
                 //修改机具
                 machine.setWarehouseId(machineRecycle.getWarehouseId());
                 machine.setUserId(0);
-//                machine.setStatus(MachineTypeEnum.RECYCLE_CONFIRM.getType());
+                machine.setStatus(MachineTypeEnum.STATUS_IS.getType());
                 machine.setMachineType(MachineTypeEnum.M_TYPE_SN.getType());
                 R<Boolean> booleanR = remoteKxsProductService.updateByMachine(machine, SecurityConstants.FROM_IN);
                 if(!booleanR.getData()){
@@ -146,18 +147,6 @@ public class KxsMachineRecycleServiceImpl extends ServiceImpl<KxsMachineRecycleM
                 recycleInfo.setStatus(RecycleOrderEnum.INFO_CANCEL.getType());
                 recycleInfo.setCancelTime(LocalDateTime.now());
                 kxsMachineRecycleInfoMapper.updateById(recycleInfo);
-
-                //修改机具状态未可回收
-                R<KxsMachine> kxsMachineR = remoteKxsProductService.loadMachineBySn(recycleInfo.getPosSn(), SecurityConstants.FROM_IN);
-                KxsMachine machine = RetOps.of(kxsMachineR)
-                        .getData()
-                        .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.SN_FIND_NULL.getDescription()));
-                machine.setStatus(MachineTypeEnum.RECYCLE_STATUS.getType());
-
-                R<Boolean> booleanR = remoteKxsProductService.updateByMachine(machine, SecurityConstants.FROM_IN);
-                if(!booleanR.getData()){
-                    throw new GlobalCustomerException(ErrorTypeEnum.REMOTE_DATA_ERROR.getDescription());
-                }
             }
         }
 
@@ -207,7 +196,7 @@ public class KxsMachineRecycleServiceImpl extends ServiceImpl<KxsMachineRecycleM
         BeanUtils.copyProperties(param, machineRecycle);
         //订单号
         String orderSn = IdUtil.getSnowflakeNextIdStr();
-        machineRecycle.setOrderSn("JJHS" + orderSn);
+        machineRecycle.setOrderSn(CommonConstants.KXS_MACHINE_RE_PREFIX + orderSn);
 
         machineRecycle.setUserId(userId.intValue());
         machineRecycle.setUsername(user.getUsername());
@@ -223,10 +212,16 @@ public class KxsMachineRecycleServiceImpl extends ServiceImpl<KxsMachineRecycleM
             KxsMachine machine = RetOps.of(kxsMachineR)
                     .getData()
                     .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.DATA_ERROR.getDescription()));
-            if(!Objects.equals(machine.getStatus(), MachineTypeEnum.RECYCLE_STATUS.getType())){
-                throw new GlobalCustomerException("机具号" + machine.getPosSn() + "不可回收");
+            if(Objects.equals(machine.getIsAct(), MachineTypeEnum.ACT.getType()) || Objects.equals(machine.getBindStatus(), MachineTypeEnum.BIND.getType())){
+                throw new GlobalCustomerException("机具号" + machine.getPosSn() + "已绑定/已激活");
+            }
+            //查询是否已提交
+            KxsMachineRecycleInfo recycleInfo = kxsMachineRecycleInfoMapper.selectOne(Wrappers.<KxsMachineRecycleInfo>lambdaQuery()
+                    .in(KxsMachineRecycleInfo::getStatus, 0, 1)
+                    .eq(KxsMachineRecycleInfo::getPosSn, sn));
+            if(recycleInfo != null){
+                throw new GlobalCustomerException("机具号" + machine.getPosSn() + "重复提交/已回收");
             }
-
             KxsMachineRecycleInfo kxsMachineRecycleInfo = new KxsMachineRecycleInfo();
             kxsMachineRecycleInfo.setPosSn(sn);
             kxsMachineRecycleInfo.setOrderId(machineRecycle.getId());
@@ -234,11 +229,6 @@ public class KxsMachineRecycleServiceImpl extends ServiceImpl<KxsMachineRecycleM
             kxsMachineRecycleInfo.setRecycleEndTime(machine.getRecycleEndTime());
             kxsMachineRecycleInfoMapper.insert(kxsMachineRecycleInfo);
 
-//            machine.setStatus(MachineTypeEnum.RECYCLE_UN_CONFIRM.getType());
-//            R<Boolean> booleanR = remoteKxsProductService.updateByMachine(machine, SecurityConstants.FROM_IN);
-//            if (!booleanR.getData()) {
-//                throw new GlobalCustomerException(ErrorTypeEnum.REMOTE_DATA_ERROR.getDescription());
-//            }
         }
         KxsUserMsg kxsUserMsg = MsgTemplateUtil.machineRecycleNote(param.getSnList(), brand.getName(), kxsWarehouse.getUserId(), user.getUserCode());
         remoteUserMsgService.pushUserMsg(kxsUserMsg, SecurityConstants.FROM_IN);
@@ -304,26 +294,16 @@ public class KxsMachineRecycleServiceImpl extends ServiceImpl<KxsMachineRecycleM
             if (recycleInfo == null) {
                 throw new GlobalCustomerException(sn + "机具已处理");
             }
-            //删除回收机具
-            kxsMachineRecycleInfoMapper.deleteById(recycleInfo.getId());
-            //修改机具状态未可回收
-//            R<KxsMachine> kxsMachineR = remoteKxsProductService.loadMachineBySn(sn, SecurityConstants.FROM_IN);
-//            KxsMachine machine = RetOps.of(kxsMachineR)
-//                    .getData()
-//                    .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.SN_FIND_NULL.getDescription()));
-//            machine.setStatus(MachineTypeEnum.RECYCLE_CANCEL.getType());
-//
-//            R<Boolean> booleanR = remoteKxsProductService.updateByMachine(machine, SecurityConstants.FROM_IN);
-//            if(!booleanR.getData()){
-//                throw new GlobalCustomerException(ErrorTypeEnum.REMOTE_DATA_ERROR.getDescription());
+            //回收机具
+            recycleInfo.setStatus(RecycleOrderEnum.INFO_RETURN.getType());
+            kxsMachineRecycleInfoMapper.updateById(recycleInfo);
+
+            //主订单
+//            Long count = kxsMachineRecycleInfoMapper.selectCount(Wrappers.lambdaQuery(KxsMachineRecycleInfo.class)
+//                    .eq(KxsMachineRecycleInfo::getOrderId, recycleInfo.getOrderId()));
+//            if(count == 0){
+//                baseMapper.deleteById(recycleInfo.getOrderId());
 //            }
-
-            //删除主订单
-            Long count = kxsMachineRecycleInfoMapper.selectCount(Wrappers.lambdaQuery(KxsMachineRecycleInfo.class)
-                    .eq(KxsMachineRecycleInfo::getOrderId, recycleInfo.getOrderId()));
-            if(count == 0){
-                baseMapper.deleteById(recycleInfo.getOrderId());
-            }
         });
 
         return R.ok();

+ 1 - 0
kxs-store/kxs-store-biz/src/main/resources/mapper/KxsMachineRecycleMapper.xml

@@ -100,6 +100,7 @@
         <where>
             and t.del_flag = 0
         </where>
+        order by  a.create_time desc
     </select>
     <select id="needConfirmList" resultType="com.kxs.store.api.vo.kxsapp.storeRecycle.NeedConfirmRecycleVO">
         select a.pos_sn, a.recycle_end_time

+ 9 - 1
kxs-system/kxs-system-api/src/main/java/com/kxs/system/api/vo/kxsapp/RecycleBrandListVO.java

@@ -2,8 +2,16 @@ package com.kxs.system.api.vo.kxsapp;
 
 import lombok.Data;
 
+/**
+ * 可回收机具列表
+ *
+ * @author 没秃顶的码农
+ * @date 2024-07-16
+ */
 @Data
 public class RecycleBrandListVO {
-    private int id;
+
+    private Integer id;
+
     private String name;
 }