admin
2020-06-20 0ab8a2ea521a838124f517daf4e61dee971a6d4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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());
            }
    }
}