|
@@ -5,10 +5,13 @@ import com.jpsoft.picc.config.JpCloudConfig;
|
|
|
import com.jpsoft.picc.modules.base.entity.TransactionRecord;
|
|
|
import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
import com.jpsoft.picc.modules.base.service.TransactionRecordService;
|
|
|
+import com.jpsoft.picc.modules.business.entity.ApplicationPolicy;
|
|
|
import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
|
|
|
import com.jpsoft.picc.modules.business.entity.InsurancePolicy;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsurancePolicyMember;
|
|
|
import com.jpsoft.picc.modules.business.service.ApplicationPolicyService;
|
|
|
import com.jpsoft.picc.modules.business.service.InsuranceApplicationService;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsurancePolicyMemberService;
|
|
|
import com.jpsoft.picc.modules.business.service.InsurancePolicyService;
|
|
|
import com.jpsoft.picc.modules.common.constant.PolicyStatus;
|
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
@@ -22,12 +25,13 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author 墨鱼_mo
|
|
@@ -54,11 +58,15 @@ public class PayController {
|
|
|
@Autowired
|
|
|
private InsurancePolicyService insurancePolicyService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InsurancePolicyMemberService insurancePolicyMemberService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CompanyService companyService;
|
|
|
|
|
|
@PostMapping(value = "/orderNotifyBack")
|
|
|
@ResponseBody
|
|
|
+ @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
|
|
public Map orderNotifyBack(String orderNo,String payType,
|
|
|
String code,String payTime,
|
|
|
String sign,String userMoney) {
|
|
@@ -66,78 +74,141 @@ public class PayController {
|
|
|
|
|
|
String status = "success";
|
|
|
String message = "订单支付成功";
|
|
|
- JSONObject body = new JSONObject();
|
|
|
+// JSONObject body = new JSONObject();
|
|
|
log.warn("payTime>>>" + payTime + "paymentType>>>" + payType + ">>>>orderNo>>" + orderNo + "sign>>>" + sign);
|
|
|
- if(StringUtils.isNotBlank(payType) && StringUtils.isNotBlank(orderNo)){
|
|
|
|
|
|
- HashMap<String,Object> signMap = new HashMap<String,Object>();
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(orderNo)) {
|
|
|
+ throw new Exception("订单号不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, Object> signMap = new HashMap<String, Object>();
|
|
|
|
|
|
- signMap.put("orderNo",orderNo);
|
|
|
- signMap.put("payType",payType);
|
|
|
- signMap.put("code",code);
|
|
|
- signMap.put("payTime",payTime);
|
|
|
- signMap.put("userMoney",userMoney);
|
|
|
+ signMap.put("orderNo", orderNo);
|
|
|
+ signMap.put("payType", payType);
|
|
|
+ signMap.put("code", code);
|
|
|
+ signMap.put("payTime", payTime);
|
|
|
+ signMap.put("userMoney", userMoney);
|
|
|
|
|
|
- boolean result = SignUtil.validateSign(signMap,"1234567890",sign);
|
|
|
+ boolean result = SignUtil.validateSign(signMap, "1234567890", sign);
|
|
|
|
|
|
- if(result){
|
|
|
- TransactionRecord transactionRecord = transactionRecordService.getByOrderNo(orderNo);
|
|
|
+ if (!result) {
|
|
|
+ throw new Exception("签名不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ TransactionRecord transactionRecord = transactionRecordService.getByOrderNo(orderNo);
|
|
|
|
|
|
+ if (transactionRecord == null) {
|
|
|
+ throw new Exception("订单不存在");
|
|
|
+ } else if ("20".equals(transactionRecord.getPaymentStatus())) {
|
|
|
+ message = "订单已支付";
|
|
|
+ status = "success";
|
|
|
+ } else {
|
|
|
InsuranceApplication insuranceApplication = insuranceApplicationService.get(transactionRecord.getApplicationId());
|
|
|
|
|
|
- if(transactionRecord != null && !"20".equals(transactionRecord.getPaymentStatus())){
|
|
|
- transactionRecord.setPaymentStatus("20");
|
|
|
- transactionRecord.setPaymentTime(new Date());
|
|
|
- transactionRecord.setBuyType(payType);
|
|
|
- transactionRecord.setUpdateTime(new Date());
|
|
|
-
|
|
|
- transactionRecordService.update(transactionRecord);
|
|
|
-
|
|
|
- //将投保单状态改为待制单
|
|
|
- if(insuranceApplication!=null) {
|
|
|
- insuranceApplication.setStatus(PolicyStatus.PendingMakePolicy.getValue() + "");
|
|
|
- insuranceApplication.setUpdateTime(new Date());
|
|
|
-
|
|
|
- insuranceApplicationService.update(insuranceApplication);
|
|
|
- }
|
|
|
-
|
|
|
- InsurancePolicy insurancePolicy = applicationPolicyService.findFirstPolicyByApplicationId(insuranceApplication.getId());
|
|
|
-
|
|
|
- if (insurancePolicy!=null){
|
|
|
- insurancePolicy.setStatus(PolicyStatus.PendingMakePolicy.getValue() + "");
|
|
|
- insurancePolicy.setUpdateTime(new Date());
|
|
|
-
|
|
|
- insurancePolicyService.update(insurancePolicy);
|
|
|
- }
|
|
|
-
|
|
|
-// body.put("orderNo", orderNo);
|
|
|
-// body.put("backStatus", "回调成功");
|
|
|
-// body.put("backTime", new Date().getTime()/1000);
|
|
|
- status="success";
|
|
|
- }else if(transactionRecord == null){
|
|
|
- message = "订单不存在";
|
|
|
- status = "fail";
|
|
|
- }else if("20".equals(transactionRecord.getPaymentStatus())){
|
|
|
- message = "订单已支付";
|
|
|
- status = "success";
|
|
|
+ transactionRecord.setPaymentStatus("20");
|
|
|
+ transactionRecord.setPaymentTime(new Date());
|
|
|
+ transactionRecord.setBuyType(payType);
|
|
|
+ transactionRecord.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ transactionRecordService.update(transactionRecord);
|
|
|
+
|
|
|
+ //将投保单状态改为待制单
|
|
|
+ if (insuranceApplication != null) {
|
|
|
+ insuranceApplication.setStatus(PolicyStatus.PendingMakePolicy.getValue() + "");
|
|
|
+ insuranceApplication.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ insuranceApplicationService.update(insuranceApplication);
|
|
|
}
|
|
|
- }else{
|
|
|
- message = "签名不正确";
|
|
|
- status = "fail";
|
|
|
+
|
|
|
+ //todo 处理合并投保单
|
|
|
+ processCombinePolicy(insuranceApplication);
|
|
|
+
|
|
|
+ message = "订单已支付";
|
|
|
+ status = "success";
|
|
|
}
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ //在实际开发中,我们往往需要在方法中进行异常的捕获,从而对异常进行判断,为客户端返回提示信息。
|
|
|
+ //但是此时由于异常的被捕获,导致事务的回滚没有被触发,导致事务的失败。
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
|
- }else{
|
|
|
- message = "订单号不存在";
|
|
|
status = "fail";
|
|
|
+ message = ex.getMessage();
|
|
|
}
|
|
|
|
|
|
retMap.put("status", status);
|
|
|
retMap.put("message", message);
|
|
|
-// retMap.put("body", body);
|
|
|
|
|
|
return retMap;
|
|
|
}
|
|
|
|
|
|
+ private void processCombinePolicy(InsuranceApplication insuranceApplication) {
|
|
|
+ InsurancePolicy firstPolicy = applicationPolicyService.findFirstPolicyByApplicationId(insuranceApplication.getId());
|
|
|
+
|
|
|
+ if (firstPolicy != null) {
|
|
|
+ //先更新状态为待制单
|
|
|
+ firstPolicy.setStatus(PolicyStatus.PendingMakePolicy.getValue() + "");
|
|
|
+ firstPolicy.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ insurancePolicyService.update(firstPolicy);
|
|
|
+ }
|
|
|
+
|
|
|
+ //todo 相同企业、相同险种、相同生效时间段 是否已经有投保单
|
|
|
+// List<InsurancePolicy> policyList = insurancePolicyService.findNextMonthPolicy(
|
|
|
+// insuranceApplication.getCompanyId(),
|
|
|
+// firstPolicy.getDefinitionId(),
|
|
|
+// firstPolicy.getStartTime(),
|
|
|
+// insuranceApplication.getEndTime(),
|
|
|
+// new String[]{PolicyStatus.Draft.getValue() + "",PolicyStatus.Back.getText() + ""});
|
|
|
+
|
|
|
+// for(InsurancePolicy policy : policyList) {
|
|
|
+// if(!policy.getId().equals(firstPolicy.getId())) {
|
|
|
+// //todo 将相同企业、相同险种、相同生效时间段的当月投保单取出,准备合并
|
|
|
+// curMonthPolicy = policyList.get(0);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ InsurancePolicy combinePolicy = null;
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(insuranceApplication.getCombinePolicyId())) {
|
|
|
+ combinePolicy = insurancePolicyService.get(insuranceApplication.getCombinePolicyId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (combinePolicy != null) {
|
|
|
+ //todo 关联参保人员
|
|
|
+ List<InsurancePolicyMember> memberList = insurancePolicyMemberService.findByPolicyId(firstPolicy.getId());
|
|
|
+
|
|
|
+ for (InsurancePolicyMember srcMember : memberList) {
|
|
|
+ //人员不重复
|
|
|
+ if (!insurancePolicyMemberService.exist(combinePolicy.getId(), srcMember.getMemberId())) {
|
|
|
+ InsurancePolicyMember destMember = new InsurancePolicyMember();
|
|
|
+
|
|
|
+ destMember.setId(UUID.randomUUID().toString());
|
|
|
+ destMember.setPolicyId(combinePolicy.getId());
|
|
|
+ destMember.setMemberId(srcMember.getMemberId());
|
|
|
+ destMember.setDelFlag(false);
|
|
|
+ destMember.setCreateTime(new Date());
|
|
|
+ destMember.setStatus(srcMember.getStatus());
|
|
|
+
|
|
|
+ insurancePolicyMemberService.insert(destMember);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ insurancePolicyService.updatePolicyNumAndAmount(combinePolicy, null);
|
|
|
+
|
|
|
+ //todo 因为已合并,将当前投保申请单、当前每月投保单设为false
|
|
|
+ insuranceApplication.setDelFlag(false);
|
|
|
+ insuranceApplication.setUpdateTime(new Date());
|
|
|
+ insuranceApplicationService.update(insuranceApplication);
|
|
|
+
|
|
|
+ firstPolicy.setDelFlag(false);
|
|
|
+ firstPolicy.setUpdateTime(new Date());
|
|
|
+ insurancePolicyService.update(firstPolicy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping(value="/paySuccess")
|
|
|
@ApiOperation(value="返回前端")
|
|
|
public String paySuccess(){
|