@Override public Team save(SysUser caller, TeamParam param) { Team itemObj = assembleTeamObject(caller, param); Date currTime = DateUtil.getTime(); String teamCode = DateUtil.formatData("yyyyMMddhhmmss", currTime); if (StringUtil.isEmptyString(itemObj.getId())) { // Create itemObj.setDeleted(0); // 正常状态,没有删除为0 itemObj.setCreatedBy(caller); itemObj.setCorporation(caller.getCorporation()); itemObj.setDepartment(caller.getStaff().getDepartment()); itemObj.setCreatedAt(currTime); itemObj.setCode(teamCode); // 用当前时间作为编号 itemObj = teamDao.save(itemObj); } else { // Update itemObj = teamDao.findById(Team.class, itemObj.getId()); itemObj.setName(param.getName()); itemObj.setDescription(param.getDescription()); itemObj.setCreatedBy(caller); itemObj.setCreatedAt(currTime); itemObj = teamDao.update(itemObj); removeMembersByTeam(itemObj.getId()); // 修改一律删除人员 } // 增加负责人 if (param.getFzIds() != null && !param.getFzIds().isEmpty()) { saveMembers(caller, itemObj, param.getFzIds(), 1); } // 增加成员 if (param.getMembersIds() != null && !param.getMembersIds().isEmpty()) { saveMembers(caller, itemObj, param.getMembersIds(), 0); } return itemObj; }
@Override public void saveMembers(SysUser caller, Team team, List<String> staffIds, int type) { Date now = DateUtil.getTime(); for (String id : staffIds) { Members member = new Members(); Staff staff = staffDao.findById(Staff.class, id); member.setStaff(staff); member.setDeleted(0); member.setMemberType(type); member.setRecorddate(now); member.setTeam(team); member.setRecorduser(caller.getUserName()); membersDao.save(member); } }