package com.njcn.advance.controller.assess;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.advance.pojo.param.assess.AssessLoadParamQuery;
import com.njcn.advance.pojo.po.assess.AssessLoadParam;
import com.njcn.advance.service.assess.IAssessLoadParamService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.web.factory.PageFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 评估用户负荷参数 前端控制器
 * </p>
 *
 * @author cdf
 * @since 2025-06-06
 */
@RestController
@RequestMapping("/assessLoadParam")
@Api(tags = "评估用户负荷参数管理")
@RequiredArgsConstructor
public class AssessLoadParamController extends BaseController {

    private final IAssessLoadParamService assessLoadParamService;

    @ApiOperation("获取评估用户负荷参数列表")
    @PostMapping("/list")
    public HttpResult<List<AssessLoadParam>> list(@RequestBody AssessLoadParamQuery assessLoadParamQuery) {
        LambdaQueryWrapper<AssessLoadParam> wrapper = Wrappers.<AssessLoadParam>lambdaQuery()
                .like(assessLoadParamQuery.getLoadName() != null, AssessLoadParam::getLoadName, assessLoadParamQuery.getLoadName())
                .eq(assessLoadParamQuery.getAssessId() != null, AssessLoadParam::getAssessId, assessLoadParamQuery.getAssessId());
        List<AssessLoadParam> list = assessLoadParamService.list(wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("分页查询评估用户负荷参数")
    @PostMapping("/page")
    public HttpResult<Page<AssessLoadParam>> page(@RequestBody AssessLoadParamQuery assessLoadParamQuery) {
        Page<AssessLoadParam> pageParam = new Page<>(
                PageFactory.getPageNum(assessLoadParamQuery),
                PageFactory.getPageSize(assessLoadParamQuery)
        );
        LambdaQueryWrapper<AssessLoadParam> wrapper = Wrappers.<AssessLoadParam>lambdaQuery()
                .like(assessLoadParamQuery.getLoadName() != null, AssessLoadParam::getLoadName, assessLoadParamQuery.getLoadName())
                .eq(assessLoadParamQuery.getAssessId() != null, AssessLoadParam::getAssessId, assessLoadParamQuery.getAssessId());
        Page<AssessLoadParam> pageData = assessLoadParamService.page(pageParam, wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), pageData,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据ID获取评估用户负荷参数详情")
    @ApiImplicitParam(name = "loadId", value = "用户负荷ID", required = true, type = "String")
    @GetMapping("/getInfo")
    public HttpResult<AssessLoadParam> getInfo(@RequestParam("loadId") String loadId) {
        AssessLoadParam assessLoadParam = assessLoadParamService.getByLoadId(loadId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), assessLoadParam,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("新增评估用户负荷参数")
    @PostMapping("/add")
    public HttpResult<Boolean> add(@RequestBody @Validated AssessLoadParamQuery assessLoadParam) {
        boolean result = assessLoadParamService.add(assessLoadParam);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), result,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("修改评估用户负荷参数")
    @PostMapping("/edit")
    public HttpResult<Boolean> edit(@RequestBody @Validated AssessLoadParamQuery.UpdateAssessLoadParamQuery updateQuery) {
        assessLoadParamService.update(updateQuery);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), true,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("删除评估用户负荷参数")
    @PostMapping("/delete")
    public HttpResult<Boolean> delete(@RequestBody List<String> loadId) {
        boolean result = assessLoadParamService.removeByIds(loadId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), result,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据评估用户ID查询负荷参数")
    @ApiImplicitParam(name = "assessId", value = "评估用户ID", required = true, type = "String")
    @GetMapping("/listByAssessId")
    public HttpResult<List<AssessLoadParam>> listByAssessId(@RequestParam("assessId") String assessId) {
        List<AssessLoadParam> list = assessLoadParamService.listByAssessId(assessId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }


}