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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}