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

import com.chinaitop.depot.intelligent.ventilation.model.TCtldevinfo;
import com.chinaitop.depot.intelligent.ventilation.model.TVentilationOperation;
import com.chinaitop.depot.intelligent.ventilation.service.AerationParameterService;
import com.chinaitop.depot.intelligent.ventilation.service.VentilationOperationService;
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.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping(value = "/intelligents/VentilationOperationController")
@Api(value = "VentilationOperationController", description = "通风作业")
public class VentilationOperationController {

    @Autowired
    private VentilationOperationService ventilationOperationService;

   
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value = "查询 通风作业列表", notes = "查询 通风作业列表，支持分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
            @ApiImplicitParam(name = "orgId", value = "库点编码", paramType = "query"),
            @ApiImplicitParam(name = "vcfcode", value = "仓库名称", paramType = "query")
    })
   public ResponseEntity<PageInfo<TVentilationOperation>> getList(Integer pageNum, Integer pageSize, String orgId, String cfbh,String cfmc) {
        List<TVentilationOperation> list = null;
        try {
            list = ventilationOperationService.getList(pageNum,pageSize,orgId,cfbh,cfmc);
        } catch (Exception e) {
            e.printStackTrace();
            ResponseEntity.failed(e.getMessage());
        }
        PageInfo<TVentilationOperation> pageInfo = new PageInfo<TVentilationOperation>(list);
        /*if(pageInfo.getList()!=null && pageInfo.getList().size()>0){
        	pageInfo.setStartRow(pageInfo.getStartRow()+1);
        	pageInfo.setEndRow(pageInfo.getEndRow()+1);
        }*/
        return ResponseEntity.ok(pageInfo);
    }

    
    @RequestMapping(value = "/getById", method = RequestMethod.POST)
    @ApiOperation(value = "根据id查询信息", notes = "根据id查询信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query")
    })
    public ResponseEntity<TVentilationOperation> getById(String id) {
    	TVentilationOperation tVentilationOperation = null;
        if (StringUtils.isNotBlank(id)) {
        	tVentilationOperation = ventilationOperationService.getById(id);
        } else {
            return ResponseEntity.failed("ID数据有误!");
        }
        return ResponseEntity.ok(tVentilationOperation);
    }

    @RequestMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    @ApiOperation(value = "数据更新与添加", notes = "数据更新与添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ventilationOperationJson", value = "表数据json串", paramType = "form")
    })
    public ResponseEntity save(String ventilationOperationJson) {
        try {
        	ventilationOperationService.save(ventilationOperationJson);
        } catch (Exception e) {
            e.printStackTrace();
            ResponseEntity.failed(e.getMessage());
        }
        return ResponseEntity.ok();
    }

    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ApiOperation(value = "根据id删除信息", notes = "根据id删除信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "粮情id", paramType = "query"),
            @ApiImplicitParam(name = "aerationParamJson", value = "通风参数json字符串", paramType = "query")
    })
    public ResponseEntity deleteById(String id) {
        if (StringUtils.isNotBlank(id)) {
            int count = ventilationOperationService.deleteById(id);
            if (count > 0) {
                return ResponseEntity.ok();
            } else {
                return ResponseEntity.failed("删除失败!");
            }
        }
        return ResponseEntity.failed("ID数据有误!");
    }

    
    
}
