wuxw
2019-02-02 9454b49eeabd56894550f1419f14e96f9d10c2ef
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
69
70
71
72
73
74
75
76
77
78
79
80
package com.java110.code.smo.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.code.dao.IPrimaryKeyServiceDao;
import com.java110.code.dao.ISnowflakeldWorker;
import com.java110.code.smo.IPrimaryKeyServiceSMO;
import com.java110.common.constant.ResponseConstant;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.core.context.CodeDataFlow;
import com.java110.core.factory.DataTransactionFactory;
import com.java110.service.init.ServiceInfoListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Map;
 
/**
 * 用户服务信息管理业务信息实现
 * Created by wuxw on 2017/4/5.
 */
@Service("primaryKeyServiceSMOImpl")
public class PrimaryKeyServiceSMOImpl extends BaseServiceSMO implements IPrimaryKeyServiceSMO {
    protected final static Logger logger = LoggerFactory.getLogger(PrimaryKeyServiceSMOImpl.class);
 
 
    @Autowired
    IPrimaryKeyServiceDao iPrimaryKeyServiceDao;
 
    @Autowired
    ISnowflakeldWorker snowflakeIdWorkerImpl;
 
    @Autowired
    private ServiceInfoListener serviceInfoListener;
 
    /**
     * 根据sequence 表中name 查询ID
     *
     * @param primaryKeyInfo name信息封装
     * @return
     */
    public JSONObject queryPrimaryKey(JSONObject primaryKeyInfo) throws Exception {
        Map paramIn = JSONObject.toJavaObject(primaryKeyInfo, Map.class);
        Map primaryKey = iPrimaryKeyServiceDao.queryPrimaryKey(paramIn);
        JSONObject returnPrimaryKey = new JSONObject();
        if (primaryKey != null && primaryKey.containsKey("targetId")) {
            returnPrimaryKey.put("targetId", primaryKey.get("targetId"));
        } else {
            //如果没定义相应name的键序列,直接返回-1 表示 自己系统需要自己生成
            returnPrimaryKey.put("targetId", "-1");
        }
        return returnPrimaryKey;
    }
 
    public void generateCode(CodeDataFlow dataFlow){
        String code = snowflakeIdWorkerImpl.getIdByPrefix(dataFlow.getPrefix(),serviceInfoListener.getWorkId());
 
        JSONObject resJson = DataTransactionFactory.createCodeResponseJson(dataFlow.getTransactionId(),code, ResponseConstant.RESULT_CODE_SUCCESS,"成功");
 
        dataFlow.setResJson(resJson);
    }
 
    public ServiceInfoListener getServiceInfoListener() {
        return serviceInfoListener;
    }
 
    public void setServiceInfoListener(ServiceInfoListener serviceInfoListener) {
        this.serviceInfoListener = serviceInfoListener;
    }
 
 
    public ISnowflakeldWorker getSnowflakeIdWorkerImpl() {
        return snowflakeIdWorkerImpl;
    }
 
    public void setSnowflakeIdWorkerImpl(ISnowflakeldWorker snowflakeIdWorkerImpl) {
        this.snowflakeIdWorkerImpl = snowflakeIdWorkerImpl;
    }
}