package com.steerinfo.ems.tcm0324.controller;

import com.steerinfo.ems.tcm0315.model.TCm0315;
import com.steerinfo.ems.tcm0324.model.TCm0324;
import com.steerinfo.ems.tcm0324.service.ITCm0324Service;
import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageList;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * TCm0324 RESTful接口：
 * @author generator
 * @version 1.0-SNAPSHORT 2019-10-28 09:32
 * 类描述
 * 修订历史：
 * 日期：2019-10-28
 * 作者：generator
 * 参考：
 * 描述：TCm0324 RESTful接口
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@RestController
@RequestMapping("/${api.version}/tcm0324s")
public class TCm0324Controller extends BaseRESTfulController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TCm0324Controller.class);

    @Autowired
    ITCm0324Service tCm0324Service;

    @ApiOperation(value="获取列表", notes="分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("tcm0324:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
        PageList<TCm0324> list = tCm0324Service.queryForPage(parmas, pageNum, pageSize);
        return success(list);
    }

    @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象，并根据传过来的tCm0324信息来更新详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "tCm0324", value = "详细实体tCm0324", required = true, dataType = "TCm0324")
    })
    //@RequiresPermissions("tcm0324:update")
    @PutMapping(value = "/{id}")
    public RESTfulResult update(@PathVariable String id, @RequestBody TCm0324 model){
        System.out.println("id:"+id+"Lowerlimit:"+model.getLowerlimit() + "Upperlimit:"+model.getUpperlimit());
        model.setRecordid(id);
        TCm0324 tCm0324 = tCm0324Service.updatelimit(model);
        return success(tCm0324);
    }

    public void add(TCm0315 tCm0315){
        TCm0324 tCm0324 = new TCm0324();
        tCm0324.setCreatyear(tCm0315.getCreatyear());
        tCm0324.setPowerdetecdepartment(tCm0315.getPowerdetecdepartment());
        tCm0324.setPowermonitorname(tCm0315.getPowermonitorname());
        tCm0324.setPowerpowersystemname(tCm0315.getPowersystemname());
        tCm0324.setRecordid(tCm0315.getRecordid());
        tCm0324.setItemname(tCm0315.getSitem());
        tCm0324.setUnit(tCm0315.getUnit());
        tCm0324Service.add(tCm0324);
    }

    public void update(TCm0315 tCm0315){
        TCm0324 tCm0324 = new TCm0324();
        tCm0324.setUnit(tCm0315.getUnit());
        tCm0324.setRecordid(tCm0315.getRecordid());
        tCm0324.setPowerpowersystemname(tCm0315.getPowersystemname());
        tCm0324.setPowerdetecdepartment(tCm0315.getPowerdetecdepartment());
        tCm0324.setItemname(tCm0315.getSitem());
        tCm0324.setCreatyear(tCm0315.getCreatyear());
        tCm0324.setPowermonitorname(tCm0315.getPowermonitorname());
        LOGGER.info("动力监测指标表修改前的数据是" + tCm0324.toString());
        TCm0324 after = tCm0324Service.modify(tCm0324);
        LOGGER.info("动力监测指标表修改后的数据是" + after.toString());
    }

    public void delete(String id){
        LOGGER.info("动力监测指标表要删除的数据是" + tCm0324Service.getById(id).toString());
        tCm0324Service.delete(id);
    }
}
