| | |
| | | import com.ld.igds.inout.service.InoutService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.models.Depot; |
| | | import com.ld.igds.models.InoutPrice; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.igds.util.DateUtil; |
| | | import com.ld.igds.util.RedisUtil; |
| | |
| | | return "没有获取到被删除数据的ID,无法删除!"; |
| | | } |
| | | |
| | | // 缓存中删除 |
| | | this.delInoutFromCache(param.getDeptId(), param.getType(), param.getId(), false); |
| | | |
| | | inoutMapper.deleteData(param); |
| | | |
| | | delInoutFromCache(param.getDeptId(), param.getType(), param.getId()); |
| | | |
| | | return null; |
| | | } |
| | |
| | | if (StringUtils.isEmpty(param.getCompanyId())) { |
| | | param.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | |
| | | // 缓存中删除 |
| | | this.delInoutFromCache(param.getDeptId(), param.getType(), param.getId(), false); |
| | | delInoutFromCache(param.getDeptId(), param.getType(), param.getId()); |
| | | |
| | | param.setProgress(InoutConstant.PROGRESS_RECORD); |
| | | param.setRecordStatus(InoutConstant.RECORD_STATUS_ERROR); |
| | |
| | | |
| | | inoutMapper.insertData(data); |
| | | |
| | | this.addInoutCache(data); |
| | | updateInoutCache(data); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("------------出入库执行保存出错---{}", e); |
| | |
| | | |
| | | @Override |
| | | public String updateData(InoutData data) throws Exception { |
| | | |
| | | data.setUpdateTime(new Date()); |
| | | if (StringUtils.isEmpty(data.getCompanyId())) { |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | |
| | | |
| | | inoutMapper.updateData(newData); |
| | | |
| | | //如果是完成状态不在进行后期处理,单独走complete方法 |
| | | if (InoutConstant.PROGRESS_RECORD.equals(newData.getProgress())) { |
| | | return null; |
| | | } |
| | | //更新缓存 |
| | | updateInoutCache(newData); |
| | | |
| | | // 更新緩存 |
| | | if (InoutConstant.PROGRESS_RECORD.equals(newData.getProgress())) { |
| | | this.delInoutFromCache(newData.getDeptId(), newData.getType(), newData.getId(), true); |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public String updateDataByHandle(InoutData data) { |
| | | data.setUpdateTime(new Date()); |
| | | if (StringUtils.isEmpty(data.getCompanyId())) { |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | InoutData newData; |
| | | if (EntityUtils.isEntity(data)) { |
| | | newData = new InoutData(); |
| | | BeanUtils.copyProperties(data, newData, new String[]{"checkItems", "files"}); |
| | | } else { |
| | | this.updateInoutCache(newData); |
| | | newData = data; |
| | | } |
| | | |
| | | inoutMapper.updateDataByHandle(newData); |
| | | |
| | | //更新缓存 |
| | | updateInoutCache(newData); |
| | | |
| | | return null; |
| | | } |
| | | |
| | |
| | | return records; |
| | | } |
| | | |
| | | // @Override |
| | | // public InoutData getLastRecord(InoutParam param) { |
| | | // return inoutMapper.getLastRecord(param); |
| | | // } |
| | | |
| | | // @Override |
| | | // public int updateCuStorage(InoutParam param) { |
| | | // return inoutMapper.updateCuStorage(param); |
| | | // } |
| | | |
| | | @Override |
| | | public String validate(String intelCard, String plateNum) { |
| | | InoutParam param = new InoutParam(); |
| | |
| | | param.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | |
| | | if (null == param.getFoodType()) { |
| | | // 根据仓库信息获取缓存 |
| | | Depot depot = commonService.getCacheDepot(param.getCompanyId(), param.getDepotId()); |
| | | param.setFoodType(depot.getFoodType()); |
| | | } |
| | | |
| | | // 清除缓存 |
| | | this.delInoutFromCache(param.getDeptId(), param.getType(), param.getId(), true); |
| | | this.delInoutFromCache(param.getDeptId(), param.getType(), param.getId()); |
| | | |
| | | inoutMapper.toComplete(param); |
| | | |
| | | return null; |
| | | } |
| | | |
| | |
| | | data.setFoodType(depot.getFoodType()); |
| | | } |
| | | |
| | | // 清除缓存 |
| | | this.delInoutFromCache(data.getDeptId(), data.getType(), data.getId(), false); |
| | | |
| | | inoutMapper.updateData(data); |
| | | |
| | | updateInoutCache(data); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void addInoutCache(InoutData data) { |
| | | data.setFiles(null); |
| | | data.setCheckItems(null); |
| | | |
| | | this.setInoutCache(data.getDeptId(), data); |
| | | |
| | | // 推送到大屏 |
| | | List<InoutData> list = this.getListInoutCache(data.getDeptId()); |
| | | |
| | | this.notifyToScreen(data.getDeptId(), list, null); |
| | | } |
| | | |
| | | @Override |
| | | public void updateInoutCache(InoutData data) { |
| | | |
| | | data.setFiles(null); |
| | | data.setCheckItems(null); |
| | | |
| | | this.setInoutCache(data.getDeptId(), data); |
| | | if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { |
| | | |
| | | // 推送到大屏 |
| | | List<InoutData> list = this.getListInoutCache(data.getDeptId()); |
| | | List<InoutData> completeList = this.getCompleteListInoutCache(data.getDeptId()); |
| | | delInoutFromCache(data.getDeptId(), data.getType(), data.getId()); |
| | | |
| | | this.notifyToScreen(data.getCompanyId(), list, completeList); |
| | | setCompleteInoutCache(data.getDeptId(), data); |
| | | |
| | | } else { |
| | | setInoutCache(data.getDeptId(), data); |
| | | } |
| | | //推送大屏 |
| | | notifyToScreen(data.getCompanyId(), data.getDeptId(), data.getProgress()); |
| | | } |
| | | |
| | | @Override |
| | | public void delInoutFromCache(String deptId, String type, String id, boolean addToComplete) { |
| | | |
| | | public void delInoutFromCache(String deptId, String type, String id) { |
| | | if (StringUtils.isEmpty(deptId)) { |
| | | return; |
| | | } |
| | |
| | | if (StringUtils.isEmpty(id)) { |
| | | return; |
| | | } |
| | | //删除未完成流程的缓存 |
| | | //从未完成列表中删除 |
| | | String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_LIST, type, id); |
| | | InoutData inoutData = (InoutData) redisUtil.get(key); |
| | | redisUtil.del(key); |
| | | List<InoutData> list = this.getListInoutCache(deptId); |
| | | |
| | | //删除已完成流程的缓存 |
| | | key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_COMPLETE_LIST, type, id); |
| | | redisUtil.del(key); |
| | | List<InoutData> completeList = this.getCompleteListInoutCache(deptId); |
| | | |
| | | if (addToComplete) { |
| | | addInoutCompleteCache(inoutData); |
| | | completeList = this.getCompleteListInoutCache(deptId); |
| | | } |
| | | |
| | | // 通知到大屏 |
| | | notifyToScreen(deptId, list, completeList); |
| | | } |
| | | |
| | | /** |
| | | * 添加到已经完成的队列中 |
| | | * |
| | | * @param data |
| | | */ |
| | | public void addInoutCompleteCache(InoutData data) { |
| | | |
| | | if (null == data.getCompleteTime()) { |
| | | data.setCompleteTime(new Date()); |
| | | } |
| | | if (!InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { |
| | | data.setProgress(InoutConstant.PROGRESS_RECORD); |
| | | } |
| | | this.setCompleteInoutCache(data.getDeptId(), data); |
| | | } |
| | | |
| | | @Override |
| | | public List<InoutData> getListInoutCache(String deptId) { |
| | | |
| | | String pattern = RedisConst.buildKey(deptId, InoutConstant.KEY_INOUT_LIST); |
| | | Set<String> keys = redisUtil.keys(pattern); |
| | | if (null == keys || keys.isEmpty()) { |
| | |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void initInoutScreen(String deptId) { |
| | | if (null == deptId) { |
| | | deptId = ContextUtil.subDeptId(null); |
| | | } |
| | | |
| | | List<InoutData> curList = this.getListInoutCache(deptId); |
| | | List<InoutData> complateList = this.getCompleteListInoutCache(deptId); |
| | | |
| | | notifyToScreen(deptId, curList, complateList); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | */ |
| | | private void setCompleteInoutCache(String deptId, InoutData data) { |
| | | String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_COMPLETE_LIST, data.getType(), data.getId()); |
| | | |
| | | //设置缓存到第二天凌晨(计算当前时间到第二天凌晨的时间差秒数) |
| | | redisUtil.set(key, data, DateUtil.getNowToNextDaySeconds()); |
| | | } |
| | |
| | | /** |
| | | * 推送到大屏,判断只有当大屏在线时候才处理当前逻辑,避免页面卡顿,调用子任务完成推送 |
| | | * |
| | | * @param deptId |
| | | * @param curList 未完成流程个数 |
| | | * @param completeList 已经完成流程个数 |
| | | * @param companyId 组织编号 |
| | | * @param deptId 分库编号 |
| | | * @param progress 流转节点 |
| | | */ |
| | | private void notifyToScreen(String deptId, List<InoutData> curList, |
| | | List<InoutData> completeList) { |
| | | public void notifyToScreen(String companyId, String deptId, String progress) { |
| | | |
| | | // 推送到大屏 |
| | | List<InoutData> curList = this.getListInoutCache(deptId); |
| | | |
| | | List<InoutData> completeList = this.getCompleteListInoutCache(deptId); |
| | | |
| | | |
| | | if (null == WebSocketServer.contextOnLineMap.get(BizType.SCREEN |
| | | .getCode())) { |
| | |
| | | || WebSocketServer.contextOnLineMap.get(BizType.SCREEN_CHECK |
| | | .getCode())) { |
| | | |
| | | if (null == completeList) { |
| | | completeList = this.getCompleteListInoutCache(deptId); |
| | | } |
| | | |
| | | // 创建一个子任务进行推送信息 |
| | | FutureTask<String> futureTask = new FutureTask<>( |
| | | new NotifyScreenTask(curList, completeList, deptId)); |
| | | FutureTask<String> futureTask = new FutureTask<>(new NotifyScreenTask(curList, completeList, deptId)); |
| | | |
| | | ExecutorService executorService = Executors.newCachedThreadPool(); |
| | | executorService.submit(futureTask); |
| | | executorService.shutdown(); |
| | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<InoutPrice> getPrice(InoutCheckParam param) { |
| | | if(null == param.getStart()){ |
| | | param.setStart(new Date()); |
| | | } |
| | | if(null == param.getEnd()){ |
| | | param.setEnd(new Date()); |
| | | } |
| | | return inoutCheckMapper.getPrice(param); |
| | | } |
| | | } |