package com.jeeplus.test.materialManagement.collect.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.test.materialManagement.collect.service.CollectService;
import com.jeeplus.test.materialManagement.collect.service.dto.CollectDto;
import com.jeeplus.test.materialManagement.collect.service.dto.WareHouseSummaryDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: 王强
 * @create: 2023-01-03 16:18
 **/
@RestController
@Api(tags ="物资管理-领用申请")
@RequestMapping(value = "/material/collect")
public class CollectController {

    @Resource
    private CollectService collectService;

    /**
     * 根据id修改状态status
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "updateStatusById")
    public void updateStatusById(@RequestBody CollectDto dto) {
        collectService.updateStatusById(dto);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "删除")
    @GetMapping("/remove")
    public ResponseEntity<String> remove(@RequestParam String id){
        String s = collectService.remove(id);
        return ResponseEntity.ok(s);
    }

    /**
     * 新增/修改
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增、修改")
    @PostMapping("/save")
    public ResponseEntity<String> save(@RequestBody CollectDto dto) throws Exception{
        String s = collectService.save(dto);
        return ResponseUtil.newInstance().add("businessTable", "material_management_collect_basics").add("businessId", s).ok ("操作成功");
    }

    /**
     * 查询
     * @param id
     * @return
     */
    @ApiOperation(value = "查询")
    @GetMapping("/findById")
    public ResponseEntity<CollectDto> findById(@RequestParam String id) throws Exception{
        CollectDto dto = collectService.findById(id);
        return ResponseEntity.ok(dto);
    }

    /**
     * 列表查询
     * @param dto
     * @return
     */
    @ApiOperation(value = "列表查询")
    @GetMapping("/list")
    public ResponseEntity<IPage<CollectDto>> list(Page<CollectDto> page, CollectDto dto) throws Exception{
        IPage<CollectDto> iPage = collectService.list(page, dto);
        return ResponseEntity.ok(iPage);
    }

    /**
     * 商品入库信息列表查询
     * @param dto
     * @return
     */
    @ApiOperation(value = "商品入库信息列表查询")
    @GetMapping("/wareHouseList")
    public ResponseEntity<IPage<WareHouseSummaryDto>> wareHouseList(Page<WareHouseSummaryDto> page, WareHouseSummaryDto dto) throws Exception{
        IPage<WareHouseSummaryDto> iPage = collectService.wareHouseList(page, dto);
        return ResponseEntity.ok(iPage);
    }
}
