public HashMap<String, Object> addPrintFile(PrintFile file, User loginUser) { HashMap<String, Object> result = Maps.newHashMap(); Map<String, Integer> params = Maps.newHashMap(); logger.info("PrintFileService addPrintFile the file SHA1:{} ", file.getSha1()); try { params.put("uid", loginUser.getId()); // 根据唯一标识查找文件 PrintFile tempFile = printFileDao.loadPrintFileBySHA1(file.getSha1()); // 如果没有,则加入文件 if (tempFile == null) { // 先添加文件到数据库 printFileDao.addPrintFile(file); PrintFile fileBySHA1 = printFileDao.loadPrintFileBySHA1(file.getSha1()); params.put("pid", fileBySHA1.getId()); logger.info("PrintFileService addPrintFile the file is not existed, add the file success"); // 如果有,则多个用户同用一个文件 } else { /** 如果根据sha1找到了文件, 就根据登陆用户去找到这个文件的id,如果此id已经存在,则返回,如果不存在则添加关联 */ params.put("pid", tempFile.getId()); String pidByUid = printFileDao.loadPidByUid(params); if (!Strings.isNullOrEmpty(pidByUid) && (Integer.parseInt(pidByUid) == tempFile.getId())) { result.put("status", 1); result.put("message", "不能重复添加文件"); logger.error( "PrintFileServiceImpl addPrintFile, with the same openId, file is not allowed to repeated"); return result; } logger.info("PrintFileService addPrintFile the file is existed, only add the Relationship"); } // 向中间表添加关联 printFileDao.addTUP(params); logger.info("PrintFileService addPrintFile the Relationship:{}", params); } catch (Exception e) { result.put("status", 1); result.put("message", "添加文件失败,详情请查看日志"); logger.error("PrintFileServiceImpl addPrintFile fail : {} ", e); return result; } result.put("status", 0); result.put("message", "添加文件成功"); logger.info( "PrintFileServiceImpl addPrintFile success, The file:{}, the result:{}", file, result); return result; }