From 2b68b71ff0153afb6e5bd970bdbbb50906906bfc Mon Sep 17 00:00:00 2001 From: 199901012 Date: Wed, 21 Apr 2021 22:57:24 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighCouponAgentController.java | 103 +++++++++++++++++- .../hai/model/HighCouponAgentCodeModel.java | 35 +++++- .../hai/service/HighCouponAgentService.java | 25 +++++ .../impl/HighCouponAgentServiceImpl.java | 65 +++++++++++ 4 files changed, 218 insertions(+), 10 deletions(-) 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 adad5d9a..513acfe0 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java @@ -9,14 +9,13 @@ 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.entity.*; 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.HighCouponCodeService; import com.hai.service.HighCouponService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -52,6 +51,9 @@ public class HighCouponAgentController { @Resource private HighAgentService highAgentService; + @Resource + private HighCouponCodeService highCouponCodeService; + @Autowired private UserCenter userCenter; @@ -146,21 +148,26 @@ public class HighCouponAgentController { } } + @RequestMapping(value = "/getAgentByCoupon", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据卡券 查询代理商") public ResponseData getAgentByCoupon(@RequestParam(name = "couponId", required = true) Long couponId, + @RequestParam(name = "status", required = false) Integer status, @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); + map.put("status", status); PageHelper.startPage(pageNum,pageSize); PageInfo pageInfo = new PageInfo<>(highCouponAgentService.getCouponAgentList(map)); - for (HighCouponAgentRel rel : pageInfo.getList()) { - rel.setHighAgent(highAgentService.findByAgentMsgId(rel.getAgentId())); + if (pageInfo.getList().size() > 0) { + for (HighCouponAgentRel code : pageInfo.getList()) { + code.setHighAgent(highAgentService.findByAgentMsgId(code.getAgentId())); + } } return ResponseMsgUtil.success(pageInfo); @@ -171,4 +178,90 @@ public class HighCouponAgentController { } + @RequestMapping(value = "/getCodeListByAgentCoupon", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "根据代理商和卡券 查询分配的销售码") + public ResponseData getCodeListByAgentCoupon(@RequestParam(name = "couponId", required = true) Long couponId, + @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()); + map.put("couponId", couponId); + + PageHelper.startPage(pageNum,pageSize); + PageInfo pageInfo = new PageInfo<>(highCouponAgentService.getCouponCodeList(map)); + if (pageInfo.getList().size() > 0) { + HighCoupon coupon = highCouponService.getCouponDetail(couponId); + for (HighCouponAgentCode code : pageInfo.getList()) { + code.setMerchantName(coupon.getMerchantName()); + code.setHighCoupon(coupon); + code.setHighCouponCode(highCouponCodeService.getCouponCodeById(code.getCouponCodeId())); + } + } + return ResponseMsgUtil.success(pageInfo); + + } catch (Exception e) { + log.error("HighCouponAgentController --> getCouponByAgent() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + + @RequestMapping(value = "/generateCode", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "生成二维码") + public ResponseData generateCode(@RequestParam(name = "couponAgentCodeId", required = true) Long couponAgentCodeId, + HttpServletRequest request) { + try { + //发布人员 + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + if (userInfoModel.getHighAgent() == null) { + log.error("HighCouponAgentController -> generateCode() error!","该角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "该角色没有权限"); + } + + return ResponseMsgUtil.success(highCouponAgentService.generateCode(couponAgentCodeId)); + + } catch (Exception e) { + log.error("HighCouponAgentController --> generateCode() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getCodeById", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "根据销售码查询详情") + public ResponseData getCodeById(@RequestParam(name = "couponAgentCodeId", required = true) Long couponAgentCodeId, + HttpServletRequest request) { + try { + // 查询卡券销售码 + HighCouponAgentCode couponAgentCode = highCouponAgentService.getCodeById(couponAgentCodeId); + if (couponAgentCode == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到销售码"); + } + + Map map = new HashMap<>(); + map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); + map.put("couponCode", highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId())); + map.put("couponAgentCode", couponAgentCode); + return ResponseMsgUtil.success(map); + + } catch (Exception e) { + log.error("HighCouponAgentController --> getCodeById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-service/src/main/java/com/hai/model/HighCouponAgentCodeModel.java b/hai-service/src/main/java/com/hai/model/HighCouponAgentCodeModel.java index f1120faf..5f188282 100644 --- a/hai-service/src/main/java/com/hai/model/HighCouponAgentCodeModel.java +++ b/hai-service/src/main/java/com/hai/model/HighCouponAgentCodeModel.java @@ -1,6 +1,8 @@ package com.hai.model; +import com.hai.entity.HighCoupon; import com.hai.entity.HighCouponAgentCode; +import com.hai.entity.HighCouponCode; import java.util.List; @@ -11,13 +13,36 @@ import java.util.List; */ public class HighCouponAgentCodeModel { - private List couponAgentCodeList; + // 商户名称 + private String merchantName; - public List getCouponAgentCodeList() { - return couponAgentCodeList; + // 卡券 + private HighCoupon highCoupon; + + // 销售码 + private HighCouponCode highCouponCode; + + public String getMerchantName() { + return merchantName; + } + + public void setMerchantName(String merchantName) { + this.merchantName = merchantName; + } + + public HighCoupon getHighCoupon() { + return highCoupon; + } + + public void setHighCoupon(HighCoupon highCoupon) { + this.highCoupon = highCoupon; + } + + public HighCouponCode getHighCouponCode() { + return highCouponCode; } - public void setCouponAgentCodeList(List couponAgentCodeList) { - this.couponAgentCodeList = couponAgentCodeList; + public void setHighCouponCode(HighCouponCode highCouponCode) { + this.highCouponCode = highCouponCode; } } 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 69c69ce0..8a4eb7f8 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java @@ -28,6 +28,31 @@ public interface HighCouponAgentService { **/ HighCouponAgentRel getRelByCouponAgent(Long couponId,Long agentId); + /** + * @Author 胡锐 + * @Description 查询卡券与代理商关系列表 + * @Date 2021/4/21 21:58 + **/ List getCouponAgentList(Map map); + /** + * @Author 胡锐 + * @Description 查询已分配销售码 + * @Date 2021/4/21 22:05 + **/ + List getCouponCodeList(Map map); + + /** + * @Author 胡锐 + * @Description 根据分配的销售码id 查询 + * @Date 2021/4/21 22:31 + **/ + HighCouponAgentCode getCodeById(Long couponAgentCodeId); + + /** + * @Author 胡锐 + * @Description 生成二维码 + * @Date 2021/4/21 22:35 + **/ + Map generateCode(Long couponAgentCodeId); } 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 64ee862a..bb7c79f0 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 @@ -3,6 +3,7 @@ package com.hai.service.impl; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.utils.ResponseMsgUtil; import com.hai.dao.HighCouponAgentCodeMapper; import com.hai.dao.HighCouponAgentRelMapper; import com.hai.entity.*; @@ -11,6 +12,8 @@ import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponService; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Date; @@ -103,4 +106,66 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { example.setOrderByClause("create_time desc"); return highCouponAgentRelMapper.selectByExample(example); } + + @Override + public List getCouponCodeList(Map map) { + HighCouponAgentCodeExample example = new HighCouponAgentCodeExample(); + HighCouponAgentCodeExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map, "couponAgentId") != null) { + criteria.andCouponAgentIdEqualTo(MapUtils.getLong(map, "couponAgentId")); + } + + if (MapUtils.getLong(map, "couponId") != null) { + criteria.andCouponIdEqualTo(MapUtils.getLong(map, "couponId")); + } + + if (MapUtils.getLong(map, "agentId") != null) { + criteria.andAgentIdEqualTo(MapUtils.getLong(map, "agentId")); + } + + if (MapUtils.getInteger(map, "status") != null) { + criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); + } + + example.setOrderByClause("create_time desc"); + return highCouponAgentCodeMapper.selectByExample(example); + } + + @Override + public HighCouponAgentCode getCodeById(Long couponAgentCodeId) { + HighCouponAgentCodeExample example = new HighCouponAgentCodeExample(); + example.createCriteria().andCouponAgentIdEqualTo(couponAgentCodeId); + List list = highCouponAgentCodeMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public Map generateCode(Long couponAgentCodeId) { + // 查询卡券销售码 + HighCouponAgentCode couponAgentCode = getCodeById(couponAgentCodeId); + if (couponAgentCode == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到销售码"); + } + if (couponAgentCode.getStatus() != 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "销售码已被销售"); + } + couponAgentCode.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 + highCouponAgentCodeMapper.updateByPrimaryKey(couponAgentCode); + + HighCouponCode couponCode = highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId()); + couponCode.setStatus(2); + couponCode.setReceiveTime(new Date()); + highCouponCodeService.updateCouponCode(couponCode); + + Map map = new HashMap<>(); + map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); + map.put("couponCode", couponCode); + map.put("couponAgentCode", couponAgentCode); + return map; + } }