package com.njcn.advance.controller.carrycapacity;

import com.njcn.advance.pojo.carrycapacity.param.CarryCapacityDeviceParam;
import com.njcn.advance.pojo.carrycapacity.po.CarryCapacityDevicePO;
import com.njcn.advance.service.carrycapacity.CarryCapacityDevicePOService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
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.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author hongawen
 * @version 1.0.0
 * @date 2023年07月21日 10:06
 */
@RestController
@RequestMapping("carrycapacitydev")
@Api(tags = "承载能力评估用户设备")
@RequiredArgsConstructor
public class CarryCapacityDevController extends BaseController {


    private final CarryCapacityDevicePOService carryCapacityDevicePOService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/add")
    @ApiOperation("承载能力评估用户设备新增")
    @ApiImplicitParam(name = "capacityDeviceParam", value = "新增参数", required = true)
    public HttpResult<Boolean> add(@RequestBody @Validated CarryCapacityDeviceParam capacityDeviceParam) {
        String methodDescribe = getMethodDescribe("add");
        Boolean flag = carryCapacityDevicePOService.add(capacityDeviceParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/remove")
    @ApiOperation("承载能力评估用户设备批量删除")
    @ApiImplicitParam(name = "devIds", value = "用户id集合", required = true)
    public HttpResult<Boolean> remove(@RequestParam("devIds") List<String> devIds) {
        String methodDescribe = getMethodDescribe("remove");
        Boolean flag = carryCapacityDevicePOService.removeByIds(devIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/update")
    @ApiOperation("承载能力评估用户设备编辑")
    @ApiImplicitParam(name = "deviceParam", value = "编辑参数", required = true)
    public HttpResult<Boolean> update(@RequestBody @Validated CarryCapacityDeviceParam.CarryCapacityDeviceUpdateParam deviceParam) {
        String methodDescribe = getMethodDescribe("update");
        Boolean flag = carryCapacityDevicePOService.updateDevice(deviceParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queyDeviceList")
    @ApiOperation("承载能力评估用户设备查询")
    @ApiImplicitParam(name = "deviceParam", value = "编辑参数", required = true)
    public HttpResult<List<CarryCapacityDevicePO>> queyDeviceList(@RequestBody @Validated CarryCapacityDeviceParam.CarryCapacityDeviceQueryParam deviceParam) {
        String methodDescribe = getMethodDescribe("queyDeviceList");
        List<CarryCapacityDevicePO> list = carryCapacityDevicePOService.lambdaQuery()
                .eq(StringUtils.isNotBlank(deviceParam.getDevId()), CarryCapacityDevicePO::getDevId, deviceParam.getDevId())
                .eq(StringUtils.isNotBlank(deviceParam.getUserId()), CarryCapacityDevicePO::getUserId, deviceParam.getUserId()).list();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }




}
