InsureApplicantController.java 6.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 137 138 139 140 141 142 143 144 145
package cn.timer.api.controller.insure;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.timer.api.bean.insure.InsureApplicant;
import cn.timer.api.bean.insure.InsureProvince;
import cn.timer.api.bean.qyzx.QyzxEntInfoM;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.exception.CustomException;
import cn.timer.api.dao.insure.InsureApplicantMapper;
import cn.timer.api.dto.insure.InsureDto;
import cn.timer.api.utils.HttpUtils;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import com.alibaba.druid.util.Base64;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;


/**
 * 投保人
 *
 * @author wgd
 * @email 862422848@qq.com
 * @date 2022-03-07 17:02:46
 */
@Api(tags = "8.0保险列表")
@RestController
@Transactional
@RequestMapping(value = "/insureApplicant", produces = {"application/json"})
public class InsureApplicantController {
    private static final Logger log = LoggerFactory.getLogger(InsureApplicantController.class);

    @PostMapping("/insureApplicationSetting")
    @ApiOperation(value = "设置投保人", httpMethod = "POST", notes = "投保申请")
    @Transactional(rollbackFor = Exception.class)
    public Result<Object> insureApplicationSetting(@RequestBody InsureApplicant params) {
        try {
            InsureApplicant insureApplicant = InsureApplicant.builder().build().selectOne(new QueryWrapper<InsureApplicant>().lambda().eq(InsureApplicant::getOrgCode, params.getOrgCode()));
            params.setId(insureApplicant.getId());
            params.updateById();
            return ResultUtil.data(params);
        } catch (Exception e) {
            log.error("设置投保人异常:",e);
            throw new CustomException("设置投保人异常");
        }
    }


    @GetMapping("/getApplicantAdmin")
    @ApiOperation(value = "获取投保人--运营后台", httpMethod = "GET", notes = "获取投保人")
    @Transactional(rollbackFor = Exception.class)
    public Result<Object> getApplicant(@RequestParam("orgCode") Integer orgCode) {
        try {
            InsureApplicant insureApplicant = InsureApplicant.builder().build().selectOne(new QueryWrapper<InsureApplicant>().lambda().eq(InsureApplicant::getOrgCode, orgCode));
            if (insureApplicant == null) {
                QyzxEntInfoM qyzxEntInfoM = QyzxEntInfoM.builder().id(orgCode).build().selectById();
                insureApplicant = getInsureApplicant(qyzxEntInfoM);
                insureApplicant.setOrgCode(orgCode);
                insureApplicant.insert();
            }
            return ResultUtil.data(insureApplicant);
        } catch (Exception e) {
            log.error("获取投保人异常:",e);
            throw new CustomException("获取投保人异常");
        }
    }

    private InsureApplicant getInsureApplicant(QyzxEntInfoM qyzxEntInfoM) {
        InsureApplicant insureApplicant;
        insureApplicant = new InsureApplicant();
        insureApplicant.setApplicantEName(qyzxEntInfoM.getName());
        insureApplicant.setApplicantEAddress(qyzxEntInfoM.getWorkAddress());
        insureApplicant.setApplicantEContacts(qyzxEntInfoM.getLinkMan());
        insureApplicant.setApplicantEPhone(qyzxEntInfoM.getPhone());/*这里为避免联系人为空,默认使用法人*/
        insureApplicant.setApplicantType("2");
        insureApplicant.setApplicantENoType("3646");
        insureApplicant.setApplicantENo(qyzxEntInfoM.getCreditCode());
        return insureApplicant;
    }

    @GetMapping("/getApplicant")
    @ApiOperation(value = "获取投保人--8小时", httpMethod = "GET", notes = "获取投保人")
    @Transactional(rollbackFor = Exception.class)
    public Result<Object> getApplicant(@CurrentUser UserBean userBean) {
        try {
            InsureApplicant insureApplicant = InsureApplicant.builder().build().selectOne(new QueryWrapper<InsureApplicant>().lambda().eq(InsureApplicant::getOrgCode, userBean.getOrgCode()));
            if (insureApplicant == null) {
                QyzxEntInfoM qyzxEntInfoM = QyzxEntInfoM.builder().id(userBean.getOrgCode()).build().selectById();
                insureApplicant = getInsureApplicant(qyzxEntInfoM);
                insureApplicant.setOrgCode(userBean.getOrgCode());
                insureApplicant.insert();
            }
            return ResultUtil.data(insureApplicant);
        } catch (Exception e) {
            log.error("获取投保人异常:",e);
            throw new CustomException("获取投保人异常");
        }
    }
    @GetMapping("/getProvince")
    @ApiOperation(value = "获取投保省市区", httpMethod = "GET", notes = "获取投保人")
    @Transactional(rollbackFor = Exception.class)
    public Result<Object> getRegion(){
        List<InsureProvince> nodeList= InsureProvince.builder().build().selectList(new QueryWrapper<InsureProvince>().lambda().isNotNull(InsureProvince::getId));
        // 配置
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        // 自定义属性名 都要默认值的
        treeNodeConfig.setIdKey("id");
        treeNodeConfig.setParentIdKey("parentId");
        // 最大递归深度
        treeNodeConfig.setDeep(4);

        List<Tree<String>> treeNodes = TreeUtil.build(nodeList, "0", treeNodeConfig, (treeNode, tree) -> {
            tree.setId(treeNode.getId().toString());
            tree.setParentId(treeNode.getPid().toString());
            tree.setName(treeNode.getName());
            tree.putExtra("value", treeNode.getValue());
        });

        return ResultUtil.data(treeNodes);
    }

}