package com.jeeplus.psimanage.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.psimanage.contract.service.PsiContractService;
import com.jeeplus.psimanage.contract.service.dto.PsiContractInfoDto;
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 = "/psi/contract")
public class PsiContractController {

    @Resource
    private PsiContractService psiContractService;

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

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

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

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

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