Browse Source

新增商户端人员配置删除接口,修改优化新增或修改人员配置接口逻辑

penghao 2 weeks ago
parent
commit
4ee68d3489

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

@@ -78,4 +78,12 @@ public class StoreStaffConfigController {
         return R.data(s);
     }
 
+    @ApiOperation("删除员工")
+    @ApiOperationSupport(order = 4)
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query", required = true)})
+    @GetMapping("/deleteStaffConfig")
+    public R<Integer> deleteStaffConfig(Integer id) {
+        log.info("StoreStaffConfigController.deleteStaffConfig?id={}", id);
+        return R.data(storeStaffConfigService.deleteStaffConfig(id));
+    }
 }

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

@@ -17,4 +17,13 @@ public interface StoreStaffConfigService {
     StoreStaffConfig getStaffConfigDeatail(Integer id);
 
     String staffConfigExport(String status) throws IOException;
+
+    /**
+     * 删除员工
+     *
+     * @param id
+     * @return
+     */
+    Integer deleteStaffConfig(Integer id);
+
 }

+ 43 - 3
alien-store/src/main/java/shop/alien/store/service/impl/StoreStaffConfigServiceImpl.java

@@ -9,7 +9,6 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import shop.alien.entity.store.StoreStaffConfig;
-import shop.alien.entity.store.excelVo.StoreInfoExpiredRecordsExcelVo;
 import shop.alien.entity.store.excelVo.StoreStaffConfigExcelVo;
 import shop.alien.entity.store.excelVo.util.ExcelGenerator;
 import shop.alien.mapper.StoreStaffConfigMapper;
@@ -57,12 +56,47 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
 
     @Override
     public int addOrUpdateStaffConfig(StoreStaffConfig storeStaffConfig) {
-        if (StringUtils.isEmpty(storeStaffConfig.getId().toString())) {
+        // 判断是新增还是更新:id为null或0或负数表示新增
+        // 注意:新增时不应该传入id,如果传入了非0的id,需要先查询是否存在
+        Integer id = storeStaffConfig.getId();
+        
+        if (id == null || id == 0) {
+            // 新增操作:id为null或0
             Date nowDate = new Date(System.currentTimeMillis());
             storeStaffConfig.setCreatedTime(nowDate);
+            // 设置删除标记为0(未删除)- 必须设置,否则可能插入失败
+            if (storeStaffConfig.getDeleteFlag() == null) {
+                storeStaffConfig.setDeleteFlag(0);
+            }
+            // 如果状态为空,设置默认状态为待审核(0)
+            if (StringUtils.isEmpty(storeStaffConfig.getStatus())) {
+                storeStaffConfig.setStatus("0");
+            }
+            // 新增时,确保id为null,让数据库自动生成
+            storeStaffConfig.setId(null);
             return storeStaffConfigMapper.insert(storeStaffConfig);
         } else {
-            return storeStaffConfigMapper.updateById(storeStaffConfig);
+            // 更新操作:id不为null且不为0
+            // 先查询记录是否存在,如果不存在则转为新增
+            StoreStaffConfig existing = storeStaffConfigMapper.selectById(id);
+            if (existing == null) {
+                // 记录不存在,转为新增操作
+                storeStaffConfig.setId(null); // 重置id,让数据库自动生成
+                Date nowDate = new Date(System.currentTimeMillis());
+                storeStaffConfig.setCreatedTime(nowDate);
+                // 设置删除标记为0(未删除)
+                if (storeStaffConfig.getDeleteFlag() == null) {
+                    storeStaffConfig.setDeleteFlag(0);
+                }
+                // 如果状态为空,设置默认状态为待审核(0)
+                if (StringUtils.isEmpty(storeStaffConfig.getStatus())) {
+                    storeStaffConfig.setStatus("0");
+                }
+                return storeStaffConfigMapper.insert(storeStaffConfig);
+            } else {
+                // 记录存在,执行更新
+                return storeStaffConfigMapper.updateById(storeStaffConfig);
+            }
         }
     }
 
@@ -110,4 +144,10 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
         return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
     }
 
+    @Override
+    public Integer deleteStaffConfig(Integer id) {
+        // 使用 MyBatis-Plus 的逻辑删除,会自动将 deleteFlag 设置为 1
+        // 因为实体类使用了 @TableLogic 注解
+        return storeStaffConfigMapper.deleteById(id);
+    }
 }