package com.mvc.controller.iotcard;

import com.mvc.model.ResPageModel;
import com.mvc.model.ResultGeekerModel;
import com.mvc.model.iotcard.TIotcardInfoModel;
import com.mvc.service.iotcard.IotCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = "NB卡信息接口")
@RequestMapping("/IotCardController")
@Controller
public class IotCardController {
    @Resource
    private IotCardService iotCardService;

    @ApiOperation("根据条件查询卡信息列表")
    @RequestMapping(value = "/findAllTIotcardInfo",method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel findAllTIotcardInfo(@RequestBody TIotcardInfoModel model){
        ResultGeekerModel resultModel;
        try {
            ResPageModel res = iotCardService.findAllTIotcardInfo(model);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }


    @ApiOperation("通过接入号/ICCID获取单卡信息")
    @RequestMapping(value = "/queryCardInfoByCCID", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel queryCardInfoByCCID(String ccid) {
        ResultGeekerModel res;
        try {
            TIotcardInfoModel resModel = iotCardService.queryCardInfoByCCID(ccid);
            res = new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            res=new ResultGeekerModel(e.getMessage());
        }
        return res  ;
    }

    @ApiOperation("从卡平台更新所有卡的信息")
    @RequestMapping(value = "/updateAllCardInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel updateAllCardInfo() {
        ResultGeekerModel res;
        try {
            iotCardService.updateAllCardInfo();
            res = new ResultGeekerModel(1);
        } catch (Exception e) {
            e.printStackTrace();
            res=new ResultGeekerModel(e.getMessage());
        }
        return res  ;
    }
}
