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

com.cq1080.pages.service.WebPageService Maven / Gradle / Ivy

The newest version!
package com.cq1080.pages.service;

import com.cq1080.bean.form.PageForm;
import com.cq1080.jpa.specification.SpecificationUtil;
import com.cq1080.pages.bean.entity.WebPage;
import com.cq1080.pages.datasouce.repository.WebPageRepository;
import com.cq1080.rest.APIError;
import com.cq1080.utils.StringUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;


@Service
@RequiredArgsConstructor
public class WebPageService {

    private final WebPageRepository webPageRepository;

    public Page getPageList(WebPage webPage, PageForm pageForm){
        webPage.setHideInList(false);
        return webPageRepository.findAll(SpecificationUtil.filter(webPage,pageForm).build(),pageForm.pageRequest());
    }


    public WebPage editWebpage(WebPage webPage){
        if (StringUtils.isEmpty(webPage.getPath())){
            APIError.e("请填写路径");
        }
        if (webPageRepository.count(SpecificationUtil.exist().ne("id",webPage.getId()).eq("path",webPage.getPath()).build())>0){
            APIError.e("该路径已存在");
        }
        return webPageRepository.save(webPage);
    }

    @Transactional
    public void deleteWebPage(String ids){
        webPageRepository.softDelete(StringUtil.toIntArray(ids));
    }

    public WebPage getPageDetail(int id) {
        return webPageRepository.findItemById(id);
    }

    public WebPage findByPath(String path){
        return webPageRepository.findAll(SpecificationUtil.exist().eq("path",path).build()).stream().findAny().orElse(null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy