| | |
| | | InoutRecord record = new InoutRecord(); |
| | | BeanUtils.copyProperties(data, record); |
| | | //保存 |
| | | int num = this.addInoutRecord(record); |
| | | int num = this.addInoutRecord(record,true); |
| | | |
| | | //附件处理 |
| | | fileService.saveInoutFiles(data.getFiles(), record.getId(), null, "INOUT"); |
| | |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public String addInoutRecordList(List<InoutRecord> list) { |
| | | public String addInoutRecordList(List<InoutRecord> list,boolean isCache) { |
| | | if (null == list || list.isEmpty()) { |
| | | return "新增失败"; |
| | | } |
| | | |
| | | for (InoutRecord inoutRecord : list) { |
| | | addInoutRecord(inoutRecord); |
| | | addInoutRecord(inoutRecord,isCache); |
| | | } |
| | | |
| | | return null; |
| | |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public int addInoutRecord(InoutRecord data) { |
| | | public int addInoutRecord(InoutRecord data,boolean isCache) { |
| | | |
| | | if (StringUtils.isBlank(data.getId())) { |
| | | String id = this.createId(data.getRegisterTime(), data.getCompanyId()); |
| | | String id = this.createId(data.getRegisterTime(), data.getCompanyId(),isCache); |
| | | if (Constant.TYPE_IN.equals(data.getType())) { |
| | | data.setId("R_" + id); |
| | | } else if (Constant.TYPE_OUT.equals(data.getType())) { |
| | |
| | | * @param companyId |
| | | * @return |
| | | */ |
| | | public String createId(Date registerTime, String companyId) { |
| | | public String createId(Date registerTime, String companyId,boolean isCache) { |
| | | |
| | | // 时间戳标签 |
| | | String timeKey = DateFormatUtils.format(registerTime, "yyyyMMdd"); |
| | |
| | | // 从缓存中获取已有的组织编码 |
| | | String cacheKey = RedisConst.buildKey(companyId, Constant.CACHE_RECORD_ID); |
| | | |
| | | String cacheId = (String) redisCache.getCacheObject(cacheKey); |
| | | String cacheId = null; |
| | | if (isCache) { |
| | | cacheId=(String) redisCache.getCacheObject(cacheKey); |
| | | } |
| | | |
| | | if (null != cacheId && cacheId.indexOf(timeKey) >= 0) { |
| | | String temp = cacheId.substring(cacheId.length() - 4); |
| | |
| | | } |
| | | |
| | | // 更新缓存 |
| | | if(isCache){ |
| | | redisCache.setCacheObject(cacheKey, cacheId); |
| | | } |
| | | |
| | | return cacheId; |
| | | } |
| | |
| | | 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) |
| | | ); |
| | | //使用likeleft |
| | | queryWrapper.likeLeft("id", id); |
| | | List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper); |
| | | if( null != inoutRecords && inoutRecords.size() > 0){ |
| | | return true; |
| | |
| | | queryWrapper.eq("company_id", companyId); |
| | | queryWrapper.like("id", timeKey); |
| | | queryWrapper.orderByDesc("register_time"); |
| | | queryWrapper.orderByDesc("id"); |
| | | List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper); |
| | | if (null == inoutRecords || inoutRecords.isEmpty()) { |
| | | return null; |