package com.njcn.advance.controller.assess;

import cn.hutool.core.util.StrUtil;
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.AssessDicShockLoadQuery;
import com.njcn.advance.pojo.po.assess.AssessDicShockLoad;
import com.njcn.advance.service.assess.IAssessDicShockLoadService;
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("/assessDicShockLoad")
@Api(tags = "冲击负荷字典管理")
@RequiredArgsConstructor
public class AssessDicShockLoadController extends BaseController {

    private final IAssessDicShockLoadService assessDicShockLoadService;

    @ApiOperation("获取冲击负荷字典列表")
    @PostMapping("/list")
    public HttpResult<List<AssessDicShockLoad>> list(@RequestBody AssessDicShockLoadQuery query) {
        LambdaQueryWrapper<AssessDicShockLoad> wrapper = Wrappers.<AssessDicShockLoad>lambdaQuery()
                .like(query.getInpactloadtypeName() != null, AssessDicShockLoad::getInpactloadtypeName, query.getInpactloadtypeName())
                .eq(query.getInpactloadStartup() != null, AssessDicShockLoad::getInpactloadStartup, query.getInpactloadStartup());
        List<AssessDicShockLoad> list = assessDicShockLoadService.list(wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("分页查询冲击负荷字典")
    @PostMapping("/page")
    public HttpResult<Page<AssessDicShockLoad>> page(@RequestBody AssessDicShockLoadQuery query) {
        Page<AssessDicShockLoad> pageParam = new Page<>(
                PageFactory.getPageNum(query),
                PageFactory.getPageSize(query)
        );
        LambdaQueryWrapper<AssessDicShockLoad> wrapper = Wrappers.<AssessDicShockLoad>lambdaQuery()
                .like(StrUtil.isNotBlank(query.getSearchValue()), AssessDicShockLoad::getInpactloadtypeName, query.getSearchValue())
                .eq(StrUtil.isNotBlank(query.getInpactloadStartup()), AssessDicShockLoad::getInpactloadStartup, query.getInpactloadStartup());
        Page<AssessDicShockLoad> pageData = assessDicShockLoadService.page(pageParam, wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), pageData,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据类型ID获取冲击负荷字典详情")
    @ApiImplicitParam(name = "inpactloadtypeId", value = "冲击负荷类型ID", required = true, type = "String")
    @GetMapping("/getInfo")
    public HttpResult<AssessDicShockLoad> getInfo(@RequestParam("inpactloadtypeId") String inpactloadtypeId) {
        AssessDicShockLoad param = assessDicShockLoadService.getByInpactloadtypeId(inpactloadtypeId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), param,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("新增冲击负荷字典")
    @PostMapping("/add")
    public HttpResult<Boolean> add(@RequestBody @Validated AssessDicShockLoadQuery param) {
        boolean result = assessDicShockLoadService.add(param);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), result,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("修改冲击负荷字典")
    @PostMapping("/edit")
    public HttpResult<Boolean> edit(@RequestBody @Validated AssessDicShockLoadQuery.UpdateAssessDicShockLoadQuery updateQuery) {
        assessDicShockLoadService.update(updateQuery);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), true,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("删除冲击负荷字典")
    @ApiImplicitParam(name = "inpactloadtypeId", value = "冲击负荷类型ID", required = true, type = "String")
    @PostMapping("/delete")
    public HttpResult<Boolean> delete(@RequestBody List<String> inpactloadtypeId) {
        boolean result = assessDicShockLoadService.removeByIds(inpactloadtypeId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), result,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据启动方式查询冲击负荷字典")
    @ApiImplicitParam(name = "inpactloadStartup", value = "冲击负荷启动方式", type = "String")
    @GetMapping("/listByStartup")
    public HttpResult<List<AssessDicShockLoad>> listByStartup(@RequestParam(required = false) String inpactloadStartup) {
        LambdaQueryWrapper<AssessDicShockLoad> wrapper = Wrappers.<AssessDicShockLoad>lambdaQuery()
                .eq(inpactloadStartup != null, AssessDicShockLoad::getInpactloadStartup, inpactloadStartup);
        List<AssessDicShockLoad> list = assessDicShockLoadService.list(wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }
}