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.ISysCodeRuleDetailService;
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
import org.nl.system.service.coderule.dto.CodeRuleDetailQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 编码规则明细表 前端控制器
 * </p>
 *
 * @author generator
 * @since 2022-12-20
 */
@Api(tags = "系统：编码详情管理")
@RestController
@RequestMapping("/api/codeDetail")
public class SysCodeRuleDetailController {

    @Autowired
    private ISysCodeRuleDetailService codeDetailService;

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

    @Log("新增编码明细")
    @ApiOperation("新增编码明细")
    @PostMapping
    @SaCheckPermission("genCode:add")
    public ResponseEntity<Object> create(@RequestBody SysCodeRuleDetail codeRuleDetail){
        codeDetailService.create(codeRuleDetail);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @Log("删除编码明细")
    @ApiOperation("删除编码明细")
    @DeleteMapping(value = "/{id}")
    @SaCheckPermission("genCode:del")
    public ResponseEntity<Object> delete(@PathVariable String id){
        codeDetailService.delete(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @Log("修改编码明细")
    @ApiOperation("修改编码明细")
    @PutMapping
    @SaCheckPermission("genCode:edit")
    public ResponseEntity<Object> update(@RequestBody SysCodeRuleDetail json){
        codeDetailService.update(json);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
}

