| | |
| | | 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); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 数据库 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); |
| | | if(isCache){ |
| | | 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); |
| | | //使用likeleft |
| | | queryWrapper.likeLeft("id", 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"); |
| | | List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper); |
| | | if (null == inoutRecords || inoutRecords.isEmpty()) { |
| | | return null; |
| | |
| | | public String inWeightBill(InoutRecord data) { |
| | | |
| | | // 获取表单数据 |
| | | InoutPrintBill bill = this.createBillData(data, "-入库单"); |
| | | InoutPrintBill bill = this.createBillData(data, "入库单"); |
| | | |
| | | // 调整模版数据并返回 |
| | | String htmlStr = InoutBill.IN_WEIGHT_DEFAULT; |
| | | String htmlStr = InoutBill.IN_WEIGHT_DEFAULT_NEW; |
| | | |
| | | htmlStr = htmlStr.replace("billTitle", bill.getBillTitle()); |
| | | |
| | |
| | | htmlStr = htmlStr.replace("handleEnd", ""); |
| | | htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId()); |
| | | htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + ""); |
| | | htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm")); |
| | | htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); |
| | | |
| | | htmlStr = htmlStr.replaceAll("weightUser", |
| | | bill.getWeightUser() == null ? "" : bill.getWeightUser()); |
| | |
| | | bill.getHandleUser() == null ? "" : bill.getHandleUser()); |
| | | htmlStr = htmlStr.replaceAll("keeperName", |
| | | bill.getKeeperUser() == null ? "" : bill.getKeeperUser()); |
| | | |
| | | htmlStr = htmlStr.replaceAll("createUser",ContextUtil.getLoginUserName()); |
| | | |
| | | return htmlStr; |
| | | } |
| | |
| | | */ |
| | | public String outWeightBill(InoutRecord data) { |
| | | // 获取表单数据 |
| | | InoutPrintBill bill = this.createBillData(data, "-出库单"); |
| | | InoutPrintBill bill = this.createBillData(data, "出库单"); |
| | | |
| | | //默认模版 |
| | | String htmlStr = InoutBill.OUT_WEIGHT_DEFAULT; |
| | | String htmlStr = InoutBill.OUT_WEIGHT_DEFAULT_NEW; |
| | | |
| | | htmlStr = htmlStr.replace("billTitle", bill.getBillTitle()); |
| | | |
| | |
| | | htmlStr = htmlStr.replace("handleEnd", ""); |
| | | htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId()); |
| | | htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + ""); |
| | | htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm")); |
| | | htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); |
| | | |
| | | htmlStr = htmlStr.replaceAll("weightUser", getValue(bill.getWeightUser())); |
| | | htmlStr = htmlStr.replace("handleUser", getValue(bill.getHandleUser())); |
| | | htmlStr = htmlStr.replaceAll("keeperName", getValue(bill.getKeeperUser())); |
| | | htmlStr = htmlStr.replaceAll("createUser",ContextUtil.getLoginUserName()); |
| | | |
| | | return htmlStr; |
| | | } |
| | | |
| | |
| | | data.setRegisterTime(new Date()); |
| | | } |
| | | bill.setRegisterTime(DateFormatUtils.format(data.getRegisterTime(), |
| | | "yyyy-MM-dd HH:mm")); |
| | | "yyyy-MM-dd HH:mm:ss")); |
| | | |
| | | if (null == data.getCompleteTime()) { |
| | | data.setCompleteTime(new Date()); |
| | | } |
| | | bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(), |
| | | "yyyy-MM-dd HH:mm")); |
| | | "yyyy-MM-dd HH:mm:ss")); |
| | | |
| | | bill.setEmptyTime(DateFormatUtils.format(data.getEmptyWeightTime(), |
| | | "yyyy-MM-dd HH:mm:ss")); |
| | |
| | | data.setSettleMoney(NumberUtil.keepPrecision(data.getPrice() * data.getRecordWeight(), 2)); |
| | | } |
| | | } |
| | | bill.setSettleMoney(data.getSettleMoney() == null ? "" : data.getSettleMoney() + ""); |
| | | bill.setSettleMoney(data.getSettleMoney() == null ? "" : String.format("%.2f", data.getSettleMoney())); |
| | | bill.setRemark(data.getRemarks() == null ? "" : data.getRemarks()); |
| | | |
| | | if (Constant.TYPE_IN.equals(data.getType())) { |