package com.shkj.wms.controller.sys;

import com.shkj.common.annotation.Log;
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.enums.BusinessType;
import com.shkj.common.utils.SecurityUtils;
import com.shkj.common.utils.poi.ExcelUtil;
import com.shkj.wms.bo.SysSeqManaAddBo;
import com.shkj.wms.service.ISysSeqManaService;
import com.shkj.wms.bo.SysSeqManaEditBo;
import com.shkj.wms.bo.SysSeqManaQueryBo;
import com.shkj.wms.config.ValidList;
import com.shkj.wms.vo.SysSeqManaVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 编码规则设置
 *
 * @author lch
 * @menu 号码管理
 * @date 2022-04-11
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/seqMana")
public class SysSeqManaController extends BaseController {

    private final ISysSeqManaService iSysSeqManaService;

    /**
     * 查询号码管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<SysSeqManaVo> list(SysSeqManaQueryBo bo) {
        startPage();
        List<SysSeqManaVo> list = iSysSeqManaService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出号码管理列表
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response, SysSeqManaQueryBo bo) {
        List<SysSeqManaVo> list = iSysSeqManaService.queryList(bo);
        ExcelUtil<SysSeqManaVo> util = new ExcelUtil<SysSeqManaVo>(SysSeqManaVo.class);
        util.exportExcel(response, list, "号码管理数据");
    }

    /**
     * 获取号码管理详细信息
     */
    @GetMapping("/{id}")
    public Result<SysSeqManaVo> getInfo(@PathVariable("id") Long id) {
        return iSysSeqManaService.queryById(id);
    }

    /**
     * 新增或者修改号码
     */
    @Log(title = "新增或者修改号码", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    @RepeatSubmit
    public Result<Boolean> saveOrUpdateSeqMana(@Valid @RequestBody List<SysSeqManaEditBo> bo) {
        return iSysSeqManaService.saveOrUpdateSeqMana(bo);
    }



    /**
     * 新增号码管理
     */
    @Log(title = "号码管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public Result<Boolean> add(@Valid @RequestBody SysSeqManaAddBo bo) {
        return iSysSeqManaService.insertByAddBo(bo);
    }

    /**
     * 修改号码管理
     */
    @Log(title = "号码管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result<Boolean> edit(@Valid @RequestBody SysSeqManaEditBo bo) {
        return iSysSeqManaService.updateByEditBo(bo);
    }

    /**
     * 删除号码管理
     */
    @Log(title = "号码管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public Result<Boolean> remove(@Valid @RequestBody ValidList<Long> ids) {
        return iSysSeqManaService.deleteWithValidById(ids, true);
    }

    /**
     * 生成号码
     */
    @GetMapping("/generator")
    public Result<String> generator() {
        return iSysSeqManaService.generatorCode("SP", "1", SecurityUtils.getCurrentBranchId());
    }


}
