|
|
@@ -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);
|
|
|
+ }
|
|
|
}
|