package com.yh.saas.plugin.news.controller;


import com.winsea.svc.base.base.constant.SystemConstant;
import com.winsea.svc.base.base.entity.CommonParameterCompany;
import com.yh.saas.plugin.news.command.ParameterCompanyCommand;
import com.yh.saas.plugin.news.entity.ParameterCompany;
import com.yh.saas.plugin.news.service.INewsParameterCompanyService;
import com.yh.saas.plugin.news.vo.ParameterCompanyVo;
import com.yh.saas.common.support.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Chenly
 * @since 2019-10-10
 */
@Api(value="基础数据",description = "基础数据管理")
@RestController
@RequestMapping("/newsParameterCompany")
public class NewsParameterCompanyController {

    @Autowired
    private INewsParameterCompanyService parameterCompanyService;

    @ApiOperation(value="查询工程类别信息",notes = "查询语言")
    @ApiImplicitParam( value="constCode（ APPROVE_UNIT：批准单位 LANGUAGE：语种 DEFECT_CATEGORY：缺陷类别 CIRCULAR_NOTICE：通函通知 缺陷类别 ACTION_CODE：行动代码 HANDLE_CODE：处理决定）")
    @GetMapping("/query/getParameterCompany")
    public List<ParameterCompanyVo> getParameterCompany(@RequestParam(required = true) String constCode, String parameterValue) {
        return parameterCompanyService.getParameterCompany(constCode,parameterValue);
    }

    @ApiOperation(value="查询工程类别信息",notes = "查询语言")
    @ApiImplicitParam( value="constCode（ APPROVE_UNIT：批准单位 LANGUAGE：语种 DEFECT_CATEGORY：缺陷类别 CIRCULAR_NOTICE：通函通知）")
    @GetMapping("/query/getParameterCompanyLanguage")
    public List<ParameterCompanyVo> getParameterCompanyLanguage(@RequestParam(required = true) String constCode, String parameterValue) {
        return parameterCompanyService.getParameterCompany(constCode,parameterValue);
    }

    @ApiOperation(value="查询工程类别信息",notes = "查询批准单位")
    @ApiImplicitParam( value="constCode（ APPROVE_UNIT：批准单位 LANGUAGE：语种 DEFECT_CATEGORY：缺陷类别 CIRCULAR_NOTICE：通函通知）")
    @GetMapping("/query/getParameterCompanyApprovedUnit")
    public List<ParameterCompanyVo> getParameterCompanyApprovedUnit(@RequestParam(required = true) String constCode, String parameterValue) {
        return parameterCompanyService.getParameterCompany(constCode,parameterValue);
    }

    @ApiOperation(value="查询工程类别信息",notes = "查询通函类别")
    @ApiImplicitParam( value="constCode（ APPROVE_UNIT：批准单位 LANGUAGE：语种 DEFECT_CATEGORY：缺陷类别 CIRCULAR_NOTICE：通函通知）")
   // @PluginFeature(id = "CircularCategory", name = "基础数据通函类别")
    @GetMapping("/query/getParameterCompanyCircularCategory")
    public List<ParameterCompanyVo> getParameterCompanyCircularCategory(@RequestParam(required = true) String constCode, String parameterValue) {
        return parameterCompanyService.getParameterCompany(constCode,parameterValue);
    }

    @ApiOperation(value="查询工程类别信息",notes = "查询缺陷类别")
    @ApiImplicitParam( value="constCode（ APPROVE_UNIT：批准单位 LANGUAGE：语种 DEFECT_CATEGORY：缺陷类别 CIRCULAR_NOTICE：通函通知）")
    @GetMapping("/query/getParameterCompanyDefectCategory")
    public List<ParameterCompanyVo> getParameterCompanyDefectCategory(@RequestParam(required = true) String constCode, String parameterValue) {
        return parameterCompanyService.getParameterCompany(constCode,parameterValue);
    }

    @ApiOperation(value="删除工程类别",notes = "根据主键删除工程类别")
    @PostMapping("/api/deleteParameterCompanyById")
    public void deleteParameterCompanyById(@RequestParam(required = true) String id) {
        parameterCompanyService.deleteParameterCompanyById(id);
    }

    @ApiOperation(value="保存工程类别",notes = "保存工程类别")
    @PostMapping("/api/saveParameterCompany")
    public String saveParameterCompanyById(@RequestBody @Validated ParameterCompanyCommand form) {
        return parameterCompanyService.saveParameterCompany(form);
    }

    @ApiOperation(value="调整顺序",notes = "根据主键调整顺序")
    @ApiImplicitParam( value="parameterId 主键以中文逗号分隔")
    @PostMapping("/api/changeOrder")
    public void changeOrder(@RequestParam(required = true) String id) {
        parameterCompanyService.changeOrder(id);
    }

    /**
     * 批量更新或新增常量
     * @param parameterList
     */
    @PostMapping("/api/createOrUpdateParameterList")
    public void createOrUpdateParameterList(@RequestBody List<CommonParameterCompany> parameterList) {
        parameterCompanyService.createOrUpdateList(parameterList);
    }

    /**
     * 根据 变量const 查询集合 不区分公司，所有公司用一套
     *
     * @param parameterCompany 变量const
     * @return 集合
     */
    @GetMapping("/query/querySystemParameter")
    public List<CommonParameterCompany> querySystemParameter(ParameterCompany parameterCompany) {
        parameterCompany.setCompId(SystemConstant.SYSTEM_COMP_ID);
        return parameterCompanyService.queryCommonParameterTenant(parameterCompany);
    }

    /**
     * 根据类型查询
     * @param parameterCompany
     * @return
     */
    @GetMapping("/query/parameterTenant")
    public List<CommonParameterCompany> queryCommonParameterTenant(ParameterCompany parameterCompany) {
        if (StringUtils.isEmpty(parameterCompany.getCompId())) {
            parameterCompany.setCompId(SystemConstant.SYSTEM_COMP_ID);
        }
        return parameterCompanyService.queryCommonParameterTenant(parameterCompany);
    }



}

