| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 数据库 ID 重复校验,确保新生成的 ID 在数据库中不存在 |
| | | while (this.checkIdExists(companyId, cacheId)) { |
| | | String temp = cacheId.substring(cacheId.length() - 4); |
| | | Integer i = Integer.valueOf(temp); |
| | | i++; |
| | | temp = String.valueOf(i); |
| | | if (temp.length() == 1) { |
| | | cacheId = timeKey + "000" + temp; |
| | | } |
| | | if (temp.length() == 2) { |
| | | cacheId = timeKey + "00" + temp; |
| | | } |
| | | if (temp.length() == 3) { |
| | | cacheId = timeKey + "0" + temp; |
| | | } |
| | | if (temp.length() == 4) { |
| | | cacheId = timeKey + temp; |
| | | } |
| | | } |
| | | |
| | | // 更新缓存 |
| | | redisCache.setCacheObject(cacheKey, cacheId); |
| | | |
| | | return cacheId; |
| | | } |
| | | |
| | | /** |
| | | * 检查 ID 是否在数据库中已存在 |
| | | * |
| | | * @param companyId |
| | | * @param id |
| | | * @return true-已存在,false-不存在 |
| | | */ |
| | | public boolean checkIdExists(String companyId, String id) { |
| | | QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("company_id", companyId); |
| | | queryWrapper.and(wrapper -> |
| | | wrapper.eq("id", id) |
| | | .or() |
| | | .eq("id", "R_" + id) |
| | | .or() |
| | | .eq("id", "C_" + id) |
| | | .or() |
| | | .eq("id", "M_" + id) |
| | | ); |
| | | List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper); |
| | | if( null != inoutRecords && inoutRecords.size() > 0){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | queryWrapper.eq("company_id", companyId); |
| | | queryWrapper.like("id", timeKey); |
| | | queryWrapper.orderByDesc("create_time"); |
| | | |
| | | queryWrapper.orderByDesc("register_time"); |
| | | queryWrapper.orderByDesc("id"); |
| | | List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper); |
| | | if (null == inoutRecords || inoutRecords.isEmpty()) { |
| | | return null; |