package com.ruoyi.ibs.rules.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ibs.rules.domain.dto.RelationRuleDTO;
import com.ruoyi.ibs.rules.domain.vo.RelationRuleVO;
import com.ruoyi.ibs.rules.service.IRelationRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 分配引擎规则;Controller
 *
 * @author ruoyi
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/system/rule")
@Api("分配引擎规则")
public class RelationRuleController extends BaseController {
    @Autowired
    private IRelationRuleService relationRuleService;

    /**
     * 查询分配引擎规则;列表
     */
//   @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    @ApiOperation("查询规则列表")
    public R<List<RelationRuleVO>> list() {
        List<RelationRuleVO> list = relationRuleService.selectRelationRuleList();
        return R.ok(list);
    }


    //   @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @PostMapping("/update")
    @ApiOperation("更新列表")
    public R<String> update(String op)
    {
        return R.ok(relationRuleService.upadteAllDate(op) == 1 ? "更新成功":"更新执行失败！");
    }

    /**
     * 新增分配引擎规则;
     */
//    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @ApiOperation("新增规则列表")
    @Log(title = "分配引擎-分配引擎规则;", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<String> add(@RequestBody List<RelationRuleDTO> relationRules) {
        relationRuleService.insertRelationRule(relationRules);
        return R.ok("新增规则成功");
    }


    /**
     * 修改分配引擎规则;
     */
//    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @ApiOperation("修改规则列表")
    @Log(title = "分配引擎-分配引擎规则;", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<String> edit(@RequestBody List<RelationRuleDTO> relationRules) {
        relationRuleService.updateRelationRule(relationRules);
        return R.ok("修改规则成功");
    }


    /**
     * 获取规则码值;
     */
//    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @ApiOperation("获取规则码值")
    @Log(title = "分配引擎-获取规则码值;", businessType = BusinessType.UPDATE)
    @PutMapping("/getParam")
    public R<Map<String, String>> getParam() {
        Map<String, String> paramList = relationRuleService.getParamList();
        return R.ok(paramList);
    }

    /**
     * 获取规则码值;
     */
//    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @ApiOperation("获取地址来源码值")
    @Log(title = "分配引擎-获取地址来源码值;", businessType = BusinessType.UPDATE)
    @GetMapping("/getAddressSource")
    public R<Map<String, String>> getAddressSource() {
        Map<String, String> paramList = relationRuleService.getAddressSource();
        return R.ok(paramList);
    }

}
