package com.tourism.webadmin.app.website.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.github.pagehelper.page.PageMethod;
import com.tourism.common.core.annotation.MyRequestBody;
import com.tourism.common.core.constant.ErrorCodeEnum;
import com.tourism.common.core.object.*;
import com.tourism.common.core.util.MyModelUtil;
import com.tourism.common.core.util.MyPageUtil;
import com.tourism.webadmin.back.dto.JobProjectDto;
import com.tourism.webadmin.back.model.JobProject;
import com.tourism.webadmin.back.service.JobProjectService;
import com.tourism.webadmin.back.vo.JobProjectVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 网页劳务项目管理操作控制器类。
 *
 * @author 吃饭睡觉
 * @date 2024-09-06
 */
@Tag(name = "网页劳务项目管理接口")
@Slf4j
@RestController
@SaIgnore
@RequestMapping("/website/basic/jobProject")
public class JobProjectToWebController {

    @Autowired
    private JobProjectService jobProjectService;

    /**
     * 列出符合过滤条件的劳务项目管理列表。
     *
     * @param jobProjectDtoFilter 过滤对象。
     * @param orderParam 排序参数。
     * @param pageParam 分页参数。
     * @return 应答结果对象，包含查询结果集。
     */
    @PostMapping("/list")
    public ResponseResult<MyPageData<JobProjectVo>> list(
            @MyRequestBody JobProjectDto jobProjectDtoFilter,
            @MyRequestBody MyOrderParam orderParam,
            @MyRequestBody MyPageParam pageParam) {
        if (pageParam != null) {
            PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getCount());
        }
        JobProject jobProjectFilter = MyModelUtil.copyTo(jobProjectDtoFilter, JobProject.class);
        String orderBy = MyOrderParam.buildOrderBy(orderParam, JobProject.class);
        List<JobProject> jobProjectList = jobProjectService.getJobProjectListWithRelation(jobProjectFilter, orderBy);
        return ResponseResult.success(MyPageUtil.makeResponseData(jobProjectList, JobProjectVo.class));
    }

    /**
     * 查看指定劳务项目管理对象详情。
     *
     * @param id 指定对象主键Id。
     * @return 应答结果对象，包含对象详情。
     */
//    @SaCheckPermission("jobProject.view")
    @GetMapping("/detail")
    public ResponseResult<JobProjectVo> detail(@RequestParam Long id) {
        JobProject jobProject = jobProjectService.getByIdWithRelation(id, MyRelationParam.full());
        if (jobProject == null) {
            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
        }
        JobProjectVo jobProjectVo = MyModelUtil.copyTo(jobProject, JobProjectVo.class);
        return ResponseResult.success(jobProjectVo);
    }
}
