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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.aop.logging.annotation.ApiLog;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.test.materialManagement.purchase.service.MaterialService;
import com.jeeplus.test.materialManagement.purchase.service.dto.MaterialInfoDto;
import com.jeeplus.test.materialManagement.wareHouse.service.WareHouseBasicService;
import com.jeeplus.test.materialManagement.wareHouse.service.dto.WareHouseDto;
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: 2022-12-29 14:13
 **/
@RestController
@Api(tags ="物资管理-入库")
@RequestMapping(value = "/material/management/wareHouse")
public class WareHouseController {

    @Resource
    private MaterialService service;

    @Resource
    private WareHouseBasicService basicService;

    /**
     * 根据id修改状态值status
     * @param dto
     * @return
     */
    @ApiOperation(value = "根据id修改状态值status")
    @PostMapping(value = "/updateStatusById")
    public ResponseEntity<String> updateStatusById(@RequestBody WareHouseDto dto) {
        String s = basicService.updateStatusById(dto);
        return ResponseEntity.ok(s);
    }

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

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

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

    /**
     * 入库汇总列表查询
     * @param dto
     * @return
     */
    @ApiOperation(value = "入库汇总列表查询")
    @GetMapping("/wareHouseSummaryList")
    public ResponseEntity<IPage<WareHouseDto>> wareHouseSummaryList(Page<WareHouseDto> page, WareHouseDto dto) throws Exception{
        IPage<WareHouseDto> iPage = basicService.summaryList(page, dto);
        return ResponseEntity.ok(iPage);
    }

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

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

    /**
     * 查询采购明细表id
     * @param purchaseNo
     * @return
     */
    @ApiOperation(value = "查询采购明细表id")
    @GetMapping("/findRequestId")
    public ResponseEntity<String> findRequestId(@RequestParam String purchaseNo) throws Exception{
        String id = basicService.findRequestId(purchaseNo);
        return ResponseEntity.ok(id);
    }
}
