CallBackContorll.java 23.5 KB
Newer Older
翁国栋 committed
1 2
package cn.timer.api.controller.insure;

翁国栋 committed
3
import cn.timer.api.bean.insure.*;
翁国栋 committed
4
import cn.timer.api.bean.yggl.YgglMainEmp;
翁国栋 committed
5
import cn.timer.api.config.exception.CustomException;
翁国栋 committed
6
import cn.timer.api.utils.HttpUtils;
翁国栋 committed
7
import cn.timer.api.utils.ResultUtil;
翁国栋 committed
8 9
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
翁国栋 committed
10
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
翁国栋 committed
11
import com.google.common.collect.Lists;
翁国栋 committed
12 13
import com.google.common.collect.Maps;
import com.mysql.cj.util.StringUtils;
翁国栋 committed
14 15
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
翁国栋 committed
16
import io.swagger.models.auth.In;
翁国栋 committed
17
import org.apache.commons.codec.digest.DigestUtils;
翁国栋 committed
18 19
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
翁国栋 committed
20
import org.springframework.beans.factory.annotation.Value;
翁国栋 committed
21
import org.springframework.scheduling.annotation.Async;
翁国栋 committed
22 23
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
翁国栋 committed
24
import org.springframework.web.servlet.ModelAndView;
翁国栋 committed
25

翁国栋 committed
26 27 28 29 30 31
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import java.util.Map;
翁国栋 committed
32
import java.util.Random;
翁国栋 committed
33 34 35 36 37 38 39 40 41 42 43 44

/**
 * @Description TODO
 * @Author wgd
 * @Date 2022/3/3 8:45
 */
@Api(tags = "8.0回调接口")
@RestController
@Transactional
@RequestMapping(value = "/callBack/policy", produces = {"application/json"})
public class CallBackContorll {
    private static final Logger log = LoggerFactory.getLogger(CallBackContorll.class);
翁国栋 committed
45 46 47 48
    @Value("${insure.appid}")
    private String appid;
    @Value("${insure.secret}")
    private String secret;
翁国栋 committed
49
    /*保全测试用*/
翁国栋 committed
50 51 52 53 54
    @Value("${insure.appidq}")
    private String appidq;
    @Value("${insure.secretq}")
    private String secretq;

翁国栋 committed
55 56 57
    @Value("${insure.getPolicyUrl}")
    private String getPolicyUrl;

翁国栋 committed
58 59
    @Value("${BASE_API_URL}")
    private String base_api_url;
翁国栋 committed
60

翁国栋 committed
61 62 63 64
    /*保全支付*/
    @Value("${insure.batchToPayUrl}")
    private String batchToPayUrl;

翁国栋 committed
65

翁国栋 committed
66 67 68 69
    /*支付回调*/
    @Value("${pay_page}")
    private String payPage;

翁国栋 committed
70
    @PostMapping(value = "/insuredCallBack")
翁国栋 committed
71
    @ApiOperation(value = "6.投保核保回调-弃用", httpMethod = "POST", notes = "投保申请回调")
翁国栋 committed
72 73
    private Map insuredCallBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp) throws IOException {
        Map map = Maps.newHashMap();
翁国栋 committed
74 75
        map.put("status", "error");
        if (StringUtils.isNullOrEmpty(pid) || StringUtils.isNullOrEmpty(sign) && StringUtils.isNullOrEmpty(timestamp)) {
翁国栋 committed
76 77
            return map;
        }
翁国栋 committed
78
        if (!pid.equals(appidq)) {
翁国栋 committed
79 80 81 82 83 84
            return map;
        }
        InputStream is = null;
        is = request.getInputStream();
        StringBuilder sb = new StringBuilder();
        byte[] b = new byte[4096];
翁国栋 committed
85
        for (int n; (n = is.read(b)) != -1; ) {
翁国栋 committed
86 87 88
            sb.append(new String(b, 0, n));
        }
        String value = DigestUtils.md5Hex(appidq + secretq + timestamp + sb.toString());
翁国栋 committed
89
        if (!value.equals(sign)) {
翁国栋 committed
90 91
            return map;
        }
翁国栋 committed
92
        CallBack callBack = JSONObject.parseObject(sb.toString(), CallBack.class);
翁国栋 committed
93
        Map trueMap = Maps.newHashMap();
翁国栋 committed
94
        trueMap.put("status", "1");
翁国栋 committed
95
        return trueMap;
翁国栋 committed
96 97
    }

翁国栋 committed
98 99
    @PostMapping(value = "/addpPayCallBack")
    @ApiOperation(value = "11.增员核保回调", httpMethod = "POST", notes = "增员核保回调")
翁国栋 committed
100
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
101
    public Map addpPayCallBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
102 103
        /*核保*/
        /*如果是在线支付的话*/
翁国栋 committed
104
        Map map = Maps.newHashMap();
翁国栋 committed
105 106
        map.put("status", "error");
        if (StringUtils.isNullOrEmpty(pid) || StringUtils.isNullOrEmpty(sign) && StringUtils.isNullOrEmpty(timestamp)) {
翁国栋 committed
107 108
            return map;
        }
翁国栋 committed
109
        if (!pid.equals(appidq)) {
翁国栋 committed
110 111
            return map;
        }
翁国栋 committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secretq + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("增员核保回调验签失败");
            }
            CallBack callBack = JSONObject.parseObject(sb.toString(), CallBack.class);
            if (callBack.getCallback_type().equals("1")) {
                List<InsureUser> insureUserList = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getTransId, callBack.getOrder_import_info().getThird_uuid()));
                InsurePolicy insurePolicy = InsurePolicy.builder().id(insureUserList.get(0).getPolicyId()).build().selectById();
                if (callBack.getStatus().equals("1")) {
                    if (insureUserList.size() > 0) {
                        insurePolicy.setStatus("4");/*设置为支付状态*/
                        insurePolicy.setUpdateTime(new Date());
                        InsurePay insurePay = InsurePay.builder().payStatus(1).
                                serialNumber(callBack.getOrder_import_info().getUuid()).policyId(insurePolicy.getId()).amount(Double.parseDouble(callBack.getOrder_import_info().getTotal_money())).build();
                        insurePay.insert();
                        insurePolicy.setPayId(insurePay.getId());
                        insurePolicy.updateById();
翁国栋 committed
137

翁国栋 committed
138
                    }
翁国栋 committed
139 140 141
                    InsureLog.builder().type(7)
                            .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/addpPayCallBack")
                            .returnCode(callBack.getStatus()).returnMsg("核保通过").policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
142
                } else {
翁国栋 committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
                    insureUserList.stream().forEach(v -> {
                        v.setStatus("2");
                        v.setInsureStatus(2);
                        v.updateById();
                    });
                    insurePolicy.setStatus("1");
                    insurePolicy.updateById();
                    List<Map> errMap = callBack.getOrder_import_info().getErr_list();
                    String errorMsg = "";
                    if (errMap.size() > 0) {
                        for (int i = 0; i < errMap.size(); i++) {
                            errorMsg = errorMsg + ("姓名:" + errMap.get(i).get("name").toString() + ",错误:" + errMap.get(i).get("err_content").toString() + ',');
                        }
                    } else {
                        errorMsg = callBack.getErr_msg();
                    }
                    //TODO 写入日志
                    InsureLog.builder().type(7)
                            .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/addpPayCallBack")
                            .returnCode(callBack.getStatus()).returnMsg(errorMsg).policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
163
                }
翁国栋 committed
164
            }
翁国栋 committed
165
        } catch (Exception e) {
翁国栋 committed
166
            log.error("增员核保回调异常:",e);
翁国栋 committed
167 168 169 170 171
            throw new CustomException("增员核保回调异常");
        } finally {
            Map trueMap = Maps.newHashMap();
            trueMap.put("status", "1");
            return trueMap;
翁国栋 committed
172 173
        }
    }
翁国栋 committed
174

翁国栋 committed
175 176
    @PostMapping(value = "/CallBack")
    @ApiOperation(value = "7.保全增员申请回调", httpMethod = "POST", notes = "投保申请回调")
翁国栋 committed
177
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
178
    public Map callBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
179 180 181 182 183 184 185 186
        Map map = Maps.newHashMap();
        map.put("status", "error");
        if (StringUtils.isNullOrEmpty(pid) || StringUtils.isNullOrEmpty(sign) && StringUtils.isNullOrEmpty(timestamp)) {
            return map;
        }
        if (!pid.equals(appidq)) {
            return map;
        }
翁国栋 committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secretq + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("保全增员申请回调验签失败");
            }
            Map paramsMap = Maps.newHashMap();
            paramsMap.put("pid", pid);
            paramsMap.put("timestamp", timestamp);
            paramsMap.put("sign", sign);
            CallBack callBack = JSONObject.parseObject(sb.toString(), CallBack.class);
翁国栋 committed
204 205 206 207
            List<InsureUser> list = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getTransId, callBack.getOrder_import_info().getThird_uuid()));
            if(list.size()<=0){
                list = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getBatchNo, callBack.getOrder_import_info().getUuid()));
            }
翁国栋 committed
208 209 210 211 212
            InsurePolicy insurePolicy = InsurePolicy.builder().build().selectOne(new QueryWrapper<InsurePolicy>().lambda().eq(InsurePolicy::getPolicyNo, list.get(0).getPolicyNo()));
            if (callBack.getStatus().equals("1")) {
                list.forEach(i -> {
                    i.setInsureStatus(1);
                    i.setStatus("1");
翁国栋 committed
213
                    i.updateById();
翁国栋 committed
214
                    YgglMainEmp.builder().isInsure(1).build().update(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getId, i.getUserId()));
翁国栋 committed
215
                });
翁国栋 committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
                List<InsureUser> oldlist = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getReplaceTransId, callBack.getOrder_import_info().getUuid()));
                if (oldlist != null && oldlist.size() > 0) {
                    oldlist.forEach(i -> {
                        i.setInsureStatus(4);
                        i.setStatus("2");
                        i.updateById();
                        YgglMainEmp.builder().isInsure(0).build().update(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getId, i.getUserId()));
                    });
                }
                if (oldlist == null || oldlist.size() == 0) {
                    insurePolicy.setTotalPremium(String.valueOf(Double.valueOf(insurePolicy.getTotalPremium()) + Double.valueOf(callBack.getOrder_import_info().getTotal_money())));
                }
                insurePolicy.setPolicyFile(callBack.getOrder_import_info().getEndorsement_file());
                InsureLog.builder().requestParam(JSONObject.toJSONString(paramsMap)).type(7)
                        .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/CallBack")
翁国栋 committed
231
                        .returnCode(callBack.getStatus()).returnMsg("保单增员-更新成功").policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
            } else {
                String errorMsg = "";
                InsureLog insureLog = InsureLog.builder().build().selectOne(new QueryWrapper<InsureLog>().lambda().eq(InsureLog::getTransId, callBack.getOrder_import_info().getThird_uuid()));
                if(callBack.getOrder_import_info().getErr_list()!=null) {
                    List<Map> errMap = callBack.getOrder_import_info().getErr_list();
                    if (errMap.size() > 0) {
                        for (int i = 0; i < errMap.size(); i++) {
                            errorMsg = errorMsg + ("姓名:" + errMap.get(i).get("name").toString() + ",错误:" + errMap.get(i).get("err_content").toString() + ',');
                        }
                    } else {
                        errorMsg = callBack.getErr_msg();
                    }
                }
                /*在保司系统点击取消申报时候会回调申报失败*/
                if(StringUtils.isNullOrEmpty(callBack.getOrder_import_info().getSingle_serial_no())){
                    list.forEach(i -> {
                        i.setInsureStatus(2);
                        i.setStatus("2");
                        i.updateById();
                        YgglMainEmp.builder().isInsure(0).build().update(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getId, i.getUserId()));
                    });
                }
                //TODO 写入日志
                InsureLog.builder().requestParam(JSONObject.toJSONString(paramsMap)).type(7)
                        .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/CallBack")
                        .returnCode(callBack.getStatus()).returnMsg(errorMsg).policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
258
            }
翁国栋 committed
259
            /*无论此次申请成功还是失败这笔单都需要重新申报*/
翁国栋 committed
260 261 262
            insurePolicy.setUpdateTime(new Date());
            insurePolicy.setStatus("1");
            insurePolicy.updateById();
翁国栋 committed
263 264

        } catch (Exception e) {
翁国栋 committed
265
            log.error("保全增员申请回调异常:",e);
翁国栋 committed
266 267 268 269 270
            throw new CustomException("保全增员申请回调异常");
        } finally {
            Map trueMap = Maps.newHashMap();
            trueMap.put("status", "1");
            return trueMap;
翁国栋 committed
271
        }
翁国栋 committed
272

翁国栋 committed
273

翁国栋 committed
274
    }
翁国栋 committed
275 276 277

    @GetMapping(value = "/payStatus")
    @ApiOperation(value = "8.支付完成跳转", httpMethod = "GET", notes = "用于支付时跳回我们系统更新状态")
翁国栋 committed
278
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
279
    public ModelAndView callBackPayStatus(HttpServletRequest request, @RequestParam Integer policyId)  {
翁国栋 committed
280 281 282 283
        InsurePolicy insurePolicy = InsurePolicy.builder().id(policyId).build().selectById();
        InsurePay insurePay = InsurePay.builder().id(insurePolicy.getPayId()).build().selectById();
        insurePay.setPayTime(new Date());
        insurePay.updateById();
翁国栋 committed
284 285
        InsureLog.builder().type(7).createTime(new Date()).requestType(2).requestPath(base_api_url + "/callBack/policy/payStatus?policyId=" + policyId)
                .returnCode("suc").returnMsg("用户已支付" + insurePay.getAmount() + "元,等待更新保单状态").policyId(policyId).build().insert();
翁国栋 committed
286
        ModelAndView mav = new ModelAndView();
翁国栋 committed
287
        mav.setViewName("redirect:" + payPage + "/#/payPage?amount="+insurePay.getAmount());
翁国栋 committed
288
        return mav;
翁国栋 committed
289 290 291 292
    }

    @PostMapping(value = "/payCallBack")
    @ApiOperation(value = "9.投保支付收银台回调", httpMethod = "POST", notes = "支付完成跳转")
翁国栋 committed
293
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
294
    public Map payCallBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secret + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("投保支付收银台回调验签失败");
            }
            PayCallBack callBack = JSONObject.parseObject(sb.toString(), PayCallBack.class);
            InsurePay insurePay = InsurePay.builder().build().selectOne(new QueryWrapper<InsurePay>().lambda().eq(InsurePay::getSerialNumber, callBack.getSerial_number()));
            insurePay.setAmount(Double.valueOf(callBack.getAmount()));
            insurePay.setPayStatus(Integer.parseInt(callBack.getPay_status()));
            insurePay.setPaySerialNo(callBack.getPay_serial_no());
            insurePay.setSerialNumber(callBack.getSerial_number());
            insurePay.setPayType(callBack.getPay_type());
            insurePay.updateById();
            InsureLog.builder().type(7).createTime(new Date()).requestType(1).requestPath(base_api_url + "/callBack/policy/payCallBack")
                    .returnCode("suc").returnMsg("确认支付成功,支付方式:" + insurePay.getPayType() + ",支付金额:" + callBack.getAmount()).policyId(insurePay.getPolicyId()).build().insert();
            /*调用出单接口更新保单状态*/
            Map paramsMap = Maps.newHashMap();
            paramsMap.put("pid", pid);
            paramsMap.put("timestamp", timestamp);
            paramsMap.put("sign", sign);
            Map bodyMap = Maps.newHashMap();
            bodyMap.put("quotation_id", callBack.getSerial_number());
            String data = HttpUtils.sendPost(getPolicyUrl, InsureContorll.setParams(JSONObject.toJSONString(bodyMap), appid, secret), bodyMap);
            Map dataMap = JSONObject.parseObject(data, Map.class);
            if (dataMap.size() > 0) {
                if (dataMap.get("errcode").toString().equals("suc") || dataMap.get("errcode").toString().equals("e25")) {
                    //TODO 如果是E25则将保单设为出单中,更新交由保单出单回调做,设为出单状态是因为之后可以手动校验
                    InsurePolicy insurePolicy = InsurePolicy.builder().id(insurePay.getPolicyId()).build().selectById();
                    insurePolicy.setStatus("2");
                    insurePolicy.setUpdateTime(new Date());
                    insurePolicy.updateById();
                }
                InsureLog.builder().requestParam(JSONObject.toJSONString(InsureContorll.setParams(JSONObject.toJSONString(bodyMap), appid, secret))).type(7)
翁国栋 committed
335
                        .requestData(JSONObject.toJSONString(bodyMap)).createTime(new Date()).requestType(1).returnBody(data).requestPath(getPolicyUrl)
翁国栋 committed
336
                        .returnCode(dataMap.get("errcode").toString()).policyId(insurePay.getPolicyId()).returnMsg(dataMap.get("errmsg").toString()).build().insert();
翁国栋 committed
337
            }
翁国栋 committed
338
        } catch (Exception e) {
翁国栋 committed
339
            log.error("投保支付收银台回调异常:",e);
翁国栋 committed
340 341 342 343 344
            throw new CustomException("投保支付收银台回调异常");
        } finally {
            Map map = Maps.newHashMap();
            map.put("status", "1");
            return map;
翁国栋 committed
345 346 347 348 349
        }
    }

    @PostMapping(value = "/issueCallback")
    @ApiOperation(value = "10.保单出单回调", httpMethod = "POST", notes = "支付完成跳转")
翁国栋 committed
350
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
351
    public Map issueCallback(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secret + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("保单出单回调验签失败");
            }
            PolicyCallBack callBack = JSONObject.parseObject(sb.toString(), PolicyCallBack.class);
            InsurePay insurePay = InsurePay.builder().build().selectOne(new QueryWrapper<InsurePay>().lambda().eq(InsurePay::getSerialNumber, callBack.getSerial_number()));
            InsurePolicy insurePolicy = InsurePolicy.builder().id(insurePay.getPolicyId()).build().selectById();
            List<InsureUser> userList = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getPolicyId, insurePolicy.getId()));
            insurePolicy.setUpdateTime(new Date());
            if (callBack.getStatus().equals("1")) {
                insurePay.setPayStatus(2);
                insurePolicy.setPolicyNo(callBack.getPolicy_no());
                insurePolicy.setTotalPremium(callBack.getTotal_premium());
                insurePolicy.setPolicyFile(callBack.getPolicy_file());
                insurePolicy.setStatus("1");
                insurePolicy.setKitUrl(callBack.getKit_url());
                userList.forEach(u -> {
                    u.setStatus("1");
                    u.setInsureStatus(1);
                    u.updateById();
                });
            } else {
                insurePay.setPayStatus(3);
                insurePolicy.setStatus("3");
                userList.forEach(u -> {
                    u.setStatus("2");
                    u.setInsureStatus(2);
                    u.updateById();
                });
            }
            insurePolicy.updateById();
            insurePay.updateById();
            InsureLog.builder().type(7).createTime(new Date()).requestType(1).returnBody(sb.toString()).requestPath(getPolicyUrl)
                    .returnCode(callBack.getStatus()).policyId(insurePay.getPolicyId()).returnMsg(callBack.getErr_msg()).build().insert();
        } catch (Exception e) {
翁国栋 committed
395
            log.error("保单出单回调:",e);
翁国栋 committed
396 397 398 399
            throw new CustomException("保单出单回调");
        } finally {
            Map map = Maps.newHashMap();
            map.put("status", "1");
翁国栋 committed
400 401
            return map;
        }
翁国栋 committed
402 403 404
    }

    @PostMapping(value = "/batchPayCallback")
翁国栋 committed
405
    @ApiOperation(value = "增员支付回调", httpMethod = "POST", notes = "增员支付回调")
翁国栋 committed
406
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
407
    public Map batchPayCallback(HttpServletRequest request,@RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
408 409 410 411 412 413 414 415 416

        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
翁国栋 committed
417
            String value = DigestUtils.md5Hex(pid + secretq + timestamp + sb.toString());
翁国栋 committed
418 419 420
            if (!value.equals(sign)) {
                throw new CustomException("增员支付回调验签失败");
            }
翁国栋 committed
421 422 423 424 425 426 427 428 429 430 431
            BatchPayCallBack callBack = JSONObject.parseObject(sb.toString(), BatchPayCallBack.class);
            InsurePay insurePay = InsurePay.builder().build().selectOne(new QueryWrapper<InsurePay>().lambda().eq(InsurePay::getSerialNumber, callBack.getOrder_import_uuid()));
            if (insurePay != null) {
                insurePay.setPayStatus(Integer.parseInt(callBack.getPay_status()));
                insurePay.setAmount(Double.parseDouble(callBack.getPay_money()));
                insurePay.setPayType(callBack.getMethod());
                insurePay.updateById();
            }
            InsureLog.builder().type(7).createTime(new Date()).requestType(1).returnBody(sb.toString()).requestPath(base_api_url + "/callBack/policy/batchPayCallback")
                    .returnCode(callBack.getPay_status()).policyId(insurePay.getPolicyId()).returnMsg("确认支付成功,支付方式:" + insurePay.getPayType() + ",支付金额:" + insurePay.getAmount()).build().insert();
        } catch (Exception e) {
翁国栋 committed
432
            log.error("增员支付回调异常:",e);
翁国栋 committed
433 434 435 436 437
            throw new CustomException("增员支付回调异常");
        } finally {
            Map map = Maps.newHashMap();
            map.put("status", "1");
            return map;
翁国栋 committed
438 439
        }
    }
翁国栋 committed
440
}