From 9c9bc2542cbfac6a9380763745fa0f63460fc2fc Mon Sep 17 00:00:00 2001 From: zhangheng <3226558941@qq.com> Date: Wed, 8 Nov 2023 16:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E4=BA=BA=E7=A6=8F=E5=88=A9=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E9=A2=86=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ResidentPatientInfoServiceImpl.java | 86 ++++++++++++++++--- .../PatientCouponReceiveMapper.java | 8 ++ .../PatientCouponReceiveMapper.xml | 8 ++ 3 files changed, 90 insertions(+), 12 deletions(-) diff --git a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java index 70b2eba..2a00329 100644 --- a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java +++ b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java @@ -4,36 +4,39 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.xinelu.common.config.AppletChatConfig; import com.xinelu.common.entity.AppletPhoneVO; +import com.xinelu.common.enums.CouponReceiveTypeEnum; +import com.xinelu.common.enums.CouponUseStatusEnum; import com.xinelu.common.exception.ServiceException; import com.xinelu.common.utils.bean.BeanUtils; import com.xinelu.common.utils.http.HttpService; import com.xinelu.common.utils.http.HttpUtils; import com.xinelu.common.utils.http.SslUtils; -import com.xinelu.common.utils.spring.SpringUtils; import com.xinelu.common.utils.uuid.IdUtils; import com.xinelu.familydoctor.applet.mapper.ResidentPatientInfoMapper; import com.xinelu.familydoctor.applet.pojo.body.PatientInfoBody; import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo; -import com.xinelu.familydoctor.applet.pojo.query.PatientInfoQuery; -import com.xinelu.familydoctor.applet.pojo.vo.SignInfoDetailVo; import com.xinelu.familydoctor.applet.service.IResidentPatientInfoService; import com.xinelu.familydoctor.applet.utils.AppletAccessTokenUtils; +import com.xinelu.manage.domain.coupon.Coupon; +import com.xinelu.manage.domain.patientcouponreceive.PatientCouponReceive; import com.xinelu.manage.domain.receiveAddressInfo.ReceiveAddressInfo; +import com.xinelu.manage.mapper.coupon.CouponMapper; +import com.xinelu.manage.mapper.patientcouponreceive.PatientCouponReceiveMapper; import com.xinelu.manage.mapper.receiveAddressInfo.ReceiveAddressInfoMapper; +import com.xinelu.manage.vo.patientcouponreceive.PatientCouponReceiveInfoVO; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -58,6 +61,10 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi private RedisTemplate redisTemplate; @Resource private ReceiveAddressInfoMapper receiveAddressInfoMapper; + @Resource + private PatientCouponReceiveMapper patientCouponReceiveMapper; + @Resource + private CouponMapper couponMapper; /** * @return com.xinelu.familydoctor.applet.pojo.entity.PatientInfo @@ -192,7 +199,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi } else { patientInfo.setDisease("0"); } - patientInfo.setLoginFlag(Long.valueOf(1)); + patientInfo.setLoginFlag(1L); patientInfo.setBindOpenid(body.getOpenid()); updatePatientInfo(patientInfo); @@ -216,7 +223,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi patientInfo.setUpdateBy(body.getCardNo()); patientInfo.setHeadPictureUrl(body.getHeadPictureUrl()); patientInfo.setDelFlag(0); - patientInfo.setLoginFlag(Long.valueOf(1)); + patientInfo.setLoginFlag(1L); if (body.getDiseaseList() != null) { patientInfo.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(","))); } else { @@ -245,7 +252,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi entity.setIsChecked("0"); entity.setCreateTime(new Date()); entity.setCreateBy(body.getCardNo()); - entity.setLoginFlag(Long.valueOf(1)); + entity.setLoginFlag(1L); entity.setDelFlag(0); entity.setBindOpenid(body.getOpenid()); residentPatientInfoMapper.insertPatientInfo(entity); @@ -264,6 +271,15 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi } this.insertReceiveAddress(patientInfo); } + PatientInfo patient = residentPatientInfoMapper.getLoginByOpenId(body.getOpenid()); + //判断是否是第一次完善,如果是则发放新人优惠券信息 + PatientCouponReceive patientCouponReceive = new PatientCouponReceive(); + patientCouponReceive.setReceiveSource(CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo()); + patientCouponReceive.setPatientId(patient.getId()); + int couponReceiveCount = patientCouponReceiveMapper.getCouponReceiveByReceiveSource(patient.getId(), CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo()); + if (Objects.nonNull(patient.getLoginFlag()) && patient.getLoginFlag() ==1 && couponReceiveCount <= 0) { + issueCoupons(patient); + } } /** 新增收货人地址信息 */ @@ -450,4 +466,50 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi HashMap.put("cityCode", cityCode); return HashMap; } + + /** + * 发放优惠券方法胡 + * + * @param patient 会员信息 + */ + public void issueCoupons(PatientInfo patient ) { + PatientCouponReceiveInfoVO receiveInfoVO = new PatientCouponReceiveInfoVO(); + //查询新人福利的优惠券列表信息 + Coupon coupon = new Coupon(); + Long patientId = patient.getId(); + coupon.setReceiveType(CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo()); + List couponList = couponMapper.selectCouponList(coupon); + if (CollectionUtils.isEmpty(couponList)) { + return ; + } + //组装优惠券信息 + List couponReceiveList = Lists.newArrayList(); + for (Coupon couponInfo : couponList) { + if (Objects.isNull(couponInfo.getId())) { + continue; + } + PatientCouponReceive couponReceive = new PatientCouponReceive(); + couponReceive.setPatientId(patientId); + couponReceive.setCouponId(couponInfo.getId()); + couponReceive.setReceiveSource(CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo()); + couponReceive.setUseStatus(CouponUseStatusEnum.NOT_USED.getInfo()); + couponReceive.setExpirationStartTime(LocalDateTime.now()); + couponReceive.setExpirationEndTime(LocalDate.now().plusDays(Objects.isNull(couponInfo.getCouponReductionDays()) ? 0 : couponInfo.getCouponReductionDays()).atTime(23, 59, 59)); + couponReceive.setReceiveTime(LocalDateTime.now()); + couponReceive.setCouponReductionDays(Objects.isNull(couponInfo.getCouponReductionDays()) ? 0 : couponInfo.getCouponReductionDays()); + couponReceive.setCreateTime(LocalDateTime.now()); + couponReceive.setCouponTitle(StringUtils.isBlank(couponInfo.getCouponTitle()) ? "" : couponInfo.getCouponTitle()); + couponReceive.setCouponPrice(Objects.isNull(couponInfo.getCouponPrice()) ? BigDecimal.ZERO : couponInfo.getCouponPrice()); + couponReceive.setCouponConsumePrice(Objects.isNull(couponInfo.getCouponConsumePrice()) ? BigDecimal.ZERO : couponInfo.getCouponConsumePrice()); + couponReceive.setCouponDescription(StringUtils.isBlank(couponInfo.getCouponDescription()) ? "" : couponInfo.getCouponDescription()); + couponReceiveList.add(couponReceive); + } + if (CollectionUtils.isNotEmpty(couponReceiveList)) { + int insertCount = patientCouponReceiveMapper.insertBatchPatientReceive(couponReceiveList); + if (insertCount <= 0) { + log.error("完善用户信息接口-新人送券执行失败,输入参数[{}]", couponReceiveList); + throw new ServiceException("完善用户信息失败,请联系管理员!"); + } + } + } } diff --git a/xinelu-nurse-manage/src/main/java/com/xinelu/manage/mapper/patientcouponreceive/PatientCouponReceiveMapper.java b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/mapper/patientcouponreceive/PatientCouponReceiveMapper.java index c013787..dd337e3 100644 --- a/xinelu-nurse-manage/src/main/java/com/xinelu/manage/mapper/patientcouponreceive/PatientCouponReceiveMapper.java +++ b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/mapper/patientcouponreceive/PatientCouponReceiveMapper.java @@ -127,4 +127,12 @@ public interface PatientCouponReceiveMapper { * @return 会员用户优惠券领取记录 */ PatientCouponReceiveInfoVO selectPatientCouponReceive(@Param("patientId") Long patientId, @Param("couponId") Long couponId); + + /** + * + * @param patientId 用户id + * @param receiveSource 优惠券状态 + * @return int + */ + int getCouponReceiveByReceiveSource(@Param("patientId") Long patientId, @Param("receiveSource") String receiveSource); } diff --git a/xinelu-nurse-manage/src/main/resources/mapper/manage/patientcouponreceive/PatientCouponReceiveMapper.xml b/xinelu-nurse-manage/src/main/resources/mapper/manage/patientcouponreceive/PatientCouponReceiveMapper.xml index 96b3072..391945f 100644 --- a/xinelu-nurse-manage/src/main/resources/mapper/manage/patientcouponreceive/PatientCouponReceiveMapper.xml +++ b/xinelu-nurse-manage/src/main/resources/mapper/manage/patientcouponreceive/PatientCouponReceiveMapper.xml @@ -363,4 +363,12 @@ where pcr.patient_id = #{patientId} and pcr.coupon_id = #{couponId} + +