完善了商品类别接口
This commit is contained in:
parent
e75643ab29
commit
11ee6f6c15
|
@ -0,0 +1,120 @@
|
|||
package com.cultural.heritage.controller.good;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.cultural.heritage.common.BaseResponse;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.common.ResultUtils;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
import com.cultural.heritage.exception.ThrowUtils;
|
||||
import com.cultural.heritage.model.dto.CommonRequest;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponAddRequest;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponQueryRequest;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponUpdateRequest;
|
||||
import com.cultural.heritage.model.entity.Coupon;
|
||||
import com.cultural.heritage.service.good.CouponService;
|
||||
import com.cultural.heritage.service.user.UserService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/coupon")
|
||||
@Slf4j
|
||||
@Tag(name = "优惠券接口")
|
||||
public class CouponController {
|
||||
|
||||
@Resource
|
||||
private CouponService couponService;
|
||||
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
|
||||
/**
|
||||
* 添加优惠券
|
||||
* @param couponAddRequest 优惠券添加请求体
|
||||
* @return 是否添加成功
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public BaseResponse<Boolean> addCoupon(@RequestBody CouponAddRequest couponAddRequest) {
|
||||
if (couponAddRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
Coupon coupon = new Coupon();
|
||||
BeanUtils.copyProperties(couponAddRequest, coupon);
|
||||
boolean result = couponService.save(coupon);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
* @param couponUpdateRequest 优惠券更新请求体
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
public BaseResponse<Boolean> updateCoupon(@RequestBody CouponUpdateRequest couponUpdateRequest) {
|
||||
if (couponUpdateRequest == null || couponUpdateRequest.getId() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
Coupon coupon = new Coupon();
|
||||
BeanUtils.copyProperties(couponUpdateRequest, coupon);
|
||||
boolean result = couponService.updateById(coupon);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
* @param couponDeleteRequest 优惠券删除请求体
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public BaseResponse<Boolean> deleteCoupon(@RequestBody CommonRequest couponDeleteRequest) {
|
||||
if (couponDeleteRequest == null || couponDeleteRequest.getId() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
Long id = couponDeleteRequest.getId();
|
||||
boolean result = couponService.removeById(id);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询优惠券列表
|
||||
* @param couponQueryRequest 优惠券查询请求体
|
||||
* @return 优惠券列表
|
||||
*/
|
||||
@PostMapping("/list/page")
|
||||
public BaseResponse<Page<Coupon>> listCouponVOByPage(@RequestBody CouponQueryRequest couponQueryRequest) {
|
||||
if (couponQueryRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
long current = couponQueryRequest.getCurrent();
|
||||
long pageSize = couponQueryRequest.getPageSize();
|
||||
Page<Coupon> page = couponService.page(new Page<>(current, pageSize),
|
||||
couponService.getQueryWrapper(couponQueryRequest));
|
||||
return ResultUtils.success(page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -68,10 +68,6 @@ public class UserController {
|
|||
*/
|
||||
@PostMapping("/logout")
|
||||
public BaseResponse<Boolean> userLogout(HttpServletRequest request) {
|
||||
System.out.println(request.getSession());
|
||||
if(request == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
boolean result = userService.userLogout(request);
|
||||
return ResultUtils.success(result);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.cultural.heritage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cultural.heritage.model.entity.Coupon;
|
||||
|
||||
public interface CouponMapper extends BaseMapper<Coupon> {
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.cultural.heritage.model.dto.coupon;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class CouponAddRequest implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 满减金额
|
||||
*/
|
||||
private Double conditionAmount;
|
||||
|
||||
|
||||
/**
|
||||
* 需要的积分
|
||||
*/
|
||||
private Integer requirePoints;
|
||||
|
||||
|
||||
/**
|
||||
* 发放数量
|
||||
*/
|
||||
private Integer totalNum;
|
||||
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer residueNum;
|
||||
|
||||
|
||||
/**
|
||||
* 用户限领量
|
||||
*/
|
||||
private Integer limitNum;
|
||||
|
||||
|
||||
/**
|
||||
* 有效开始日期
|
||||
*/
|
||||
private Date startTime;
|
||||
|
||||
|
||||
/**
|
||||
* 有效截止日期
|
||||
*/
|
||||
private Date endTime;
|
||||
|
||||
/**
|
||||
* 使用说明
|
||||
*/
|
||||
private String description;
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.cultural.heritage.model.dto.coupon;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.cultural.heritage.common.PageRequest;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CouponQueryRequest extends PageRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* 有效开始日期
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date startTime;
|
||||
|
||||
|
||||
/**
|
||||
* 有效截止日期
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date endTime;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.cultural.heritage.model.dto.coupon;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class CouponUpdateRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 满减金额
|
||||
*/
|
||||
private Double conditionAmount;
|
||||
|
||||
|
||||
/**
|
||||
* 需要的积分
|
||||
*/
|
||||
private Integer requirePoints;
|
||||
|
||||
|
||||
/**
|
||||
* 发放数量
|
||||
*/
|
||||
private Integer totalNum;
|
||||
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer residueNum;
|
||||
|
||||
|
||||
/**
|
||||
* 用户限领量
|
||||
*/
|
||||
private Integer limitNum;
|
||||
|
||||
|
||||
/**
|
||||
* 有效开始日期
|
||||
*/
|
||||
private Date startTime;
|
||||
|
||||
|
||||
/**
|
||||
* 有效截止日期
|
||||
*/
|
||||
private Date endTime;
|
||||
|
||||
/**
|
||||
* 使用说明
|
||||
*/
|
||||
private String description;
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -2,13 +2,19 @@ package com.cultural.heritage.model.entity;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 地址表
|
||||
* @TableName address
|
||||
*/
|
||||
@Data
|
||||
@TableName("address")
|
||||
public class Address implements Serializable {
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,13 +3,19 @@ package com.cultural.heritage.model.entity;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品类别表
|
||||
* @TableName category
|
||||
*/
|
||||
@Data
|
||||
@TableName("category")
|
||||
public class Category implements Serializable {
|
||||
|
||||
|
||||
|
@ -17,7 +23,7 @@ public class Category implements Serializable {
|
|||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,109 @@
|
|||
package com.cultural.heritage.model.entity;
|
||||
|
||||
|
||||
public class Coupon {
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 优惠券列表
|
||||
* @TableName coupon
|
||||
*/
|
||||
@Data
|
||||
@TableName("coupon")
|
||||
public class Coupon implements Serializable {
|
||||
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 满减金额
|
||||
*/
|
||||
private Double conditionAmount;
|
||||
|
||||
|
||||
/**
|
||||
* 需要的积分
|
||||
*/
|
||||
private Integer requirePoints;
|
||||
|
||||
|
||||
/**
|
||||
* 发放数量
|
||||
*/
|
||||
private Integer totalNum;
|
||||
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer residueNum;
|
||||
|
||||
|
||||
/**
|
||||
* 用户限领量
|
||||
*/
|
||||
private Integer limitNum;
|
||||
|
||||
/**
|
||||
* 优惠券简介
|
||||
*/
|
||||
private String intro;
|
||||
|
||||
/**
|
||||
* 优惠券图片
|
||||
*/
|
||||
private String image;
|
||||
|
||||
/**
|
||||
* 有效开始日期
|
||||
*/
|
||||
private Date startTime;
|
||||
|
||||
|
||||
/**
|
||||
* 有效截止日期
|
||||
*/
|
||||
private Date endTime;
|
||||
|
||||
/**
|
||||
* 使用说明
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer isDelete;
|
||||
|
||||
|
||||
@Serial
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,12 @@ import lombok.Data;
|
|||
import java.io.Serial;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品表
|
||||
* @TableName good
|
||||
*/
|
||||
@TableName(value = "good")
|
||||
@Data
|
||||
|
||||
public class Good {
|
||||
/**
|
||||
* 商品编号
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.io.Serializable;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
* 用户表
|
||||
* @TableName user
|
||||
*/
|
||||
@TableName(value = "user")
|
||||
|
@ -58,6 +58,12 @@ public class User implements Serializable {
|
|||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 积分
|
||||
*/
|
||||
private Integer points;
|
||||
|
||||
|
||||
/**
|
||||
* 用户角色:user/admin/ban
|
||||
*/
|
||||
|
|
|
@ -27,6 +27,11 @@ public class UserVO implements Serializable {
|
|||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 积分
|
||||
*/
|
||||
private Integer points;
|
||||
|
||||
/**
|
||||
* 用户身份
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.cultural.heritage.service.good;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponQueryRequest;
|
||||
import com.cultural.heritage.model.entity.Coupon;
|
||||
|
||||
public interface CouponService extends IService<Coupon> {
|
||||
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*/
|
||||
QueryWrapper<Coupon> getQueryWrapper(CouponQueryRequest couponQueryRequest);
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.cultural.heritage.service.good.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.constant.CommonConstant;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
import com.cultural.heritage.mapper.CouponMapper;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponQueryRequest;
|
||||
import com.cultural.heritage.model.entity.Coupon;
|
||||
import com.cultural.heritage.service.good.CouponService;
|
||||
import com.cultural.heritage.utils.SqlUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.yaml.snakeyaml.scanner.Constant;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements CouponService {
|
||||
|
||||
|
||||
@Override
|
||||
public QueryWrapper<Coupon> getQueryWrapper(CouponQueryRequest couponQueryRequest) {
|
||||
if (couponQueryRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
Long id = couponQueryRequest.getId();
|
||||
String name = couponQueryRequest.getName();
|
||||
Date startTime = couponQueryRequest.getStartTime();
|
||||
Date endTime = couponQueryRequest.getEndTime();
|
||||
String sortField = couponQueryRequest.getSortField();
|
||||
String sortOrder = couponQueryRequest.getSortOrder();
|
||||
QueryWrapper<Coupon> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
|
||||
queryWrapper.like(StringUtils.isNotBlank(name), "name", name);
|
||||
queryWrapper.ge(ObjectUtils.isNotEmpty(startTime), "startTime", startTime);
|
||||
queryWrapper.le(ObjectUtils.isNotEmpty(endTime), "endTime", endTime);
|
||||
queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
|
||||
sortField);
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import com.cultural.heritage.model.dto.good.GoodQueryRequest;
|
|||
import com.cultural.heritage.model.entity.Good;
|
||||
import com.cultural.heritage.service.good.GoodService;
|
||||
import com.cultural.heritage.utils.SqlUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -37,11 +38,11 @@ public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements Go
|
|||
String sortOrder = goodQueryRequest.getSortOrder();
|
||||
|
||||
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(id != null, "id", id);
|
||||
queryWrapper.eq(StringUtils.isNotBlank(name), "name", name);
|
||||
queryWrapper.eq(StringUtils.isNotBlank(type), "type", type);
|
||||
queryWrapper.eq(festivalOrder != null, "festivalOrder", festivalOrder);
|
||||
queryWrapper.eq(isShelves != null, "isShelves", isShelves);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
|
||||
queryWrapper.like(StringUtils.isNotBlank(name), "name", name);
|
||||
queryWrapper.like(StringUtils.isNotBlank(type), "type", type);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(festivalOrder), "festivalOrder", festivalOrder);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(isShelves), "isShelves", isShelves);
|
||||
queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
|
||||
sortField);
|
||||
return queryWrapper;
|
||||
|
|
7
src/main/resources/mapper/CouponMapper.xml
Normal file
7
src/main/resources/mapper/CouponMapper.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cultural.heritage.mapper.CouponMapper">
|
||||
|
||||
</mapper>
|
13
src/test/java/com/cultural/heritage/test/Test.java
Normal file
13
src/test/java/com/cultural/heritage/test/Test.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package com.cultural.heritage.test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String format = sdf.format(date);
|
||||
System.out.println(format);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user