Bläddra i källkod

新增商户端员工置顶接口,修改列表排序逻辑

penghao 2 veckor sedan
förälder
incheckning
7945c134e1

+ 11 - 0
alien-entity/src/main/java/shop/alien/entity/store/StoreStaffConfig.java

@@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 import java.util.Date;
 
@@ -16,6 +17,7 @@ import java.util.Date;
  * @Description: 员工管理
  */
 @Data
+@EqualsAndHashCode(callSuper = false)
 @JsonInclude
 @TableName("store_staff_config")
 @ApiModel(value = "StoreStaffConfig对象", description = "员工管理")
@@ -89,4 +91,13 @@ public class StoreStaffConfig extends Model<StoreStaffConfig> {
     @ApiModelProperty(value = "修改人ID")
     @TableField("updated_user_id")
     private Integer updatedUserId;
+
+    @ApiModelProperty(value = "置顶状态, 0:未置顶, 1:已置顶")
+    @TableField("top_status")
+    private Integer topStatus;
+
+    @ApiModelProperty(value = "置顶时间")
+    @TableField("top_time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date topTime;
 }

+ 12 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreStaffConfigController.java

@@ -86,6 +86,18 @@ public class StoreStaffConfigController {
         log.info("StoreStaffConfigController.deleteStaffConfig?id={}", id);
         return R.data(storeStaffConfigService.deleteStaffConfig(id));
     }
+
+    @ApiOperation("置顶员工")
+    @ApiOperationSupport(order = 5)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "topStatus", value = "置顶状态 0-取消置顶, 1-置顶", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/setTopStatus")
+    public R<Integer> setTopStatus(Integer id, Integer topStatus) {
+        log.info("StoreStaffConfigController.setTopStatus?id={},topStatus={}", id, topStatus);
+        return R.data(storeStaffConfigService.setTopStatus(id, topStatus));
+    }
     /**
      * 员工列表查询接口(用户端)
      *

+ 9 - 0
alien-store/src/main/java/shop/alien/store/service/StoreStaffConfigService.java

@@ -26,6 +26,15 @@ public interface StoreStaffConfigService {
      */
     Integer deleteStaffConfig(Integer id);
 
+    /**
+     * 置顶员工
+     *
+     * @param id 员工ID
+     * @param topStatus 置顶状态 0-未置顶, 1-置顶
+     * @return
+     */
+    Integer setTopStatus(Integer id, Integer topStatus);
+
 
     /**
      * 员工列表查询

+ 20 - 2
alien-store/src/main/java/shop/alien/store/service/impl/StoreStaffConfigServiceImpl.java

@@ -1,6 +1,7 @@
 package shop.alien.store.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -51,7 +52,8 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
         IPage<StoreStaffConfig> storePage = new Page<>(page, size);
         QueryWrapper<StoreStaffConfig> queryWrapper = new QueryWrapper<>();
         queryWrapper.like(null != status && !status.isEmpty(), "status", status);
-        queryWrapper.orderByDesc("created_time");
+        // 排序规则:先按置顶状态降序(置顶的在前),再按置顶时间降序,最后按创建时间降序
+        queryWrapper.orderByDesc("top_status", "top_time", "created_time");
         return storeStaffConfigMapper.selectPage(storePage, queryWrapper);
     }
 
@@ -60,7 +62,7 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
         // 判断是新增还是更新:id为null或0或负数表示新增
         // 注意:新增时不应该传入id,如果传入了非0的id,需要先查询是否存在
         Integer id = storeStaffConfig.getId();
-
+        
         if (id == null || id == 0) {
             // 新增操作:id为null或0
             Date nowDate = new Date(System.currentTimeMillis());
@@ -153,6 +155,22 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
     }
 
     @Override
+    public Integer setTopStatus(Integer id, Integer topStatus) {
+        if (id == null || topStatus == null) {
+            return 0;
+        }
+        LambdaUpdateWrapper<StoreStaffConfig> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
+        lambdaUpdateWrapper.eq(StoreStaffConfig::getId, id);
+        lambdaUpdateWrapper.set(StoreStaffConfig::getTopStatus, topStatus);
+        if (topStatus == 0) {
+            lambdaUpdateWrapper.set(StoreStaffConfig::getTopTime, null);
+        } else {
+            lambdaUpdateWrapper.set(StoreStaffConfig::getTopTime, new Date());
+        }
+        return storeStaffConfigMapper.update(null, lambdaUpdateWrapper);
+    }
+
+    @Override
     public IPage<StoreStaffConfig> queryStaffList(Integer page, Integer size, Integer storeId, String status) {
         IPage<StoreStaffConfig> storePage = new Page<>(page, size);
         QueryWrapper<StoreStaffConfig> queryWrapper = new QueryWrapper<>();