package com.chinaweal.aiccs.aiccs.revoke.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chinaweal.aiccs.aiccs.revoke.entity.CaseReport;
import com.chinaweal.aiccs.aiccs.revoke.service.CaseReportService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aiccs.common.util.ConstantsUtil;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.util.AssertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 案件调查终结报告信息表 前端控制器
 * </p>
 *
 * @author Lee
 * @since 2021-08-05
 */
@RestController
@RequestMapping("/caseReport")
public class CaseReportController extends BaseController {

    @Autowired
    private CaseReportService caseReportService;

    /**
     * 案件调查报告保存
     * @param caseReport 报告信息
     * @return
     */
    @PostMapping("saveReportInfo")
    public RestResult<?> saveReportInfo(@RequestBody CaseReport caseReport){
        AssertUtils.isNotBlank(caseReport.getCaseReportId());
        return RestResult.ok(caseReportService.updateById(caseReport));
    }

    /**
     * 获取案件调查报告信息
     * @param bizseq  业务号
     * @return
     */
    @PostMapping("getReportInfo")
    public RestResult<?> getReportInfo(String bizseq){
        AssertUtils.isNotBlank(bizseq);
        LambdaQueryWrapper<CaseReport> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CaseReport::getBizseq,bizseq);
        CaseReport report = caseReportService.getOne(wrapper);
//        if(StringUtils.isNotBlank(report.getAreaCode())) {// 获取地区简称
//            String areaCodeName = ConstantsUtil.getAreaShortName(report.getAreaCode());
//            report.setAreaCodeName(areaCodeName != null?  areaCodeName: StringUtils.EMPTY);
//        }
        if(StringUtils.isNotBlank(report.getAreaCode())) {// 获取地区名称
            String areaName = ConstantsUtil.getAreaName(report.getAreaCode());
            report.setAreaName(areaName != null?  areaName: StringUtils.EMPTY);
        }

        return RestResult.ok(report);
    }
}

