package com.unis.base.server.controller;

import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.CompanyQualificationInfoVO;
import com.unis.base.common.vo.CompanyQualificationQueryVO;
import com.unis.base.common.vo.TyHtxxVO;
import com.unis.base.server.service.CompanyQualificationService;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zoujieli
 * @Date 2019/9/6 21:14
 * Version 1.0
 */

@RestController
@Api(value = "企业资格信息", tags = "企业资格信息维护")
@Slf4j
public class CompanyQualificationController {

    @Autowired
    private CompanyQualificationService companyQualService;

    @ApiOperation(value = "分页获取企业资格信息列表", notes = "参数:统一社会信用代码,企业ID,资格类型代码")
    @PostMapping(value = "/companyQualification/{pageNum}/{pageSize}")
    public ResponseWrapper getCompanyQualificationPage(@RequestBody CompanyQualificationQueryVO companyQualQueryVO,
                                                       @PathVariable("pageNum")Integer pageNum,
                                                       @PathVariable("pageSize") Integer pageSize){
        try {
            PageInfo<CompanyQualificationInfoVO> pageInfo = new PageInfo<>(companyQualService.getCompanyQualificationPage(companyQualQueryVO,pageNum,pageSize));
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), pageInfo);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }

    @ApiOperation(value = "获取企业资格信息列表", notes = "参数:统一社会信用代码,企业ID,资格类型代码,orgid")
    @PostMapping(value = "/companyQualification")
    public ResponseWrapper getCompanyQualificationList(@RequestBody CompanyQualificationQueryVO companyQualQueryVO){
        try {
            List<CompanyQualificationInfoVO> companyQualInfoVOList = companyQualService.getCompanyQualificationList(companyQualQueryVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), companyQualInfoVOList);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }

    @ApiOperation(value = "获取企业资格信息详情", notes = "参数:统一社会信用代码,资格类型代码")
    @PostMapping(value = "/companyQualificationInfo")
    public ResponseWrapper getCompanyQualificationInfo(@RequestParam(value = "qyId") Integer qyId,
                                                       @RequestParam(value = "zglxDm") String zglxDm){
        try {
            CompanyQualificationInfoVO qualificationInfoVO = companyQualService.getCompanyQualificationInfo(qyId,zglxDm);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(),qualificationInfoVO);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }

}
