package com.chinaweal.aiccs.aiccs.seriousillegal.controller;

import cn.hutool.core.util.IdUtil;
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.seriousillegal.entity.TSBizSerIllegalDiss;
import com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList;
import com.chinaweal.aiccs.aiccs.seriousillegal.entity.dto.DissentIllegalAppDto;
import com.chinaweal.aiccs.aiccs.seriousillegal.service.TSBizSerIllegalDissService;
import com.chinaweal.aiccs.aiccs.seriousillegal.service.TSSerIllegalListService;
import com.chinaweal.aiccs.aiccs.system.service.TRBaseCodeService;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 严重违法失信异议移动端
 *
 * @author ymc
 * @since 2024年09月14日 11:58
 */
@Slf4j
@RestController
@RequestMapping("/wx/bizSerIllegalDiss")
public class BizSerIllegalDissAppController {

    @Autowired
    private TSBizSerIllegalDissService tsBizSerIllegalDissService;
    @Resource
    private EBaseinfoService eBaseinfoService;
    @Autowired
    private TSSerIllegalListService tsSerIllegalListService;

    /**
     * 启动待办
     *
     * @param dissentIllegalAppDto
     * @return
     * @author ymc
     * @since 2024年9月14日 10:06
     */
    @PostMapping("/startAppDissent")
    public RestResult<?> startAppDissent(@RequestBody DissentIllegalAppDto dissentIllegalAppDto) {
        tsBizSerIllegalDissService.startAppDissent(dissentIllegalAppDto);
        return RestResult.ok();
    }


    /**
     * 办理页面
     *
     * @param dissentIllegalAppDto
     * @param request
     * @return
     * @author ymc
     * @since 2024年9月14日 15:40
     */
    @PostMapping(value = "/info")
    public Map<String, Object> info(@RequestBody DissentIllegalAppDto dissentIllegalAppDto, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>();
        String uniscid = dissentIllegalAppDto.getUniscid();
        String illegalListID = dissentIllegalAppDto.getIllegalListID();

        // 封装参数
        LambdaQueryWrapper<EBaseinfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EBaseinfo::getUniscid, uniscid);
        wrapper.eq(EBaseinfo::getRegstate, "1");
        wrapper.select(EBaseinfo::getPripid, EBaseinfo::getCerno,
                EBaseinfo::getUniscid, EBaseinfo::getRegno,
                EBaseinfo::getEntname, EBaseinfo::getDom,
                EBaseinfo::getName, EBaseinfo::getPhone);

        // 查询基本信息
        EBaseinfo eBaseinfo = eBaseinfoService.getOne(wrapper);

        // 严重违法信息
        TSSerIllegalList serIllegalList = tsSerIllegalListService.getById(illegalListID);

        result.put("eBaseinfo", eBaseinfo); //企业基本信息
        result.put("bizseqUp", IdUtil.randomUUID());
        result.put("illegalList", serIllegalList); //严重违法信息
        return result;
    }


    /**
     * 检验该笔件已经在申请中了
     * @author ymc
     * @since 2024年9月24日 9:56
     * @param illegalListID
     * @return
     */
    @GetMapping(value = "/checkTaskList")
    public RestResult<?> checkTaskList(@RequestParam String illegalListID) {
        TSBizSerIllegalDiss bizSerIllegalDiss = tsBizSerIllegalDissService.lambdaQuery().eq(TSBizSerIllegalDiss::getIllegalListID, illegalListID).notIn(TSBizSerIllegalDiss::getStatus, "3", "4").one();
        if (bizSerIllegalDiss != null) {
            return RestResult.ok(bizSerIllegalDiss.getStatus());
        } else {
            return RestResult.ok(false);
        }
    }
}
