All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rexsheng.springboot.faster.system.dict.adapter.DictController Maven / Gradle / Ivy

The newest version!
package com.github.rexsheng.springboot.faster.system.dict.adapter;

import com.github.rexsheng.springboot.faster.common.constant.CommonConstant;
import com.github.rexsheng.springboot.faster.common.domain.Result;
import com.github.rexsheng.springboot.faster.logging.RequestLog;
import com.github.rexsheng.springboot.faster.system.dict.application.DictService;
import com.github.rexsheng.springboot.faster.system.dict.application.dto.AddDictRequest;
import com.github.rexsheng.springboot.faster.system.dict.application.dto.QueryDictRequest;
import com.github.rexsheng.springboot.faster.system.dict.application.dto.UpdateDictRequest;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("/sys/dict")
@Tag(name = "DictController",description = "字典管理")
@ConditionalOnProperty(prefix = "app.module.management",name = "controller",havingValue = "true",matchIfMissing = true)
public class DictController {

    private static Logger logger= LoggerFactory.getLogger(DictController.class);

    @Resource
    private DictService dictService;

    @GetMapping
    @PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DICT_LIST)")
    public Result getDictPagedList(@RequestParam(required = false) Integer dictType,
                                   @RequestParam(required = false) String label,
                                   @RequestParam Long pageIndex,
                                   @RequestParam Long pageSize){
        QueryDictRequest request=new QueryDictRequest();
        request.setDictType(dictType);
        request.setLabel(label);
        request.setPageIndex(pageIndex);
        request.setPageSize(pageSize);
        return Result.success(dictService.pagedList(request));
    }

    @GetMapping("/{dictId}")
    @PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DICT_EDIT)")
    public Result getDict(@PathVariable Long dictId){
        return Result.success(dictService.get(dictId));
    }

    @PostMapping
    @PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DICT_ADD)")
    @RequestLog("新增字典")
    public Result addDict(@RequestBody @Validated AddDictRequest request){
        dictService.add(request);
        return Result.success();
    }

    @PutMapping("/{dictId}")
    @PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DICT_EDIT)")
    @RequestLog("修改字典")
    public Result updateDict(@PathVariable Long dictId, @RequestBody @Validated UpdateDictRequest request){
        request.setDictId(dictId);
        dictService.update(request);
        return Result.success();
    }

    @PutMapping("/{dictIds}/status/{status}")
    @PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DICT_EDIT)")
    @RequestLog("修改字典状态")
    public Result changeDictValid(@PathVariable Long[] dictIds,@PathVariable Boolean status){
        dictService.updateStatus(UpdateDictRequest.of(dictIds,status?CommonConstant.STATUS_RUNNING:CommonConstant.STATUS_STOP));
        return Result.success();
    }

    @DeleteMapping
    @PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DICT_DEL)")
    @RequestLog("删除字典")
    public Result deleteDict(@RequestBody Long[] ids){
        dictService.delete(Arrays.asList(ids));
        return Result.success();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy