package com.hotent.enterpriseDeclare.controller.material;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import com.hotent.constant.BaseConstant;
import com.hotent.enterpriseDeclare.req.CostTaskEvidencePageReq;
import com.hotent.project.manager.CostProjectTaskEvidenceManager;
import com.hotent.project.model.CostProjectTaskEvidence;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "子任务提取资料登记")
@RestController
@RequestMapping("/api/enterprise/taskEvidence")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
public class CostProjectTaskEvidenceController {

    @Autowired
    private CostProjectTaskEvidenceManager costProjectTaskEvidenceManager;


    /**
     * 根据任务ID查询资料列表
     */
    @GetMapping(value = "/listByTaskId")
    @ApiOperation(value = "根据任务ID查询资料列表", httpMethod = "GET", notes = "根据任务ID查询资料列表")
    public CommonResult<List<CostProjectTaskEvidence>> listByTaskId(@RequestParam String taskId) {
        LambdaQueryWrapper<CostProjectTaskEvidence> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CostProjectTaskEvidence::getTaskId, taskId)
                   .eq(CostProjectTaskEvidence::getIsDeleted, BaseConstant.NORMAL_STATUS)
                   .orderByAsc(CostProjectTaskEvidence::getOrderNum);

        List<CostProjectTaskEvidence> list = costProjectTaskEvidenceManager.list(queryWrapper);
        return CommonResult.<List<CostProjectTaskEvidence>>ok().value(list);
    }


    /**
     * 新增资料登记
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增资料登记", httpMethod = "POST", notes = "新增资料登记")
    public CommonResult<String> add(@RequestBody CostProjectTaskEvidence evidence) {
        costProjectTaskEvidenceManager.createOrUpdate(evidence);
        return CommonResult.<String>ok().value("操作成功");
    }

    /**
     * 更新资料登记
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "更新资料登记", httpMethod = "POST", notes = "更新资料登记")
    public CommonResult<String> update(@RequestBody CostProjectTaskEvidence evidence) {
        costProjectTaskEvidenceManager.createOrUpdate(evidence);
        return CommonResult.<String>ok().value("更新成功");
    }

    /**
     * 删除资料登记
     */
    @PostMapping(value = "/delete")
    @ApiOperation(value = "删除资料登记", httpMethod = "POST", notes = "删除资料登记")
    public CommonResult<String> delete(@RequestBody CostProjectTaskEvidence evidence) {
        costProjectTaskEvidenceManager.removeById(evidence.getId());
        return CommonResult.<String>ok().value("删除成功");
    }
}
