YYC
2023-11-01 b04a7e554c7d7c5ffb6305915bb142ed26d0cabf
igds-recir/src/main/java/com/ld/igds/drug/service/HDrugService.java
@@ -14,6 +14,7 @@
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -93,7 +94,7 @@
        data.setUpdateUser(ContextUtil.getLoginUserCName());
        try {
            if (null == data.getId()) {
                String id = createId(data.getCompanyId());
                String id = createId(data.getCompanyId(), data.getCgrq());
                data.setId(id);
                session.save(data);
            } else {
@@ -184,26 +185,27 @@
    }
    public String createId(String companyId) {
    public String createId(String companyId, Date time) {
        String timeKey = DateFormatUtils.format(time, "yyyyMMdd");
        // 从缓存中获取已有的组织编码
        String cacheKey = RedisConst.buildKey(companyId, HDrugService.CACHE_DRUG_ID);
        String cacheId = (String) redisUtil.get(cacheKey);
        if (null != cacheId) {
        if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
            String temp = cacheId.substring(cacheId.length() - 3);
            Integer i = Integer.valueOf(temp);
            cacheId = String.format("%03d", ++i);
            cacheId = timeKey + String.format("%03d", ++i);
        } else {
            List<Drug> result = listDrug(companyId, null);
            if (null == result || result.size() == 0) {
                cacheId = "001";
                cacheId = timeKey + "001";
            } else {
                Drug drug = result.get(0);
                String temp = drug.getId().substring(drug.getId().length() - 3);
                Integer i = Integer.valueOf(temp);
                cacheId = String.format("%03d", ++i);
                cacheId = timeKey + String.format("%03d", ++i);
            }
        }
        // 更新缓存