package com.jeeplus.test.materialManagement.contract.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.contract.service.ContractService;
import com.jeeplus.test.materialManagement.contract.service.dto.ContractInfoDto;
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-13 13:55
 **/
@RestController
@Api(tags ="物资管理-合同")
@RequestMapping(value = "/material/contract")
public class ContractController {

    @Resource
    private ContractService contractService;

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

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

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

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

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