package com.chinaitop.depot.intelligent.basicdata.controller;

import com.chinaitop.depot.intelligent.basicdata.model.TStation;
import com.chinaitop.depot.intelligent.basicdata.model.TStationtype;
import com.chinaitop.depot.intelligent.basicdata.service.TStationtypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unissoft.model.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping(value = "/intelligents/stationType")
@Api(value = "TStationtypeController", description = "站点类型控制类")
public class TStationtypeController {

    @Resource
    private TStationtypeService tStationtypeService;

    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value = "查询 站点类型 信息列表", notes = "查询 站点类型 信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query")
    })
    public ResponseEntity getList(Integer pageNum, Integer pageSize) {
        List<TStationtype> list = null;
        try {
            if (null != pageNum && null != pageSize) {
                PageHelper.startPage(pageNum, pageSize);
            }
            list = tStationtypeService.getList();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.failed("查询站点类型列表失败");
        }
        PageInfo<TStationtype> pageInfo = new PageInfo<TStationtype>(list);
        return ResponseEntity.ok(pageInfo);
    }

    @RequestMapping(value = "/synchronizationAll", method = RequestMethod.GET)
    @ApiOperation(value = "与智远同步站点类型基础数据", notes = "与智远同步站点类型基础数据")
    @ApiImplicitParam(name = "orgId", value = "库房编码", paramType = "query")
    public ResponseEntity synchronizationAll(String orgId) {
        if (StringUtils.isBlank(orgId)){
            return ResponseEntity.ok("库房编码不能为空！");
        }
        String msg = null;
        try {
            msg = tStationtypeService.synchronizationAll(orgId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.ok("同步失败！");
        }
        return ResponseEntity.ok(msg);
    }
}
