From bb12f5a10a6ec09fae0d6859d261711d7307a663 Mon Sep 17 00:00:00 2001 From: liquanyu Date: Thu, 30 Apr 2020 08:38:42 +0800 Subject: [PATCH] update --- .../web/facade/PremaritalCheckupFacade.java | 2 +- .../web/service/impl/PreEugebicsServiceImpl.java | 42 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PremaritalCheckupFacade.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PremaritalCheckupFacade.java index 7705c2c..ae424da 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PremaritalCheckupFacade.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PremaritalCheckupFacade.java @@ -583,7 +583,7 @@ public class PremaritalCheckupFacade { * 修改妇女的婚检状态 * */ ResidentsArchiveModel residentsArchiveModel = new ResidentsArchiveModel(); - residentsArchiveModel.setCheckup("1"); + residentsArchiveModel.setCheckup(StringUtils.isEmpty(archiveModel.getCheckup()) ? "1" : String.valueOf(Integer.parseInt(archiveModel.getCheckup())+1)); residentsArchiveModel.setCheckupTime(new Date()); residentsArchiveService.updateResident(residentsArchiveModel, archiveModel.getId()); id = addOrUpdate(addRequest, userId, archiveModel); diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PreEugebicsServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PreEugebicsServiceImpl.java index 8124202..048e2d5 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PreEugebicsServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PreEugebicsServiceImpl.java @@ -21,6 +21,9 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; @@ -550,7 +553,7 @@ public class PreEugebicsServiceImpl extends BaseServiceImpl implements IPreEugen @Override public BaseObjectResponse getRcCount(String time, Integer userId) { - List> datas = getDatas( time, userId); + List> datas = getDatas(time, userId); return new BaseObjectResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(datas); } @@ -604,7 +607,7 @@ public class PreEugebicsServiceImpl extends BaseServiceImpl implements IPreEugen e.printStackTrace(); } } - int hjCount = residentsArchiveService.queryResidentCount(query.convertToQuery()); + long hjCount = sumField("lyms_resident", "checkup", query.convertToQuery().getCriteria()); hjAllCount+=hjCount; Query yquery = new Query(); @@ -645,4 +648,37 @@ public class PreEugebicsServiceImpl extends BaseServiceImpl implements IPreEugen } return datas; } -} \ No newline at end of file + + public Integer sumField(String collection,String filedName,Criteria criteria) { + + Integer total = 0; + Query query = new Query(); + if(criteria!=null){ + query.addCriteria(criteria); + } + List operations = new ArrayList<>(); + operations.add(Aggregation.match(criteria)); + operations.add(Aggregation.group().sum(filedName).as("total")); + Aggregation aggregation = Aggregation.newAggregation(operations); + AggregationResults results =mongoTemplate.aggregate(aggregation, collection, Total.class); + List totals = results.getMappedResults(); + if (CollectionUtils.isNotEmpty(totals)) + { + total = totals.get(0).getTotal(); + } + return total; + } +} +class Total +{ + private int total; + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } +} + -- 1.8.3.1