You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
284 lines
13 KiB
284 lines
13 KiB
package com.bweb.controller;
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.hai.common.exception.ErrorCode;
|
|
import com.hai.common.exception.ErrorHelp;
|
|
import com.hai.common.exception.SysCode;
|
|
import com.hai.common.security.SessionObject;
|
|
import com.hai.common.security.UserCenter;
|
|
import com.hai.common.utils.DateUtil;
|
|
import com.hai.common.utils.MemberValidateUtil;
|
|
import com.hai.common.utils.ResponseMsgUtil;
|
|
import com.hai.entity.*;
|
|
import com.hai.enum_type.ApproveType;
|
|
import com.hai.model.HighCouponModel;
|
|
import com.hai.model.ResponseData;
|
|
import com.hai.model.UserInfoModel;
|
|
import com.hai.service.HighApproveService;
|
|
import com.hai.service.HighCouponService;
|
|
import com.hai.service.HighMerchantService;
|
|
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.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @Auther: 胡锐
|
|
* @Description:
|
|
* @Date: 2021/3/11 22:16
|
|
*/
|
|
@Controller
|
|
@RequestMapping(value = "/coupon")
|
|
@Api(value = "卡卷接口")
|
|
public class HighCouponController {
|
|
|
|
private static Logger log = LoggerFactory.getLogger(HighCouponController.class);
|
|
|
|
@Autowired
|
|
private UserCenter userCenter;
|
|
|
|
@Resource
|
|
private HighMerchantService highMerchantService;
|
|
|
|
@Resource
|
|
private HighCouponService highCouponService;
|
|
|
|
@Resource
|
|
private HighApproveService highApproveService;
|
|
|
|
@RequestMapping(value="/insertCoupon",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ApiOperation(value = "增加卡卷")
|
|
public ResponseData insertCoupon(@RequestBody HighCouponModel highCoupon, HttpServletRequest request) {
|
|
try {
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
if (highCoupon.getMerchantId() == null
|
|
|| StringUtils.isBlank(highCoupon.getCouponName())
|
|
|| StringUtils.isBlank(highCoupon.getCouponImg())
|
|
|| StringUtils.isBlank(highCoupon.getCouponCarouselImg())
|
|
|| StringUtils.isBlank(highCoupon.getCouponDesc())
|
|
|| highCoupon.getCouponPrice() == null
|
|
|| highCoupon.getCouponType() == null
|
|
|| highCoupon.getSalesEndTime() == null
|
|
|| highCoupon.getRecycleDay() == null
|
|
|| highCoupon.getLimitNumber()== null
|
|
|| highCoupon.getSalesPrice()== null
|
|
|| highCoupon.getIsPresent() == null) {
|
|
log.error("HighCouponController -> insertCoupon() error!","参数错误");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
|
|
}
|
|
|
|
// 是否赠送卡卷
|
|
if (highCoupon.getIsPresent() == true) {
|
|
if (highCoupon.getHandselCouponList() == null || highCoupon.getHandselCouponList().size() == 0) {
|
|
log.error("HighCouponController -> insertCoupon() error!","请选择赠送卡卷名单");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.SELECT_HANDSEL_COUPON_ERROR, "");
|
|
}
|
|
for (HighCouponHandsel handsel : highCoupon.getHandselCouponList()) {
|
|
handsel.setCreateTime(new Date());
|
|
handsel.setStatus(1); // 状态 0:删除 1:正常
|
|
handsel.setOperatorId(userInfoModel.getSecUser().getId());
|
|
handsel.setOperatorName(userInfoModel.getSecUser().getUserName());
|
|
}
|
|
}
|
|
|
|
// 查询商户
|
|
HighMerchant merchant = highMerchantService.getMerchantById(highCoupon.getCompanyId());
|
|
if (merchant == null) {
|
|
log.error("HighCouponController -> insertCoupon() error!","未找到商户");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
|
|
}
|
|
|
|
String setCouponKey = DateUtil.date2String(new Date(), "yyyyMMddhhmmss") + ((Math.random()*9+1)*10000); //订单号生成 年月日小时分秒 + 5位随机数
|
|
highCoupon.setCouponKey(setCouponKey);
|
|
highCoupon.setCompanyId(merchant.getCompanyId());
|
|
highCoupon.setOperatorId(userInfoModel.getSecUser().getId());
|
|
highCoupon.setOperatorName(userInfoModel.getSecUser().getUserName());
|
|
highCoupon.setCreateTime(new Date());
|
|
highCoupon.setUpdateTime(new Date());
|
|
highCoupon.setStatus(1); // 状态:0.删除 1.编辑中 2.已上架 3.已下架 101.上架审批中 102.上架审批驳回
|
|
highCouponService.insertCoupon(highCoupon);
|
|
|
|
return ResponseMsgUtil.success(highCoupon);
|
|
} catch (Exception e) {
|
|
log.error("HighCouponController -> insertCoupon() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(value="/updateCoupon",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ApiOperation(value = "修改卡卷")
|
|
public ResponseData updateCoupon(@RequestBody HighCouponModel highCoupon, HttpServletRequest request) {
|
|
try {
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
if (highCoupon.getMerchantId() == null
|
|
|| StringUtils.isBlank(highCoupon.getCouponName())
|
|
|| StringUtils.isBlank(highCoupon.getCouponImg())
|
|
|| StringUtils.isBlank(highCoupon.getCouponCarouselImg())
|
|
|| StringUtils.isBlank(highCoupon.getCouponDesc())
|
|
|| highCoupon.getCouponPrice() == null
|
|
|| highCoupon.getCouponType() == null
|
|
|| highCoupon.getSalesEndTime() == null
|
|
|| highCoupon.getRecycleDay() == null
|
|
|| highCoupon.getLimitNumber()== null
|
|
|| highCoupon.getSalesPrice()== null
|
|
|| highCoupon.getIsPresent() == null) {
|
|
log.error("HighCouponController -> insertCoupon() error!","参数错误");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
|
|
}
|
|
|
|
// 是否赠送卡卷
|
|
if (highCoupon.getIsPresent() == true) {
|
|
if (highCoupon.getHandselCouponList() == null || highCoupon.getHandselCouponList().size() == 0) {
|
|
log.error("HighCouponController -> updateCoupon() error!","请选择赠送卡卷名单");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.SELECT_HANDSEL_COUPON_ERROR, "");
|
|
}
|
|
for (HighCouponHandsel handsel : highCoupon.getHandselCouponList()) {
|
|
// 如果没有id 就是需要增加的
|
|
if (handsel.getId() == null) {
|
|
handsel.setCreateTime(new Date());
|
|
handsel.setStatus(1); // 状态 0:删除 1:正常
|
|
handsel.setOperatorId(userInfoModel.getSecUser().getId());
|
|
handsel.setOperatorName(userInfoModel.getSecUser().getUserName());
|
|
}
|
|
}
|
|
}
|
|
|
|
// 查询卡券
|
|
HighCouponModel coupon = highCouponService.getCouponById(highCoupon.getId());
|
|
if (coupon == null) {
|
|
log.error("HighCouponController -> updateCoupon() error!","未找到卡卷信息");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
|
|
}
|
|
|
|
// 查询商户
|
|
HighMerchant merchant = highMerchantService.getMerchantById(highCoupon.getCompanyId());
|
|
if (merchant == null) {
|
|
log.error("HighCouponController -> updateCoupon() error!","未找到商户");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
|
|
}
|
|
|
|
highCoupon.setCompanyId(merchant.getCompanyId());
|
|
highCoupon.setOperatorId(userInfoModel.getSecUser().getId());
|
|
highCoupon.setOperatorName(userInfoModel.getSecUser().getUserName());
|
|
highCoupon.setUpdateTime(new Date());
|
|
|
|
highCouponService.updateCoupon(highCoupon);
|
|
|
|
return ResponseMsgUtil.success(highCoupon);
|
|
} catch (Exception e) {
|
|
log.error("HighCouponController -> updateCoupon() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value="/upShelfApprove",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "卡卷上架审批")
|
|
public ResponseData upShelfApprove(@RequestParam(name = "id", required = true) Long id, HttpServletRequest request) {
|
|
try {
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
// 查询卡券
|
|
HighCouponModel coupon = highCouponService.getCouponById(id);
|
|
if (coupon == null) {
|
|
log.error("HighCouponController -> upShelfApprove() error!","未找到卡卷信息");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
|
|
}
|
|
// 如果卡卷状态不处于 编辑中、已下架、审上架批驳回
|
|
if (coupon.getStatus() != 1 || coupon.getStatus() != 3 || coupon.getStatus() != 102) {
|
|
log.error("HighCouponController -> upShelfApprove() error!","卡卷状态错误");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_UNABLE_UP_SHELF, "");
|
|
}
|
|
|
|
HighApprove approve = new HighApprove();
|
|
approve.setObjectType(ApproveType.UP_SHELF_APPROVE.getType());
|
|
approve.setObjectId(id);
|
|
approve.setApproveSerialNo(DateUtil.date2String(new Date(), "MMddhhmmss") + ((Math.random()*9+1)*10000));
|
|
approve.setStatus(1);
|
|
approve.setCreateTime(new Date());
|
|
approve.setUpdateTime(new Date());
|
|
approve.setSubmitOperatorId(userInfoModel.getSecUser().getId());
|
|
approve.setSubmitOperatorName(userInfoModel.getSecUser().getUserName());
|
|
|
|
// 增加审批
|
|
highApproveService.insertApprove(approve);
|
|
|
|
return ResponseMsgUtil.success("操作成功");
|
|
} catch (Exception e) {
|
|
log.error("HighCouponController -> upShelfApprove() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value="/ofShelfApprove",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "卡卷下架")
|
|
public ResponseData ofShelfApprove(@RequestParam(name = "id", required = true) Long id) {
|
|
try {
|
|
|
|
highCouponService.ofShelfCoupon(id);
|
|
|
|
return ResponseMsgUtil.success("操作成功");
|
|
} catch (Exception e) {
|
|
log.error("HighCouponController -> ofShelfApprove() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value="/getCouponById",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "根据id 查询卡卷")
|
|
public ResponseData getCouponById(@RequestParam(name = "id", required = true) Long id) {
|
|
try {
|
|
|
|
return ResponseMsgUtil.success(highCouponService.getCouponById(id));
|
|
|
|
} catch (Exception e) {
|
|
log.error("HighCouponController -> getCouponById() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value="/getCouponList",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "卡卷列表")
|
|
public ResponseData getCouponList(@RequestParam(name = "companyId", required = false) Long companyId,
|
|
@RequestParam(name = "merchantId", required = false) Long merchantId,
|
|
@RequestParam(name = "couponName", required = false) String couponName,
|
|
@RequestParam(name = "couponType", required = false) Integer couponType,
|
|
@RequestParam(name = "status", required = false) Integer status,
|
|
@RequestParam(name = "pageNum", required = true) Integer pageNum,
|
|
@RequestParam(name = "pageSize", required = true) Integer pageSize) {
|
|
try {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("companyId", companyId);
|
|
map.put("merchantId", merchantId);
|
|
map.put("couponName", couponName);
|
|
map.put("couponType", couponType);
|
|
map.put("status", status);
|
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
return ResponseMsgUtil.success(new PageInfo<>(highCouponService.getCouponList(map)));
|
|
} catch (Exception e) {
|
|
log.error("HighCouponController -> getCouponList() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
}
|
|
|