'完成卡券分配给代理商'

dev-discount
199901012 4 years ago
parent dded298ed2
commit 20447d83f5
  1. 79
      hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java
  2. 6
      hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java
  3. 34
      hai-service/src/main/java/com/hai/model/HighCouponAgentRelModel.java
  4. 3
      hai-service/src/main/java/com/hai/service/HighCouponAgentService.java
  5. 21
      hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java

@ -1,5 +1,8 @@
package com.bweb.controller; 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.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
@ -22,14 +25,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -64,34 +67,34 @@ public class HighCouponAgentController {
SessionObject sessionObject = userCenter.getSessionObject(request); SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
if (userInfoModel.getBsCompany() == null) { if (userInfoModel.getBsCompany() == null) {
log.error("HighAgentController -> insertAgent() error!","该主角色没有权限"); log.error("HighCouponAgentController -> assignCouponAgent() error!","该主角色没有权限");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
} }
if(highCouponAgentRel.getCouponId() == null if(highCouponAgentRel.getCouponId() == null
|| highCouponAgentRel.getAgentId() == null || highCouponAgentRel.getAgentId() == null
|| highCouponAgentRel.getStockCount() == null) { || highCouponAgentRel.getStockCount() == null) {
log.error("HighAgentController -> insertAgent() error!","参数错误"); log.error("HighCouponAgentController -> assignCouponAgent() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 查询卡券详情 // 查询卡券详情
HighCoupon coupon = highCouponService.getCouponById(highCouponAgentRel.getCouponId()); HighCoupon coupon = highCouponService.getCouponById(highCouponAgentRel.getCouponId());
if (coupon == null) { if (coupon == null) {
log.error("HighAgentController -> insertAgent() error!","未找到卡券信息"); log.error("HighCouponAgentController -> assignCouponAgent() error!","未找到卡券信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
} }
// 查询代理商 // 查询代理商
HighAgent highAgent = highAgentService.findByAgentMsgId(highCouponAgentRel.getAgentId()); HighAgent highAgent = highAgentService.findByAgentMsgId(highCouponAgentRel.getAgentId());
if (highAgent == null) { if (highAgent == null) {
log.error("HighAgentController -> insertAgent() error!","未找到代理商信息"); log.error("HighCouponAgentController -> assignCouponAgent() error!","未找到代理商信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_AGENT, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_AGENT, "");
} }
// 校验是否重复分配 // 校验是否重复分配
if (highCouponAgentService.getRelByCouponAgent(highCouponAgentRel.getCouponId(),highCouponAgentRel.getAgentId()) != null) { if (highCouponAgentService.getRelByCouponAgent(highCouponAgentRel.getCouponId(),highCouponAgentRel.getAgentId()) != null) {
log.error("HighAgentController -> insertAgent() error!","参数错误"); log.error("HighCouponAgentController -> assignCouponAgent() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + "已分配给" + highAgent.getAgentName()); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + "已分配给" + highAgent.getAgentName());
} }
@ -106,7 +109,63 @@ public class HighCouponAgentController {
return ResponseMsgUtil.success("分配成功"); return ResponseMsgUtil.success("分配成功");
} catch (Exception e) { } catch (Exception e) {
log.error("HighAgentController --> assignCouponAgent() error!", 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); return ResponseMsgUtil.exception(e);
} }
} }

@ -1,5 +1,7 @@
package com.hai.entity; package com.hai.entity;
import com.hai.model.HighCouponAgentRelModel;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@ -13,7 +15,7 @@ import java.util.Date;
* 代码由工具生成 * 代码由工具生成
* *
**/ **/
public class HighCouponAgentRel implements Serializable { public class HighCouponAgentRel extends HighCouponAgentRelModel implements Serializable {
/** /**
* 主键 * 主键
*/ */
@ -246,4 +248,4 @@ public class HighCouponAgentRel implements Serializable {
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
} }
} }

@ -0,0 +1,34 @@
package com.hai.model;
import com.hai.entity.HighAgent;
import com.hai.entity.HighCoupon;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/4/21 21:37
*/
public class HighCouponAgentRelModel {
// 卡券信息
private HighCoupon highCoupon;
//代理商信息
private HighAgent highAgent;
public HighCoupon getHighCoupon() {
return highCoupon;
}
public void setHighCoupon(HighCoupon highCoupon) {
this.highCoupon = highCoupon;
}
public HighAgent getHighAgent() {
return highAgent;
}
public void setHighAgent(HighAgent highAgent) {
this.highAgent = highAgent;
}
}

@ -4,6 +4,8 @@ import com.hai.entity.HighCouponAgentCode;
import com.hai.entity.HighCouponAgentRel; import com.hai.entity.HighCouponAgentRel;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.util.List;
import java.util.Map;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -26,5 +28,6 @@ public interface HighCouponAgentService {
**/ **/
HighCouponAgentRel getRelByCouponAgent(Long couponId,Long agentId); HighCouponAgentRel getRelByCouponAgent(Long couponId,Long agentId);
List<HighCouponAgentRel> getCouponAgentList(Map<String, Object> map);
} }

@ -9,6 +9,7 @@ import com.hai.entity.*;
import com.hai.service.HighCouponAgentService; import com.hai.service.HighCouponAgentService;
import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponCodeService;
import com.hai.service.HighCouponService; import com.hai.service.HighCouponService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -34,6 +35,8 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
@Resource @Resource
private HighCouponCodeService highCouponCodeService; private HighCouponCodeService highCouponCodeService;
@Resource
private HighCouponService highCouponService;
@Override @Override
public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel) { public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel) {
@ -82,4 +85,22 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
} }
return null; return null;
} }
@Override
public List<HighCouponAgentRel> getCouponAgentList(Map<String, Object> map) {
HighCouponAgentRelExample example = new HighCouponAgentRelExample();
HighCouponAgentRelExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "couponId") != null) {
criteria.andCouponIdEqualTo(MapUtils.getLong(map, "couponId"));
}
if (MapUtils.getLong(map, "agentId") != null) {
criteria.andAgentIdEqualTo(MapUtils.getLong(map, "agentId"));
}
criteria.andStatusEqualTo(1);
example.setOrderByClause("create_time desc");
return highCouponAgentRelMapper.selectByExample(example);
}
} }

Loading…
Cancel
Save