You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-java/src/main/java/com/glxp/api/util/IdUtil.java

37 lines
940 B
Java

package com.glxp.api.util;
import com.glxp.api.constant.Constant;
import com.glxp.api.dao.inv.DeptDeviceDetailDao;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* ID
*/
@Component
public class IdUtil {
@Resource
private RedisUtil redisUtil;
@Resource
private DeptDeviceDetailDao deptDeviceDetailDao;
/**
*
*
* @return
*/
public String getDeptDeviceCode() {
Long code = redisUtil.incr(Constant.DEPT_CACHE_CODE, 1);
if (code == 1) {
//redis中的key不存在重新缓存当前最大的key进去
redisUtil.set(Constant.DEPT_CACHE_CODE, Long.valueOf(deptDeviceDetailDao.selectMaxCode()));
//重新获取最新的编码
code = redisUtil.incr(Constant.DEPT_CACHE_CODE, 1);
}
return String.valueOf(code);
}
}