From 20447d83f5236a97dc1a134c8e1e2a5d13d4792c Mon Sep 17 00:00:00 2001 From: 199901012 Date: Wed, 21 Apr 2021 21:50:47 +0800 Subject: [PATCH] =?UTF-8?q?'=E5=AE=8C=E6=88=90=E5=8D=A1=E5=88=B8=E5=88=86?= =?UTF-8?q?=E9=85=8D=E7=BB=99=E4=BB=A3=E7=90=86=E5=95=86'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighCouponAgentController.java | 79 ++++++++++++++++--- .../com/hai/entity/HighCouponAgentRel.java | 6 +- .../hai/model/HighCouponAgentRelModel.java | 34 ++++++++ .../hai/service/HighCouponAgentService.java | 3 + .../impl/HighCouponAgentServiceImpl.java | 21 +++++ 5 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/model/HighCouponAgentRelModel.java diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java index b9ee2f0b..adad5d9a 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java @@ -1,5 +1,8 @@ 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; @@ -22,14 +25,14 @@ 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.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +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: 胡锐 @@ -64,34 +67,34 @@ public class HighCouponAgentController { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); 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, ""); } if(highCouponAgentRel.getCouponId() == null || highCouponAgentRel.getAgentId() == null || highCouponAgentRel.getStockCount() == null) { - log.error("HighAgentController -> insertAgent() error!","参数错误"); + 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("HighAgentController -> insertAgent() error!","未找到卡券信息"); + 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("HighAgentController -> insertAgent() error!","未找到代理商信息"); + log.error("HighCouponAgentController -> assignCouponAgent() error!","未找到代理商信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_AGENT, ""); } // 校验是否重复分配 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()); } @@ -106,7 +109,63 @@ public class HighCouponAgentController { return ResponseMsgUtil.success("分配成功"); } 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 map = new HashMap<>(); + map.put("agentId", userInfoModel.getHighAgent().getId()); + + PageHelper.startPage(pageNum,pageSize); + PageInfo 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 map = new HashMap<>(); + map.put("couponId", couponId); + + PageHelper.startPage(pageNum,pageSize); + PageInfo 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); } } diff --git a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java index c4839073..d7efdce4 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java +++ b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java @@ -1,5 +1,7 @@ package com.hai.entity; +import com.hai.model.HighCouponAgentRelModel; + import java.io.Serializable; import java.math.BigDecimal; 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("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/model/HighCouponAgentRelModel.java b/hai-service/src/main/java/com/hai/model/HighCouponAgentRelModel.java new file mode 100644 index 00000000..88bb8261 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/HighCouponAgentRelModel.java @@ -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; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java index 313d8713..69c69ce0 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java @@ -4,6 +4,8 @@ import com.hai.entity.HighCouponAgentCode; import com.hai.entity.HighCouponAgentRel; import java.security.PrivateKey; +import java.util.List; +import java.util.Map; /** * @Auther: 胡锐 @@ -26,5 +28,6 @@ public interface HighCouponAgentService { **/ HighCouponAgentRel getRelByCouponAgent(Long couponId,Long agentId); + List getCouponAgentList(Map map); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java index 437a0003..64ee862a 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java @@ -9,6 +9,7 @@ import com.hai.entity.*; import com.hai.service.HighCouponAgentService; import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponService; +import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -34,6 +35,8 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { @Resource private HighCouponCodeService highCouponCodeService; + @Resource + private HighCouponService highCouponService; @Override public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel) { @@ -82,4 +85,22 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { } return null; } + + @Override + public List getCouponAgentList(Map 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); + } }