123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- package com.txz.mall.controller;
- import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.txz.mall.business.OrderServiceBusiness;
- import com.txz.mall.core.Result;
- import com.txz.mall.core.ResultCode;
- import com.txz.mall.core.ServiceException;
- import com.txz.mall.model.StoreCombination;
- import com.txz.mall.service.StoreCombinationService;
- import com.txz.mall.service.StoreOrderService;
- import com.txz.mall.util.I18nUtil;
- import com.txz.mall.web.param.addparam.StoreCombinationAddParam;
- import dto.GoPinkDTO;
- import dto.StoreProductDTO;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import tk.mybatis.mapper.entity.Condition;
- import tk.mybatis.mapper.entity.Example;
- import vo.StoreCombinationRankVO;
- import javax.annotation.Resource;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * Created by CodeGenerator on 2025/07/14.
- */
- @Api(tags = "[后台]拼团商品管理")
- @RestController
- @RequestMapping("/combination")
- public class CombinationController {
- private static Logger log = LoggerFactory.getLogger(CombinationController.class);
- @Resource
- private StoreCombinationService storeCombinationService;
- @Resource
- private StoreOrderService storeOrderService;
- @Resource
- private OrderServiceBusiness orderServiceBusiness;
- @PostMapping("/add")
- @ApiOperation(value = "拼团商品表新增")
- public Result add(@RequestBody StoreCombination storeCombination) {
- if (storeCombination == null) {
- return Result.fail(ResultCode.OBJECT_IS_NULL);
- }
- try {
- storeCombination.setCreateTime(new Date());
- // storeCombination.setCreateUserId(userId);
- storeCombinationService.save(storeCombination);
- } catch (Exception e) {
- log.error("新增对象操作异常e:{}", e);
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
- }
- return Result.success();
- }
- @DeleteMapping("/delete")
- @ApiOperation(value = "拼团商品表删除")
- public Result delete(@RequestParam Long id) {
- if (id == null) {
- return Result.fail(ResultCode.ID_IS_NULL);
- }
- StoreCombination combination = storeCombinationService.findById(id);
- if (combination == null) {
- return Result.fail(ResultCode.OBJECT_IS_NULL);
- }
- Date date = new Date();
- if (combination.getIsShow().equals(1) && combination.getStartTime().before(date) && combination.getStopTime().after(date)) {
- throw new ServiceException("the.activity.is.ongoing.and.the.product.does.not.support.deletion");
- }
- try {
- StoreCombination storeCombination = new StoreCombination();
- storeCombination.setId(id);
- storeCombination.setIsDelete(1);
- storeCombinationService.update(storeCombination);
- } catch (Exception e) {
- log.error("删除对象操作异常e:{}", e);
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
- }
- return Result.success();
- }
- @PutMapping("/update")
- @ApiOperation(value = "拼团商品表更新")
- public Result update(@RequestBody StoreCombination storeCombination) {
- if (storeCombination == null) {
- return Result.fail(ResultCode.OBJECT_IS_NULL);
- }
- if (storeCombination.getId() == null) {
- return Result.fail(ResultCode.ID_IS_NULL);
- }
- try {
- storeCombination.setUpdateTime(new Date());
- // storeCombination.setUpdateUserId(userId);
- storeCombinationService.update(storeCombination);
- } catch (Exception e) {
- log.error("更新对象操作异常e:{}", e);
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
- }
- return Result.success();
- }
- @GetMapping("/detail")
- @ApiOperation(value = "拼团商品表获取详情")
- public Result<StoreCombination> detail(@RequestParam Long id) {
- if (id == null) {
- return Result.fail(ResultCode.ID_IS_NULL);
- }
- StoreCombination storeCombination = null;
- try {
- storeCombination = storeCombinationService.findById(id);
- } catch (Exception e) {
- log.error("查询对象操作异常e:{}", e);
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
- }
- return Result.success(storeCombination);
- }
- @PostMapping("/app/list")
- @ApiOperation(value = "拼团商品表获取列表")
- public Result<List<StoreCombination>> list(@RequestBody StoreProductDTO dto) {
- PageHelper.startPage(dto.getPage(), dto.getSize());
- Condition condition = new Condition(StoreCombination.class);
- Example.Criteria criteria = condition.createCriteria();
- criteria.andEqualTo("isDelete", 0);
- criteria.andEqualTo("isShow", 1);
- if (dto.getSortWay() == null) {
- dto.setSortWay(0);
- }
- switch (dto.getSortWay()) {
- case 1:
- condition.setOrderByClause("price ASC");
- break;
- case 2:
- condition.setOrderByClause("price DESC");
- break;
- case 3:
- condition.setOrderByClause("sales DESC");
- break;
- case 4:
- condition.setOrderByClause("sales ASC");
- break;
- default:
- condition.setOrderByClause("create_time DESC");
- break;
- }
- if (dto.getIsNew() != null) {
- criteria.andEqualTo("isNew", 1);
- }
- if (dto.getMinPrice() != null && dto.getMaxPrice() != null) {
- criteria.andBetween("price", dto.getMinPrice(), dto.getMaxPrice());
- }
- PageInfo pageInfo = null;
- try {
- List<StoreCombination> list = storeCombinationService.findByCondition(condition);
- pageInfo = new PageInfo(list);
- } catch (Exception e) {
- log.error("查询对象操作异常e:{}", e);
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
- }
- return Result.success(pageInfo);
- }
- @PostMapping("/addActivityProduct")
- @ApiOperation(value = "添加活动商品")
- public Result addActivityProduct(@RequestBody StoreCombinationAddParam storeCombinationAddParam) {
- if (CollectionUtils.isEmpty(storeCombinationAddParam.getList())) {
- throw new ServiceException(I18nUtil.get("the.added.product.cannot.be.empty"));
- }
- if (storeCombinationAddParam.getActivityId() == null) {
- return Result.fail(ResultCode.ID_IS_NULL);
- }
- storeCombinationService.addActivityProduct(storeCombinationAddParam.getList(), storeCombinationAddParam.getActivityId());
- return Result.success();
- }
- @GetMapping("/getActivityProductIds")
- @ApiOperation(value = "获取活动商品ids")
- public Result<List<Long>> getActivityProductIds(@RequestParam("activityId") Long activityId) {
- Condition condition = new Condition(StoreCombination.class);
- Example.Criteria criteria = condition.createCriteria();
- criteria.andEqualTo("isDelete", 0);
- criteria.andEqualTo("activityId", activityId);
- List<StoreCombination> combinationList = storeCombinationService.findByCondition(condition);
- List<Long> arrayList = combinationList.stream().map(StoreCombination::getProductId).collect(Collectors.toList());
- return Result.success(arrayList);
- }
- /**
- * 去开团
- */
- // @ApiOperation(value = "支付成功-去开团")
- // @PostMapping(value = "/open")
- public Result goOpen(@RequestParam("orderId") String orderId) {
- storeOrderService.goOpen(orderId);
- return Result.success();
- }
- /**
- * 去拼团
- */
- // @ApiOperation(value = "去拼团")
- // @PostMapping(value = "/pink")
- public Result goPink(@Validated @RequestBody GoPinkDTO dto) {
- if (dto.getPinkId() == null && dto.getCid() == null) {
- return Result.fail(ResultCode.ID_IS_NULL);
- }
- storeOrderService.goPink(dto);
- return Result.success();
- }
- /**
- * 更多拼团
- */
- @ApiOperation(value = "更多拼团")
- @GetMapping(value = "/more")
- public Result<PageInfo<StoreCombination>> getMore(@RequestParam Integer comId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
- PageHelper.startPage(page, size);
- PageInfo pageInfo = null;
- try {
- List<StoreCombination> list = storeCombinationService.getMore(comId);
- pageInfo = new PageInfo(list);
- } catch (Exception e) {
- log.error("查询对象操作异常e:{}", e);
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
- }
- return Result.success(pageInfo);
- }
- @ApiOperation(value = "排行榜")
- @GetMapping(value = "/rank")
- public Result<List<StoreCombinationRankVO>> getRank(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
- PageHelper.startPage(page, size);
- PageInfo pageInfo = null;
- try {
- List<StoreCombinationRankVO> list = orderServiceBusiness.getRank();
- pageInfo = new PageInfo(list);
- } catch (Exception e) {
- log.error("查询对象操作异常e:{}", e);
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
- }
- return Result.success(pageInfo);
- }
- }
|