|
@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ebei.screen.common.constants.CommonConstants;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
@@ -85,17 +86,18 @@ public class EbaUtils {
|
|
|
* @param pkId 区分键
|
|
|
* @param collectionName 集合名字
|
|
|
* @param flag true 覆盖原有数据只保留一条最新的 false追加原有数据
|
|
|
+ * @param mongoId 如果设置了该参数 则取该参数id
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<Map> setDataField(Object obj, String pkId, String collectionName, boolean flag) {
|
|
|
+ public static List<Map> setDataField(Object obj, String pkId, String collectionName, boolean flag, String mongoId) {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
int year = now.getYear();
|
|
|
int month = now.getMonthValue();
|
|
|
int day = now.getDayOfMonth();
|
|
|
int hour = now.getHour();
|
|
|
- Map monthMap = mongoTemplate.findById(pkId + "_" + year + "_" + month, Map.class, collectionName);
|
|
|
+ Map monthMap = mongoTemplate.findById(StringUtils.isNotBlank(mongoId) ? mongoId : (pkId + "_" + year + "_" + month), Map.class, collectionName);
|
|
|
if (MapUtil.isEmpty(monthMap)) {
|
|
|
- monthMap = Levi.by("_id", pkId + "_" + year + "_" + month).set("data", getEmptyTemplate());
|
|
|
+ monthMap = Levi.by("_id", StringUtils.isNotBlank(mongoId) ? mongoId : (pkId + "_" + year + "_" + month)).set("data", getEmptyTemplate());
|
|
|
}
|
|
|
List<Map> dayList = (List<Map>) monthMap.get("data");
|
|
|
Map dayMap = dayList.get(day - 1);
|