@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; }
private Team assembleTeamObject(SysUser caller, TeamParam param) { Team item = new Team(); if (StringUtil.isEmptyString(param.getId())) { item.setId(param.getId()); item.setCode(param.getCode()); // 用当前时间作为编号 item.setName(param.getName()); item.setDescription(param.getDescription()); } else { // Update a existed record item = teamDao.findById(Team.class, param.getId()); } return item; }
private Query getBroadcastQuery(BroadcastQueryListCriteria searchVo, String type) { Map<String, Object> param = new HashMap<String, Object>(); StringBuffer hql = new StringBuffer(); if (SEARCH.equals(type)) { hql.append(" SELECT broadcast FROM Broadcasting broadcast WHERE 1=1 "); } else if (COUNT.equals(type)) { hql.append(" SELECT COUNT(broadcast) FROM Broadcasting broadcast WHERE 1=1 "); } if (!StringUtil.isEmptyString(searchVo.getCorporationId())) { hql.append(" AND broadcast.corporation.id = :corporationId "); param.put("corporationId", searchVo.getCorporationId()); } if (searchVo.getStatus() != null) { hql.append(" AND broadcast.status = :status "); param.put("status", searchVo.getStatus()); } if (searchVo.getCategory() != null) { if (searchVo.getCategory() == BroadcastingCategory.SYSBROADCAST) { hql.append(" AND (broadcast.category = :category1 OR broadcast.category = :category2)"); param.put("category1", searchVo.getCategory()); param.put("category2", BroadcastingCategory.REWARDBROADCAST); } else { hql.append(" AND broadcast.category = :category "); param.put("category", searchVo.getCategory()); } } if (!StringUtil.isEmptyString(searchVo.getQueryKey())) { hql.append(" AND broadcast.content LIKE :queryKey "); param.put("queryKey", "%" + searchVo.getQueryKey() + "%"); } if (!StringUtil.isEmptyString(searchVo.getCreatedByUserName())) { hql.append(" AND broadcast.createdBy.staff.name LIKE :createdByUserName "); param.put("createdByUserName", "%" + searchVo.getCreatedByUserName() + "%"); } if (searchVo.getBroadcastingTimeStart() != null && searchVo.getBroadcastingTimeEnd() != null) { hql.append( " and ( broadcast.broadcastingTimeStart between :broadcastingTimeStart and :broadcastingTimeEnd)"); param.put("broadcastingTimeStart", searchVo.getBroadcastingTimeStart()); param.put("broadcastingTimeEnd", searchVo.getBroadcastingTimeEnd()); } if (searchVo.isNowDate()) { hql.append( " and ( SYSDATE between broadcast.broadcastingTimeStart and broadcast.broadcastingTimeEnd)"); } if (!StringUtil.isEmptyString(searchVo.getCreateUserId())) { hql.append(" AND broadcast.createdBy.id = :createUserId "); param.put("createUserId", searchVo.getCreateUserId()); } hql.append(" AND broadcast.broadcastMessagetype = :broadcastMessagetype "); param.put("broadcastMessagetype", searchVo.getBroadcastMessagetype()); hql.append(" AND broadcast.deleted = :deleted "); param.put("deleted", false); if (searchVo.getBroadcastList() != null && searchVo.getBroadcastList().size() > 0) { if (!StringUtil.isEmptyString(searchVo.getUserId())) { hql.append( " AND ( broadcast.id IN (:broadcastList) or broadcast.createdBy.id = :userId ) "); param.put("broadcastList", searchVo.getBroadcastList()); param.put("userId", searchVo.getUserId()); } else { hql.append(" AND broadcast.id IN (:broadcastList) "); param.put("broadcastList", searchVo.getBroadcastList()); } } else if (!StringUtil.isEmptyString(searchVo.getUserId())) { hql.append(" AND broadcast.createdBy.id = :userId "); param.put("userId", searchVo.getUserId()); } else if (StringUtil.isEmptyString(searchVo.getUserId())) { if (searchVo.getBroadcastMessagetype() != BroadcastMessage.MESSAGE) { // 过滤,悄悄话,和调戏 hql.append(" AND broadcast.category != :categoryQ AND broadcast.category != :categoryD"); param.put("categoryQ", BroadcastingCategory.QUIETLYINFORMATION); param.put("categoryD", BroadcastingCategory.DALLIANCEINFORMATION); } else { hql.append(" AND broadcast.category is null "); } } // ORDER BY if (SEARCH.equals(type)) { if (searchVo.getSortingDetail() != null && searchVo.getSortingDetail().getSort() != null && searchVo.getSortingDetail().getDirection() != null) { hql.append( " ORDER BY broadcast." + searchVo.getSortingDetail().getSort() + " " + searchVo.getSortingDetail().getDirection()); } else { if (searchVo.getBroadcastMessagetype() == BroadcastMessage.BROADCASTING) hql.append(" ORDER BY broadcast.lastModifiedAt DESC "); else hql.append(" ORDER BY broadcast.lastModifiedAt DESC "); } } logger.debug(" HQL:{} ", hql); Query query = getEm().createQuery(hql.toString()); if (SEARCH.equals(type)) { if (searchVo.getPaginationDetail() != null && searchVo.getPaginationDetail().getLimit() != 0) { int limit = searchVo.getPaginationDetail().getLimit(); int start = searchVo.getPaginationDetail().getStart(); logger.debug("pagination - start{}, limit:{}", new Object[] {start, limit}); query.setMaxResults(limit); query.setFirstResult(start); } } if (param.size() > 0) { Set<String> key = param.keySet(); for (String s : key) { query.setParameter(s, param.get(s)); } } return query; }