package com.njcn.device.pq.controller;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.device.pq.pojo.param.PqSensitiveUserParam;
import com.njcn.device.pq.pojo.vo.PqSensitiveUserVo;
import com.njcn.device.pqUser.service.IPqSensitiveUserService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xy
 * @since 2025-11-17
 */
@Slf4j
@RestController
@RequestMapping("/pqSensitiveUser")
@Api(tags = "敏感负荷用户管理")
@AllArgsConstructor
public class PqSensitiveUserController extends BaseController {

    private final IPqSensitiveUserService pqSensitiveUserService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getList")
    @ApiOperation("获取敏感负荷用户列表")
    @ApiImplicitParam(name = "param", value = "查询参数", required = true)
    public HttpResult<Page<PqSensitiveUserVo>> getList(@RequestBody BaseParam param) {
        String methodDescribe = getMethodDescribe("getList");
        Page<PqSensitiveUserVo> page = pqSensitiveUserService.getList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getListByIds")
    @ApiOperation("根据id集合获取敏感负荷用户列表")
    @ApiImplicitParam(name = "ids", value = "id集合")
    public HttpResult<List<PqSensitiveUser>> getListByIds(@RequestParam(name = "ids", required = false) List<String> ids) {
        String methodDescribe = getMethodDescribe("getListByIds");
        List<PqSensitiveUser> list;
        list = pqSensitiveUserService.list(
                new LambdaQueryWrapper<PqSensitiveUser>().in(PqSensitiveUser::getId, ids)
        );
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    /**
     * 新增用户对象
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/save")
    @ApiOperation("新增用户对象")
    public HttpResult<Boolean> save(@RequestBody @Validated PqSensitiveUserParam pqSensitiveUserParam) {
        String methodDescribe = getMethodDescribe("save");
        pqSensitiveUserService.save(pqSensitiveUserParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 修改用户对象
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改用户对象")
    public HttpResult<Boolean> update(@RequestBody @Validated PqSensitiveUserParam.UpdatePqSensitiveUserParam pqSensitiveUserParam) {
        String methodDescribe = getMethodDescribe("update");
        pqSensitiveUserService.update(pqSensitiveUserParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


    /**
     * 删除用户对象
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.DELETE)
    @PostMapping("/delete")
    @ApiOperation("删除用户对象")
    @ApiImplicitParam(name = "ids", value = "id集合")
    public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delete");
        pqSensitiveUserService.removeByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

}

