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.AssessShockLoadParamQuery;
import com.njcn.advance.pojo.po.assess.AssessShockLoadParam;
import com.njcn.advance.service.assess.IAssessShockLoadParamService;
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("/assessShockLoadParam")
@Api(tags = "评估用户冲击负荷参数管理")
@RequiredArgsConstructor
public class AssessShockLoadParamController extends BaseController {

    private final IAssessShockLoadParamService assessShockLoadParamService;

    @ApiOperation("获取评估用户冲击负荷参数列表")
    @PostMapping("/list")
    public HttpResult<List<AssessShockLoadParam>> list(@RequestBody AssessShockLoadParamQuery query) {
        LambdaQueryWrapper<AssessShockLoadParam> wrapper = Wrappers.<AssessShockLoadParam>lambdaQuery()
                .like(query.getAssessId() != null, AssessShockLoadParam::getAssessId, query.getAssessId())
                .eq(query.getInpactloadtypeId() != null, AssessShockLoadParam::getInpactloadtypeId, query.getInpactloadtypeId())
                .like(query.getInpactloadhighScale() != null, AssessShockLoadParam::getInpactloadhighScale, query.getInpactloadhighScale());
        List<AssessShockLoadParam> list = assessShockLoadParamService.list(wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }

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

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

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

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

    @ApiOperation("删除评估用户冲击负荷参数")
    @PostMapping("/delete")
    public HttpResult<Boolean> delete(@RequestBody List<String> inpactloadId) {
        boolean result = assessShockLoadParamService.removeByIds(inpactloadId);
        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<AssessShockLoadParam>> listByAssessId(@RequestParam("assessId") String assessId) {
        List<AssessShockLoadParam> list = assessShockLoadParamService.listByAssessId(assessId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据冲击负荷类型ID查询参数")
    @ApiImplicitParam(name = "inpactloadtypeId", value = "冲击负荷类型ID", required = true, type = "String")
    @GetMapping("/listByTypeId")
    public HttpResult<List<AssessShockLoadParam>> listByTypeId(@RequestParam("inpactloadtypeId") String inpactloadtypeId) {
        List<AssessShockLoadParam> list = assessShockLoadParamService.listByTypeId(inpactloadtypeId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }
}