package com.chinaweal.aiccs.aiccs.blacklist.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chinaweal.aiccs.aiccs.blacklist.entity.TPyBlacklist;
import com.chinaweal.aiccs.aiccs.blacklist.service.ITPyBlacklistService;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.page.PageRequestDto;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.sso.util.SSOUtil;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * <p>
 * 番禺企业黑名单库 控制器
 * </p>
 *
 * @author chinaweal
 * @since 2024-06-27
 */
@Api(tags = "番禺企业黑名单库")
@ApiSort(1)
@RestController
@RequestMapping("/py/blacklist")
public class TPyBlacklistController {

    @Resource
    private ITPyBlacklistService iTPyBlacklistService;

    @ApiOperation(value = "分页查询番禺企业黑名单库")
    @PostMapping("/list")
    public RestResult<IPage<TPyBlacklist>> listTPyBlacklist(@RequestBody PageRequestDto pageRequestDto) {
        IPage<TPyBlacklist> data = iTPyBlacklistService.defaultPaging(pageRequestDto, wrapper -> {
            wrapper.lambda().eq(TPyBlacklist::getIsDisabled, false);
        }, null);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "导入黑名单市场主体（番禺）")
    @PostMapping("/importBlacklist")
    public RestResult<?> importBlacklist(MultipartFile file) {
        iTPyBlacklistService.importBlacklist(file);
        return RestResult.ok();
    }

    @ApiOperation(value = "是否存在番禺黑名单中")
    @GetMapping("/check")
    public RestResult<?> check(@ApiParam("统一社会信用代码") @RequestParam String uniscid,
                               @ApiParam("标注类型") @RequestParam String tagType) {
        return RestResult.ok(iTPyBlacklistService.check(uniscid, tagType));
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public RestResult<?> delete(@ApiParam("id") @RequestParam String id) {
        TPyBlacklist tPyBlacklist = iTPyBlacklistService.getById(id);
        if (StringUtils.isNotBlank(tPyBlacklist.getUniscid())) {
            iTPyBlacklistService.update(Wrappers.<TPyBlacklist>lambdaUpdate().set(TPyBlacklist::getIsDisabled, true).eq(TPyBlacklist::getId, tPyBlacklist.getId()));
        }
        return RestResult.ok();
    }
}
