package com.huatek.busi.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.dto.SysConfigDTO;
import com.huatek.busi.entity.SysConfig;
import com.huatek.busi.service.SysConfigService;
import com.huatek.torch.frame.log.KerLog;
import com.huatek.torch.frame.permission.KerPermission;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

/**
 * 系统配置
 *
 * @author edward_luo
 * @date Jun 25, 2019 15:58:32 PM
 */
@RestController
@RequestMapping("/api/sysConfig")
public class SysConfigController {

    protected final Logger logger = LoggerFactory.getLogger(SysConfigController.class);

    @Reference(check = false)
    private SysConfigService sysConfigService;
    

     /**
     * 参数管理列表
     *
     * @param sysConfigDTO 系统配置Dto
     * @return map map
     */
    @KerLog(projectName = "PROJECTNAME", modelName = "SYSCONFIG.MODELNAME", methodName = "SYSCONFIG.METHODNAME.QUERYSYSCONFIGLIST")
    @PostMapping(value="/queryList", produces = {"application/json;charset=utf-8"})
    @KerPermission("")
    public Map<String, Object> queryList(@RequestBody SysConfigDTO sysConfigDTO) {
    	Map<String, Object> map = sysConfigService.findSysConfigPage(sysConfigDTO);
        return map;
    }

    /**
     * 新增系统参数
     * @param sysConfigDTO 系统配置Dto
     * @return map map
     */
    @KerLog(projectName = "PROJECTNAME", modelName = "SYSCONFIG.MODELNAME", methodName = "SYSCONFIG.METHODNAME.ADDSYSCONFIG")
    @PostMapping(value = "/addSysConfig", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> addSysConfig(@RequestBody SysConfigDTO sysConfigDTO) {
        int count = sysConfigService.addSysConfig(sysConfigDTO);
        logger.debug("addSysConfig: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "新增系统参数成功", "");
        return map;
    }

     /**
     * 根据ID查询系统配置参数
     *
     * @param id id
     * @return map map
     */
    @KerLog(projectName = "PROJECTNAME", modelName = "SYSCONFIG.MODELNAME", methodName = "SYSCONFIG.METHODNAME.FINDSYSCONFIG")
    @GetMapping(value = "/findSysConfig/{id}", produces = {"application/json;charset=utf-8"})
    public Map<String, Object>  findSysConfig(@PathVariable(value="id")String id) {
        SysConfig sysConfig = sysConfigService.findSysConfig(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", sysConfig);
    }

    /**
     * 修改系统配置参数
     * @param busiSiteDto  系统配置Dto
     * @return the map
     */
    @KerLog(projectName = "PROJECTNAME", modelName = "SYSCONFIG.MODELNAME", methodName = "SYSCONFIG.METHODNAME.UPDATESYSCONFIG")
    @PostMapping(value = "/updateSysConfig", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> updateSysConfig(String token,@RequestBody SysConfigDTO sysConfigDTO){
        int count = sysConfigService.updateSysConfig(sysConfigDTO);
        logger.debug("updateSysConfig: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }

    /**
     * 删除系统参数
     * @param busiSiteDto 系统配置Dto
     * @return map map
     */
    @KerLog(projectName = "PROJECTNAME", modelName = "SYSCONFIG.MODELNAME", methodName = "SYSCONFIG.METHODNAME.DELETESYSCONFIG")
    @PostMapping(value = "/deleteSysConfig/{id}", produces = {"application/json;charset=utf-8"})
    @KerPermission("")
    public Map<String, Object> deleteSysConfig(@PathVariable(value="id") String[] ids){
        int count = sysConfigService.deleteSysConfig(ids);
        logger.debug("deleteSysConfig: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }
}