package com.mvc.controller.taizhang;

import com.mvc.model.CorrectMap;
import com.mvc.model.TAicbqCfgModel;
import com.mvc.model.ErrorMap;
import com.mvc.service.taizhang.TAicbqCfgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "AI抄表器参数配置接口")
@RequestMapping("/TAicbqCfgAction")
@Controller
public class TAicbqCfgAction {

    @Resource
    private TAicbqCfgService tAicbqCfgService;

    @ApiOperation("AI抄表器参数配置分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findAllTAicbqCfg(@RequestBody TAicbqCfgModel model) {
        try {
            Map<String, Object> res = tAicbqCfgService.findAllTAicbqCfg(model);
            Map<String, Object> resMap = new CorrectMap();
            resMap.put("res", res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String, Object> resMap = new ErrorMap();
            resMap.put("error", e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("新增AI抄表器参数配置")
    @RequestMapping(value = "/saveTAicbqCfg", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> saveTAicbqCfg(@RequestBody TAicbqCfgModel model) {

        try {
            TAicbqCfgModel resModel = tAicbqCfgService.saveTAicbqCfg(model);
            Map<String, Object> resMap = new CorrectMap();
            resMap.put("res", resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String, Object> resMap = new ErrorMap();
            resMap.put("error", e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("更新AI抄表器参数配置")
    @RequestMapping(value = "/updateTAicbqCfg", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateTAicbqCfg(@RequestBody TAicbqCfgModel model) {
        try {
            TAicbqCfgModel resModel = tAicbqCfgService.updateTAicbqCfg(model);
            Map<String, Object> resMap = new CorrectMap();
            resMap.put("res", resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String, Object> resMap = new ErrorMap();
            resMap.put("error", e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("删除AI抄表器参数配置")
    @RequestMapping(value = "/deleteTAicbqCfg/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> deleteTAicbqCfg(@PathVariable("id") int id) {
        try {
            int res = tAicbqCfgService.deleteTAicbqCfg(id);
            Map<String, Object> resMap = new CorrectMap();
            resMap.put("res", res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String, Object> resMap = new ErrorMap();
            resMap.put("error", e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("查询AI抄表器对象")
    @RequestMapping(value = "/findTAicbqCfg/{deviceSn}", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> findTAicbqCfg(@PathVariable("deviceSn") String deviceSn) {
        try {
            //stationCode和useFlag 暂时先固定了,加上前台调用有问题
            //List<TAicbqCfgModel> resList = tAicbqCfgService.findTAicbqCfg(deviceSn, "", "1");
            List<TAicbqCfgModel> resList = tAicbqCfgService.findTAicbqCfgModelByDeviceSn(deviceSn);
            Map<String, Object> resMap = new CorrectMap();
            resMap.put("res", resList);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String, Object> resMap = new ErrorMap();
            resMap.put("error", e.getMessage());
            return resMap;
        }
    }
}
