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


import com.chinaitop.depot.intelligent.ventilation.model.TJob;
import com.chinaitop.depot.intelligent.ventilation.service.AerationJobService;
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.List;

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

    @Autowired
    private AerationJobService aerationJobService;

   
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value = "查询 通风参数值列表", notes = "查询 通风参数值列表，支持分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
            @ApiImplicitParam(name = "tJob", value = "查询的对象", paramType = "query")
    })
   public ResponseEntity<PageInfo<TJob>> getList(Integer pageNum, Integer pageSize, TJob tJob) {
        List<TJob> list = null;
        try {
            if (null != pageNum && null != pageSize) {
                PageHelper.startPage(pageNum, pageSize);
            }
            list = aerationJobService.getList(tJob);
        } catch (Exception e) {
            e.printStackTrace();
            ResponseEntity.failed(e.getMessage());
        }
        PageInfo<TJob> pageInfo = new PageInfo<TJob>(list);
        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<TJob> getById(String id) {
    	TJob tJob = null;
        if (StringUtils.isNotBlank(id)) {
        	tJob = aerationJobService.getById(id);
        } else {
            return ResponseEntity.failed("ID数据有误!");
        }
        return ResponseEntity.ok(tJob);
    }

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

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

    
    
    
}
