com.leazxl.cms.service.CmsSiteService Maven / Gradle / Ivy
package com.leazxl.cms.service;
import com.leazxl.cms.dao.CmsSiteDao;
import com.leazxl.cms.model.CmsSite;
import com.leazxl.core.dto.DataRet;
import com.leazxl.core.dto.PageRet;
import com.leazxl.core.idservice.IdService;
import com.leazxl.core.util.Assert;
import com.leazxl.core.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
*
*/
@Service
public class CmsSiteService {
@Autowired
private CmsSiteDao cmsSiteDao;
@Autowired
private IdService idService;
public PageRet querySiteList(String key, Pageable pageable) {
return cmsSiteDao.queryPage(new CmsSite(), pageable);
}
/**
* 保存或修改站点信息
*
* @param cmsSite
* @return
*/
@Transactional
public DataRet save(CmsSite cmsSite) {
DataRet ret = new DataRet();
if (cmsSite.getId() != null && !"".equals(cmsSite.getId())) {
cmsSite.setUpdateBy(SecurityUtils.getUserId());
cmsSite.setUpdateDate(new Date());
cmsSiteDao.updateTemplateById(cmsSite);
} else {
cmsSite.setCreateBy(SecurityUtils.getUserId());
cmsSite.setCreateDate(new Date());
cmsSite.setUpdateBy(SecurityUtils.getUserId());
cmsSite.setUpdateDate(new Date());
cmsSite.setDelFlag("0");
cmsSite.setId(idService.getId());
cmsSiteDao.save(cmsSite);
}
ret.setBody(cmsSite);
ret.setMessage("修改成功");
return ret;
}
/**
* 删除站点
*
* @param id
* @return
*/
public DataRet delete(String id) {
DataRet ret = new DataRet<>();
Assert.notNull(id, "站点ID不能为空");
CmsSite cmsSite = cmsSiteDao.get(id);
cmsSite.setDelFlag("1");
cmsSite.setUpdateBy(SecurityUtils.getUserId());
cmsSite.setUpdateDate(new Date());
cmsSiteDao.updateTemplateById(cmsSite);
ret.setMessage("删除成功");
return ret;
}
/**
* 获取站点
*
* @param site
* @return
*/
public CmsSite get(String site) {
return cmsSiteDao.get(site);
}
}