/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.stocks.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.stocks.dto.MaterialTypeDto;
import com.tofly.stocks.entity.MaterialType;
import com.tofly.stocks.service.MaterialTypeService;
import lombok.AllArgsConstructor;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 库存物资类型表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/materialtype")
@Api(tags="库存物资类型表接口")
public class MaterialTypeController {

    private final  MaterialTypeService materialTypeService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param materialType 库存物资类型表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getMaterialTypePage(Page page, @ModelAttribute MaterialType materialType) {
      return ResultRespone.success(materialTypeService.page(page, Wrappers.query(materialType)));
    }
    
    
    
    /**
     * 物资类型list
     * @return
     */
     @GetMapping("/list" )
     @ApiOperation(value = "获取物资类型list")
     public ResultRespone getMaterialTypeList() {
    	 
    	 try {
    	       List<Map<String,String>> typeList = materialTypeService.getMaterialTypeList();
    	       return ResultRespone.success(typeList);
    	 }catch (Exception e) {
    		 return ResultRespone.success(e.getMessage());
		 }
     }


    /**
     * 通过id查询库存物资类型表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(materialTypeService.getById(id));
    }

    /**
     * 新增库存物资类型表
     * @param materialType 库存物资类型表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增库存物资类型表" )
    @ApiOperation(value = "新增库存物资类型表")
    @PostMapping
    public ResultRespone save(@RequestBody MaterialType materialType) {
      return ResultRespone.success(materialTypeService.save(materialType));
    }

    /**
     * 修改库存物资类型表
     * @param materialType 库存物资类型表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改库存物资类型表" )
    @ApiOperation(value = "修改库存物资类型表")
    @PutMapping
    public ResultRespone updateById(@RequestBody MaterialType materialType) {
      return ResultRespone.success(materialTypeService.updateById(materialType));
    }

    /**
     * 通过id删除库存物资类型表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除库存物资类型表" )
    @ApiOperation(value = "通过ID删除库存物资类型表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(materialTypeService.removeById(id));
    }

    /**
     * 通过id批量删除库存物资类型表
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id批量删除库存物资类型表" )
    @ApiOperation(value = "通过ID批量删除库存物资类型表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(materialTypeService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
