package com.usky.fire.controller.web;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.fire.domain.DemLawSituation;
import com.usky.fire.service.DemLawSituationService;
import com.usky.fire.service.vo.DemLawSituationExportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 行政处罚情况表 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-09-27
 */
@RestController
@RequestMapping("/demLawSituation")
public class DemLawSituationController {

    @Autowired
    private DemLawSituationService demLawSituationService;

    /**
     * 处罚整改数据-列表查询
     *
     * @param punishedPerson      被处罚人
     * @param legalRepresentative 行政相对人类别
     * @param id                  主键ID
     * @param pageNum             当前页
     * @param pageSize            每页条数
     * @return
     */
    @GetMapping("lawSituationList")
    public ApiResult<CommonPage<Object>> lawSituationList(@RequestParam(value = "punishedPerson", required = false) String punishedPerson,
                                                          @RequestParam(value = "legalRepresentative", required = false) String legalRepresentative,
                                                          @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                                                          @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(demLawSituationService.lawSituationList(punishedPerson, legalRepresentative, id, pageNum, pageSize));
    }

    /**
     * 处罚整改数据-列表查询-导出
     *
     * @param punishedPerson      被处罚人
     * @param legalRepresentative 法人代表
     * @param id                  主键ID
     * @param exportTitle         文件名
     * @throws IOException
     */
    @PostMapping("lawSituationListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "punishedPerson", required = false) String punishedPerson,
                       @RequestParam(value = "legalRepresentative", required = false) String legalRepresentative,
                       @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                       @RequestParam(value = "exportTitle") String exportTitle) throws IOException{
        List<DemLawSituationExportVO> list = demLawSituationService.lawSituationListExport(punishedPerson, legalRepresentative, id);
        ExcelUtil<DemLawSituationExportVO> util = new ExcelUtil<DemLawSituationExportVO>(DemLawSituationExportVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }


    /**
     * 处罚整改数据-修改
     *
     * @param demLawSituation
     */
    @Log(title = "处罚整改数据-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateLawSituation")
    public ApiResult<Void> updateLawSituation(@RequestBody DemLawSituation demLawSituation) {
        demLawSituationService.updateLawSituation(demLawSituation);
        return ApiResult.success();
    }

    /**
     * 处罚整改数据-删除
     *
     * @param id 主键ID
     */
    @Log(title = "处罚整改数据-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delLawSituation")
    public ApiResult<Void> delLawSituation(@RequestParam(value = "id") Integer id) {
        demLawSituationService.delLawSituation(id);
        return ApiResult.success();
    }
}

