yujian
2020-05-17 de4110d3d3944ffcd797fd8c43f0d455cc731f84
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
61
62
63
64
65
66
67
68
package com.yeshi.fanli.service.impl.homemodule;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.homemodule.CommonShareInfoMapper;
import com.yeshi.fanli.entity.bus.homemodule.CommonShareInfo;
import com.yeshi.fanli.entity.bus.homemodule.CommonShareInfo.CommonShareInfoEnum;
import com.yeshi.fanli.exception.goods.ConvertLinkExceptionException;
import com.yeshi.fanli.exception.homemodule.SpecialException;
import com.yeshi.fanli.service.inter.homemodule.CommonShareInfoService;
import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class CommonShareInfoServiceImpl implements CommonShareInfoService {
 
    @Resource
    private CommonShareInfoMapper commonShareInfoMapper;
    
    @Resource
    private ConvertLinkManager convertLinkManager;
 
    @Override
    public void save(CommonShareInfo record) throws SpecialException {
        if (record == null || record.getPid() == null || record.getType() == null)
            throw new SpecialException(1, "参数不完整");
 
        if (!StringUtil.isNullOrEmpty(record.getComment())) {
            if (record.getNeedSpin() == null)
                record.setNeedSpin(false);
            
            if (record.getNeedSpin()) {
                try {
                    convertLinkManager.convertLinkFromText(record.getComment(), Constant.LINK_TOKEN_VERIFY_UID, true);
                } catch (ConvertLinkExceptionException e) {
                    if (ConvertLinkExceptionException.CODE_NONE != e.getCode()) {
                        throw new SpecialException(1, "包含不可转链的口令与链接");
                    }
                } catch (Exception e) {
                    throw new SpecialException(1, "包含不可转链的口令与链接");
                }
            }
        }
        
        CommonShareInfo info = commonShareInfoMapper.getByPidAndType(record.getPid(), record.getType().name());
        if (info == null) {
            commonShareInfoMapper.insertSelective(record);
        } else {
            record.setId(info.getId());
            commonShareInfoMapper.updateByPrimaryKeySelective(record);
        }
    }
 
    
    @Override
    public CommonShareInfo getByPidAndType(Long pid, String type) {
        return commonShareInfoMapper.getByPidAndType(pid, type);
    }
    
    
    @Override
    public void deleteByPidAndType(Long pid, String type) {
        commonShareInfoMapper.deleteByPidAndType(pid, type);
    }
}