package com.chinaweal.aiccs.aiccs.force.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chinaweal.aiccs.aiccs.business.entity.dto.ApprovalFormDto;
import com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterRem;
import com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterRes;
import com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterSpe;
import com.chinaweal.aiccs.aiccs.force.service.IXrForceDeregisterRemService;
import com.chinaweal.aiccs.aiccs.force.service.IXrForceDeregisterResService;
import com.chinaweal.aiccs.aiccs.force.service.IXrForceDeregisterService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 拟强制注销公告详细 控制器
 *
 * @author zhouxy
 * @since 2025/10/7
 */
@Api(tags = "拟强制注销公告详细")
@RestController
@RequestMapping("/XrForceDeregister")
@Slf4j
public class XrForceDeregisterController extends BaseController {

    @Resource
    private IXrForceDeregisterService iXrForceDeregisterService;
    @Resource
    private IXrForceDeregisterRemService iXrForceDeregisterRemService;
    @Resource
    private IXrForceDeregisterResService iXrForceDeregisterResService;


    @ApiOperation(value = "1.业务号获取审批表", position = 1)
    @GetMapping("/getApprovalFormByBizSeqNo")
    public RestResult<ApprovalFormDto> getApprovalFormByBizSeqNo(@RequestParam @ApiParam("id") String bizSeqNo, String forceSpeId) {
        ApprovalFormDto approvalDto = iXrForceDeregisterService.getApprovalFormByBizSeqNo(bizSeqNo, forceSpeId);
        return RestResult.ok(approvalDto);
    }

    @ApiOperation(value = "2.生成强制注销决定书内容", position = 2)
    @PostMapping("/getDecisionContent")
    public RestResult<?> getDecisionContent(@RequestBody XrForceDeregisterSpe xrForceDeregisterSpe, HttpServletRequest request) {
        AICUser user = getLoginUser(request);
        String noticeContent = iXrForceDeregisterService.getDecisionContent(user,xrForceDeregisterSpe);
        if(noticeContent != null){
            return RestResult.ok(noticeContent);
        } else {
            return RestResult.error(ResultCode.PARAM_IS_BLANK);
        }
    }

    @ApiOperation(value = "3.生成强制注销送达公告内容", position = 3)
    @PostMapping("/getForceNoticeContent")
    public RestResult<?> getForceNoticeContent(@RequestBody XrForceDeregisterSpe xrForceDeregisterSpe, HttpServletRequest request) {
        AICUser user = getLoginUser(request);
        String noticeContent = iXrForceDeregisterService.getForceNoticeContent(user,xrForceDeregisterSpe);
        if(noticeContent != null){
            return RestResult.ok(noticeContent);
        } else {
            return RestResult.error(ResultCode.PARAM_IS_BLANK);
        }
    }

    @ApiOperation(value = "4.业务号查询强制注销详细数据", position = 4)
    @GetMapping("/selectByBizSeqNo")
    public RestResult<XrForceDeregisterRes> selectByBizSeqNo(@RequestParam @ApiParam("id") String bizSeqNo) {
        LambdaQueryWrapper<XrForceDeregisterRem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(XrForceDeregisterRem::getBizSeqNo, bizSeqNo);
        XrForceDeregisterRem xrForceRem = iXrForceDeregisterRemService.getOne(queryWrapper);
        XrForceDeregisterRes xrForceDeregisterRes = iXrForceDeregisterResService.getById(xrForceRem.getForceResId());
        return RestResult.ok(xrForceDeregisterRes);
    }

}
