package com.zjrs.zwnw.sxgl.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.persistens.PageResult;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.zwnw.sxgl.bpo.SxclwhBPO;
import com.zjrs.zwnw.sxgl.dto.SxclwhDTO;
import com.zjrs.zwnw.sxgl.dto.SxclwhDeleteDTO;
import com.zjrs.zwnw.sxgl.dto.SxclwhQueryDTO;
import com.zjrs.zwnw.sxgl.po.SdzlsxPO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.Map;

@Api("事项材料维护")
@RestController
@RequestMapping("/api/sxgl/sxclwh")
public class SxclwhController {
    private static final Logger LOG = LoggerFactory.getLogger(SxclwhController.class);

    @Resource
    private SxclwhBPO sxclwhBPO;

    /**
     * 根据条件查询事项材料列表
     *
     * @param dto 查询条件
     * @return 分页list
     */
    @ApiOperation(value = "根据条件查询事项材料列表", notes = "根据条件查询事项材料列表")
    @PostMapping("/querySxclList")
    public AjaxResponse querySxclList(@RequestBody SxclwhQueryDTO dto) {
        LOG.info("查询事项材料列表开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        Integer pagenum = dto.getPagenum();
        Integer pagesize = dto.getPagesize();
        try {
            PageResult pageResult = sxclwhBPO.querySxclList(dto, pagenum, pagesize);
            ajaxResponse.setData("data", pageResult);
            ajaxResponse.setData("pagesize", pagesize);
            ajaxResponse.setData("pagenum", pagenum);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("查询事项材料列表结束");
        return ajaxResponse;
    }

    /**
     * 新增事项材料
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增事项材料", notes = "新增事项材料")
    @PostMapping("/addSxcl")
    public AjaxResponse addSxcl(@RequestBody SxclwhDTO dto) {
        LOG.info("新增事项材料开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            Map<String, String> resultMap = this.sxclwhBPO.addSxcl(dto);
            ajaxResponse.setAppcode(resultMap.get("code"));
            ajaxResponse.setMsg(resultMap.get("msg"));
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("新增事项材料结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "更新事项材料", notes = "更新事项材料")
    @PostMapping("/updateSxcl")
    public AjaxResponse updateSxcl(@RequestBody SxclwhDTO dto) {
        LOG.info("更新事项材料开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            Map<String, String> resultMap = this.sxclwhBPO.updateSxcl(dto);
            ajaxResponse.setAppcode(resultMap.get("code"));
            ajaxResponse.setMsg(resultMap.get("msg"));
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("更新事项材料结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "查询事项材料详情", notes = "查询事项材料详情")
    @PostMapping("/getSxclById")
    public AjaxResponse getSxclById(@RequestBody SxclwhQueryDTO dto) {
        LOG.info("查询事项材料详情开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            SdzlsxPO sdzlsxPo = this.sxclwhBPO.getSxclById(dto);
            ajaxResponse.setData("data", sdzlsxPo);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("查询事项材料详情结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "批量删除材料", notes = "批量删除材料")
    @PostMapping("/deleteSxclByIds")
    public AjaxResponse deleteSxclByIds(@RequestBody @Valid SxclwhDeleteDTO dto) {
        LOG.info("批量删除材料开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            Map<String, String> resultMap = this.sxclwhBPO.deleteSxclByIds(dto);
            ajaxResponse.setAppcode(resultMap.get("code"));
            ajaxResponse.setMsg(resultMap.get("msg"));
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("批量删除材料结束");
        return ajaxResponse;
    }
}
