package com.ks.tool.bkz.service.impl.sdlj;
|
|
import com.ks.tool.bkz.dao.mybatis.sdlj.SDLJDocTemplateMapper;
|
import com.ks.tool.bkz.entity.sdlj.SDLJDocTemplate;
|
import com.ks.tool.bkz.exception.SDLJDocTemplateException;
|
import com.ks.tool.bkz.service.sdlj.SDLJDocTemplateService;
|
import com.ks.tool.bkz.util.StringUtil;
|
import com.ks.tool.bkz.util.sdlj.DocTemplateUtil;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
|
@Service
|
public class SDLJDocTemplateServiceImpl implements SDLJDocTemplateService {
|
|
@Resource
|
private SDLJDocTemplateMapper sdljDocTemplateMapper;
|
|
@Transactional
|
@Override
|
public void addTemplate(SDLJDocTemplate template) throws SDLJDocTemplateException {
|
if (template == null || StringUtil.isNullOrEmpty(template.getTemplate()) || template.getUid() == null)
|
throw new SDLJDocTemplateException(1, "参数不完整");
|
//验证格式是否正确
|
if (!DocTemplateUtil.IsRight(template.getTemplate())) {
|
throw new SDLJDocTemplateException(2, "模板格式有误");
|
}
|
SDLJDocTemplate old = selectByUid(template.getUid());
|
if (old == null) {
|
if (template.getCreateTime() == null)
|
template.setCreateTime(new Date());
|
sdljDocTemplateMapper.updateByPrimaryKeySelective(template);
|
}else{//更新
|
template.setId(old.getId());
|
template.setUpdateTime(new Date());
|
sdljDocTemplateMapper.updateByPrimaryKeySelective(template);
|
}
|
}
|
|
@Override
|
public SDLJDocTemplate selectByUid(Long uid) {
|
List<SDLJDocTemplate> list= sdljDocTemplateMapper.listByUid(uid);
|
if(list!=null&&list.size()>0)
|
return list.get(0);
|
return null;
|
}
|
|
@Transactional
|
@Override
|
public void deleteByUid(Long uid) {
|
List<SDLJDocTemplate> list= sdljDocTemplateMapper.listByUid(uid);
|
if(list!=null)
|
for(SDLJDocTemplate template:list){
|
sdljDocTemplateMapper.deleteByPrimaryKey(template.getId());
|
}
|
}
|
}
|