From d4c710a01fdf3d474877fc3ce080751aeb929ae2 Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Tue, 7 Dec 2021 20:47:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HighDiscountPackageController.java | 44 ++++++++++++- .../service/HighDiscountPackageService.java | 12 ++++ .../impl/HighDiscountPackageServiceImpl.java | 62 +++++++++++++++++-- .../impl/OutRechargePriceServiceImpl.java | 2 +- 4 files changed, 111 insertions(+), 9 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java index 4ccd39ce..d1042d98 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java @@ -165,6 +165,8 @@ public class HighDiscountPackageController { highDiscountPackage.setCreatedUserId(userInfoModel.getSecUser().getId().intValue()); highDiscountPackage.setUpdatedTime(new Date()); highDiscountPackage.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue()); + highDiscountPackage.setTotalStock(0); + highDiscountPackage.setSurplusStock(0); highDiscountPackageService.insertDiscountPackage(highDiscountPackage); @@ -376,7 +378,7 @@ public class HighDiscountPackageController { throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); } - HighDiscountPackage highDiscountPackage = highDiscountPackageService.findDiscountPackageById(object.getInteger("discountId")); + HighDiscountPackage highDiscountPackage = highDiscountPackageService.findDiscountPackageById(object.getInteger("discountPackageId")); if (highDiscountPackage == null || highDiscountPackage.getStatus() == 1) { log.error("highCouponPackage -> highCouponPackageInfo() error!","状态错误"); @@ -412,7 +414,7 @@ public class HighDiscountPackageController { throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); } - HighDiscountPackage highDiscountPackage = highDiscountPackageService.findDiscountPackageById(object.getInteger("discountId")); + HighDiscountPackage highDiscountPackage = highDiscountPackageService.findDiscountPackageById(object.getInteger("discountPackageId")); if (highDiscountPackage == null || highDiscountPackage.getStatus() == 1 ) { log.error("highCouponPackage -> highCouponPackageInfo() error!","状态错误"); @@ -448,7 +450,7 @@ public class HighDiscountPackageController { throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); } - HighDiscountPackage highDiscountPackage = highDiscountPackageService.findDiscountPackageById(object.getInteger("discountId")); + HighDiscountPackage highDiscountPackage = highDiscountPackageService.findDiscountPackageById(object.getInteger("discountPackageId")); if (highDiscountPackage == null) { log.error("highCouponPackage -> highCouponPackageInfo() error!","状态错误"); @@ -501,4 +503,40 @@ public class HighDiscountPackageController { } } + @RequestMapping(value="/addDiscountPackageStock",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "增加优惠券包库存") + public ResponseData addDiscountPackageStock(@RequestBody JSONObject object, HttpServletRequest request) { + try { + //发布人员 + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + if (userInfoModel.getBsCompany() == null) { + log.error("highCouponPackage -> highCouponPackageInfo() error!","该主角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); + } + + HighDiscountPackage highDiscountPackage = highDiscountPackageService.findDiscountPackageById(object.getInteger("discountPackageId")); + + if (highDiscountPackage == null) { + log.error("highCouponPackage -> highCouponPackageInfo() error!","当前优惠券包不存在"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, ""); + } + + if (object.getInteger("num") == null) { + log.error("highCouponPackage -> highCouponPackageInfo() error!","请传入库存数量"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, ""); + } + + highDiscountPackageService.addDiscountPackageStock(highDiscountPackage , userInfoModel , object.getInteger("num")); + + return ResponseMsgUtil.success("增加库存成功"); + + } catch (Exception e) { + log.error("HighDiscountController -> getDiscountById() error!",e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountPackageService.java b/hai-service/src/main/java/com/hai/service/HighDiscountPackageService.java index 7bd74765..4b5c0527 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountPackageService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountPackageService.java @@ -3,8 +3,10 @@ package com.hai.service; import com.hai.entity.HighDiscount; import com.hai.entity.HighDiscountPackage; import com.hai.entity.HighDiscountPackageRecord; +import com.hai.model.UserInfoModel; import io.swagger.models.auth.In; +import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; @@ -77,5 +79,15 @@ public interface HighDiscountPackageService { */ List getDiscountPackageRecordList(Map map); + /** + * @Author Sum1Dream + * @name addDiscountPackageStock.java + * @Description // 新增优惠券包库存 + * @Date 11:32 上午 2021/12/7 + * @Param [com.hai.entity.HighDiscountPackage] + * @return void + */ + void addDiscountPackageStock(HighDiscountPackage highDiscountPackage, UserInfoModel userInfoModel , Integer num); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java index 2d25a914..9692734a 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java @@ -1,16 +1,19 @@ package com.hai.service.impl; -import com.hai.dao.HighDiscountPackageMapper; -import com.hai.dao.HighDiscountPackageRecordMapper; +import com.hai.dao.*; import com.hai.entity.*; -import com.hai.service.HighDiscountPackageService; +import com.hai.model.UserInfoModel; +import com.hai.service.*; import com.hai.service.HighDiscountPackageService; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.List; -import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import java.util.*; /** * @serviceName HighDiscountPackageServiceImpl.java @@ -28,6 +31,24 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic @Resource private HighDiscountPackageRecordMapper highDiscountPackageRecordMapper; + @Resource + private HighDiscountPackageDetailsService highDiscountPackageDetailsService; + + @Resource + private HighDiscountAgentRelService highDiscountAgentRelService; + + @Resource + private HighDiscountAgentCodeService highDiscountAgentCodeService; + + @Resource + private HighDiscountInventoryRecordMapper highDiscountInventoryRecordMapper; + + @Resource + private HighDiscountPackageActualMapper discountPackageActualMapper; + + @Resource + private HighDiscountPackageDiscountActualMapper discountPackageDiscountActualMapper; + @Override public List getDiscountPackageList(Map map) { @@ -116,4 +137,35 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic return highDiscountPackageRecordMapper.selectByExample(example); } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) + public void addDiscountPackageStock(HighDiscountPackage highDiscountPackage, UserInfoModel userInfoModel , Integer num) { + + Map mapRule = new HashMap<>(); + mapRule.put("discountPackageId", highDiscountPackage.getId()); + + // 查询优惠券包规则 + List discountPackageDetailsList = highDiscountPackageDetailsService.getDiscountPackageDetailsList(mapRule); + + // 生成优惠券包实际库存实体 + HighDiscountPackageActual discountPackageActual = new HighDiscountPackageActual(); + discountPackageActual.setDiscountPackageId(highDiscountPackage.getId()); + discountPackageActual.setCreatedUserId(userInfoModel.getSecUser().getId().intValue()); + // 状态: 1: 待分配 2:预分配(售卖)3:已分配 + discountPackageActual.setStatus(1); + + for (int i = 0; i < num; i++) { + discountPackageActual.setCreatedTime(new Date()); + discountPackageActualMapper.insert(discountPackageActual); + } + + // 循环 优惠券包规则详情 列表 + for (HighDiscountPackageDetails detailsList: discountPackageDetailsList) { + // 查询代理商与优惠券关系 列表 + List discountAgentRels = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue() , detailsList.getAgentId()); + + } + + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java index 644dff08..82d0d5f1 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java @@ -34,7 +34,7 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { OutRechargePriceExample example = new OutRechargePriceExample(); OutRechargePriceExample.Criteria criteria = example.createCriteria(); - criteria.andStatusEqualTo(1); + criteria.andStatusNotEqualTo(0); if (StringUtils.isNotBlank(map.get("type"))) { criteria.andTypeEqualTo(Integer.valueOf(map.get("type"))); From 25435d859b1b0d49ea5ad26e0c530ed7c2e9e215 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Tue, 7 Dec 2021 22:32:50 +0800 Subject: [PATCH 2/2] 1 --- .../service/HighDiscountAgentCodeService.java | 11 +++++ .../HighDiscountAgentCodeServiceImpl.java | 8 ++++ .../impl/HighDiscountPackageServiceImpl.java | 43 ++++++++++++++----- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java index 4595b701..d8155383 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java @@ -1,6 +1,7 @@ package com.hai.service; import com.hai.entity.HighDiscountAgentCode; +import io.swagger.models.auth.In; import java.util.List; import java.util.Map; @@ -51,6 +52,16 @@ public interface HighDiscountAgentCodeService { **/ List getDiscountCodeByDiscountAgentId(Long discountAgentId); + /** + * @Author Sum1Dream + * @name getDiscountCodeByDiscountAgentId.java + * @Description // 根据关系id 查询 未领取的卡券 + * @Date 14:20 2021/9/29 + * @Param [discountAgentId] + * @return java.util.List + **/ + List getDiscountCodeByStatus(Long discountAgentId , Integer status); + /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java index 23499ce6..06066ffb 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java @@ -101,6 +101,14 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe return highDiscountAgentCodeMapper.selectByExample(example); } + @Override + public List getDiscountCodeByStatus(Long discountAgentId, Integer status) { + HighDiscountAgentCodeExample example = new HighDiscountAgentCodeExample(); + HighDiscountAgentCodeExample.Criteria criteria = example.createCriteria(); + criteria.andDiscountAgentIdEqualTo(discountAgentId).andStatusEqualTo(status); + example.setOrderByClause("create_time desc"); + return highDiscountAgentCodeMapper.selectByExample(example); + } @Override public HighDiscountAgentCode getCodeById(Long id) { diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java index 9692734a..c89c93d1 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java @@ -88,10 +88,11 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic } @Override - public HighDiscountPackage getCallExclusive(Integer usingAttribution , Integer companyId) { + public HighDiscountPackage getCallExclusive(Integer usingAttribution, Integer companyId) { HighDiscountPackageExample example = new HighDiscountPackageExample(); HighDiscountPackageExample.Criteria criteria = example.createCriteria(); - criteria.andUsingAttributionEqualTo(usingAttribution).andStatusNotEqualTo(4).andCompanyIdEqualTo(companyId);; + criteria.andUsingAttributionEqualTo(usingAttribution).andStatusNotEqualTo(4).andCompanyIdEqualTo(companyId); + ; return highDiscountPackageMapper.selectByExample(example).get(0); } @@ -139,10 +140,10 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic } @Override - @Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) - public void addDiscountPackageStock(HighDiscountPackage highDiscountPackage, UserInfoModel userInfoModel , Integer num) { + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void addDiscountPackageStock(HighDiscountPackage highDiscountPackage, UserInfoModel userInfoModel, Integer num) { - Map mapRule = new HashMap<>(); + Map mapRule = new HashMap<>(); mapRule.put("discountPackageId", highDiscountPackage.getId()); // 查询优惠券包规则 @@ -158,14 +159,34 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic for (int i = 0; i < num; i++) { discountPackageActual.setCreatedTime(new Date()); discountPackageActualMapper.insert(discountPackageActual); - } - - // 循环 优惠券包规则详情 列表 - for (HighDiscountPackageDetails detailsList: discountPackageDetailsList) { - // 查询代理商与优惠券关系 列表 - List discountAgentRels = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue() , detailsList.getAgentId()); + // 循环 优惠券包规则详情 列表 + for (HighDiscountPackageDetails detailsList : discountPackageDetailsList) { + // 查询代理商与优惠券关系 列表 + HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue(), detailsList.getAgentId()); + List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByStatus(discountAgentRel.getId() , 1); + + // 赠送优惠券 + for (HighDiscountAgentCode discountAgentCode : discountAgentCodeList.subList(0, detailsList.getNum())) { + HighDiscountPackageDiscountActual discountPackageDiscountActual = new HighDiscountPackageDiscountActual(); + discountPackageDiscountActual.setDiscountPackageId(highDiscountPackage.getId()); + discountPackageDiscountActual.setDiscountPackageActualId(discountPackageActual.getId()); + discountPackageDiscountActual.setCreatedUserId(userInfoModel.getSecUser().getId().intValue()); + discountPackageDiscountActual.setCreatedTime(new Date()); + discountPackageDiscountActual.setAgentDiscountCodeId(discountAgentCode.getId()); + discountPackageDiscountActual.setStatus(1); + discountPackageDiscountActualMapper.insert(discountPackageDiscountActual); + + // 修改优惠券二维码状态 + discountAgentCode.setStatus(5); + highDiscountAgentCodeService.updateCode(discountAgentCode); + + } + + } } + highDiscountPackage.setTotalStock(num); + highDiscountPackage.setSurplusStock(highDiscountPackage.getSurplusStock() + num); } }