package com.jeeplus.test.program.configuration.projectList.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.program.configuration.projectList.domain.ProgramProjectListInfo;
import com.jeeplus.test.program.configuration.projectList.service.ProjectListService;
import com.jeeplus.test.program.configuration.projectList.service.dto.ContractDto;
import com.jeeplus.test.program.configuration.projectList.service.dto.ProjectListDto;
import com.jeeplus.test.workContract.domain.WorkContractInfo;
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;

@Api(tags ="项目列表管理")
@RestController
@RequestMapping(value = "/program/projectList")
public class ProjectListController {

    @Resource
    private ProjectListService projectListService;

    /**
     * 新增/修改
     */
    @ApiOperation(value = "新增/修改")
    @PostMapping(value = "/save")
    public ResponseEntity<String> save(@RequestBody ProjectListDto projectListDto) throws Exception{
        String id = projectListService.save(projectListDto);
        return ResponseUtil.newInstance().add("businessTable", "program_project_list_info").add("businessId", id).ok ("操作成功");
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/findById")
    public ResponseEntity<ProjectListDto> save(@RequestParam String id){
        ProjectListDto dto = projectListService.findById(id);
        return ResponseEntity.ok(dto);
    }

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

    /**
     * 合同信息列表查询
     * @param dto
     * @param page
     * @return
     */
    @ApiOperation(value = "合同信息列表查询")
    @GetMapping(value = "/findContractPageList")
    public ResponseEntity<IPage<WorkContractInfo>> findContractPageList(ContractDto dto, Page<WorkContractInfo> page) {
        IPage<WorkContractInfo> pageList = projectListService.findContractPageList(dto, page);
        return ResponseEntity.ok(pageList);
    }

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

    /**
     * 合同登记列表
     * @param info
     * @param page
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "合同登记列表")
    @GetMapping(value = "/list")
    public ResponseEntity<IPage<ProgramProjectListInfo>> list(ProgramProjectListInfo info, Page<ProgramProjectListInfo> page) throws Exception {
        IPage<ProgramProjectListInfo> list = projectListService.list(page, info);
        return ResponseEntity.ok (list);
    }


}
