package com.huatek.busi.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.huatek.busi.service.IecBydworkParamService;
import com.huatek.busi.vo.curve.IecBydworkParamPointVo;
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.github.pagehelper.PageInfo;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.IecBaseConfDto;
import com.huatek.busi.entity.IecBaseConf;
import com.huatek.busi.service.IecBaseConfService;
import com.huatek.busi.vo.IecBaseConfVo;
import com.huatek.torch.frame.log.KerLog;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * IEC104-基础地址配置表 控制层
 *
 * @author anker_cheng
 * @date 2019-8-1 9:40:34
 */
@Api(tags = {Tags.IEC_BASIC_CONFIG})
@RestController
@RequestMapping("/api/IecBaseConf")
public class IecBaseConfController {

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

    @Reference(check = false)
    private IecBaseConfService iecBaseConfService;

    @Reference(check = false)
    private IecBydworkParamService iecBydworkParamService;

     /**
     * IEC104-基础地址配置表 分页列表
     *
     * @param iecBaseConfDto IEC104-基础地址配置表Dto
     * @return map map
     */
    @ApiOperation(value = "获取IEC104-基础地址配置列表", response = IecBaseConfVo.class)
    @KerLog(projectName = "PROJECTNAME", modelName = "IECBASECONF.MODELNAME", methodName = "IECBASECONF.METHODNAME.QUERYLIST")
    @PostMapping(value="/queryList", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> queryList(@RequestBody IecBaseConfDto iecBaseConfDto) {
        PageInfo<IecBaseConfVo> iecBaseConfs = iecBaseConfService.findIecBaseConfPage(iecBaseConfDto);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, iecBaseConfs.getTotal(), "", iecBaseConfs.getList());
    }

    /**
     * 添加 IEC104-基础地址配置表
     *
     * @param iecBaseConfDto IEC104-基础地址配置表Dto
     * @return map map
     */
    @ApiOperation(value = "添加IEC104-基础地址配置")
    @KerLog(projectName = "PROJECTNAME", modelName = "IECBASECONF.MODELNAME", methodName = "IECBASECONF.METHODNAME.ADDIECBASECONF")
    @PostMapping(value = "/addIecBaseConf", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> addIecBaseConf(@RequestBody IecBaseConfDto iecBaseConfDto) {
        int count = iecBaseConfService.addIecBaseConf(iecBaseConfDto);
        logger.debug("addIecBaseConf: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }

     /**
     * 通过id查找 IEC104-基础地址配置表
     *
     * @param id id
     * @return map map
     */
    @KerLog(projectName = "PROJECTNAME", modelName = "IECBASECONF.MODELNAME", methodName = "IECBASECONF.METHODNAME.FINDIECBASECONF")
    @GetMapping(value = "/findIecBaseConf/{id}", produces = {"application/json;charset=utf-8"})
    public Map<String, Object>  findIecBaseConf(@PathVariable(value="id")String id) {
        IecBaseConf iecBaseConf =iecBaseConfService.findIecBaseConf(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", iecBaseConf);
    }

    /**
     * 修改 IEC104-基础地址配置表
     * @param iecBaseConfDto  IEC104-基础地址配置表Dto
     * @return the map
     */
    @ApiOperation(value = "修改IEC104-基础地址配置")
    @KerLog(projectName = "PROJECTNAME", modelName = "IECBASECONF.MODELNAME", methodName = "IECBASECONF.METHODNAME.UPDATEIECBASECONF")
    @PostMapping(value = "/updateIecBaseConf", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> updateIecBaseConf(@RequestBody IecBaseConfDto iecBaseConfDto){
        int count = iecBaseConfService.updateIecBaseConf(iecBaseConfDto);
        logger.debug("updateIecBaseConf: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }

    /**
     * 删除 IEC104-基础地址配置表
     * @param -基础地址配置表Dto
     * @return map map
     */
    @ApiOperation(value = "删除IEC104-基础地址配置")
    @KerLog(projectName = "PROJECTNAME", modelName = "IECBASECONF.MODELNAME", methodName = "IECBASECONF.METHODNAME.DELETEIECBASECONF")
    @PostMapping(value = "/deleteIecBaseConf", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> deleteIecBaseConf(@RequestBody String[] ids){
        int count = iecBaseConfService.deleteIecBaseConf(ids);
        logger.debug("deleteIecBaseConf: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }

    /**
     * 根据eqmCode查询数据
     *
     * @param result
     * @return
     */
    @PostMapping(value = "/getIecBydworkParamWorks", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getIecBydworkParamWorks(@RequestBody Map<String, Object> result) {
        String eqmCode = (String) result.get("eqmCode");
        List<IecBydworkParamPointVo> pointVos = iecBydworkParamService.getdworkParamByEqmCode(eqmCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", pointVos);
    }

    /**
     * 根据eqmCode查询数据
     *
     * @param result
     * @return
     */
    @GetMapping(value = "/getIecBydworkParamWorks/{eqmCode}", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getIecBydworkParamWorks(@PathVariable String eqmCode) {
        List<IecBydworkParamPointVo> pointVos = iecBydworkParamService.getdworkParamByEqmCode(eqmCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", pointVos);
    }

}