package com.jeeplus.test.cw.projectRecords.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.sys.constant.enums.LogTypeEnum;
import com.jeeplus.test.cw.projectRecords.service.CwManHourManagementService;
import com.jeeplus.test.cw.projectRecords.service.dto.CwManHourManagementDTO;
import io.swagger.annotations.Api;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author: 徐滕
 * @version: 2022-12-06 16:28
 */
@RestController
@Api("财务项目工时管理信息")
@RequestMapping(value = "/manHourManagement")
public class CwManHourManagementController {

    @Resource
    private CwManHourManagementService cwManHourManagementService;

    /**
     * 查询财务项目信息列表
     * @param cwManHourManagementDTO
     * @param page
     * @return
     */
    @ApiLog("查询财务项目工时管理列表")
    @PreAuthorize("hasAuthority('manHourManagement:list')")
    @GetMapping("list")
    public ResponseEntity<IPage<CwManHourManagementDTO>> data(CwManHourManagementDTO cwManHourManagementDTO, Page<CwManHourManagementDTO> page) throws Exception {
        IPage<CwManHourManagementDTO> result = new Page<CwManHourManagementDTO>();
        result = cwManHourManagementService.findList (page,cwManHourManagementDTO);
        return ResponseEntity.ok (result);
    }

    /**
     * 查询财务项目详情
     * @param id
     * @return
     */
    @ApiLog("查询财务项目工时管理详情")
    @PreAuthorize ("hasAnyAuthority('manHourManagement:view','manHourManagement:add','manHourManagement:edit')")
    @GetMapping("queryById")
    public ResponseEntity queryById(@RequestParam("id") String id) {
        CwManHourManagementDTO cwManHourManagementDTO = cwManHourManagementService.queryById ( id );
        return ResponseEntity.ok (cwManHourManagementDTO);
    }

    /**
     * 保存财务项目信息
     * @param cwManHourManagementDTO
     * @return
     */
    @ApiLog(value = "修改/新增财务项目工时管理信息", type = LogTypeEnum.SAVE)
    @PreAuthorize("hasAnyAuthority('manHourManagement:add','manHourManagement:edit')")
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody CwManHourManagementDTO cwManHourManagementDTO) throws Exception {
        cwManHourManagementService.save(cwManHourManagementDTO);
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 更改状态
     * @param id
     * @return
     */
    @ApiLog("查询财务项目工时管理详情")
    @PreAuthorize ("hasAnyAuthority('manHourManagement:add','manHourManagement:edit')")
    @GetMapping("updateStatus")
    public ResponseEntity updateStatus(@RequestParam("id") String id) {
        cwManHourManagementService.updateStatus ( id );
        return ResponseEntity.ok ("确认工时成功");
    }

    /**
     * 删除财务项目信息
     * @param ids
     * @return
     */
    @ApiLog(value = "删除财务项目工时管理信息", type = LogTypeEnum.SAVE)
    @PreAuthorize ("hasAuthority('manHourManagement:del')")
    @DeleteMapping("delete")
    public ResponseEntity delete(String ids) {
        return cwManHourManagementService.deleteByIds(ids);
    }

}

