package org.nl.system.controller.coderule;


import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nl.common.base.TableDataInfo;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.logging.annotation.Log;
import org.nl.system.service.coderule.ISysCodeRuleService;
import org.nl.system.service.coderule.dao.SysCodeRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 编码规则表 前端控制器
 * </p>
 *
 * @author generator
 * @since 2022-12-19
 */
@RestController
@Api(tags = "系统：编码生成")
@RequestMapping("/api/genCode")
public class SysCodeRuleController {
    @Autowired
    private ISysCodeRuleService codeRuleService;

    @ApiOperation("查询编码")
    @GetMapping
    @SaCheckPermission("genCode:list")
    public ResponseEntity<Object> queryAll(@RequestParam Map form, PageQuery pageable) {
        return new ResponseEntity<>(TableDataInfo.build(codeRuleService.queryAll(form, pageable)), HttpStatus.OK);
    }

    @Log("新增编码")
    @ApiOperation("新增编码")
    @PostMapping
    @SaCheckPermission("genCode:add")
    public ResponseEntity<Object> create(@Validated @RequestBody SysCodeRule codeRule) {
        codeRuleService.create(codeRule);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @Log("删除编码")
    @ApiOperation("删除编码")
    @DeleteMapping
    @SaCheckPermission("genCode:del")
    public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
        codeRuleService.deleteCodeRule(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @Log("修改编码")
    @ApiOperation("修改编码")
    @PutMapping
    @SaCheckPermission("genCode:edit")
    public ResponseEntity<Object> update(@RequestBody SysCodeRule codeRule) {
        codeRuleService.updateCodeRule(codeRule);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @ApiOperation("导出任务数据")
    @GetMapping(value = "/codeDemo")
    @SaCheckPermission("genCode:list")
    public ResponseEntity<Object> CodeDemo(@RequestParam Map form) throws IOException {
        return new ResponseEntity<>(codeRuleService.codeDemo(form), HttpStatus.OK);
    }
}

