package com.shkj.wms.controller.base;

import com.shkj.common.annotation.RepeatSubmit;
import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.common.core.page.TableDataInfo;
import com.shkj.common.core.validate.AddGroup;
import com.shkj.common.core.validate.EditGroup;
import com.shkj.wms.bo.BasRuleAddBo;
import com.shkj.wms.bo.BasRuleBo;
import com.shkj.wms.common.SwitchStatusEntity;
import com.shkj.wms.domain.BasRule;
import com.shkj.wms.service.IBasRuleService;
import com.shkj.wms.vo.BasRuleVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 编码规则(待定)
 *
 * @author j.liang
 * @date 2022-12-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/basics/rule")
public class BasRuleController extends BaseController {

    private final IBasRuleService iBasRuleService;

    /**
     * 查询编码规则列表
     */
    @GetMapping("/list")
    public TableDataInfo<BasRuleVo> list(BasRuleBo bo) {
        startPage();
        List<BasRuleVo> basRuleVos = iBasRuleService.queryPageList(bo);
        return getDataTable(basRuleVos);
    }


    /**
     * 获取编码规则详细信息
     *
     * @param ruleId 主键
     */
    @GetMapping("/getBaseRuleById")
    public Result<BasRule> getBaseRuleById(Long ruleId) {
        return Result.ok().data(iBasRuleService.queryById(ruleId));
    }

    /**
     * 新增编码规则
     */
    @RepeatSubmit()
    @PostMapping("/add")
    public Result<Boolean> add(@Validated(AddGroup.class) @RequestBody BasRuleAddBo bo) {
        return iBasRuleService.insertBasRuleByBo(bo);
    }

    /**
     * 修改编码规则
     */
    @RepeatSubmit()
    @PutMapping("/edit")
    public Result<Boolean> edit(@Validated(EditGroup.class) @RequestBody BasRuleAddBo bo) {
        return Result.ok().data(iBasRuleService.updateByBo(bo));
    }

    /**
     * 删除编码规则
     *
     * @param id 主键串
     */

    @DeleteMapping("/del")
    public Result<Boolean> del(@RequestParam Long id) {
        iBasRuleService.deleteWithValidById(id);
        return Result.ok();
    }

    /**
     * 启用/停用编码规则
     */

    @RepeatSubmit()
    @PostMapping("/switchStatus")
    public Result<Boolean> switchStatus(@Validated(EditGroup.class) @RequestBody SwitchStatusEntity bo) {
        return iBasRuleService.switchStatus(bo.getId(), bo.getIsuse());
    }
}
