package com.steerinfo.ems.usagedataconfig.controller;

import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.ems.trmtransfereactvalue.model.TRmTransfereActValue;
import com.steerinfo.ems.usagedataconfig.model.UsageDataConfig;
import com.steerinfo.ems.usagedataconfig.service.IUsageDataConfigService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

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

    @Autowired
    IUsageDataConfigService usageDataConfigService;

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

    @ApiOperation(value="获取列表", notes="分页模糊查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
        @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("usagedataconfig:view")
    @GetMapping(value = "/like/")
    public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
        PageList<UsageDataConfig> list = usageDataConfigService.queryLikeForPage(parmas, pageNum, pageSize);
        return success(list);
    }
    
    @ApiOperation(value="创建", notes="根据UsageDataConfig对象创建")
    @ApiImplicitParam(name = "usageDataConfig", value = "详细实体usageDataConfig", required = true, dataType = "UsageDataConfig")
    //@RequiresPermissions("usagedataconfig:create")
    @PostMapping(value = "/")
    public RESTfulResult add(@ModelAttribute UsageDataConfig model){
        UsageDataConfig usageDataConfig = usageDataConfigService.add(model);
        return success(usageDataConfig);
    }

    @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "Short")
    //@RequiresPermissions("usagedataconfig:view")
    @GetMapping(value = "/{id}")
    public RESTfulResult get(@PathVariable Short id){
        UsageDataConfig usageDataConfig = usageDataConfigService.getById(id);
        return success(usageDataConfig);
    }
    
    @ApiOperation(value="更新数据", notes="根据传过来的usageDataConfig信息来更新详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "UsageDataConfig", value = "详细实体UsageDataConfig", required = true, dataType = "UsageDataConfig")
    })
    //@RequiresPermissions("usagedataconfig:update")
    @PutMapping(value = "/batchupdate", produces  = "application/json;charset=UTF-8")
    public RESTfulResult update(@RequestBody UsageDataConfig[] models){
    	for (int i = 0; i< models.length; i++) {
    		UsageDataConfig model = models[i];
        	usageDataConfigService.modify(model);
    	}
        return success();
    }

    @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象，并根据传过来的usageDataConfig信息来更新详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "Short"),
        @ApiImplicitParam(name = "usageDataConfig", value = "详细实体usageDataConfig", required = true, dataType = "UsageDataConfig")
    })
    //@RequiresPermissions("usagedataconfig:update")
    @PutMapping(value = "/{id}", produces  = "application/json;charset=UTF-8")
    public RESTfulResult update(@PathVariable Short id, @RequestBody UsageDataConfig model){
        model.setId(id);
        UsageDataConfig usageDataConfig = usageDataConfigService.modify(model);
        return success(usageDataConfig);
    }

    @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "Short")
    //@RequiresPermissions("usagedataconfig:delete")
    @DeleteMapping(value = "/{id}")
    public RESTfulResult delete(@PathVariable Short id){
        usageDataConfigService.delete(id);
        return success();
    }
    
    @ApiOperation(value="删除", notes="批量删除")
    @ApiImplicitParam(name = "ids", value = "ids", required = true, dataType = "String")
    //@RequiresPermissions("usagedataconfig:delete")
    @DeleteMapping(value = "/batchdelete/{ids}", produces  = "application/json;charset=UTF-8")
    public RESTfulResult delete(@PathVariable String ids){
        String[] array = ids.split(",");
        List<Short> idList = new ArrayList<Short>();
        for (int i = 0; i < array.length; i++) {
        	Short id = new Short(array[i]);
        	if(id > 0) 
        	{
        		idList.add(id);
        	}
        }
        
        usageDataConfigService.delete(idList);
        
        return success();
    }
    
    @ApiOperation(value="删除", notes="批量删除")
    @ApiImplicitParam(name = "usagedataconfig", value = "usagedataconfig", required = true, dataType = "usagedataconfig")
    //@RequiresPermissions("usagedataconfig:delete")
    @DeleteMapping(value = "/batchdelete1", produces  = "application/json;charset=UTF-8")
    public RESTfulResult delete(@RequestBody UsageDataConfig[] models){
    	for (int i = 0; i< models.length; i++) {
    		UsageDataConfig model = models[i];
        	usageDataConfigService.delete(model.getId());
    	}
        return success();
    }

    @ApiOperation(value = "获取Id 和 Name",notes = "获取下拉框得值")
    @GetMapping(value = "/getIdAndNote")
    public RESTfulResult getIdAndNote(){
        List<UsageDataConfig> idAndNote = usageDataConfigService.getIdAndNote();
        return success(idAndNote);
    }

}
