package com.zjrs.ggfw.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.mohrss.leaf.core.framework.persistens.PageResult;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.ggfw.portal.bpo.CommBPO;
import com.zjrs.ggfw.portal.dto.*;
import com.zjrs.ggfw.portal.po.VRsWbRmfw;
import com.zjrs.ggfw.portal.po.VRsWbRmsx;
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.*;

import java.util.List;
import java.util.Map;


/***
 * 公共Controller
 *
 * @author 2020-12-02
 *
 */
@Api("公共服务")
@RestController
@RequestMapping("/api/portal/comm")
public class CommController {
    /**
     * 日志
     */
    private static final Logger LOG = LoggerFactory.getLogger(CommController.class);
    
    @Resource
    private CommBPO commBPO;

    /**
     * 获取静态字典
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取静态字典", notes = "获取静态字典")
    @PostMapping("/getDict")
    public AjaxResponse getDict(@RequestBody @Validated DictQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
	        Map<String, Object> resultMap = commBPO.getDict(dto);
	        ajaxResponse.setData("data", resultMap);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    /**
     * 获取湛江市行政区划
     * @param 
     * @return
     */
    @ApiOperation(value = "获取湛江市行政区划", notes = "获取湛江市行政区划")
    @GetMapping("/getZjXzqhDict")
    public AjaxResponse getZjXzqhDict() {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
	        Map<String, Object> resultMap = commBPO.getZjXzqhDict();
	        ajaxResponse.setData("data", resultMap);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取行政区划", notes = "获取行政区划")
    @PostMapping("/getXzqhDict")
    public AjaxResponse getXzqhDict(@RequestBody @Validated XzqhQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = commBPO.getXzqhDict(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取所属行业", notes = "获取所属行业")
    @PostMapping("/getSshy")
    public AjaxResponse getSshy(@RequestBody @Validated SshyQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = commBPO.getSshy(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    /**
     * 获取事项列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取事项列表", notes = "获取事项列表")
    @PostMapping("/querySxList")
    public AjaxResponse getSxList(@RequestBody @Validated SxQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
	        PageResult pageResult = commBPO.getSxList(dto);
            ajaxResponse.setData("data", pageResult);
            ajaxResponse.setData("pagesize", dto.getPagesize());
            ajaxResponse.setData("pagenum", dto.getPagenum());
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取政策法规业务主题记录数", notes = "获取政策法规业务主题记录数")
    @PostMapping("/getZcfgYwztCntList")
    public AjaxResponse getZcfgYwztCntList() {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	
        try {
        	ajaxResponse = commBPO.getZcfgYwztCntList();
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    /**
     * 获取政策法规
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取政策法规", notes = "获取政策法规")
    @PostMapping("/queryZcfgList")
    public AjaxResponse queryZcfgList(@RequestBody @Validated ZcfgQueryDTO dto, BindingResult bindingResult) {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	//校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	if(StringUtils.isBlank(dto.getXxlx())) {
        		ajaxResponse.setAppcode("1");
                ajaxResponse.setErrorMsg("消息类型不能为空");
                return ajaxResponse;
        	}
        	PageResult pageResult = commBPO.getZcfgList(dto);
	        ajaxResponse.setData("data", pageResult);
	        ajaxResponse.setData("pagesize", dto.getPagesize());
            ajaxResponse.setData("pagenum", dto.getPagenum());
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    /**
     * 获取政策法规附件
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取政策法规附件", notes = "获取政策法规附件")
    @PostMapping("/queryZcfgFjList")
    public AjaxResponse queryZcfgFjList(@RequestBody @Validated ZcfgfjQueryDTO dto, BindingResult bindingResult) {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	//校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	PageResult pageResult = commBPO.getZcfgFjList(dto);
	        ajaxResponse.setData("data", pageResult);
	        ajaxResponse.setData("pagesize", dto.getPagesize());
            ajaxResponse.setData("pagenum", dto.getPagenum());
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取热门事项列表", notes = "获取热门事项列表")
    @GetMapping("/getRmSxList")
    public AjaxResponse getRmSxList(@Validated RmsxQueryDTO dto, BindingResult bindingResult) {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	//校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	List<VRsWbRmsx> VRsWbRmsxList = commBPO.getRmSxList(dto);
        	ajaxResponse.setData("data", VRsWbRmsxList);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取热门服务", notes = "获取热门服务")
    @GetMapping("/getRmFwList")
    public AjaxResponse getRmFwList() {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
        	List<VRsWbRmfw> VRsWbRmfwList = commBPO.getRmFwList();
        	ajaxResponse.setData("data", VRsWbRmfwList);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取高层次人才卡", notes = "获取高层次人才卡")
    @PostMapping("/getGccrck")
    public AjaxResponse getGccrck(@RequestBody @Validated GccrcQueryDTO dto, BindingResult bindingResult) {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	//校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = commBPO.getGccrck(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取高校毕业生学生档案", notes = "获取高校毕业生学生档案")
    @PostMapping("/getGxbysXsda")
    public AjaxResponse getGxbysXsda(@RequestBody @Validated GxbysdaQueryDTO dto, BindingResult bindingResult) {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	//校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = commBPO.getGxbysXsda(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取高校毕业生人事代理档案", notes = "获取高校毕业生人事代理档案")
    @PostMapping("/getGxbysRsdlda")
    public AjaxResponse getGxbysRsdlda(@RequestBody @Validated GxbysdaQueryDTO dto, BindingResult bindingResult) {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	//校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = commBPO.getGxbysRsdlda(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    /**
     * 获取政策法规
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取最新政策法规", notes = "获取最新政策法规")
    @PostMapping("/getLatestZcfg")
    public AjaxResponse getLatestZcfg(@RequestBody @Validated ZcfgQueryDTO dto, BindingResult bindingResult) {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	//校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
            ajaxResponse = commBPO.getLatestZcfg(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

}