com.zyy.common.service.impl.TemplateServiceImpl Maven / Gradle / Ivy
package com.zyy.common.service.impl;
import com.zyy.common.mapper.TemplateMapper;
import com.zyy.common.model.TemplateModel;
import com.zyy.common.service.TemplateService;
import com.zyy.common.util.PageHandle;
import com.zyy.common.util.StringUtils;
import com.zyy.common.vo.TemplateVo;
import lombok.AllArgsConstructor;
import tk.mybatis.mapper.entity.Example;
import java.util.HashMap;
import java.util.Map;
@AllArgsConstructor
public class TemplateServiceImpl implements TemplateService {
private final TemplateMapper templateMapper;
/**
* 分页查询模板文件
*
* @param templateVo 模板
* @return 分页信息
*/
@Override
public Map selectTemplateByPage(TemplateVo templateVo) {
PageHandle.setPage(templateVo.getPage());
Map map = new HashMap<>();
map.put("page", templateVo.getPage());
templateVo.getPage().setTotal((long) templateMapper.selectCount(new TemplateModel()));
Example example = new Example(TemplateModel.class);
example.setOrderByClause("created_on desc limit " + templateVo.getPage().getStart() + "," + templateVo.getPage().getPageSize());
Example.Criteria criteria = example.createCriteria();
if (StringUtils.isNotEmpty(templateVo.getTemplateName()))
criteria.andLike("template_name", "%" + templateVo.getTemplateName() + "%");
map.put("list", templateMapper.selectByExample(example));
return map;
}
/**
* 插入方法
*
* @param model 插入对象
*/
@Override
public void insert(TemplateModel model) {
templateMapper.insertSelective(model);
}
/**
* 更新方法
*
* @param model 更新对象
*/
@Override
public void update(TemplateModel model) {
templateMapper.updateByPrimaryKeySelective(model);
}
/**
* 删除方法
*
* @param id 删除id
*/
@Override
public void deleteById(String id) {
templateMapper.deleteByPrimaryKey(id);
}
}