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

com.nb6868.onex.cms.controller.SiteController Maven / Gradle / Ivy

There is a newer version: 4.2.3
Show newest version
package com.nb6868.onex.cms.controller;

import com.nb6868.onex.cms.dto.SiteDTO;
import com.nb6868.onex.cms.dto.SiteQueryForm;
import com.nb6868.onex.cms.service.SiteService;
import com.nb6868.onex.common.annotation.LogOperation;
import com.nb6868.onex.common.annotation.QueryDataScope;
import com.nb6868.onex.common.exception.ErrorCode;
import com.nb6868.onex.common.jpa.QueryWrapperHelper;
import com.nb6868.onex.common.pojo.IdForm;
import com.nb6868.onex.common.pojo.PageData;
import com.nb6868.onex.common.pojo.Result;
import com.nb6868.onex.common.validator.AssertUtils;
import com.nb6868.onex.common.validator.group.AddGroup;
import com.nb6868.onex.common.validator.group.DefaultGroup;
import com.nb6868.onex.common.validator.group.PageGroup;
import com.nb6868.onex.common.validator.group.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 站点
 *
 * @author Charles [email protected]
 */
@RestController
@RequestMapping("/cms/site")
@Validated
@Tag(name="站点")
public class SiteController {

    @Autowired
    private SiteService siteService;

    @PostMapping("list")
    @Operation(summary = "列表")
    @RequiresPermissions("cms:site:query")
    @QueryDataScope(tenantFilter = true, tenantValidate = false)
    public Result list(@Validated @RequestBody SiteQueryForm form) {
        List list = siteService.listDto(QueryWrapperHelper.getPredicate(form, "list"));

        return new Result<>().success(list);
    }

    @PostMapping("page")
    @Operation(summary = "分页")
    @RequiresPermissions("cms:site:query")
    @QueryDataScope(tenantFilter = true, tenantValidate = false)
    public Result page(@Validated({PageGroup.class}) @RequestBody SiteQueryForm form) {
        PageData page = siteService.pageDto(form, QueryWrapperHelper.getPredicate(form, "page"));

        return new Result<>().success(page);
    }

    @PostMapping("info")
    @Operation(summary = "信息")
    @LogOperation("信息")
    @RequiresPermissions("cms:site:query")
    public Result info(@Validated @RequestBody IdForm form) {
        SiteDTO data = siteService.oneDto(QueryWrapperHelper.getPredicate(form));
        AssertUtils.isNull(data, ErrorCode.DB_RECORD_NOT_EXISTED);

        return new Result<>().success(data);
    }

    @PostMapping("save")
    @Operation(summary = "保存")
    @LogOperation("保存")
    @RequiresPermissions("cms:site:edit")
    @QueryDataScope(tenantFilter = true, tenantValidate = false)
    public Result save(@Validated(value = {DefaultGroup.class, AddGroup.class}) @RequestBody SiteDTO dto) {
        siteService.saveDto(dto);

        return new Result<>().success(dto);
    }

    @PostMapping("update")
    @Operation(summary = "修改")
    @LogOperation("修改")
    @RequiresPermissions("cms:site:edit")
    @QueryDataScope(tenantFilter = true, tenantValidate = false)
    public Result update(@Validated(value = {DefaultGroup.class, UpdateGroup.class}) @RequestBody SiteDTO dto) {
        siteService.updateDto(dto);

        return new Result<>().success(dto);
    }

    @PostMapping("delete")
    @Operation(summary = "删除")
    @LogOperation("删除")
    @RequiresPermissions("cms:site:delete")
    @QueryDataScope(tenantFilter = true, tenantValidate = false)
    public Result delete(@Validated @RequestBody IdForm form) {
        siteService.removeById(form.getId());

        return new Result<>();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy