parent
d35ad4185b
commit
24d939bbff
@ -0,0 +1,93 @@
|
||||
package com.cyl.ums.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.cyl.ums.convert.MemberCartConvert;
|
||||
import com.cyl.ums.domain.MemberCart;
|
||||
import com.cyl.ums.pojo.query.MemberCartQuery;
|
||||
import com.cyl.ums.service.MemberCartService;
|
||||
import com.cyl.ums.pojo.vo.MemberCartVO;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
/**
|
||||
* 购物车Controller
|
||||
*
|
||||
* @author zcc
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Api(description ="购物车接口列表")
|
||||
@RestController
|
||||
@RequestMapping("/ums/memberCart")
|
||||
public class MemberCartController extends BaseController {
|
||||
@Autowired
|
||||
private MemberCartService service;
|
||||
@Autowired
|
||||
private MemberCartConvert convert;
|
||||
|
||||
@ApiOperation("查询购物车列表")
|
||||
@PreAuthorize("@ss.hasPermi('ums:memberCart:list')")
|
||||
@PostMapping("/list")
|
||||
public ResponseEntity<Page<MemberCart>> list(@RequestBody MemberCartQuery query, Pageable page) {
|
||||
List<MemberCart> list = service.selectList(query, page);
|
||||
return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
|
||||
}
|
||||
|
||||
@ApiOperation("导出购物车列表")
|
||||
@PreAuthorize("@ss.hasPermi('ums:memberCart:export')")
|
||||
@Log(title = "购物车", businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export")
|
||||
public ResponseEntity<String> export(MemberCartQuery query) {
|
||||
List<MemberCart> list = service.selectList(query, null);
|
||||
ExcelUtil<MemberCartVO> util = new ExcelUtil<>(MemberCartVO.class);
|
||||
return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "购物车数据"));
|
||||
}
|
||||
|
||||
@ApiOperation("获取购物车详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('ums:memberCart:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public ResponseEntity<MemberCart> getInfo(@PathVariable("id") Long id) {
|
||||
return ResponseEntity.ok(service.selectById(id));
|
||||
}
|
||||
|
||||
@ApiOperation("新增购物车")
|
||||
@PreAuthorize("@ss.hasPermi('ums:memberCart:add')")
|
||||
@Log(title = "购物车", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public ResponseEntity<Integer> add(@RequestBody MemberCart memberCart) {
|
||||
return ResponseEntity.ok(service.insert(memberCart));
|
||||
}
|
||||
|
||||
@ApiOperation("修改购物车")
|
||||
@PreAuthorize("@ss.hasPermi('ums:memberCart:edit')")
|
||||
@Log(title = "购物车", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public ResponseEntity<Integer> edit(@RequestBody MemberCart memberCart) {
|
||||
return ResponseEntity.ok(service.update(memberCart));
|
||||
}
|
||||
|
||||
@ApiOperation("删除购物车")
|
||||
@PreAuthorize("@ss.hasPermi('ums:memberCart:remove')")
|
||||
@Log(title = "购物车", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Integer> remove(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.deleteById(id));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.cyl.ums.convert;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import com.cyl.ums.domain.MemberCart;
|
||||
import com.cyl.ums.pojo.vo.MemberCartVO;
|
||||
import java.util.List;
|
||||
/**
|
||||
* 购物车 DO <=> DTO <=> VO / BO / Query
|
||||
*
|
||||
* @author zcc
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface MemberCartConvert {
|
||||
|
||||
List<MemberCartVO> dos2vos(List<MemberCart> list);
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package com.cyl.ums.domain;
|
||||
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import com.ruoyi.common.core.domain.BaseAudit;
|
||||
import lombok.Data;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
/**
|
||||
* 购物车对象 ums_member_cart
|
||||
*
|
||||
* @author zcc
|
||||
*/
|
||||
@ApiModel(description="购物车对象")
|
||||
@Data
|
||||
@TableName("ums_member_cart")
|
||||
public class MemberCart extends BaseAudit {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("购物车表ID")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
@Excel(name = "用户ID")
|
||||
private Long memberId;
|
||||
|
||||
@ApiModelProperty("商品ID")
|
||||
@Excel(name = "商品ID")
|
||||
private Long productId;
|
||||
|
||||
@ApiModelProperty("展示图片")
|
||||
@Excel(name = "展示图片")
|
||||
private String pic;
|
||||
|
||||
@ApiModelProperty("SKU ID")
|
||||
@Excel(name = "SKU ID")
|
||||
private Long skuId;
|
||||
|
||||
@ApiModelProperty("PRODUCT_NAME")
|
||||
@Excel(name = "PRODUCT_NAME")
|
||||
private String productName;
|
||||
|
||||
@ApiModelProperty("商品属性")
|
||||
@Excel(name = "商品属性")
|
||||
private String spData;
|
||||
|
||||
@ApiModelProperty("商品数量")
|
||||
@Excel(name = "商品数量")
|
||||
private Integer cartNum;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.cyl.ums.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.cyl.ums.domain.MemberCart;
|
||||
|
||||
/**
|
||||
* 购物车Mapper接口
|
||||
*
|
||||
* @author zcc
|
||||
*/
|
||||
public interface MemberCartMapper extends BaseMapper<MemberCart> {
|
||||
/**
|
||||
* 查询购物车列表
|
||||
*
|
||||
* @param memberCart 购物车
|
||||
* @return 购物车集合
|
||||
*/
|
||||
List<MemberCart> selectByEntity(MemberCart memberCart);
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.cyl.ums.pojo.query;
|
||||
|
||||
import lombok.Data;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* 购物车 查询 对象
|
||||
*
|
||||
* @author zcc
|
||||
*/
|
||||
@ApiModel(description="购物车 查询 对象")
|
||||
@Data
|
||||
public class MemberCartQuery {
|
||||
@ApiModelProperty("用户ID 精确匹配")
|
||||
private Long memberId;
|
||||
|
||||
@ApiModelProperty("商品ID 精确匹配")
|
||||
private Long productId;
|
||||
|
||||
@ApiModelProperty("展示图片 精确匹配")
|
||||
private String pic;
|
||||
|
||||
@ApiModelProperty("SKU ID 精确匹配")
|
||||
private Long skuId;
|
||||
|
||||
@ApiModelProperty("PRODUCT_NAME 精确匹配")
|
||||
private String productNameLike;
|
||||
|
||||
@ApiModelProperty("商品属性 精确匹配")
|
||||
private String spData;
|
||||
|
||||
@ApiModelProperty("商品数量 精确匹配")
|
||||
private Integer cartNum;
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.cyl.ums.pojo.vo;
|
||||
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.domain.BaseAudit;
|
||||
import lombok.Data;
|
||||
/**
|
||||
* 购物车 数据视图对象
|
||||
*
|
||||
* @author zcc
|
||||
*/
|
||||
@Data
|
||||
public class MemberCartVO extends BaseAudit {
|
||||
/** 购物车表ID */
|
||||
private Long id;
|
||||
/** 用户ID */
|
||||
@Excel(name = "用户ID")
|
||||
private Long memberId;
|
||||
/** 商品ID */
|
||||
@Excel(name = "商品ID")
|
||||
private Long productId;
|
||||
/** 展示图片 */
|
||||
@Excel(name = "展示图片")
|
||||
private String pic;
|
||||
/** SKU ID */
|
||||
@Excel(name = "SKU ID")
|
||||
private Long skuId;
|
||||
/** PRODUCT_NAME */
|
||||
@Excel(name = "PRODUCT_NAME")
|
||||
private String productName;
|
||||
/** 商品属性 */
|
||||
@Excel(name = "商品属性")
|
||||
private String spData;
|
||||
/** 商品数量 */
|
||||
@Excel(name = "商品数量")
|
||||
private Integer cartNum;
|
||||
}
|
||||
@ -0,0 +1,110 @@
|
||||
package com.cyl.ums.service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.cyl.ums.mapper.MemberCartMapper;
|
||||
import com.cyl.ums.domain.MemberCart;
|
||||
import com.cyl.ums.pojo.query.MemberCartQuery;
|
||||
|
||||
/**
|
||||
* 购物车Service业务层处理
|
||||
*
|
||||
*
|
||||
* @author zcc
|
||||
*/
|
||||
@Service
|
||||
public class MemberCartService {
|
||||
@Autowired
|
||||
private MemberCartMapper memberCartMapper;
|
||||
|
||||
/**
|
||||
* 查询购物车
|
||||
*
|
||||
* @param id 购物车主键
|
||||
* @return 购物车
|
||||
*/
|
||||
public MemberCart selectById(Long id) {
|
||||
return memberCartMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询购物车列表
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param page 分页条件
|
||||
* @return 购物车
|
||||
*/
|
||||
public List<MemberCart> selectList(MemberCartQuery query, Pageable page) {
|
||||
if (page != null) {
|
||||
PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
|
||||
}
|
||||
QueryWrapper<MemberCart> qw = new QueryWrapper<>();
|
||||
Long memberId = query.getMemberId();
|
||||
if (memberId != null) {
|
||||
qw.eq("member_id", memberId);
|
||||
}
|
||||
Long productId = query.getProductId();
|
||||
if (productId != null) {
|
||||
qw.eq("product_id", productId);
|
||||
}
|
||||
String pic = query.getPic();
|
||||
if (!StringUtils.isEmpty(pic)) {
|
||||
qw.eq("pic", pic);
|
||||
}
|
||||
Long skuId = query.getSkuId();
|
||||
if (skuId != null) {
|
||||
qw.eq("sku_id", skuId);
|
||||
}
|
||||
String productNameLike = query.getProductNameLike();
|
||||
if (!StringUtils.isEmpty(productNameLike)) {
|
||||
qw.like("product_name", productNameLike);
|
||||
}
|
||||
String spData = query.getSpData();
|
||||
if (!StringUtils.isEmpty(spData)) {
|
||||
qw.eq("sp_data", spData);
|
||||
}
|
||||
Integer cartNum = query.getCartNum();
|
||||
if (cartNum != null) {
|
||||
qw.eq("cart_num", cartNum);
|
||||
}
|
||||
return memberCartMapper.selectList(qw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增购物车
|
||||
*
|
||||
* @param memberCart 购物车
|
||||
* @return 结果
|
||||
*/
|
||||
public int insert(MemberCart memberCart) {
|
||||
memberCart.setCreateTime(LocalDateTime.now());
|
||||
return memberCartMapper.insert(memberCart);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改购物车
|
||||
*
|
||||
* @param memberCart 购物车
|
||||
* @return 结果
|
||||
*/
|
||||
public int update(MemberCart memberCart) {
|
||||
return memberCartMapper.updateById(memberCart);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除购物车信息
|
||||
*
|
||||
* @param id 购物车主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteById(Long id) {
|
||||
return memberCartMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?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.cyl.ums.mapper.MemberCartMapper">
|
||||
|
||||
<resultMap type="MemberCart" id="MemberCartResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="productId" column="product_id"/>
|
||||
<result property="pic" column="pic"/>
|
||||
<result property="skuId" column="sku_id"/>
|
||||
<result property="productName" column="product_name"/>
|
||||
<result property="spData" column="sp_data"/>
|
||||
<result property="cartNum" column="cart_num"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectMemberCartVo">
|
||||
select id, member_id, product_id, pic, sku_id, product_name, sp_data, cart_num, create_by, create_time, update_by, update_time from ums_member_cart
|
||||
</sql>
|
||||
|
||||
<select id="selectByEntity" parameterType="MemberCart" resultMap="MemberCartResult">
|
||||
<include refid="selectMemberCartVo"/>
|
||||
<where>
|
||||
<if test="memberId != null "> and member_id = #{memberId}</if>
|
||||
<if test="productId != null "> and product_id = #{productId}</if>
|
||||
<if test="pic != null and pic != ''"> and pic = #{pic}</if>
|
||||
<if test="skuId != null "> and sku_id = #{skuId}</if>
|
||||
<if test="productName != null and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
|
||||
<if test="spData != null and spData != ''"> and sp_data = #{spData}</if>
|
||||
<if test="cartNum != null "> and cart_num = #{cartNum}</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,22 @@
|
||||
-- 菜单 SQL
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('购物车', '3', '1', 'memberCart', 'ums/memberCart/index', 1, 0, 'C', '0', '0', 'ums:memberCart:list', '#', 1, sysdate(), '', null, '购物车菜单');
|
||||
|
||||
-- 按钮父菜单ID
|
||||
SELECT @parentId := LAST_INSERT_ID();
|
||||
|
||||
-- 按钮 SQL
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('购物车查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', 'ums:memberCart:query', '#', 1, sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('购物车新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', 'ums:memberCart:add', '#', 1, sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('购物车修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', 'ums:memberCart:edit', '#', 1, sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('购物车删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', 'ums:memberCart:remove', '#', 1, sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('购物车导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', 'ums:memberCart:export', '#', 1, sysdate(), '', null, '');
|
||||
Loading…
Reference in new issue