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

import com.alibaba.fastjson.JSONObject;
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.install.entity.MaterialUse;
import com.tofly.install.entity.OtherFees;
import com.tofly.install.service.OtherFeesService;

import lombok.AllArgsConstructor;
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.Arrays;
import java.util.List;
/**
 * 报装业务表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/otherFees")
@Api(tags="其他费用接口")
public class OtherFeesController {

    private final  OtherFeesService otherFeesService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param materialType 库存物资类型表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getMaterialTypePage(Page page, @ModelAttribute OtherFees otherFees) {
      return ResultRespone.success(otherFeesService.page(page, Wrappers.query(otherFees)));
    }


    /**
     * 通过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(otherFeesService.getById(id));
    }

    /**
     * 新增报装业务
     * @param applyInstall 报装业务
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增其他费用信息" )
    @ApiOperation(value = "新增其他费用信息")
    @PostMapping
    public ResultRespone save(@RequestBody String objects) {
    	List<OtherFees> dataList = JSONObject.parseArray(objects,OtherFees.class);    	
    	for(OtherFees otherFees:dataList) {
    		otherFeesService.save(otherFees);
    	}    	    	
    	return ResultRespone.success("新增成功");
    }

    /**
     * 修改报装业务
     * @param applyInstall 报装业务表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改其他费用信息" )
    @ApiOperation(value = "修改其他费用信息")
    @PutMapping
    public ResultRespone updateById(@RequestBody String objects) {
    	
    	List<OtherFees> dataList = JSONObject.parseArray(objects,OtherFees.class);    	
    	for(OtherFees otherFees:dataList) {
    		otherFeesService.updateById(otherFees);
    	}    
    	return ResultRespone.success("修改成功");
    }

    /**
     * 通过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(otherFeesService.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(otherFeesService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
