package com.zcloud.domain.web;


import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.domain.api.ProjectTaskServiceI;
import com.zcloud.domain.dto.ProjectTaskAddCmd;
import com.zcloud.domain.dto.ProjectTaskPageQry;
import com.zcloud.domain.dto.ProjectTaskUpdateCmd;
import com.zcloud.domain.dto.clientobject.ProjectTaskCO;
import com.zcloud.domain.dto.clientobject.ProjectTaskDetailsCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:29:57
 */
@Api(tags = "课题任务管理")
@RequestMapping("/${application.gateway}/projectTask")
@RestController
@AllArgsConstructor
public class ProjectTaskController {
    private final ProjectTaskServiceI projectTaskService;

    @ApiOperation("课题任务新增")
    @PostMapping("/save")
    public SingleResponse<ProjectTaskCO> add(@Validated @RequestBody ProjectTaskAddCmd cmd) {
        return projectTaskService.add(cmd);
    }

    @ApiOperation("课题任务分页")
    @PostMapping("/projectPage")
    @PreAuthorize("@pms.hasAnyPermission('gfd-ktrw','qyd-ktrw')")
    public PageResponse<ProjectTaskCO> listPage(@RequestBody ProjectTaskPageQry qry) {
        return projectTaskService.listPage(qry);
    }

    @ApiOperation("课题评分分页")
    @PostMapping("/projectScorepage")
    @PreAuthorize("@pms.hasAnyPermission('gfd-ktpf','qyd-ktpf')")
    public PageResponse<ProjectTaskCO> projectScorepage(@RequestBody ProjectTaskPageQry qry) {
        return projectTaskService.listPage(qry);
    }


    @ApiOperation("课题任务详情")
    @GetMapping("/getInfoById/{id}")
    public SingleResponse<ProjectTaskDetailsCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(projectTaskService.getInfoById(id));
    }

    @ApiOperation("删除")
    @GetMapping("/remove/{id}")
    public Response remove(@PathVariable("id") Long id) {
        projectTaskService.remove(id);
        return SingleResponse.buildSuccess();
    }

 /*   @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam Long[] ids) {
        projectTaskService.removeBatch(ids);
        return SingleResponse.buildSuccess();
    }*/

    @ApiOperation("修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody ProjectTaskUpdateCmd projectTaskUpdateCmd) {
        projectTaskService.edit(projectTaskUpdateCmd);
        return SingleResponse.buildSuccess();
    }
}

