修改限购问题

dev
袁野 1 week ago
parent 0455cd52ab
commit 15429ed270
  1. 1
      bweb/src/main/java/com/bweb/config/AuthConfig.java
  2. 316
      bweb/src/main/java/com/bweb/controller/goods/GoodsAutoController.java
  3. 68
      schedule/src/main/java/com/schedule/controller/OrderGoodsSchedule.java
  4. 5
      service/pom.xml
  5. 4
      service/src/main/java/com/hfkj/config/ShanGaoConfig.java
  6. 77
      service/src/main/java/com/hfkj/service/goods/GoodsAutoRelService.java
  7. 83
      service/src/main/java/com/hfkj/service/goods/GoodsAutoTaskService.java
  8. 204
      service/src/main/java/com/hfkj/service/goods/impl/GoodsAutoRelServiceImpl.java
  9. 225
      service/src/main/java/com/hfkj/service/goods/impl/GoodsAutoTaskServiceImpl.java

@ -89,6 +89,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/fileUpload/*") .excludePathPatterns("/fileUpload/*")
.excludePathPatterns("/common/*") .excludePathPatterns("/common/*")
.excludePathPatterns("/test/*") .excludePathPatterns("/test/*")
.excludePathPatterns("/goodsAuto/*")
.excludePathPatterns("/apiMer/*") .excludePathPatterns("/apiMer/*")
.excludePathPatterns("/secMenu/queryMenuList") .excludePathPatterns("/secMenu/queryMenuList")
.excludePathPatterns("/user/phgDataUser") .excludePathPatterns("/user/phgDataUser")

@ -0,0 +1,316 @@
package com.bweb.controller.goods;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.GoodsAutoRel;
import com.hfkj.entity.GoodsAutoTask;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.goods.GoodsAutoRelService;
import com.hfkj.service.goods.GoodsAutoTaskService;
import com.hfkj.service.goods.GoodsMsgService;
import com.hfkj.sysenum.SecUserObjectTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.naming.NamingEnumeration;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value="/goodsAuto")
@Api(value="商品自动上下架")
public class GoodsAutoController {
private static final Logger log = LoggerFactory.getLogger(GoodsAutoController.class);
@Resource
private GoodsAutoRelService goodsAutoRelService;
@Resource
private GoodsAutoTaskService goodsAutoTaskService;
@Resource
private UserCenter userCenter;
@RequestMapping(value="/queryList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询列表")
public ResponseData queryList(@RequestParam(value = "taskTitle" , required = false) String taskTitle,
@RequestParam(value = "listingTime" , required = false) Long listingTime,
@RequestParam(value = "removalTime" , required = false) Long removalTime,
@RequestParam(value = "pageNum" , required = true) Integer pageNum,
@RequestParam(value = "pageSize" , required = true) Integer pageSize) {
try {
SecUserSessionObject sessionModel = userCenter.getSessionModel(SecUserSessionObject.class);
if (sessionModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
Map<String,Object> param = new HashMap<>();
param.put("taskTitle", taskTitle);
param.put("listingTime", listingTime);
param.put("removalTime", removalTime);
PageHelper.startPage(pageNum, pageSize);
return ResponseMsgUtil.success(new PageInfo<>(goodsAutoTaskService.getList(param)));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/goodsAutoTask",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "创建商品自动上架任务")
public ResponseData createGoodPresent(@RequestBody GoodsAutoTask body, HttpServletRequest request) {
try {
SecUserSessionObject sessionModel = userCenter.getSessionModel(SecUserSessionObject.class);
// 检查sessionModel是否为空,如果为空则抛出账号未登录异常
if (sessionModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
// 检查当前用户是否为指定类型(type1),如果不是则抛出无权限异常
if (!sessionModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
}
// 检查请求参数是否完整,包括上架时间、下架时间和任务标题是否为空
if (body == null
|| body.getType() == null
|| StringUtils.isBlank(body.getTaskTitle())
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
if (body.getType() == 1) {
if (body.getListingTime() == null || body.getInventory() == null)
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
if (body.getType() == 2) {
if (body.getRemovalTime() == null)
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 设置创建时间为当前时间
body.setCreateTime(new Date());
// 设置创建用户ID为当前登录用户的ID
body.setCreateUserId(sessionModel.getAccount().getId());
// 设置创建用户名为当前登录用户的用户名
body.setCreateUserName(sessionModel.getAccount().getUserName());
// 设置任务状态为1
body.setStatus(1);
// 调用服务层方法创建商品自动任务
goodsAutoTaskService.create(body);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/delete",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "删除")
public ResponseData delete(@RequestParam(value = "id" , required = false) Long id) {
try {
SecUserSessionObject sessionModel = userCenter.getSessionModel(SecUserSessionObject.class);
if (sessionModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
// 创建GoodsAutoTask对象,通过id查询任务详情
GoodsAutoTask goodsAutoTask = goodsAutoTaskService.queryDetail(id);
// 判断任务是否存在,如果不存在则抛出异常
if (goodsAutoTask == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "任务不存在");
}
// 查询 任务关联商品内容
Map<String , Object> map = new HashMap<>();
map.put("taskId" , id);
// 从goodsAutoRelService中获取符合条件的数据列表
List<GoodsAutoRel> list = goodsAutoRelService.getList(map);
// 判断列表是否为null或空列表
if (list != null && !list.isEmpty()) {
// 遍历列表中的每个元素
for (GoodsAutoRel goodsAutoRel : list) {
// 删除每个元素对应的记录,第二个参数false表示不进行某种操作(可能是事务或日志记录)
goodsAutoRelService.delete(goodsAutoRel.getId() , false);
}
}
// 删除指定ID的goodsAutoTask记录,第二个参数false同样表示不进行某种操作
goodsAutoTaskService.delete(id , false);
return ResponseMsgUtil.success("删除成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/goodsTaskRel",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "自动任务关联商品")
public ResponseData goodsTaskRel(@RequestBody JSONObject body) {
try {
SecUserSessionObject sessionModel = userCenter.getSessionModel(SecUserSessionObject.class);
// 检查sessionModel是否为空,如果为空则抛出账号未登录异常
if (sessionModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
// 检查当前用户是否为指定类型(type1),如果不是则抛出无权限异常
if (!sessionModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
}
// 检查请求参数是否完整
if (body == null
|| body.getLong("taskId") == null
|| StringUtils.isBlank(body.getString("goodsIds"))
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
goodsAutoRelService.goodsTaskRel(body.getLong("taskId"), body.getString("goodsIds"), sessionModel.getAccount().getId(), sessionModel.getAccount().getUserName());
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/deleteRel",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "删除关联内容")
public ResponseData deleteRel(@RequestParam(value = "id" , required = false) Long id) {
try {
SecUserSessionObject sessionModel = userCenter.getSessionModel(SecUserSessionObject.class);
if (sessionModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
// 创建GoodsAutoTask对象,通过id查询任务详情
GoodsAutoRel goodsAutoRel = goodsAutoRelService.queryDetail(id);
// 判断任务是否存在,如果不存在则抛出异常
if (goodsAutoRel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "任务不存在");
}
goodsAutoRelService.delete(id , false);
return ResponseMsgUtil.success("删除成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/queryListTaskGoodsRel",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询列表")
public ResponseData queryListTaskGoodsRel(@RequestParam(value = "taskId" , required = false) Long taskId) {
try {
SecUserSessionObject sessionModel = userCenter.getSessionModel(SecUserSessionObject.class);
if (sessionModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
Map<String,Object> param = new HashMap<>();
param.put("taskId", taskId);
return ResponseMsgUtil.success(goodsAutoRelService.getList(param));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getListingTimeList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "定时查询上架任务")
public ResponseData getListingTimeList() {
try {
List<GoodsAutoTask> list = goodsAutoTaskService.getListingTimeList();
if (!list.isEmpty()) {
for (GoodsAutoTask goodsAutoTask : list) {
// 当前时间是否满足上架时间
if(goodsAutoTask.getListingTime() != null) {
// 执行逻辑
goodsAutoTaskService.startListingTask(goodsAutoTask , 1);
}
}
}
return ResponseMsgUtil.success("成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getRemovalTimeList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "定时查询下架任务")
public ResponseData getRemovalTimeList() {
try {
List<GoodsAutoTask> list = goodsAutoTaskService.getRemovalTimeList();
for (GoodsAutoTask goodsAutoTask : list) {
// 当前时间是否满足上架时间
if(goodsAutoTask.getRemovalTime() != null) {
// 执行逻辑
goodsAutoTaskService.startListingTask(goodsAutoTask , 2);
}
}
return ResponseMsgUtil.success("成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -7,6 +7,7 @@ import com.hfkj.jd.JdService;
import com.hfkj.qianzhu.StarbucksService; import com.hfkj.qianzhu.StarbucksService;
import com.hfkj.service.goods.BsOrderGoodsService; import com.hfkj.service.goods.BsOrderGoodsService;
import com.hfkj.service.goods.BsOrderStarbucksService; import com.hfkj.service.goods.BsOrderStarbucksService;
import com.hfkj.service.goods.GoodsAutoTaskService;
import com.hfkj.service.goods.impl.BsOrderMeiTuanServiceImpl; import com.hfkj.service.goods.impl.BsOrderMeiTuanServiceImpl;
import com.hfkj.service.goods.impl.BsOrderStarbucksServiceImpl; import com.hfkj.service.goods.impl.BsOrderStarbucksServiceImpl;
import com.hfkj.service.order.BsOrderChildService; import com.hfkj.service.order.BsOrderChildService;
@ -55,7 +56,21 @@ public class OrderGoodsSchedule {
@Resource @Resource
private JdService jdService; private JdService jdService;
//每日凌晨12点5秒执行一次 @Resource
private GoodsAutoTaskService goodsAutoTaskService;
/**
* 使用Spring的@Scheduled注解定义一个定时任务
* 该任务将在每天午夜0点30分执行
* cron表达式 "0 30 0 * * ?" 表示
* - 0秒位表示在第0秒执行
* - 30分位表示在第30分钟执行
* - 0时位表示在0点午夜执行
* - *日位表示每一天都执行
* - *月位表示每一月都执行
* - ?周位使用"?"表示不指定具体的星期几
*/
@Scheduled(cron = "0 30 0 * * ?") @Scheduled(cron = "0 30 0 * * ?")
public void orderGoodsConfirmReceipt() { public void orderGoodsConfirmReceipt() {
Map<String , Object> map = new HashMap<>(); Map<String , Object> map = new HashMap<>();
@ -197,4 +212,55 @@ public class OrderGoodsSchedule {
} }
} }
/**
* 使用Spring的@Scheduled注解定义一个定时任务
* 该任务使用cron表达式来设置执行周期
* cron表达式为"0 0/1 * * * ?"含义是每分钟执行一次
* 具体解析
* 0 - 秒位表示在第0秒时触发
* 0/1 - 分位表示从0秒开始每1分钟触发一次
* * - 时位表示每小时都触发
* * - 日位表示每天触发
* * - 月位表示每月触发
* ? - 周位表示不指定具体的星期几
* 该注解需要配合Spring的定时任务配置使用
*/
@Scheduled(cron = "0 0/1 * * * ?")
public void getListingTimeList() {
try {
List<GoodsAutoTask> list = goodsAutoTaskService.getListingTimeList();
if (!list.isEmpty()) {
for (GoodsAutoTask goodsAutoTask : list) {
if(goodsAutoTask.getListingTime() != null) {
// 执行逻辑
goodsAutoTaskService.startListingTask(goodsAutoTask , 1);
}
}
}
} catch (Exception e) {
log.error("OrderGoodsSchedule --> getListingTimeList() error!", e);
}
}
@Scheduled(cron = "0 0/1 * * * ?")
public void getRemovalTimeList() {
try {
List<GoodsAutoTask> list = goodsAutoTaskService.getRemovalTimeList();
for (GoodsAutoTask goodsAutoTask : list) {
if(goodsAutoTask.getRemovalTime() != null) {
// 执行逻辑
goodsAutoTaskService.startListingTask(goodsAutoTask , 2);
}
}
} catch (Exception e) {
log.error("OrderGoodsSchedule --> getRemovalTimeList() error!", e);
}
}
} }

@ -39,6 +39,11 @@
<artifactId>mybatis-spring-boot-starter</artifactId> <artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version> <version>1.3.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.34.70.ALL</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

@ -4,9 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature; import com.alibaba.fastjson.parser.Feature;
import com.alipay.api.internal.util.AlipaySignature; import com.alipay.api.internal.util.AlipaySignature;
import com.hfkj.common.pay.entity.AliPayReqInfo;
import com.hfkj.common.utils.HttpsUtils;
import io.netty.handler.codec.http.HttpUtil;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import java.io.InputStream; import java.io.InputStream;

@ -0,0 +1,77 @@
package com.hfkj.service.goods;
import com.hfkj.entity.GoodsAutoRel;
import java.util.List;
import java.util.Map;
public interface GoodsAutoRelService {
/**
* @MethodName create
* @Description: 创建
* @param goodsAutoRel
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:40
*/
void create(GoodsAutoRel goodsAutoRel);
/**
* @MethodName update
* @Description: 更新
* @param goodsAutoRel
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
void update(GoodsAutoRel goodsAutoRel);
/**
* @MethodName delete
* @Description: 删除
* @param id
* @param fullDelete
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
void delete(Long id , Boolean fullDelete);
/**
* @MethodName queryDetail
* @Description: 查询详情
* @param id
* @return: com.hfkj.entity.GoodsAutoRel
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
GoodsAutoRel queryDetail(Long id);
/**
* @MethodName queryDetailByMap
* @Description: 根据map查询详情
* @param map
* @return: com.hfkj.entity.GoodsAutoRel
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
GoodsAutoRel queryDetailByMap(Map<String , Object> map);
/**
* @MethodName goodsTaskRel
* @Description: 商品任务关联
* @param taskId
* @param goodsIds
* @param createUserId
* @param createUserName
*/
void goodsTaskRel(Long taskId , String goodsIds , Long createUserId , String createUserName);
/**
* @MethodName getList
* @Description: 查询列表
* @param map
* @return: java.util.List<com.hfkj.entity.GoodsAutoRel>
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
List<GoodsAutoRel> getList(Map<String , Object> map);
}

@ -0,0 +1,83 @@
package com.hfkj.service.goods;
import com.hfkj.entity.GoodsAutoTask;
import java.util.List;
import java.util.Map;
public interface GoodsAutoTaskService {
/**
* @MethodName create
* @Description: 创建
* @param goodsAutoTask
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:40
*/
void create(GoodsAutoTask goodsAutoTask) throws Exception;
/**
* @MethodName update
* @Description: 更新
* @param goodsAutoTask
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
void update(GoodsAutoTask goodsAutoTask);
/**
* @MethodName delete
* @Description: 删除
* @param id
* @param fullDelete
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
void delete(Long id , Boolean fullDelete);
/**
* @MethodName queryDetail
* @Description: 查询详情
* @param id
* @return: com.hfkj.entity.GoodsAutoTask
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
GoodsAutoTask queryDetail(Long id);
/**
* @MethodName queryDetailByMap
* @Description: 根据map查询详情
* @param map
* @return: com.hfkj.entity.GoodsAutoTask
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
GoodsAutoTask queryDetailByMap(Map<String , Object> map);
/**
* @MethodName getList
* @Description: 查询列表
* @param map
* @return: java.util.List<com.hfkj.entity.GoodsAutoTask>
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
List<GoodsAutoTask> getList(Map<String , Object> map);
List<GoodsAutoTask> getListingTimeList();
List<GoodsAutoTask> getRemovalTimeList();
/**
* @MethodName startTask
* @Description: 启动任务
* @param goodsAutoTask
* @throws Exception
* @Author: Sum1Dream
* @Date: 2025/7/1 下午4:41
*/
void startListingTask(GoodsAutoTask goodsAutoTask , Integer taskType);
}

@ -0,0 +1,204 @@
package com.hfkj.service.goods.impl;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.GoodsAutoRelMapper;
import com.hfkj.entity.GoodsAutoRel;
import com.hfkj.entity.GoodsAutoRelExample;
import com.hfkj.entity.GoodsAutoTask;
import com.hfkj.entity.GoodsMsg;
import com.hfkj.service.goods.GoodsAutoRelService;
import com.hfkj.service.goods.GoodsAutoTaskService;
import com.hfkj.service.goods.GoodsMsgService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service("goodsAutoRelService")
public class GoodsAutoRelServiceImpl implements GoodsAutoRelService {
@Resource
private GoodsAutoRelMapper goodsAutoRelMapper;
@Resource
private GoodsMsgService goodsMsgService;
@Resource
private GoodsAutoTaskService goodsAutoTaskService;
@Override
public void create(GoodsAutoRel goodsAutoRel) {
goodsAutoRelMapper.insert(goodsAutoRel);
}
@Override
public void update(GoodsAutoRel goodsAutoRel) {
goodsAutoRelMapper.updateByPrimaryKey(goodsAutoRel);
}
@Override
public void delete(Long id, Boolean fullDelete) {
if (fullDelete) {
goodsAutoRelMapper.deleteByPrimaryKey(id);
} else {
GoodsAutoRel goodsAutoRel = queryDetail(id);
goodsAutoRel.setStatus(0);
goodsAutoRel.setUpdateTime(new Date());
update(goodsAutoRel);
}
}
@Override
public GoodsAutoRel queryDetail(Long id) {
return goodsAutoRelMapper.selectByPrimaryKey(id);
}
@Override
public GoodsAutoRel queryDetailByMap(Map<String, Object> map) {
GoodsAutoRelExample example = new GoodsAutoRelExample();
GoodsAutoRelExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "goodsId") != null) {
criteria.andGoodsIdEqualTo(MapUtils.getLong(map, "goodsId"));
}
if (MapUtils.getInteger(map, "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map, "type"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "taskTitle"))) {
criteria.andTaskTitleLike("%"+MapUtils.getString(map, "taskTitle")+"%");
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "goodsName"))) {
criteria.andGoodsNameLike("%"+MapUtils.getString(map, "goodsName")+"%");
}
if (MapUtils.getLong(map, "listingTime") != null) {
criteria.andListingTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "listingTime")));
}
if (MapUtils.getLong(map, "removalTime") != null) {
criteria.andRemovalTimeLessThanOrEqualTo(new Date(MapUtils.getLong(map, "removalTime")));
}
if (MapUtils.getLong(map, "taskId") != null) {
criteria.andTaskIdEqualTo(MapUtils.getLong(map, "taskId"));
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}else {
criteria.andStatusNotEqualTo(0);
}
if (MapUtils.getLong(map , "id") != null) {
criteria.andIdEqualTo(MapUtils.getLong(map , "id"));
}
example.setOrderByClause("create_time desc");
List<GoodsAutoRel> list = goodsAutoRelMapper.selectByExample(example);
return list.isEmpty() ? null : list.get(0);
}
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class})
public void goodsTaskRel(Long taskId, String goodsIds , Long createUserId , String createUserName) {
// 根据任务ID查询任务详情
GoodsAutoTask goodsAutoTask = goodsAutoTaskService.queryDetail(taskId);
if (goodsAutoTask == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "任务不存在!");
}
// 将传入的商品ID字符串按逗号分割成数组
String [] goodsIdArray = goodsIds.split(",");
// 检查商品ID数组是否为空
if (goodsIdArray.length == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商品为空!");
}
// 遍历商品ID数组
for (String goodsId : goodsIdArray) {
// 根据商品ID查询商品信息
GoodsMsg goodsMsg = goodsMsgService.queryDetail(Long.valueOf(goodsId));
// 检查商品是否存在
if (goodsMsg == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商品不存在!");
}
// 创建商品与任务的关联实体对象
GoodsAutoRel goodsAutoRel = new GoodsAutoRel();
goodsAutoRel.setType(goodsAutoTask.getType());
// 设置商品ID
goodsAutoRel.setGoodsId(Long.valueOf(goodsId));
// 设置商品名称
goodsAutoRel.setGoodsName(goodsMsg.getTitle());
// 设置任务ID
goodsAutoRel.setTaskId(taskId);
// 设置任务标题
goodsAutoRel.setTaskTitle(goodsAutoTask.getTaskTitle());
// 设置上架时间
goodsAutoRel.setListingTime(goodsAutoTask.getListingTime());
// 设置下架时间
goodsAutoRel.setRemovalTime(goodsAutoTask.getRemovalTime());
// 设置状态为1(正常状态)
goodsAutoRel.setStatus(1);
// 设置创建时间
goodsAutoRel.setCreateTime(new Date());
// 设置创建用户ID
goodsAutoRel.setCreateUserId(createUserId);
// 设置创建用户名称
goodsAutoRel.setCreateUserName(createUserName);
// 保存商品与任务的关联关系
create(goodsAutoRel);
}
}
@Override
public List<GoodsAutoRel> getList(Map<String, Object> map) {
GoodsAutoRelExample example = new GoodsAutoRelExample();
GoodsAutoRelExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "goodsId") != null) {
criteria.andGoodsIdEqualTo(MapUtils.getLong(map, "goodsId"));
}
if (MapUtils.getInteger(map, "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map, "type"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "taskTitle"))) {
criteria.andTaskTitleLike("%"+MapUtils.getString(map, "taskTitle")+"%");
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "goodsName"))) {
criteria.andGoodsNameLike("%"+MapUtils.getString(map, "goodsName")+"%");
}
if (MapUtils.getLong(map, "listingTime") != null) {
criteria.andListingTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "listingTime")));
}
if (MapUtils.getLong(map, "removalTime") != null) {
criteria.andRemovalTimeLessThanOrEqualTo(new Date(MapUtils.getLong(map, "removalTime")));
}
if (MapUtils.getLong(map, "taskId") != null) {
criteria.andTaskIdEqualTo(MapUtils.getLong(map, "taskId"));
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}else {
criteria.andStatusNotEqualTo(0);
}
if (MapUtils.getLong(map , "id") != null) {
criteria.andIdEqualTo(MapUtils.getLong(map , "id"));
}
example.setOrderByClause("create_time desc");
return goodsAutoRelMapper.selectByExample(example);
}
}

@ -0,0 +1,225 @@
package com.hfkj.service.goods.impl;
import cn.binarywang.wx.miniapp.bean.WxMaGetLiveInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.GoodsAutoTaskMapper;
import com.hfkj.entity.*;
import com.hfkj.service.goods.GoodsAutoRelService;
import com.hfkj.service.goods.GoodsAutoTaskService;
import com.hfkj.service.goods.GoodsMsgService;
import com.hfkj.service.goods.GoodsSpecsService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@Service("goodsAutoTaskService")
public class GoodsAutoTaskServiceImpl implements GoodsAutoTaskService {
@Resource
private GoodsAutoTaskMapper goodsAutoTaskMapper;
@Resource
private GoodsAutoRelService goodsAutoRelService;
@Resource
private GoodsMsgService goodsMsgService;
@Resource
private GoodsSpecsService goodsSpecsService;
@Override
public void create(GoodsAutoTask goodsAutoTask) throws Exception {
goodsAutoTaskMapper.insert(goodsAutoTask);
}
@Override
public void update(GoodsAutoTask goodsAutoTask) {
goodsAutoTaskMapper.updateByPrimaryKey(goodsAutoTask);
}
@Override
public void delete(Long id, Boolean fullDelete) {
if (fullDelete) {
goodsAutoTaskMapper.deleteByPrimaryKey(id);
} else {
GoodsAutoTask goodsAutoTask = queryDetail(id);
goodsAutoTask.setStatus(0);
goodsAutoTask.setUpdateTime(new Date());
update(goodsAutoTask);
}
}
@Override
public GoodsAutoTask queryDetail(Long id) {
return goodsAutoTaskMapper.selectByPrimaryKey(id);
}
@Override
public GoodsAutoTask queryDetailByMap(Map<String, Object> map) {
GoodsAutoTaskExample example = new GoodsAutoTaskExample();
GoodsAutoTaskExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "listingTime") != null) {
criteria.andListingTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "listingTime")));
}
if (MapUtils.getLong(map, "removalTime") != null) {
criteria.andRemovalTimeLessThanOrEqualTo(new Date(MapUtils.getLong(map, "removalTime")));
}
if (MapUtils.getInteger(map, "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map, "type"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "taskTitle"))) {
criteria.andTaskTitleLike("%"+MapUtils.getString(map, "taskTitle")+"%");
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}else {
criteria.andStatusNotEqualTo(0);
}
if (MapUtils.getLong(map , "id") != null) {
criteria.andIdEqualTo(MapUtils.getLong(map , "id"));
}
example.setOrderByClause("create_time desc");
List<GoodsAutoTask> list = goodsAutoTaskMapper.selectByExample(example);
return list.isEmpty() ? null : list.get(0);
}
@Override
public List<GoodsAutoTask> getList(Map<String, Object> map) {
GoodsAutoTaskExample example = new GoodsAutoTaskExample();
GoodsAutoTaskExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "listingTime") != null) {
criteria.andListingTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "listingTime")));
}
if (MapUtils.getInteger(map, "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map, "type"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "taskTitle"))) {
criteria.andTaskTitleLike("%"+MapUtils.getString(map, "taskTitle")+"%");
}
if (MapUtils.getLong(map, "removalTime") != null) {
criteria.andRemovalTimeLessThanOrEqualTo(new Date(MapUtils.getLong(map, "removalTime")));
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
}else {
criteria.andStatusNotEqualTo(0);
}
if (MapUtils.getLong(map , "id") != null) {
criteria.andIdEqualTo(MapUtils.getLong(map , "id"));
}
example.setOrderByClause("create_time desc");
return goodsAutoTaskMapper.selectByExample(example);
}
@Override
public List<GoodsAutoTask> getListingTimeList() {
return goodsAutoTaskMapper.listingList();
}
@Override
public List<GoodsAutoTask> getRemovalTimeList() {
return goodsAutoTaskMapper.removalList();
}
@Override
@Transactional
public void startListingTask(GoodsAutoTask goodsAutoTask , Integer taskType) {
try {
// 创建一个HashMap对象,用于存储任务ID
Map<String , Object> map = new HashMap<>();
// 向map中添加任务ID
map.put("taskId" , goodsAutoTask.getId());
// 根据任务ID查询商品自动关联关系列表
List<GoodsAutoRel> goodsAutoRel = goodsAutoRelService.getList(map);
// 如果商品自动关联关系列表不为空
if (!goodsAutoRel.isEmpty()) {
// 遍历商品自动关联关系列表
for (GoodsAutoRel rel : goodsAutoRel) {
try {
// 根据商品ID查询商品详情
GoodsMsg goodsMsg = goodsMsgService.queryDetail(rel.getGoodsId());
// 如果商品详情为空,抛出异常
if (goodsMsg == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商品不存在!");
}
// 创建规格查询条件map
Map<String , Object> specsMap = new HashMap<>();
// 向map中添加商品ID
specsMap.put("goodsId" , goodsMsg.getId());
// 判断是上架操作还是下架操作
if (taskType == 1) {
// 判断商品上架时间是否已到(将时间戳转换为秒进行比较)
if (rel.getListingTime().getTime() / 1000 <= System.currentTimeMillis() / 1000) {
// 上架操作,更新商品状态为上架
// 根据商品ID查询规格列表
List<GoodsSpecs> specs = goodsSpecsService.getList(specsMap);
// 如果规格列表为空,抛出异常
if (specs.isEmpty()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商品规格不存在!");
}
// 遍历规格列表,更新库存和更新时间
for (GoodsSpecs spec : specs) {
spec.setStock(goodsAutoTask.getInventory()); // 设置商品规格的库存数量
spec.setUpdateTime(new Date()); // 设置商品规格的更新时间
goodsSpecsService.update(spec); // 更新商品规格信息
}
// 更新商品状态和更新时间
goodsMsg.setStatus(1); // 设置商品状态为已上架
}
} else {
// 检查商品是否应该被下架
// 比较商品的下架时间和当前时间(秒级)
if (rel.getRemovalTime().getTime() / 1000 <= System.currentTimeMillis() / 1000) {
// 下架操作,更新商品状态为下架
goodsMsg.setStatus(2);
}
}
goodsMsg.setUpdateTime(new Date());
goodsMsgService.update(goodsMsg);
// 更新关联关系状态、备注和更新时间
rel.setStatus(2);
rel.setRemak("成功");
rel.setUpdateTime(new Date());
goodsAutoRelService.update(rel);
} catch (Exception e) {
// 处理异常,更新关联关系状态、异常信息和更新时间
rel.setStatus(3);
rel.setUpdateTime(new Date());
rel.setRemak(e.getMessage());
goodsAutoRelService.update(rel);
}
}
}
// 更新任务状态和更新时间
goodsAutoTask.setStatus(2);
goodsAutoTask.setUpdateTime(new Date());
update(goodsAutoTask);
} catch (Exception e) {
// 处理异常,更新任务状态和更新时间
goodsAutoTask.setStatus(3);
goodsAutoTask.setUpdateTime(new Date());
update(goodsAutoTask);
}
}
}
Loading…
Cancel
Save