package com.zjrs.zwnw.sxgl.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.zwnw.sxgl.bpo.HcpglBPO;
import com.zjrs.zwnw.sxgl.dto.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
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;

@Api("好差评管理")
@RestController
@RequestMapping("/api/sxgl/hcpgl")
public class HcpglController {
	
    private static final Logger LOG = LoggerFactory.getLogger(HcpglController.class);

    @Resource
    private HcpglBPO hcpglBPO;

    @ApiOperation(value = "查询好差评列表", notes = "查询好差评列表")
    @PostMapping("/getHcpList")
    public AjaxResponse getHcpList(@RequestBody @Validated HcpQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
            ajaxResponse = hcpglBPO.getHcpList(dto);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

    @ApiOperation(value = "修改好差评评价信息", notes = "修改好差评评价信息")
    @PostMapping("/editHcp")
    public AjaxResponse editHcp(@RequestBody @Validated HcpEditDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
            ajaxResponse = hcpglBPO.editHcp(dto);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "查询主办科室", notes = "查询主办科室")
    @PostMapping("/getZbks")
    public AjaxResponse getZbks(@RequestBody @Validated ZbksQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
            ajaxResponse = hcpglBPO.getZbks(dto);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "查询一窗通办评价办件信息", notes = "查询一窗通办评价办件信息")
    @PostMapping("/getSlxx")
    public AjaxResponse getSlxx(@RequestBody @Validated HcpCkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
            ajaxResponse = hcpglBPO.getSlxx(dto);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

    @ApiOperation(value = "保存一窗通办评价信息", notes = "保存一窗通办评价信息")
    @PostMapping("/saveHcp")
    public AjaxResponse saveHcp(@RequestBody @Validated HcpCkDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
            ajaxResponse = hcpglBPO.saveCkHcp(dto);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}
