Jelajahi Sumber

feat:优惠券、im推送

caoliqin 2 hari lalu
induk
melakukan
fa47e67844

+ 7 - 2
fs-service/src/main/java/com/fs/gtPush/service/impl/uniPush2ServiceImpl.java

@@ -18,6 +18,7 @@ import com.fs.gtPush.domain.PushResult;
 import com.fs.gtPush.domain.UniPushLog;
 import com.fs.gtPush.service.UniPushLogService;
 import com.fs.gtPush.service.uniPush2Service;
+import com.fs.his.enums.PushLogTypeEnum;
 import com.fs.his.mapper.FsUserMapper;
 import com.fs.im.config.IMConfig;
 import com.fs.im.dto.OpenImResponseDTO;
@@ -35,6 +36,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 @Service
 @Slf4j
@@ -71,6 +73,9 @@ public class uniPush2ServiceImpl implements uniPush2Service {
             throw new RuntimeException("his.config 中未配置 appPushUrl");
         }
         String result = HttpUtil.post(url, JSON.toJSONString(push));
+        log.info("推送地址{}",url);
+        log.info("推送请求体{}",JSON.toJSONString(push));
+        log.info("推送返回结果{}",result);
         return JSONUtil.toBean(result, PushResult.class);
     }
     @Override
@@ -314,14 +319,14 @@ public class uniPush2ServiceImpl implements uniPush2Service {
                                    Float type, Integer desType, String imJsonString) {
         if (userId == null) return null;
         String jpushId = "";
-        FsUser fsUser = userService.selectFsUserByUserId(userId);
-        if (fsUser == null){
+        if (Objects.equals(type, PushLogTypeEnum.UTOC.getValue())){
             CompanyUser companyUser = companyUserMapper.selectCompanyUserById(userId);
             if (companyUser == null){
                 return null;
             }
             jpushId = companyUser.getJpushId();
         } else {
+            FsUser fsUser = userService.selectFsUserByUserId(userId);
             jpushId = fsUser.getJpushId();
         }
 

+ 7 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsCouponServiceImpl.java

@@ -156,6 +156,13 @@ public class FsCouponServiceImpl implements IFsCouponService
         userCoupon.setCreateTime(new Date());
         userCoupon.setCompanyUserId(param.getCompanyUserId());
         userCoupon.setCompanyId(param.getCompanyId());
+        if (coupon.getLimitType() == 2){
+            long limitDay = coupon.getLimitDay().longValue() * 24 * 60 * 60 * 1000;
+            long time = new Date().getTime();
+            userCoupon.setLimitTime(new Date(limitDay+time));
+        }else {
+            userCoupon.setLimitTime(coupon.getLimitTime());
+        }
         if(fsUserCouponMapper.insertFsUserCoupon(userCoupon)>0){
             //更新剩余数量
             fsCouponMapper.updateRemainCount(coupon.getCouponId());

+ 15 - 2
fs-service/src/main/java/com/fs/his/service/impl/FsUserCouponServiceImpl.java

@@ -143,10 +143,13 @@ public class FsUserCouponServiceImpl implements IFsUserCouponService
             throw new CustomException("用户不能为空");
         }
         FsCoupon coupon = fsCouponMapper.selectFsCouponByCouponId(param.getCouponId());
-        if (coupon.getRemainNumber()<1){
+        if (coupon == null) {
+            throw new CustomException("优惠券不存在");
+        }
+        if (coupon.getRemainNumber() == null || coupon.getRemainNumber() < 1){
             throw new CustomException("优惠劵剩余数量不足");
         }
-        if (coupon.getCouponType()==2){
+        if (Integer.valueOf(2).equals(coupon.getCouponType())){
             Integer integer = fsUserCouponMapper.selectFsUserCouponByUserIdCount(param.getUserId(), coupon.getCouponType());
             if (integer>0){
                 throw new CustomException("已经发送过同类型的优惠劵");
@@ -174,6 +177,16 @@ public class FsUserCouponServiceImpl implements IFsUserCouponService
             fsUserCoupon.setCompanyId(param.getCompanyId());
             System.out.println("销售发送人id:"+ fsUserCoupon.getCompanyUserId());
         }
+        if (Integer.valueOf(2).equals(coupon.getLimitType())){
+            if (coupon.getLimitDay() == null) {
+                throw new CustomException("优惠券领取后有效期天数未配置");
+            }
+            long limitDay = coupon.getLimitDay().longValue() * 24 * 60 * 60 * 1000;
+            long time = new Date().getTime();
+            fsUserCoupon.setLimitTime(new Date(limitDay+time));
+        }else {
+            fsUserCoupon.setLimitTime(coupon.getLimitTime());
+        }
         fsUserCoupon.setStatus(0);
         int i = fsUserCouponMapper.insertFsUserCoupon(fsUserCoupon);
         coupon.setRemainNumber(coupon.getRemainNumber()-1);