添加优惠券管理接口
This commit is contained in:
@@ -5,7 +5,6 @@ import com.macro.mall.dto.PmsProductParam;
|
||||
import com.macro.mall.dto.PmsProductQueryParam;
|
||||
import com.macro.mall.dto.PmsProductResult;
|
||||
import com.macro.mall.model.PmsProduct;
|
||||
import com.macro.mall.model.PmsProductVertifyRecord;
|
||||
import com.macro.mall.service.PmsProductService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -60,7 +59,7 @@ public class PmsProductController {
|
||||
}
|
||||
|
||||
@ApiOperation("查询商品")
|
||||
@RequestMapping(value = "list", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object getList(PmsProductQueryParam productQueryParam,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.macro.mall.controller;
|
||||
|
||||
import com.macro.mall.dto.CommonResult;
|
||||
import com.macro.mall.dto.SmsCouponParam;
|
||||
import com.macro.mall.model.SmsCoupon;
|
||||
import com.macro.mall.service.SmsCouponService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券管理Controller
|
||||
* Created by macro on 2018/8/28.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "SmsCouponController", description = "优惠券管理")
|
||||
@RequestMapping("/coupon")
|
||||
public class SmsCouponController {
|
||||
@Autowired
|
||||
private SmsCouponService couponService;
|
||||
@ApiOperation("添加优惠券")
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object add(@RequestBody SmsCouponParam couponParam) {
|
||||
int count = couponService.add(couponParam);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
|
||||
@ApiOperation("删除优惠券")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object delete(@PathVariable Long id) {
|
||||
int count = couponService.delete(id);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
|
||||
@ApiOperation("修改优惠券")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object update(@PathVariable Long id,@RequestBody SmsCouponParam couponParam) {
|
||||
int count = couponService.update(id,couponParam);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
|
||||
@ApiOperation("根据优惠券名称和类型分页获取优惠券列表")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object list(
|
||||
@RequestParam(value = "name",required = false) String name,
|
||||
@RequestParam(value = "type",required = false) Integer type,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
List<SmsCoupon> couponList = couponService.list(name,type,pageSize,pageNum);
|
||||
return new CommonResult().pageSuccess(couponList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.macro.mall.dao;
|
||||
|
||||
import com.macro.mall.model.SmsCouponProductCategoryRelation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券和商品分类关系自定义Dao
|
||||
* Created by macro on 2018/8/28.
|
||||
*/
|
||||
public interface SmsCouponProductCategoryRelationDao {
|
||||
int insertList(@Param("list")List<SmsCouponProductCategoryRelation> productCategoryRelationList);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.macro.mall.dao;
|
||||
|
||||
import com.macro.mall.model.SmsCouponProductRelation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券和产品关系自定义Dao
|
||||
* Created by macro on 2018/8/28.
|
||||
*/
|
||||
public interface SmsCouponProductRelationDao {
|
||||
int insertList(@Param("list")List<SmsCouponProductRelation> productRelationList);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.macro.mall.dto;
|
||||
|
||||
import com.macro.mall.model.SmsCoupon;
|
||||
import com.macro.mall.model.SmsCouponProductCategoryRelation;
|
||||
import com.macro.mall.model.SmsCouponProductRelation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券信息封装,包括绑定商品和绑定分类
|
||||
* Created by macro on 2018/8/28.
|
||||
*/
|
||||
public class SmsCouponParam extends SmsCoupon {
|
||||
//优惠券绑定的商品
|
||||
private List<SmsCouponProductRelation> productRelationList;
|
||||
//优惠券绑定的商品分类
|
||||
private List<SmsCouponProductCategoryRelation> productCategoryRelationList;
|
||||
|
||||
public List<SmsCouponProductRelation> getProductRelationList() {
|
||||
return productRelationList;
|
||||
}
|
||||
|
||||
public void setProductRelationList(List<SmsCouponProductRelation> productRelationList) {
|
||||
this.productRelationList = productRelationList;
|
||||
}
|
||||
|
||||
public List<SmsCouponProductCategoryRelation> getProductCategoryRelationList() {
|
||||
return productCategoryRelationList;
|
||||
}
|
||||
|
||||
public void setProductCategoryRelationList(List<SmsCouponProductCategoryRelation> productCategoryRelationList) {
|
||||
this.productCategoryRelationList = productCategoryRelationList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.dto.SmsCouponParam;
|
||||
import com.macro.mall.model.SmsCoupon;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券管理Service
|
||||
* Created by macro on 2018/8/28.
|
||||
*/
|
||||
public interface SmsCouponService {
|
||||
/**
|
||||
* 添加优惠券
|
||||
*/
|
||||
@Transactional
|
||||
int add(SmsCouponParam couponParam);
|
||||
|
||||
/**
|
||||
* 根据优惠券id删除优惠券
|
||||
*/
|
||||
@Transactional
|
||||
int delete(Long id);
|
||||
|
||||
/**
|
||||
* 根据优惠券id更新优惠券信息
|
||||
*/
|
||||
@Transactional
|
||||
int update(Long id, SmsCouponParam couponParam);
|
||||
|
||||
/**
|
||||
* 分页获取优惠券列表
|
||||
*/
|
||||
List<SmsCoupon> list(String name, Integer type, Integer pageSize, Integer pageNum);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.dao.SmsCouponProductCategoryRelationDao;
|
||||
import com.macro.mall.dao.SmsCouponProductRelationDao;
|
||||
import com.macro.mall.dto.SmsCouponParam;
|
||||
import com.macro.mall.mapper.SmsCouponMapper;
|
||||
import com.macro.mall.mapper.SmsCouponProductCategoryRelationMapper;
|
||||
import com.macro.mall.mapper.SmsCouponProductRelationMapper;
|
||||
import com.macro.mall.model.*;
|
||||
import com.macro.mall.service.SmsCouponService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券管理Service实现类
|
||||
* Created by macro on 2018/8/28.
|
||||
*/
|
||||
@Service
|
||||
public class SmsCouponServiceImpl implements SmsCouponService {
|
||||
@Autowired
|
||||
private SmsCouponMapper couponMapper;
|
||||
@Autowired
|
||||
private SmsCouponProductRelationMapper productRelationMapper;
|
||||
@Autowired
|
||||
private SmsCouponProductCategoryRelationMapper productCategoryRelationMapper;
|
||||
@Autowired
|
||||
private SmsCouponProductRelationDao productRelationDao;
|
||||
@Autowired
|
||||
private SmsCouponProductCategoryRelationDao productCategoryRelationDao;
|
||||
@Override
|
||||
public int add(SmsCouponParam couponParam) {
|
||||
//插入优惠券表
|
||||
// TODO: 2018/8/28 生成优惠券条码
|
||||
int count = couponMapper.insert(couponParam);
|
||||
//插入优惠券和商品关系表
|
||||
if(couponParam.getUseType().equals(2)){
|
||||
for(SmsCouponProductRelation productRelation:couponParam.getProductRelationList()){
|
||||
productRelation.setCouponId(couponParam.getId());
|
||||
}
|
||||
productRelationDao.insertList(couponParam.getProductRelationList());
|
||||
}
|
||||
//插入优惠券和商品分类关系表
|
||||
if(couponParam.getUseType().equals(1)){
|
||||
for (SmsCouponProductCategoryRelation couponProductCategoryRelation : couponParam.getProductCategoryRelationList()) {
|
||||
couponProductCategoryRelation.setCouponId(couponParam.getId());
|
||||
}
|
||||
productCategoryRelationDao.insertList(couponParam.getProductCategoryRelationList());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
//删除优惠券
|
||||
int count = couponMapper.deleteByPrimaryKey(id);
|
||||
//删除商品关联
|
||||
deleteProductRelation(id);
|
||||
//删除商品分类关联
|
||||
deleteProductCategoryRelation(id);
|
||||
return count;
|
||||
}
|
||||
|
||||
private void deleteProductCategoryRelation(Long id) {
|
||||
SmsCouponProductCategoryRelationExample productCategoryRelationExample = new SmsCouponProductCategoryRelationExample();
|
||||
productCategoryRelationExample.createCriteria().andCouponIdEqualTo(id);
|
||||
productCategoryRelationMapper.deleteByExample(productCategoryRelationExample);
|
||||
}
|
||||
|
||||
private void deleteProductRelation(Long id) {
|
||||
SmsCouponProductRelationExample productRelationExample = new SmsCouponProductRelationExample();
|
||||
productRelationExample.createCriteria().andCouponIdEqualTo(id);
|
||||
productRelationMapper.deleteByExample(productRelationExample);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Long id, SmsCouponParam couponParam) {
|
||||
couponParam.setId(id);
|
||||
int count =couponMapper.updateByPrimaryKey(couponParam);
|
||||
//删除后插入优惠券和商品关系表
|
||||
if(couponParam.getUseType().equals(2)){
|
||||
for(SmsCouponProductRelation productRelation:couponParam.getProductRelationList()){
|
||||
productRelation.setCouponId(couponParam.getId());
|
||||
}
|
||||
deleteProductRelation(id);
|
||||
productRelationDao.insertList(couponParam.getProductRelationList());
|
||||
}
|
||||
//删除后插入优惠券和商品分类关系表
|
||||
if(couponParam.getUseType().equals(1)){
|
||||
for (SmsCouponProductCategoryRelation couponProductCategoryRelation : couponParam.getProductCategoryRelationList()) {
|
||||
couponProductCategoryRelation.setCouponId(couponParam.getId());
|
||||
}
|
||||
deleteProductCategoryRelation(id);
|
||||
productCategoryRelationDao.insertList(couponParam.getProductCategoryRelationList());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SmsCoupon> list(String name, Integer type, Integer pageSize, Integer pageNum) {
|
||||
SmsCouponExample example = new SmsCouponExample();
|
||||
SmsCouponExample.Criteria criteria = example.createCriteria();
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
criteria.andNameLike("%"+name+"%");
|
||||
}
|
||||
if(type!=null){
|
||||
criteria.andTypeEqualTo(type);
|
||||
}
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
return couponMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user