diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java index 5f51b8fa..2f6d2861 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java @@ -73,5 +73,9 @@ public class BaseConstants { public static final String BALANCE_CHANGE_RULE_JC = "jc"; /**卡券积分变更核销规则-金额*/ public static final String BALANCE_CHANGE_RULE_ME = "je"; + /**0否*/ + public static final String GENERAL_NO = "0"; + /**1是*/ + public static final String GENERAL_YES = "1"; } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/ErrorCodeConstants.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/ErrorCodeConstants.java index e5a59380..78ac5a83 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/ErrorCodeConstants.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/ErrorCodeConstants.java @@ -8,4 +8,6 @@ public interface ErrorCodeConstants { ErrorCode BASE_WAREHOUSE_EXITS_CHILDREN = new ErrorCode(500, "存在子配置类型,无法删除"); ErrorCode BASE_TYPE_NAME_DUPLICATE = new ErrorCode(500, "同父级下配置类型名称或编码重复"); ErrorCode BASE_WAREHOUSE_NAME_DUPLICATE = new ErrorCode(500, "同父级下仓库区域名称或编码重复"); + ErrorCode CUSTOMER_ACTIVE_ONE_COUPON = new ErrorCode(500, "请至少选择一个礼包卡"); + ErrorCode CUSTOMER_ACTIVE_NO_RULE = new ErrorCode(500, "当前活动未设置充值规则,请联系管理员设置"); } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java index beaaeb1a..8af387df 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java @@ -29,21 +29,22 @@ public class CustomerActiveController { @Resource private CustomerActiveService customerActiveService; - @PostMapping("/create") - @Operation(summary = "创建用户参与活动记录") - @PreAuthorize("@ss.hasPermission('base:customer-active:create')") - public CommonResult createCustomerActive(@Valid @RequestBody CustomerActiveSaveReqVO createReqVO) { - return success(customerActiveService.createCustomerActive(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新用户参与活动记录") - @PreAuthorize("@ss.hasPermission('base:customer-active:update')") - public CommonResult updateCustomerActive(@Valid @RequestBody CustomerActiveSaveReqVO updateReqVO) { - customerActiveService.updateCustomerActive(updateReqVO); + /** + * 参加活动 + * + * @param createReqVO CustomerActiveSaveReqVO + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + * @author PQZ + * @date 9:49 2024/9/21 + **/ + @PostMapping("/attendActive") + @Operation(summary = "参加活动") + public CommonResult attendActive(@RequestBody CustomerActiveSaveReqVO createReqVO) { + customerActiveService.attendActive(createReqVO); return success(true); } + @DeleteMapping("/delete") @Operation(summary = "删除用户参与活动记录") @Parameter(name = "id", description = "编号", required = true) diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerCouponController.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerCouponController.java index a657960b..b4f926dc 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerCouponController.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerCouponController.java @@ -47,7 +47,7 @@ public class CustomerCouponController { /** * 删除用户卡券 * @author PQZ - * @date 22:57 2024/9/20 + * @date 23:01 2024/9/20 * @param id TODO * @return cn.iocoder.yudao.framework.common.pojo.CommonResult **/ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerActive.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerActive.java index c9a89387..7930e952 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerActive.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerActive.java @@ -32,7 +32,7 @@ public class CustomerActive extends TenantBaseDO { /** * 用户id */ - private Integer userId; + private Long userId; /** * 参加活动id */ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalance.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalance.java index c570931b..8de52ca0 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalance.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalance.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.custom.entity; import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; @@ -34,7 +35,7 @@ public class CustomerBalance extends TenantBaseDO { /** * 用户id */ - private Integer userId; + private Long userId; /** * 积分余额 */ @@ -47,5 +48,7 @@ public class CustomerBalance extends TenantBaseDO { * 累计充值额度 */ private BigDecimal allBalance; + @TableField(exist = false) + private BigDecimal nowChange; } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalanceChange.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalanceChange.java index 66ffac95..b4fb0682 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalanceChange.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerBalanceChange.java @@ -34,7 +34,7 @@ public class CustomerBalanceChange extends TenantBaseDO { /** * 用户id */ - private Integer userId; + private Long userId; /** * 关联卡券id */ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerCoupon.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerCoupon.java index 7ed56530..efbaed14 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerCoupon.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerCoupon.java @@ -39,7 +39,7 @@ public class CustomerCoupon extends TenantBaseDO { /** * 用户id */ - private Integer userId; + private Long userId; /** * 卡券id */ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java index ad66c11f..c9b42334 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java @@ -15,20 +15,17 @@ import javax.validation.Valid; */ public interface CustomerActiveService extends IService { - /** - * 创建用户参与活动记录 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - String createCustomerActive(@Valid CustomerActiveSaveReqVO createReqVO); /** - * 更新用户参与活动记录 + * 参与活动 * - * @param updateReqVO 更新信息 - */ - void updateCustomerActive(@Valid CustomerActiveSaveReqVO updateReqVO); + * @param saveReqVO CustomerActiveSaveReqVO实体 + * @author PQZ + * @date 9:57 2024/9/21 + **/ + void attendActive(CustomerActiveSaveReqVO saveReqVO); + + /** * 删除用户参与活动记录 diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerBalanceChangeService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerBalanceChangeService.java index 120636f8..ce326e7d 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerBalanceChangeService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerBalanceChangeService.java @@ -30,8 +30,24 @@ public interface CustomerBalanceChangeService extends IService { */ void updateCustomerBalance(@Valid CustomerBalanceSaveReqVO updateReqVO); + /** + * 根据用户id更新用户余额表 + * @author PQZ + * @date 11:56 2024/9/21 + * @param balance CustomerBalance + * @return void + **/ + void updateByCusId(CustomerBalance balance); + } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCouponService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCouponService.java index 8836048f..09538bd1 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCouponService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCouponService.java @@ -48,6 +48,7 @@ public interface CustomerCouponService extends IService { **/ CustomerCouponRespVO getCustomerCoupon(String id); + /** * 获得用户卡券分页 * diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java index 07153220..c2089f77 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java @@ -2,16 +2,35 @@ package cn.iocoder.yudao.module.custom.service.impl; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.custom.entity.CustomerActive; +import cn.iocoder.yudao.module.custom.entity.*; import cn.iocoder.yudao.module.custom.mapper.CustomerActiveMapper; -import cn.iocoder.yudao.module.custom.service.CustomerActiveService; +import cn.iocoder.yudao.module.custom.service.*; import cn.iocoder.yudao.module.custom.vo.CustomerActivePageReqVO; import cn.iocoder.yudao.module.custom.vo.CustomerActiveSaveReqVO; +import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO; +import cn.iocoder.yudao.module.member.entity.ActiveMain; +import cn.iocoder.yudao.module.member.entity.ActiveRule; +import cn.iocoder.yudao.module.member.entity.MemberCoupon; +import cn.iocoder.yudao.module.member.service.ActiveMainService; +import cn.iocoder.yudao.module.member.service.MemberCouponService; +import cn.iocoder.yudao.module.member.vo.ActiveMainRespVO; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mzt.logapi.service.IFunctionService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import static cn.iocoder.yudao.common.BaseConstants.*; +import static cn.iocoder.yudao.common.ErrorCodeConstants.CUSTOMER_ACTIVE_NO_RULE; +import static cn.iocoder.yudao.common.ErrorCodeConstants.CUSTOMER_ACTIVE_ONE_COUPON; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 用户参与活动记录 Service 实现类 @@ -24,23 +43,185 @@ public class CustomerActiveServiceImpl extends ServiceImpl changeList = new ArrayList<>(); + //需要保存的参与活动日志 + CustomerActive customerActive = new CustomerActive(); + //需保保存的用户卡券领取内容 + List customerCouponList; + //需保保存的用户积分余额信息 + CustomerBalance balance; + + /*2、活动关联卡券处理*/ + if (GENERAL_YES.equals(active.getIsCoupon())) { + if (GENERAL_YES.equals(active.getIsPack())) { + /*2.1 打包领取情况*/ + List couponList = active.getCouponList(); + //抓换卡券信息 + customerCouponList = transCoupon(active.getId(), customer.getId(), customer.getUserId(), couponList); + //转换日志信息 + changeList = transChange(customer.getId(), customer.getUserId(), active.getName(), couponList); + } else { + /*2.2 非打包领取情况*/ + //选中卡券校验 + if (null == saveReqVO.getSelectCoupon() || saveReqVO.getSelectCoupon().isEmpty()) { + throw exception(CUSTOMER_ACTIVE_ONE_COUPON); + } + //查询出当前选中的卡券及附属卡券 + List ids = saveReqVO.getSelectCoupon().stream().map(MemberCoupon::getId).collect(Collectors.toList()); + List couponList = couponService.listByIds(ids, true); + //转换卡券信息 + customerCouponList = transCoupon(active.getId(), customer.getId(), customer.getUserId(), couponList); + //转换日志信息 + changeList = transChange(customer.getId(), customer.getUserId(), active.getName(), couponList); + } + //保存用户卡券 + customerCouponService.saveBatch(customerCouponList); + } + + /*3、活动关联充值规则处理*/ + if (GENERAL_YES.equals(active.getIsRechRule())) { + //校验是否存在充值规则 + if (null == active.getRuleList() || active.getRuleList().isEmpty()) { + throw exception(CUSTOMER_ACTIVE_NO_RULE); + } + List ruleList = active.getRuleList(); + //转换余额信息 + balance = transBalance(customer,saveReqVO.getTopUpAmount(),ruleList); + //记录日志 + CustomerBalanceChange change = changeService.initChange(customer.getId(), + customer.getUserId(), null, BALANCE_CHANGE_TYPE_CZ, BALANCE_CHANGE_MAIN_YE, + null, balance.getNowChange(), balance.getBalance(), "参加" + active.getName() + "活动"); + changeList.add(change); + //保存余额信息 + balanceService.updateByCusId(balance); + } + + /*4、保存参与活动信息*/ + customerActive.setActiveId(active.getId()); + customerActive.setUserId(customer.getUserId()); + customerActive.setCusId(customer.getId()); + customerActive.setActiveName(active.getName()); + customerActive.setActiveType(active.getType()); + customerActive.setRemark(active.getRemark()); + save(customerActive); + + /*5、保存变动日志*/ + //保存变动日志 + changeService.saveBatch(changeList); + } - @Override - public void updateCustomerActive(CustomerActiveSaveReqVO updateReqVO) { - // 更新 - CustomerActive updateObj = BeanUtils.toBean(updateReqVO, CustomerActive.class); - customerActiveMapper.updateById(updateObj); + /** + * 卡券实体转换 + * + * @param couponList MemberCoupon集合 + * @return java.util.List + * @author PQZ + * @date 11:01 2024/9/21 + **/ + List transCoupon(String activeId, String cusId, Long userId, List couponList) { + List transList = new ArrayList<>(); + couponList.forEach(item -> { + CustomerCoupon coupon = new CustomerCoupon(); + coupon.setCusId(cusId); + coupon.setUserId(userId); + coupon.setActiveId(activeId); + coupon.setCouponId(item.getId()); + coupon.setAmount(item.getAmount()); + coupon.setBalance(item.getAmount()); + coupon.setUnitPrice(item.getUnitPrice()); + coupon.setOutRule(item.getOutRule()); + coupon.setIsValid(GENERAL_YES); + transList.add(coupon); + }); + return transList; } + + /** + * 卡券转换记录 + * + * @param cusId 客户id + * @param userId 用户id + * @param activeName 活动名称 + * @param couponList 卡券集合 + * @return java.util.List + * @author PQZ + * @date 11:20 2024/9/21 + **/ + List transChange(String cusId, Long userId, String activeName, List couponList) { + List transList = new ArrayList<>(); + couponList.forEach(item -> { + CustomerBalanceChange change = changeService.initChange(cusId, + userId, item.getId(), BALANCE_CHANGE_TYPE_ZS, BALANCE_CHANGE_MAIN_KQ, + item.getOutRule(), item.getAmount(), item.getAmount(), "参加" + activeName + "活动领取"); + transList.add(change); + }); + return transList; + } + + + /** + * 转换余额 + * + * @param customer 用户信息 + * @param amount 实际充值金额 + * @param ruleList 规则 + * @return cn.iocoder.yudao.module.custom.entity.CustomerBalance + * @author PQZ + * @date 11:30 2024/9/21 + **/ + CustomerBalance transBalance(CustomerMainRespVO customer, BigDecimal amount, List ruleList) { + CustomerBalance result = new CustomerBalance(); + result.setCusId(customer.getId()); + result.setUserId(customer.getUserId()); + List sortList = ruleList.stream().sorted(Comparator.comparing(ActiveRule::getRechAmount).reversed()).collect(Collectors.toList()); + for (ActiveRule item : sortList) { + if (amount.compareTo(item.getRechAmount()) >= 0) { + BigDecimal nowChange = amount.add(item.getGiveAmount()); + //余额 + result.setBalance(customer.getBalance().add(nowChange)); + //累计充值金额 + result.setAllBalance(customer.getBalance().add(nowChange)); + result.setNowChange(nowChange); + break; + } + } + return result; + } + + @Override public void deleteCustomerActive(String id) { // 删除 @@ -48,7 +229,6 @@ public class CustomerActiveServiceImpl extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(CustomerBalance::getCusId,balance.getCusId()).eq(BaseDO::getDeleted,'0'); + remove(lambdaQueryWrapper); + this.save(balance); + } } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerActiveSaveReqVO.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerActiveSaveReqVO.java index e7f40a5f..9df90275 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerActiveSaveReqVO.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerActiveSaveReqVO.java @@ -1,15 +1,19 @@ package cn.iocoder.yudao.module.custom.vo; import cn.iocoder.yudao.module.custom.entity.CustomerActive; +import cn.iocoder.yudao.module.member.entity.MemberCoupon; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; + +import java.math.BigDecimal; import java.util.*; import javax.validation.constraints.*; @Schema(description = "管理后台 - 用户参与活动记录新增/修改 Request VO") @Data public class CustomerActiveSaveReqVO extends CustomerActive { - - - + /**充值金额*/ + private BigDecimal topUpAmount; + /**选中的优惠券*/ + private List selectCoupon; } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/controller/admin/ActiveMainController.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/controller/admin/ActiveMainController.java index 9bc77244..238935b5 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/controller/admin/ActiveMainController.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/controller/admin/ActiveMainController.java @@ -92,7 +92,7 @@ public class ActiveMainController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('member:active-main:query')") public CommonResult getActiveMain(@RequestParam("id") String id) { - ActiveMain activeMain = activeMainService.getActiveMain(id); + ActiveMain activeMain = activeMainService.getActiveMain(id,false); return success(BeanUtils.toBean(activeMain, ActiveMainRespVO.class)); } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/entity/ActiveRule.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/entity/ActiveRule.java index 98a8f0d8..95bffbad 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/entity/ActiveRule.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/entity/ActiveRule.java @@ -47,6 +47,6 @@ public class ActiveRule extends TenantBaseDO { /** * 赠送金额 */ - private String giveAmount; + private BigDecimal giveAmount; } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveMainService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveMainService.java index ea7470cd..b8abf007 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveMainService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveMainService.java @@ -35,12 +35,14 @@ public interface ActiveMainService extends IService { /** * 根据营销活动获取详情 + * + * @param id 营销活动id + * @param isChild 是否查询出关联的附属卡券信息 + * @return cn.iocoder.yudao.module.member.vo.ActiveMainRespVO * @author PQZ * @date 18:23 2024/9/19 - * @param id 营销活动id - * @return cn.iocoder.yudao.module.member.vo.ActiveMainRespVO - **/ - ActiveMainRespVO getActiveMain(String id); + **/ + ActiveMainRespVO getActiveMain(String id, boolean isChild); /** * 分页查询营销活动 diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveRuleCouponService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveRuleCouponService.java index 9a01f00a..ec72c6cf 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveRuleCouponService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/ActiveRuleCouponService.java @@ -36,11 +36,12 @@ public interface ActiveRuleCouponService extends IService { /** * 根据主表id查询关联关系 * - * @param id 主表id + * @param id 主表id + * @param isChild 是否查询出关联的附属卡券信息 * @return java.util.List * @author PQZ * @date 17:59 2024/9/19 **/ - List queryByMainId(String id); + List queryByMainId(String id, boolean isChild); } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/MemberCouponService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/MemberCouponService.java index d5ffb06c..76d9c333 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/MemberCouponService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/MemberCouponService.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import javax.validation.Valid; +import java.util.List; /** * 基础卡券 Service 接口 @@ -27,6 +28,17 @@ public interface MemberCouponService extends IService { **/ void saveCoupon(@Valid MemberCouponSaveReqVO saveReqVO); + /** + * 通过id集合查询卡券信息 + * + * @param ids id集合 + * @param isChild 是否查询出关联的卡券信息 + * @return java.util.List + * @author PQZ + * @date 10:47 2024/9/21 + **/ + List listByIds(List ids, boolean isChild); + /** * 删除基础卡券 * @@ -36,11 +48,12 @@ public interface MemberCouponService extends IService { /** * 查询基础卡券及附属信息 - * @author PQZ - * @date 21:55 2024/9/19 + * * @param id 卡券id * @return cn.iocoder.yudao.module.member.vo.MemberCouponRespVO - **/ + * @author PQZ + * @date 21:55 2024/9/19 + **/ MemberCouponRespVO getCoupon(String id); /** @@ -56,10 +69,11 @@ public interface MemberCouponService extends IService { /** * 复制卡券附属权益 + * + * @param saveReqVO MemberCouponSaveReqVO * @author PQZ * @date 21:25 2024/9/19 - * @param saveReqVO MemberCouponSaveReqVO - **/ + **/ void copyMemberCoupon(MemberCouponSaveReqVO saveReqVO); } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveMainServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveMainServiceImpl.java index ab433ceb..d12b3998 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveMainServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveMainServiceImpl.java @@ -82,13 +82,13 @@ public class ActiveMainServiceImpl extends ServiceImpl ruleList = ruleService.listByActiveId(id); - //删除关联卡券 - List couponList = activeRuleCouponService.queryByMainId(id); + //查询关联卡券 + List couponList = activeRuleCouponService.queryByMainId(id,isChild); result.setRuleList(ruleList); result.setCouponList(couponList); return result; diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveRuleCouponServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveRuleCouponServiceImpl.java index 2a8fb836..90c216e8 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveRuleCouponServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/ActiveRuleCouponServiceImpl.java @@ -38,7 +38,7 @@ public class ActiveRuleCouponServiceImpl extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(ActiveRuleCoupon::getMainId,id); + lambdaQueryWrapper.eq(ActiveRuleCoupon::getMainId, id); remove(lambdaQueryWrapper); } @@ -70,24 +70,23 @@ public class ActiveRuleCouponServiceImpl extends ServiceImpl * @author PQZ * @date 17:59 2024/9/19 **/ @Override - public List queryByMainId(String id) { + public List queryByMainId(String id, boolean isChild) { //查询关联关系 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(ActiveRuleCoupon::getMainId,id).eq(ActiveRuleCoupon::getDeleted,"0"); + lambdaQueryWrapper.eq(ActiveRuleCoupon::getMainId, id).eq(ActiveRuleCoupon::getDeleted, "0"); List list = list(lambdaQueryWrapper); List idList = list.stream().map(ActiveRuleCoupon::getCouponId).collect(Collectors.toList()); //查询关联卡券信息 List result = new ArrayList<>(); - if (!idList.isEmpty()){ - LambdaQueryWrapper couponLambdaQueryWrapper = new LambdaQueryWrapper<>(); - couponLambdaQueryWrapper.in(MemberCoupon::getId,idList).eq(MemberCoupon::getDeleted,"0"); - result = couponService.list(couponLambdaQueryWrapper); + if (!idList.isEmpty()) { + result = couponService.listByIds(idList,isChild); } return result; } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/MemberCouponServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/MemberCouponServiceImpl.java index e1b6dc6c..2517df03 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/MemberCouponServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/member/service/impl/MemberCouponServiceImpl.java @@ -21,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * 基础卡券 Service 实现类 @@ -49,6 +50,35 @@ public class MemberCouponServiceImpl extends ServiceImpl + * @author PQZ + * @date 10:47 2024/9/21 + **/ + @Override + public List listByIds(List ids, boolean isChild) { + List couponList = new ArrayList<>(); + if (!ids.isEmpty()) { + LambdaQueryWrapper couponLambdaQueryWrapper = new LambdaQueryWrapper<>(); + couponLambdaQueryWrapper.in(MemberCoupon::getId, ids).eq(MemberCoupon::getDeleted, "0"); + couponList = list(couponLambdaQueryWrapper); + } + List result = new ArrayList<>(couponList); + if (isChild){ + //查询附属卡片 + List parentIds = couponList.stream().map(MemberCoupon::getId).collect(Collectors.toList()); + LambdaQueryWrapper couponLambdaQueryWrapper = new LambdaQueryWrapper<>(); + couponLambdaQueryWrapper.in(MemberCoupon::getParentId, parentIds).eq(MemberCoupon::getDeleted, "0"); + List childList = list(couponLambdaQueryWrapper); + result.addAll(childList); + } + return result; + } + @Override public void deleteCoupon(String id) { // 删除 diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java index 7d0ccdba..1e29b112 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java @@ -187,4 +187,7 @@ public class RescueInfo extends TenantBaseDO @TableField(exist = false) private List roadIds; + + @TableField(exist = false) + private List deptList; } diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/mapper/RescueInfoMapper.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/mapper/RescueInfoMapper.java index 552b048c..659fdea3 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/mapper/RescueInfoMapper.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/mapper/RescueInfoMapper.java @@ -55,7 +55,7 @@ public interface RescueInfoMapper extends BaseMapper void dealOverTimeRescue(); List getOverTimeRescue(); Map getRescueStatistics(RescueInfo rescueInfo); - Map getRescueStatisticsByAdmin(RescueInfo rescueInfo); + Map getRescueStatisticsByAdmin(@Param("map") RescueInfo rescueInfo); void deleteOtherInfo1(@Param("rescueId") Long rescueId); void deleteOtherInfo2(@Param("rescueId") Long rescueId); diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java index 4c033d43..1505f7fc 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.rescue.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; @@ -234,8 +235,15 @@ public class RescueInfoServiceImpl extends ServiceImpl selectRescueInfoListByAdmin(RescueInfo rescueInfo, Page page) { LoginUser user = getLoginUser(); + AdminUserRespDTO adminUser = userService.getUser(user.getId()); + List childDeptList = deptService.getChildDeptList(adminUser.getDeptId()); + List deptList = childDeptList.stream().map(DeptRespDTO::getId).collect(Collectors.toList()); + deptList.add(adminUser.getDeptId()); + rescueInfo.setDeptList(deptList); + IPage rescueInfos = baseMapper.selectRescueInfoList(rescueInfo, page); + for (RescueInfo info : rescueInfos.getRecords()) { String dljy_type = dictDataService.getDictDataLabel("dljy_type", info.getRescueType()); info.setRescueTypeStr(dljy_type); @@ -821,6 +829,12 @@ public class RescueInfoServiceImpl extends ServiceImpl getRescueStatisticsByAdmin(RescueInfo rescueInfo) { + LoginUser user = getLoginUser(); + AdminUserRespDTO adminUser = userService.getUser(user.getId()); + List childDeptList = deptService.getChildDeptList(adminUser.getDeptId()); + List deptList = childDeptList.stream().map(DeptRespDTO::getId).collect(Collectors.toList()); + deptList.add(adminUser.getDeptId()); + rescueInfo.setDeptList(deptList); Map res = baseMapper.getRescueStatisticsByAdmin(rescueInfo); return res; diff --git a/dl-module-rescue/src/main/resources/mapper/rescue/RescueInfoMapper.xml b/dl-module-rescue/src/main/resources/mapper/rescue/RescueInfoMapper.xml index 1a0642d8..c6e2d7be 100644 --- a/dl-module-rescue/src/main/resources/mapper/rescue/RescueInfoMapper.xml +++ b/dl-module-rescue/src/main/resources/mapper/rescue/RescueInfoMapper.xml @@ -48,6 +48,11 @@ and ri.license_num like concat('%', #{map.licenseNum}, '%') + + and ri.dept_id in + #{item} + + order by ri.create_time desc @@ -341,6 +346,11 @@ FROM rescue_info ri left join rescue_order_info roi on roi.rescue_info_id = ri.id where 1 = 1 + + and ri.dept_id in + #{item} + + DELETE