嗨森逛服务
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.
hai-server/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java

174 lines
7.6 KiB

package com.bweb.controller;
import com.github.pagehelper.Page;
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.ResponseMsgUtil;
import com.hai.entity.HighAgent;
import com.hai.entity.HighCoupon;
import com.hai.entity.HighCouponAgentRel;
import com.hai.model.HighAgentModel;
import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel;
import com.hai.service.HighAgentService;
import com.hai.service.HighCouponAgentService;
import com.hai.service.HighCouponService;
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.List;
import java.util.Map;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/4/20 23:47
*/
@Controller
@RequestMapping(value = "/highCouponAgent")
@Api(value = "代理商接口")
public class HighCouponAgentController {
private static Logger log = LoggerFactory.getLogger(HighCouponAgentController.class);
@Resource
private HighCouponAgentService highCouponAgentService;
@Resource
private HighAgentService highAgentService;
@Autowired
private UserCenter userCenter;
@Resource
private HighCouponService highCouponService;
@RequestMapping(value = "/assignCouponAgent", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "分配卡券给代理商")
public ResponseData assignCouponAgent(@RequestBody HighCouponAgentRel highCouponAgentRel, HttpServletRequest request) {
try {
//发布人员
SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
if (userInfoModel.getBsCompany() == null) {
log.error("HighCouponAgentController -> assignCouponAgent() error!","该主角色没有权限");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
}
if(highCouponAgentRel.getCouponId() == null
|| highCouponAgentRel.getAgentId() == null
|| highCouponAgentRel.getStockCount() == null) {
log.error("HighCouponAgentController -> assignCouponAgent() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 查询卡券详情
HighCoupon coupon = highCouponService.getCouponById(highCouponAgentRel.getCouponId());
if (coupon == null) {
log.error("HighCouponAgentController -> assignCouponAgent() error!","未找到卡券信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
}
// 查询代理商
HighAgent highAgent = highAgentService.findByAgentMsgId(highCouponAgentRel.getAgentId());
if (highAgent == null) {
log.error("HighCouponAgentController -> assignCouponAgent() error!","未找到代理商信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_AGENT, "");
}
// 校验是否重复分配
if (highCouponAgentService.getRelByCouponAgent(highCouponAgentRel.getCouponId(),highCouponAgentRel.getAgentId()) != null) {
log.error("HighCouponAgentController -> assignCouponAgent() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + "已分配给" + highAgent.getAgentName());
}
highCouponAgentRel.setCouponName(coupon.getCouponName());
highCouponAgentRel.setSalesPrice(coupon.getSalesPrice());
highCouponAgentRel.setStatus(1); // 状态 0:删除 1:正常
highCouponAgentRel.setCreateTime(new Date());
highCouponAgentRel.setOperatorId(userInfoModel.getSecUser().getId());
highCouponAgentRel.setOperatorName(userInfoModel.getSecUser().getUserName());
highCouponAgentService.assignCouponAgent(highCouponAgentRel);
return ResponseMsgUtil.success("分配成功");
} catch (Exception e) {
log.error("HighCouponAgentController --> assignCouponAgent() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getCouponByAgent", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据代理商 查询卡券")
public ResponseData getCouponByAgent(@RequestParam(name = "pageNum", required = true) Integer pageNum,
@RequestParam(name = "pageSize", required = true) Integer pageSize,
HttpServletRequest request) {
try {
//发布人员
SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
if (userInfoModel.getHighAgent() == null) {
log.error("HighCouponAgentController -> getCouponByAgent() error!","该角色没有权限");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "该角色没有权限");
}
Map<String,Object> map = new HashMap<>();
map.put("agentId", userInfoModel.getHighAgent().getId());
PageHelper.startPage(pageNum,pageSize);
PageInfo<HighCouponAgentRel> pageInfo = new PageInfo<>(highCouponAgentService.getCouponAgentList(map));
for (HighCouponAgentRel rel : pageInfo.getList()) {
rel.setHighCoupon(highCouponService.getCouponById(rel.getCouponId()));
}
return ResponseMsgUtil.success(pageInfo);
} catch (Exception e) {
log.error("HighCouponAgentController --> getCouponByAgent() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getAgentByCoupon", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据卡券 查询代理商")
public ResponseData getAgentByCoupon(@RequestParam(name = "couponId", required = true) Long couponId,
@RequestParam(name = "pageNum", required = true) Integer pageNum,
@RequestParam(name = "pageSize", required = true) Integer pageSize,
HttpServletRequest request) {
try {
Map<String,Object> map = new HashMap<>();
map.put("couponId", couponId);
PageHelper.startPage(pageNum,pageSize);
PageInfo<HighCouponAgentRel> pageInfo = new PageInfo<>(highCouponAgentService.getCouponAgentList(map));
for (HighCouponAgentRel rel : pageInfo.getList()) {
rel.setHighAgent(highAgentService.findByAgentMsgId(rel.getAgentId()));
}
return ResponseMsgUtil.success(pageInfo);
} catch (Exception e) {
log.error("HighCouponAgentController --> getAgentByCoupon() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}