package com.chinaweal.aiccs.aiccs.expelled.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chinaweal.aiccs.aiccs.expelled.entity.EntBaseExpelledInfo;
import com.chinaweal.aiccs.aiccs.expelled.entity.ExpelledApplyInfo;
import com.chinaweal.aiccs.aiccs.expelled.entity.ExpelledBizInfo;
import com.chinaweal.aiccs.aiccs.expelled.service.IEntBaseExpelledInfoService;
import com.chinaweal.aiccs.aiccs.expelled.service.IExpelledApplyInfoService;
import com.chinaweal.aiccs.aiccs.expelled.service.IExpelledAuditInfoService;
import com.chinaweal.aiccs.aiccs.expelled.service.IExpelledBizInfoService;
import com.chinaweal.aiccs.aiccs.expelled.vo.AuditInfoVo;
import com.chinaweal.aiccs.aiccs.expelled.vo.BizInfoVo;
import com.chinaweal.aiccs.aiccs.expelled.vo.RemoveApproveInfo;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: 市场主体拟除名管理控制层
 * @Author: TiAmo-cc
 * @Email: 1049976610@qq.com
 * @Date: 2026/1/3 18:15
 */
@Api(tags = "1.市场主体拟除名管理控制层")
@ApiSort(1)
@RestController
@RequestMapping("/expelled")
@Slf4j
public class EntBaseExpelledInfoController extends BaseController {

    @Resource
    private IEntBaseExpelledInfoService entBaseExpelledInfoService;
    @Resource
    private IExpelledBizInfoService expelledBizInfoService;
    @Resource
    private IExpelledAuditInfoService expelledAuditInfoService;
    @Resource
    private IExpelledApplyInfoService expelledApplyInfoService;

    @ApiOperation(value = "1.分页查询市场主体拟除名名单信息", position = 1)
    @PostMapping("/list")
    public RestResult<IPage<EntBaseExpelledInfo>> list(@RequestBody BaseQuery<EntBaseExpelledInfo> query) {
        IPage<EntBaseExpelledInfo> data = entBaseExpelledInfoService.listEntBaseExpelledInfo(query);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "2.新增、更新、删除市场主体拟除名名单信息", position = 2)
    @PostMapping("/save")
    public RestResult<?> save(@RequestBody EntBaseExpelledInfo query) {
        entBaseExpelledInfoService.saveEntBaseExpelledInfo(query);
        return RestResult.ok();
    }

    @ApiOperation(value = "3.下载批量导入excel模板", position = 3)
    @GetMapping("/downloadTemplate")
    @ResponseBody
    public void downloadTemplate(HttpServletResponse response) {
        entBaseExpelledInfoService.downloadTemplate(response);
    }

    @ApiOperation(value = "4.批量导入市场主体拟除名名单信息", position = 4)
    @PostMapping("/batchImport")
    public RestResult batchImport(@RequestParam MultipartFile annex) throws IOException {
        if (annex == null || annex.isEmpty()) {
            return RestResult.error(ResultCode.PARAM_IS_BLANK);
        }
        String fileName = annex.getOriginalFilename();
        if (StringUtils.isBlank(fileName)
                || (!fileName.toLowerCase().endsWith(".xls") && !fileName.toLowerCase().endsWith(".xlsx"))) {
            return RestResult.error(ResultCode.BUSINESS_LOGIC_ERROR,"文件类型错误");
        }
        entBaseExpelledInfoService.batchImportExpelledInfo(annex);
        return RestResult.ok();
    }

    @ApiOperation(value = "5.启动除名告知业务", position = 5)
    @PostMapping("/notice/startBiz")
    public RestResult<?> startNoticeBiz(@RequestBody ExpelledBizInfo query, HttpServletRequest request) {
        return expelledBizInfoService.startNoticeBiz(query, request);
    }

    @ApiOperation(value = "6.获取除名告知业务详情", position = 6)
    @GetMapping("/notice/getBiz")
    public RestResult<?> getNoticeBiz(String bizId) {
        return expelledBizInfoService.getNoticeBiz(bizId);
    }

    @ApiOperation(value = "7.除名告知业务审批流程", position = 7)
    @PostMapping("/notice/nextBiz")
    public RestResult<?> nextNoticeBiz(@RequestBody RemoveApproveInfo removeApproveInfo, HttpServletRequest request) {
        return expelledBizInfoService.nextNoticeBiz(removeApproveInfo, request);
    }

    @ApiOperation(value = "8.分页查询可引用的市场主体拟除名告知业务信息", position = 8)
    @PostMapping("/notice/toDo")
    public RestResult<IPage<BizInfoVo>> listTodoNoticeInfo(@RequestBody BaseQuery<BizInfoVo> query) {
        IPage<BizInfoVo> data = expelledBizInfoService.listTodoNoticeInfo(query);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "9.启动除名异议业务", position = 9)
    @PostMapping("/objection/startBiz")
    public RestResult<?> startObjectionBiz(@RequestBody AuditInfoVo query, HttpServletRequest request) {
        return expelledAuditInfoService.startObjectionBiz(query, request);
    }

    @ApiOperation(value = "10.获取除名异议业务详情", position = 10)
    @GetMapping("/objection/getBiz")
    public RestResult<?> getObjectionBiz(String bizId) {
        return expelledAuditInfoService.getObjectionBiz(bizId);
    }

    @ApiOperation(value = "11.除名异议业务审批流程", position = 11)
    @PostMapping("/objection/nextBiz")
    public RestResult<?> nextObjectionBiz(@RequestBody RemoveApproveInfo removeApproveInfo, HttpServletRequest request) {
        return expelledAuditInfoService.nextObjectionBiz(removeApproveInfo, request);
    }

    @ApiOperation(value = "12.启动除名决定业务", position = 12)
    @PostMapping("/audit/startBiz")
    public RestResult<?> startAuditBiz(@RequestBody AuditInfoVo query, HttpServletRequest request) {
        return expelledAuditInfoService.startAuditBiz(query, request);
    }

    @ApiOperation(value = "13.获取除名决定业务详情", position = 13)
    @GetMapping("/audit/getBiz")
    public RestResult<?> getAuditBiz(String bizId) {
        return expelledAuditInfoService.getAuditBiz(bizId);
    }

    @ApiOperation(value = "14.除名决定业务审批流程", position = 14)
    @PostMapping("/audit/nextBiz")
    public RestResult<?> nextAuditBiz(@RequestBody RemoveApproveInfo removeApproveInfo, HttpServletRequest request) {
        return expelledAuditInfoService.nextAuditBiz(removeApproveInfo, request);
    }

    @ApiOperation(value = "15.分页查询除名公告管理", position = 15)
    @PostMapping("/announcement/list")
    public RestResult<IPage<AuditInfoVo>> listAnnouncement(@RequestBody BaseQuery<AuditInfoVo> query) {
        IPage<AuditInfoVo> data = expelledAuditInfoService.listHavedoAuditInfo(query);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "16.启动除名修复业务", position = 16)
    @PostMapping("/repair/startBiz")
    public RestResult<?> startRepairBiz(@RequestBody AuditInfoVo query, HttpServletRequest request) {
        return expelledApplyInfoService.startRepairBiz(query, request);
    }

    @ApiOperation(value = "17.获取除名修复业务详情", position = 17)
    @GetMapping("/repair/getBiz")
    public RestResult<?> getRepairBiz(String bizId) {
        return expelledApplyInfoService.getRepairBiz(bizId);
    }

    @ApiOperation(value = "18.除名修复业务审批流程", position = 18)
    @PostMapping("/repair/nextBiz")
    public RestResult<?> nextRepairBiz(@RequestBody RemoveApproveInfo removeApproveInfo, HttpServletRequest request) {
        return expelledApplyInfoService.nextRepairBiz(removeApproveInfo, request);
    }

    @ApiOperation(value = "19.启动除名复议业务", position = 19)
    @PostMapping("/review/startBiz")
    public RestResult<?> startReviewBiz(@RequestBody AuditInfoVo query, HttpServletRequest request) {
        return expelledApplyInfoService.startReviewBiz(query, request);
    }

    @ApiOperation(value = "20.获取除名复议业务详情", position = 20)
    @GetMapping("/review/getBiz")
    public RestResult<?> getReviewBiz(String bizId) {
        return expelledApplyInfoService.getReviewBiz(bizId);
    }

    @ApiOperation(value = "21.除名复议业务审批流程", position = 21)
    @PostMapping("/review/nextBiz")
    public RestResult<?> nextReviewBiz(@RequestBody RemoveApproveInfo removeApproveInfo, HttpServletRequest request) {
        return expelledApplyInfoService.nextReviewBiz(removeApproveInfo, request);
    }

    @ApiOperation(value = "22.启动除名撤销业务", position = 22)
    @PostMapping("/revoke/startBiz")
    public RestResult<?> startRevokeBiz(@RequestBody AuditInfoVo query, HttpServletRequest request) {
        return expelledApplyInfoService.startRevokeBiz(query, request);
    }

    @ApiOperation(value = "23.获取除名撤销业务详情", position = 23)
    @GetMapping("/revoke/getBiz")
    public RestResult<?> getRevokeBiz(String bizId) {
        return expelledApplyInfoService.getRevokeBiz(bizId);
    }

    @ApiOperation(value = "24.除名撤销业务审批流程", position = 24)
    @PostMapping("/revoke/nextBiz")
    public RestResult<?> nextRevokeBiz(@RequestBody RemoveApproveInfo removeApproveInfo, HttpServletRequest request) {
        return expelledApplyInfoService.nextRevokeBiz(removeApproveInfo, request);
    }

    @ApiOperation(value = "25.分页查询撤销除名公告管理", position = 25)
    @PostMapping("/revoke/listAnnouncement")
    public RestResult<IPage<ExpelledApplyInfo>> listRevokeAnnouncement(@RequestBody BaseQuery<ExpelledApplyInfo> query) {
        IPage<ExpelledApplyInfo> data = expelledApplyInfoService.listRevokeAnnouncement(query);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "26.下载除名告知书", position = 26)
    @GetMapping("/downloadNoticeDoc")
    @ResponseBody
    public void downloadNoticeDoc(HttpServletResponse response, String noticeNo) {
        expelledBizInfoService.downloadNoticeDoc(response, noticeNo);
    }

    @ApiOperation(value = "27.下载除名决定书", position = 27)
    @GetMapping("/downloadAuditDoc")
    @ResponseBody
    public void downloadAuditDoc(HttpServletResponse response, String resultId, String noticeNo) {
        expelledAuditInfoService.downloadAuditDoc(response, resultId, noticeNo);
    }

    @ApiOperation(value = "27.下载文书", position = 27)
    @GetMapping("/downloadDoc")
    @ResponseBody
    public void downloadDoc(HttpServletResponse response, String bizId, String attachType) {
        expelledApplyInfoService.downloadApproveDoc(response, bizId, attachType);
    }
}
