InsurePlanController.java 2.64 KB
Newer Older
翁国栋 committed
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
package cn.timer.api.controller.insure;

import cn.timer.api.bean.insure.InsurePlan;
import cn.timer.api.bean.insure.InsureProduct;
import cn.timer.api.bean.insure.InsureProductPlan;
import cn.timer.api.dao.insure.InsurePlanMapper;
import cn.timer.api.dao.insure.InsureProductPlanMapper;
import cn.timer.api.dto.insure.ProductDto;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 投保方案
 *
 * @author wgd
 * @email 862422848@qq.com
 * @date 2022-09-23 11:53:23
 */
@Api(tags = "8.0保险列表")
@RestController
@Transactional
@RequestMapping(value = "/insurePlan", produces = {"application/json"})
public class InsurePlanController {

    @Autowired
    private InsurePlanMapper insurePlanMapper;

    @Autowired
    private InsureProductPlanMapper insureProductPlanMapper;

    @GetMapping(value = "/planList")
    @ApiOperation(value = "方案列表", httpMethod = "GET", notes = "方案列表")
    public Result<Object> planList() {
        List<InsurePlan> list = insurePlanMapper.getList();
        Map<String, List<InsurePlan>> map = list.stream().collect(Collectors.groupingBy(InsurePlan::getType));
        return ResultUtil.data(map);
    }
    @GetMapping(value = "/getPlanListbyProduct")
    @ApiOperation(value = "产品方案列表", httpMethod = "GET", notes = "产品方案列表")
    public Result<Object> getPlanListbyProduct(@RequestParam("productId") Integer productId) {
        List<ProductDto> list = insureProductPlanMapper.getListByProductId(productId);
        return ResultUtil.data(list);
    }

    @PostMapping(value = "/savePlan")
    @ApiOperation(value = "保存方案", httpMethod = "POST", notes = "保存方案")
    public Result<Object> savePlan(@RequestBody ProductDto productDto) {
        InsureProduct insureProduct = InsureProduct.builder().id(productDto.getProductId()).build().selectById();
        InsureProductPlan insureProductPlan = InsureProductPlan.builder().productId(insureProduct.getId())
                .createTime(new Date()).name(productDto.getPlanName()).price(productDto.getPrice()).planJson(productDto.getPlanJson().toString()).build();
        if (insureProductPlan.insert()) {
            return ResultUtil.data("保存成功");
        }
        return ResultUtil.error("保存失败");
    }

    ;
}