package org.jeecg.modules.dynamicStaticAnalysis.controller;


import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.modules.dynamicStaticAnalysis.entity.ConfigDynamics;
import org.jeecg.modules.dynamicStaticAnalysis.service.IConfigDynamicsService;
import org.springframework.web.bind.annotation.*;

import org.jeecg.common.system.base.controller.JeecgController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 动静态分析-动态分析-参数配置 前端控制器
 * </p>
 *
 * @author hkl
 * @since 2023-07-21
 */
@RestController
@RequestMapping("/dynamicStaticAnalysis/config/dynamics")
@Api("动静态分析-动态分析-参数配置")
public class ConfigDynamicsController extends JeecgController<ConfigDynamics, IConfigDynamicsService> {

    @AutoLog(value = "动静态分析-动态分析-参数配置-列表查询")
    @ApiOperation(value = "动静态分析-动态分析-参数配置-列表查询", notes = "动静态分析-动态分析-参数配置-列表查询")
    @GetMapping(value = "/list")
    public Result<List<ConfigDynamics>> queryPageList() {
        return Result.OK(this.service.list());
    }


    @AutoLog(value = "动静态分析-动态分析-参数配置-编辑")
    @ApiOperation(value = "资产管理-曲线管理-编辑", notes = "资产管理-曲线管理-编辑")
    @PostMapping(value = "/edit")
    public Result<String> edit(@RequestBody ConfigDynamics record) {
        if (ObjectUtil.isEmpty(record.getId())) {
            record.setId(UUIDGenerator.generate());
        }
        this.service.saveOrUpdate(record);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "动静态分析-动态分析-参数配置-通过id删除")
    @ApiOperation(value = "动静态分析-动态分析-参数配置-通过id删除", notes = "动静态分析-动态分析-参数配置-通过id删除")
    @GetMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        this.service.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "动静态分析-动态分析-参数配置-批量删除")
    @ApiOperation(value = "动静态分析-动态分析-参数配置-批量删除", notes = "动静态分析-动态分析-参数配置-批量删除")
    @GetMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.service.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }
}
