package com.chinaweal.aiccs.crgs.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaweal.aiccs.crgs.entity.CppenaltyInfoGs;
import com.chinaweal.aiccs.crgs.service.ICppenaltyInfoGsService;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
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 javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 行政处罚信息 控制器
 * </p>
 *
 * @author chinaweal
 * @since 2021-12-25
 */
@Api(tags = "行政处罚信息")
@ApiSort(1)
@RestController
@RequestMapping("/crgs/cppenaltyInfoGs")
public class CppenaltyInfoGsController {

    @Resource
    private ICppenaltyInfoGsService iCppenaltyInfoGsService;

    @ApiOperation(value = "1.通过主键查询", position = 1)
    @GetMapping("/getById")
    public RestResult<CppenaltyInfoGs> getById(@RequestParam String caseId) {
        CppenaltyInfoGs cppenaltyInfoGs = iCppenaltyInfoGsService.getById(caseId);
        return RestResult.ok(cppenaltyInfoGs);
    }

    @ApiOperation(value = "2.通过处罚决定书文号模糊搜索", position = 2)
    @GetMapping("/likePendecNo")
    public RestResult<List<CppenaltyInfoGs>> likePendecNo(@RequestParam @ApiParam("pendecNo") String pendecNo,
                                                          @RequestParam @ApiParam("caseName") String caseName) {
        LambdaQueryWrapper<CppenaltyInfoGs> lqw= Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(pendecNo), CppenaltyInfoGs::getPendecNo, pendecNo);
        lqw.like(StringUtils.isNotBlank(caseName), CppenaltyInfoGs::getCaseName,caseName);
        //默认最多查询25条
        Page<CppenaltyInfoGs> page = iCppenaltyInfoGsService.page(new Page<>(0, 5,false), lqw);
        return RestResult.ok(page.getRecords());
    }

}
