package com.njcn.product.carrycapacity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

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.product.carrycapacity.pojo.param.CarryCapacityUserParam;
import com.njcn.product.carrycapacity.pojo.po.CarryCapacityUserPO;
import com.njcn.product.carrycapacity.service.CarryCapacityUserPOService;
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.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("carrycapacityuser")
@Api(tags = "承载能力评估用户")
@RequiredArgsConstructor
public class CarryCapacityUserController extends BaseController {


    private final CarryCapacityUserPOService carryCapacityUserPOService;

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


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/remove")
    @ApiOperation("承载能力评估用户批量删除")
    @ApiImplicitParam(name = "userIds", value = "用户id集合", required = true)
    public HttpResult<Boolean> remove(@RequestParam("userIds") List<String> userIds) {
        String methodDescribe = getMethodDescribe("remove");
        Boolean flag = carryCapacityUserPOService.lambdaUpdate().in(CarryCapacityUserPO::getUserId,userIds).set(CarryCapacityUserPO::getStatus,0).update();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/update")
    @ApiOperation("承载能力评估用户编辑")
    @ApiImplicitParam(name = "userUpdateParam", value = "编辑参数", required = true)
    public HttpResult<Boolean> update(@RequestBody @Validated CarryCapacityUserParam.CarryCapacityUserUpdateParam userUpdateParam) {
        String methodDescribe = getMethodDescribe("update");
        Boolean flag = carryCapacityUserPOService.updateUser(userUpdateParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queyDetailUser")
    @ApiOperation("承载能力评估用户查询")
    @ApiImplicitParam(name = "pageParam", value = "编辑参数", required = true)
    public HttpResult<IPage<CarryCapacityUserPO>> queyDetailUser(@RequestBody @Validated CarryCapacityUserParam.CarryCapacityUserPageParam pageParam) {
        String methodDescribe = getMethodDescribe("queyDetailUser");
        IPage<CarryCapacityUserPO> page = carryCapacityUserPOService.queyDetailUser(pageParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queyDetailUserById")
    @ApiOperation("承载能力评估用户查询")
    public HttpResult<CarryCapacityUserPO> queyDetailUserById(@RequestParam("userId") String userId) {
        String methodDescribe = getMethodDescribe("queyDetailUserById");
        CarryCapacityUserPO po = carryCapacityUserPOService.queyDetailUserById(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }




}
