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


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo;
import com.chinaweal.aiccs.aiccs.abnormal.service.EBaseinfoService;
import com.chinaweal.aiccs.aiccs.revoke.Vo.CaseVo;
import com.chinaweal.aiccs.aiccs.revoke.entity.Illegalact;
import com.chinaweal.aiccs.aiccs.revoke.entity.TsCase;
import com.chinaweal.aiccs.aiccs.revoke.entity.Tsbizrevlist;
import com.chinaweal.aiccs.aiccs.revoke.service.CaseService;
import com.chinaweal.aiccs.aiccs.revoke.service.IllegalactService;
import com.chinaweal.aiccs.aiccs.revoke.service.TsbizrevlistService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aiccs.common.constant.BaseDataConstant;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

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

import java.util.List;


/**
 * <p>
 * 案件审批表 前端控制器
 * </p>
 *
 * @author Lee
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/case")
public class CaseController extends BaseController {

    @Autowired
    private CaseService caseService;
    @Autowired
    private TsbizrevlistService tsbizrevlistService;
    @Autowired
    private EBaseinfoService eBaseinfoService;
    @Autowired
    private IllegalactService illegalactService;

    /**
     * 通过业务id获取相应案件信息
     * @param bizseq
     * @return
     */
    @GetMapping("getCaseByBizseq")
    public RestResult<?> getCaseByBizseq(String bizseq){
        AssertUtils.isNotBlank(bizseq);
        LambdaQueryWrapper<TsCase> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TsCase::getBizseq,bizseq);
        TsCase tsCase = caseService.getOne(wrapper);
        CaseVo caseVo = new CaseVo();

        BeanUtils.copyProperties(tsCase,caseVo);
        // 违法类型中文
        String illegalTypeCn = BaseDataConstant.REVOKE_ILLEGALTYPE_MAP.get(caseVo.getIllegalType());
        if(StringUtils.isNotEmpty(illegalTypeCn)) {
            caseVo.setIllegalTypeCn(illegalTypeCn);
        }
        //以拟吊销主体列表第一个回显
//        LambdaQueryWrapper<Tsbizrevlist> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(Tsbizrevlist::getBizseq,bizseq).ne(Tsbizrevlist::getIsRemove,'1');
//        List<Tsbizrevlist> list = tsbizrevlistService.list(queryWrapper);
//        String pripid = list.get(0).getPripid();
//        EBaseinfo eBaseinfo = eBaseinfoService.getById(pripid);
//        caseVo.setEntname(eBaseinfo.getEntname());
//        caseVo.setIndustryphy(eBaseinfo.getIndustryphy());//行业分类
//        caseVo.setIndustryco(eBaseinfo.getIndustryco());//行业代码
//        caseVo.setEnttype(eBaseinfo.getEnttype());
//        caseVo.setEnttypeCn(eBaseinfo.getEnttypeCn());
//        caseVo.setUniscid(eBaseinfo.getUniscid());
//        caseVo.setRegno(eBaseinfo.getRegno());
//        caseVo.setName(eBaseinfo.getName());
//        caseVo.setDom(eBaseinfo.getDom());
        //封装违法行为信息
//        List<Illegalact> illegalactList = illegalactService.list(new LambdaQueryWrapper<Illegalact>().eq(Illegalact::getCaseId, tsCase.getCaseId()));
//        caseVo.setIllegactList(illegalactList);

        return RestResult.ok(caseVo);
    }

}

