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.AssessTransformerParamQuery;
import com.njcn.advance.pojo.po.assess.AssessTransformerParam;
import com.njcn.advance.service.assess.IAssessTransformerParamService;
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("/assessTransformerParam")
@Api(tags = "评估变压器参数管理")
@RequiredArgsConstructor
public class AssessTransformerParamController extends BaseController {

    private final IAssessTransformerParamService assessTransformerParamService;

    @ApiOperation("获取评估变压器参数列表")
    @PostMapping("/list")
    public HttpResult<List<AssessTransformerParam>> list(@RequestBody AssessTransformerParamQuery query) {
        LambdaQueryWrapper<AssessTransformerParam> wrapper = Wrappers.<AssessTransformerParam>lambdaQuery()
                .like(query.getTransName() != null, AssessTransformerParam::getTransName, query.getTransName())
                .eq(query.getAssessId() != null, AssessTransformerParam::getAssessId, query.getAssessId())
                .eq(query.getTranstypeId() != null, AssessTransformerParam::getTranstypeId, query.getTranstypeId());
        List<AssessTransformerParam> list = assessTransformerParamService.list(wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("分页查询评估变压器参数")
    @PostMapping("/page")
    public HttpResult<Page<AssessTransformerParam>> page(@RequestBody AssessTransformerParamQuery query) {
        Page<AssessTransformerParam> pageParam = new Page<>(
                PageFactory.getPageNum(query),
                PageFactory.getPageSize(query)
        );
        LambdaQueryWrapper<AssessTransformerParam> wrapper = Wrappers.<AssessTransformerParam>lambdaQuery()
                .like(query.getTransName() != null, AssessTransformerParam::getTransName, query.getTransName())
                .eq(query.getAssessId() != null, AssessTransformerParam::getAssessId, query.getAssessId())
                .eq(query.getTranstypeId() != null, AssessTransformerParam::getTranstypeId, query.getTranstypeId());
        Page<AssessTransformerParam> pageData = assessTransformerParamService.page(pageParam, wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), pageData,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据ID获取评估变压器参数详情")
    @ApiImplicitParam(name = "transId", value = "变压器ID", required = true, type = "String")
    @GetMapping("/getInfo")
    public HttpResult<AssessTransformerParam> getInfo(@RequestParam("transId") String transId) {
        AssessTransformerParam param = assessTransformerParamService.getByTransId(transId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), param,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("新增评估变压器参数")
    @PostMapping("/add")
    public HttpResult<Boolean> add(@RequestBody @Validated AssessTransformerParamQuery param) {
        boolean result = assessTransformerParamService.add(param);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), result,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("修改评估变压器参数")
    @PostMapping("/edit")
    public HttpResult<Boolean> edit(@RequestBody @Validated AssessTransformerParamQuery.UpdateAssessTransformerParamQuery updateQuery) {
        assessTransformerParamService.update(updateQuery);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), true,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("删除评估变压器参数")
    @ApiImplicitParam(name = "transId", value = "变压器ID", required = true, type = "String")
    @PostMapping("/delete")
    public HttpResult<Boolean> delete(@RequestBody List<String> transId) {
        boolean result = assessTransformerParamService.removeByIds(transId);
        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<AssessTransformerParam>> listByAssessId(@RequestParam("assessId") String assessId) {
        List<AssessTransformerParam> list = assessTransformerParamService.listByAssessId(assessId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }
}