|
@@ -0,0 +1,246 @@
|
|
|
+package com.gree.mall.miniapp.logic.policy;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.gree.mall.miniapp.bean.PayDetail;
|
|
|
+import com.gree.mall.miniapp.bean.policy.PolicyDetail;
|
|
|
+import com.gree.mall.miniapp.bean.policy.PolicyOrderDetail;
|
|
|
+import com.gree.mall.miniapp.bean.policy.WorkerRemind;
|
|
|
+import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
|
|
|
+import com.gree.mall.miniapp.enums.ExamineWorkerStatusEnum;
|
|
|
+import com.gree.mall.miniapp.enums.IsEnum;
|
|
|
+import com.gree.mall.miniapp.enums.IsYesNoEnum;
|
|
|
+import com.gree.mall.miniapp.logic.common.CommonLogic;
|
|
|
+import com.gree.mall.miniapp.logic.common.outside.WechatLogic;
|
|
|
+import com.gree.mall.miniapp.plus.entity.*;
|
|
|
+import com.gree.mall.miniapp.plus.service.*;
|
|
|
+import com.gree.mall.miniapp.utils.IpUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class WorkerLogic {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ WebsitUserService websitUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CommonLogic commonLogic;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ WorkerPolicyService workerPolicyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AdminWebsitService adminWebsitService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PolicyService policyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PolicyRangeService policyRangeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PolicyWebsitService policyWebsitService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ WechatLogic wechatLogic;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PolicyOrderService policyOrderService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public List<WorkerRemind> remind() {
|
|
|
+
|
|
|
+ CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
|
|
|
+
|
|
|
+ List<WebsitUser> websitUsers = websitUserService.lambdaQuery().list();
|
|
|
+
|
|
|
+ List<WorkerRemind> workerReminds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (WebsitUser websitUser : websitUsers) {
|
|
|
+ //保险购买状态,没有购买的意外险
|
|
|
+ if (websitUser.getExamineStatus().equals(ExamineWorkerStatusEnum.WAIT_WORKER.getKey()) &&
|
|
|
+ workerPolicyService.lambdaQuery()
|
|
|
+ .in(WorkerPolicy::getStatus,"ON","WAIT_ON")
|
|
|
+ .eq(WorkerPolicy::getPolicyType,"AC")
|
|
|
+ .eq(WorkerPolicy::getWebsitUserId,websitUser.getId())
|
|
|
+ .count() < 1) {
|
|
|
+
|
|
|
+ AdminWebsit adminWebsit = adminWebsitService.getById(websitUser.getWebsitId());
|
|
|
+
|
|
|
+ WorkerRemind workerRemind = new WorkerRemind();
|
|
|
+ workerRemind.setWebsitId(websitUser.getWebsitId());
|
|
|
+ workerRemind.setWebsitName(adminWebsit.getName());
|
|
|
+ workerRemind.setRemindIn(1);
|
|
|
+
|
|
|
+ workerReminds.add(workerRemind);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 购买的意外险,七天后过期 每天提醒一次
|
|
|
+ if ( workerPolicyService.lambdaQuery()
|
|
|
+ .in(WorkerPolicy::getStatus,"ON","WAIT_ON")
|
|
|
+ .le(WorkerPolicy::getEndTime, DateUtil.offsetDay(new Date(),7))
|
|
|
+ .eq(WorkerPolicy::getPolicyType,"AC")
|
|
|
+ .eq(WorkerPolicy::getWebsitUserId,websitUser.getId())
|
|
|
+ .le(WorkerPolicy::getExTime,new Date())
|
|
|
+ .count() > 0){
|
|
|
+
|
|
|
+ workerPolicyService.lambdaUpdate()
|
|
|
+ .in(WorkerPolicy::getStatus,"OFF")
|
|
|
+ .notIn(WorkerPolicy::getStatus,"ON","WAIT_ON")
|
|
|
+ .eq(WorkerPolicy::getPolicyType,"AC")
|
|
|
+ .eq(WorkerPolicy::getWebsitUserId,websitUser.getId())
|
|
|
+ .set(WorkerPolicy::getExTime,DateUtil.endOfDay(new Date())).update();
|
|
|
+
|
|
|
+ AdminWebsit adminWebsit = adminWebsitService.getById(websitUser.getWebsitId());
|
|
|
+
|
|
|
+ WorkerRemind workerRemind = new WorkerRemind();
|
|
|
+ workerRemind.setWebsitId(websitUser.getWebsitId());
|
|
|
+ workerRemind.setWebsitName(adminWebsit.getName());
|
|
|
+ workerRemind.setRemindIn(2);
|
|
|
+
|
|
|
+ workerReminds.add(workerRemind);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 意外险失效,没有购买的意外险
|
|
|
+ if ( workerPolicyService.lambdaQuery()
|
|
|
+ .in(WorkerPolicy::getStatus,"OFF")
|
|
|
+ .notIn(WorkerPolicy::getStatus,"ON","WAIT_ON")
|
|
|
+ .eq(WorkerPolicy::getPolicyType,"AC")
|
|
|
+ .eq(WorkerPolicy::getWebsitUserId,websitUser.getId())
|
|
|
+ .le(WorkerPolicy::getExTime,new Date())
|
|
|
+ .count() > 0){
|
|
|
+
|
|
|
+ workerPolicyService.lambdaUpdate()
|
|
|
+ .in(WorkerPolicy::getStatus,"OFF")
|
|
|
+ .notIn(WorkerPolicy::getStatus,"ON","WAIT_ON")
|
|
|
+ .eq(WorkerPolicy::getPolicyType,"AC")
|
|
|
+ .eq(WorkerPolicy::getWebsitUserId,websitUser.getId())
|
|
|
+ .set(WorkerPolicy::getExTime,DateUtil.endOfDay(new Date())).update();
|
|
|
+
|
|
|
+ AdminWebsit adminWebsit = adminWebsitService.getById(websitUser.getWebsitId());
|
|
|
+
|
|
|
+ WorkerRemind workerRemind = new WorkerRemind();
|
|
|
+ workerRemind.setWebsitId(websitUser.getWebsitId());
|
|
|
+ workerRemind.setWebsitName(adminWebsit.getName());
|
|
|
+ workerRemind.setRemindIn(3);
|
|
|
+
|
|
|
+ workerReminds.add(workerRemind);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return workerReminds;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Page<WorkerPolicy> myPolicy(String userId, Integer pageNum, Integer pageSize) {
|
|
|
+
|
|
|
+ Page<WorkerPolicy> page = workerPolicyService.lambdaQuery()
|
|
|
+ .eq(WorkerPolicy::getWorkerId,userId)
|
|
|
+ .eq(WorkerPolicy::getPolicyType,"AC")
|
|
|
+ .eq(WorkerPolicy::getType,"IN")
|
|
|
+ .page(new Page<>(pageNum, pageSize));
|
|
|
+
|
|
|
+
|
|
|
+ return page;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public PolicyOrderDetail myDetail(String id) {
|
|
|
+
|
|
|
+ WorkerPolicy workerPolicy = workerPolicyService.getById(id);
|
|
|
+
|
|
|
+ PolicyOrderDetail policyOrderDetail = BeanUtil.toBean(workerPolicy, PolicyOrderDetail.class);
|
|
|
+
|
|
|
+ Policy policy = policyService.getById(workerPolicy.getPolicyId());
|
|
|
+
|
|
|
+
|
|
|
+ List<PolicyRange> policyRanges = policyRangeService.lambdaQuery().eq(PolicyRange::getPolicyId, policy.getId()).list();
|
|
|
+ policyOrderDetail.setPolicy(policy);
|
|
|
+ policyOrderDetail.setPolicyRanges(policyRanges);
|
|
|
+ return policyOrderDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page<Policy> policy(String websitId,Integer pageNum, Integer pageSize) {
|
|
|
+
|
|
|
+ List<PolicyWebsit> policyWebsits = policyWebsitService.lambdaQuery().eq(PolicyWebsit::getWebsitId, websitId).list();
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(policyWebsits))
|
|
|
+ return new Page<>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Page<Policy> page = policyService.lambdaQuery()
|
|
|
+ .in(Policy::getId,policyWebsits.stream().map(PolicyWebsit::getPolicyId).collect(Collectors.toList()))
|
|
|
+ .eq(Policy::getIsBuy, IsYesNoEnum.YES.getKey())
|
|
|
+ .le(Policy::getStartTime,new Date())
|
|
|
+ .ge(Policy::getEndTime,new Date())
|
|
|
+ .page(new Page<>(pageNum, pageSize));
|
|
|
+
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PolicyDetail detail(String id) {
|
|
|
+
|
|
|
+ Policy policy = policyService.getById(id);
|
|
|
+ PolicyDetail policyDetail = BeanUtil.toBean(policy, PolicyDetail.class);
|
|
|
+
|
|
|
+ List<PolicyRange> policyRanges = policyRangeService.lambdaQuery().eq(PolicyRange::getPolicyId, policyDetail.getId()).list();
|
|
|
+
|
|
|
+ policyDetail.setPolicyRanges(policyRanges);
|
|
|
+
|
|
|
+ return policyDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PolicyOrder order(String policyId, String websitId, String userId) {
|
|
|
+ CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
|
|
|
+ Policy policy = policyService.getById(policyId);
|
|
|
+
|
|
|
+ AdminWebsit adminWebsit = adminWebsitService.getById(websitId);
|
|
|
+
|
|
|
+ PolicyOrder policyOrder = new PolicyOrder();
|
|
|
+ policyOrder.insert();
|
|
|
+
|
|
|
+ return policyOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PayDetail pay(String policyOrderId, HttpServletRequest request) {
|
|
|
+
|
|
|
+ String ip = IpUtil.getIpAddr(request);
|
|
|
+
|
|
|
+ CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
|
|
|
+
|
|
|
+ String source = commonLogic.getSource();
|
|
|
+
|
|
|
+ PayDetail payDetail = new PayDetail();
|
|
|
+
|
|
|
+ PolicyOrder policyOrder = policyOrderService.getById(policyOrderId);
|
|
|
+
|
|
|
+ if (source.equals("B")) {
|
|
|
+ payDetail = wechatLogic.paymentH5(policyOrder.getId(), policyOrder.getPayAmount(), currentCompanyWechat.getUser().getOpenId(),
|
|
|
+ "N", ip, currentCompanyWechat.getCompanyWechatId());
|
|
|
+ } else {
|
|
|
+ payDetail = wechatLogic.payment(policyOrder.getId(), policyOrder.getPayAmount(),
|
|
|
+ currentCompanyWechat.getUser().getOpenId(),
|
|
|
+ "N", ip, currentCompanyWechat.getCompanyWechatId(), true);
|
|
|
+ }
|
|
|
+
|
|
|
+ return payDetail;
|
|
|
+ }
|
|
|
+}
|