Commit cc86484b authored by 赵啸非's avatar 赵啸非

重新调整统计线程实现

parent 8bec0536
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 统计模式枚举类
*
* @author zxfei
*/
public enum StatTypeEnum {
STAT_PH(0, "排号"),
STAT_PJ(1, "评价"),
STAT_ALL(2, "All");
private Integer value;
private String desc;
StatTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static StatTypeEnum getByValue(Integer value) {
for (StatTypeEnum activeEnum : StatTypeEnum.values()) {
if (activeEnum.getValue() == value) {
return activeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (StatTypeEnum item : StatTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.thread;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.model.AccessSystemEntity;
import com.mortals.xhx.module.access.service.AccessService;
import com.mortals.xhx.module.ph.model.PhQueueQuery;
import com.mortals.xhx.module.ph.service.PhQueueStatService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
/**
* 排号统计数据
* @author: zxfei
* @date: 2024/8/2 14:13
*/
@Slf4j
@AllArgsConstructor
public class PhStatThread implements Runnable {
private DateTime attendStart;
private Long compare;
private SitePdu site;
private Context context;
@Override
public void run() {
StopWatch stopWatch = new StopWatch();
PhQueueStatService phQueueStatService= SpringUtil.getBean(PhQueueStatService.class);
phQueueStatService.updateSitePhStatLog(attendStart, compare, stopWatch, site, context);
}
}
package com.mortals.xhx.common.thread;
import cn.hutool.core.date.DateTime;
import cn.hutool.extra.spring.SpringUtil;
import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.StatTypeEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.module.ph.service.PhQueueStatService;
import com.mortals.xhx.module.pj.service.PjEvaluateStatService;
import com.mortals.xhx.module.stat.service.StatService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;
import java.util.List;
/**
* 站点统计数据线程
*
* @author: zxfei
* @date: 2024/8/2 14:13
*/
@Slf4j
@AllArgsConstructor
public class StatThread implements Runnable {
private DateTime attendStart;
private Long compare;
private SitePdu site;
private Context context;
private List<Integer> typeStatList;
@Override
public void run() {
StopWatch stopWatch = new StopWatch();
PhQueueStatService phQueueStatService = SpringUtil.getBean(PhQueueStatService.class);
PjEvaluateStatService pjEvaluateStatService = SpringUtil.getBean(PjEvaluateStatService.class);
StatService statService = SpringUtil.getBean(StatService.class);
if (typeStatList.contains(StatTypeEnum.STAT_PH.getValue())) {
phQueueStatService.updateSitePhStatLog(attendStart, compare, stopWatch, site, context);
}
if (typeStatList.contains(StatTypeEnum.STAT_PJ.getValue())) {
pjEvaluateStatService.updateSitePjStatLog(attendStart, compare, stopWatch, site, context);
}
if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) {
statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context);
}
}
}
package com.mortals.xhx.daemon.task; package com.mortals.xhx.daemon.task;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICacheService; import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.ITask; import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService; import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.common.code.AccessTypeEnum; import com.mortals.xhx.common.code.AccessTypeEnum;
import com.mortals.xhx.common.code.StatTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.RedisKey; import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.keys.RedisCacheKeys; import com.mortals.xhx.common.keys.RedisCacheKeys;
import com.mortals.xhx.common.pdu.RespData; import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.site.SitePdu; import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.thread.StatThread;
import com.mortals.xhx.feign.site.ISiteFeign; import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.access.model.AccessEntity; import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery; import com.mortals.xhx.module.access.model.AccessQuery;
...@@ -80,161 +84,15 @@ public class SiteStatTaskImpl implements ITaskExcuteService { ...@@ -80,161 +84,15 @@ public class SiteStatTaskImpl implements ITaskExcuteService {
private void statByDate() { private void statByDate() {
List<SitePdu> sitePduList = accessService.getStatSiteList(); List<SitePdu> sitePduList = accessService.getStatSiteList();
Long compare =4L;
DateTime attendStart = DateUtil.offsetDay(new Date(), -compare.intValue());
for (SitePdu site : sitePduList) { for (SitePdu site : sitePduList) {
if (ObjectUtils.isEmpty(site.getId())) continue; if (ObjectUtils.isEmpty(site.getId())) continue;
StopWatch allStopWatch = new StopWatch("allStopWatch"); StatThread statThread = new StatThread(attendStart, compare, site, null,
StopWatch pjqStopWatch = new StopWatch("pjqStopWatch"); Arrays.asList(StatTypeEnum.STAT_PH.getValue(),StatTypeEnum.STAT_PJ.getValue(),StatTypeEnum.STAT_ALL.getValue()));
StopWatch pdjStopWatch = new StopWatch("pdjStopWatch"); ThreadPool.getInstance().execute(statThread);
allStopWatch.start();
AccessStatLogEntity statLogAllEntity = new AccessStatLogEntity();
statLogAllEntity.initAttrValue();
statLogAllEntity.setCreateUserId(1L);
statLogAllEntity.setCreateTime(new Date());
statLogAllEntity.setSiteId(site.getId());
statLogAllEntity.setSiteCode(site.getSiteCode());
statLogAllEntity.setSiteName(site.getSiteName());
statLogAllEntity.setStatStartTime(new Date());
statLogAllEntity.setType(AccessTypeEnum.全部.getValue());
pjqStopWatch.start();
AccessStatLogEntity statLogEntity = new AccessStatLogEntity();
statLogEntity.initAttrValue();
statLogEntity.setCreateUserId(1L);
statLogEntity.setCreateTime(new Date());
statLogEntity.setSiteId(site.getId());
statLogEntity.setSiteCode(site.getSiteCode());
statLogEntity.setSiteName(site.getSiteName());
AccessQuery accessQuery = new AccessQuery();
accessQuery.setSiteId(site.getId() == null ? 0L : site.getId());
AccessEntity accessEntity = accessService.selectOne(accessQuery);
if (!ObjectUtils.isEmpty(accessEntity)) {
statLogEntity.setAccessId(accessEntity.getId());
} }
statLogEntity.setStatStartTime(new Date());
statLogEntity.setType(AccessTypeEnum.评价器.getValue());
int range = 4;
for (int i = 0; i < range; i++) {
DateTime beforeDate = DateUtil.offsetDay(new Date(), -i);
int year = beforeDate.year();
int month = beforeDate.month() + 1;
int day = beforeDate.dayOfMonth();
PjEvaluateStatEntity sitestatEntity = new PjEvaluateStatEntity();
sitestatEntity.initAttrValue();
sitestatEntity.setSiteId(site.getId());
sitestatEntity.setSiteName(site.getSiteName());
sitestatEntity.setSiteCode(site.getSiteCode());
sitestatEntity.setYear(year);
sitestatEntity.setMonth(month);
sitestatEntity.setDay(day);
//设置年月日
pjEvaluateStatService.updateSitePjStat(sitestatEntity, null);
}
pjqStopWatch.stop();
statLogEntity.setStatEndTime(new Date());
statLogEntity.setDuration(pjqStopWatch.getLastTaskTimeMillis());
accessStatLogService.save(statLogEntity, null);
pdjStopWatch.start();
statLogEntity.setStatStartTime(new Date());
statLogEntity.setType(AccessTypeEnum.排队机.getValue());
for (int i = 0; i < range; i++) {
DateTime beforeDate = DateUtil.offsetDay(new Date(), -i);
int year = beforeDate.year();
int month = beforeDate.month() + 1;
int day = beforeDate.dayOfMonth();
//设置排号
PhQueueStatEntity phQueueStatEntity = new PhQueueStatEntity();
phQueueStatEntity.initAttrValue();
phQueueStatEntity.setSiteId(site.getId());
phQueueStatEntity.setSiteName(site.getSiteName());
phQueueStatEntity.setSiteCode(site.getSiteCode());
phQueueStatEntity.setYear(year);
phQueueStatEntity.setMonth(month);
phQueueStatEntity.setDay(day);
phQueueStatService.updateSitePhStat(phQueueStatEntity, null);
}
pdjStopWatch.stop();
statLogEntity.setStatEndTime(new Date());
statLogEntity.setDuration(pjqStopWatch.getLastTaskTimeMillis());
accessStatLogService.save(statLogEntity, null);
for (int i = 0; i < range; i++) {
DateTime beforeDate = DateUtil.offsetDay(new Date(), -i);
int year = beforeDate.year();
int month = beforeDate.month() + 1;
int day = beforeDate.dayOfMonth();
StatEntity statEntity = new StatEntity();
statEntity.initAttrValue();
statEntity.setSiteId(site.getId());
statEntity.setSiteName(site.getSiteName());
statEntity.setSiteCode(site.getSiteCode());
statEntity.setYear(year);
statEntity.setMonth(month);
statEntity.setDay(day);
//设置年月日
statService.updateSiteStat(statEntity, null);
}
allStopWatch.stop();
statLogAllEntity.setStatEndTime(new Date());
statLogAllEntity.setDuration(pjqStopWatch.getLastTaskTimeMillis());
accessStatLogService.save(statLogAllEntity, null);
}
}
/* private List<SitePdu> getStatSiteList() {
AccessQuery accessQuery = new AccessQuery();
// accessQuery.setTagNotList(Arrays.asList(""));
List<AccessEntity> accessEntities = accessService.find(accessQuery);
accessEntities = accessEntities.stream().filter(item -> {
List<AccessSystemEntity> accessSystemList = item.getAccessSystemList();
//判断排队机或者评价系统是否开通
if(ObjectUtils.isEmpty(accessSystemList))return false;
List<AccessSystemEntity> collect = accessSystemList.stream().filter(f -> f.getEnabled() == YesNoEnum.YES.getValue()).collect(Collectors.toList());
if(ObjectUtils.isEmpty(collect)){return false;}
return true;
}).collect(Collectors.toList());
List<SitePdu> sitePduList = new ArrayList<>();
for (AccessEntity accessEntity : accessEntities) {
if(accessEntity.getSiteId()==1L){
SitePdu site = new SitePdu();
site.setId(accessEntity.getSiteId());
site.setSiteName(accessEntity.getSiteName());
site.setSiteCode(accessEntity.getSiteCode());
site.setAreaCode(accessEntity.getAreaCode());
sitePduList.add(site);
continue;
}
SitePdu sitePdu = new SitePdu();
sitePdu.setId(accessEntity.getSiteId());
Rest<List<SitePdu>> sitesRest = siteFeign.getFlatSitesBySiteId(sitePdu);
if (YesNoEnum.YES.getValue() == sitesRest.getCode()) {
sitePduList.addAll(sitesRest.getData());
}
}
if (!ObjectUtils.isEmpty(sitePduList)) {
sitePduList = sitePduList.stream().collect(
collectingAndThen(
toCollection(() -> new TreeSet<>(Comparator.comparing(SitePdu::getId))), ArrayList::new));
} }
return sitePduList;
}*/
private void updateSiteCache() { private void updateSiteCache() {
List<SitePdu> sitePduList = accessService.getStatSiteList(); List<SitePdu> sitePduList = accessService.getStatSiteList();
......
...@@ -18,5 +18,9 @@ public interface AccessService extends ICRUDService<AccessEntity,Long>{ ...@@ -18,5 +18,9 @@ public interface AccessService extends ICRUDService<AccessEntity,Long>{
AccessDao getDao(); AccessDao getDao();
/**
* 获取统计站点列表
* @return
*/
List<SitePdu> getStatSiteList(); List<SitePdu> getStatSiteList();
} }
\ No newline at end of file
...@@ -129,7 +129,6 @@ public class AccessServiceImpl extends AbstractCRUDServiceImpl<AccessDao, Access ...@@ -129,7 +129,6 @@ public class AccessServiceImpl extends AbstractCRUDServiceImpl<AccessDao, Access
@Override @Override
public List<SitePdu> getStatSiteList() { public List<SitePdu> getStatSiteList() {
AccessQuery accessQuery = new AccessQuery(); AccessQuery accessQuery = new AccessQuery();
// accessQuery.setTagNotList(Arrays.asList(""));
List<AccessEntity> accessEntities = this.find(accessQuery); List<AccessEntity> accessEntities = this.find(accessQuery);
accessEntities = accessEntities.stream().filter(item -> { accessEntities = accessEntities.stream().filter(item -> {
List<AccessSystemEntity> accessSystemList = item.getAccessSystemList(); List<AccessSystemEntity> accessSystemList = item.getAccessSystemList();
...@@ -144,9 +143,7 @@ public class AccessServiceImpl extends AbstractCRUDServiceImpl<AccessDao, Access ...@@ -144,9 +143,7 @@ public class AccessServiceImpl extends AbstractCRUDServiceImpl<AccessDao, Access
List<SitePdu> sitePduList = new ArrayList<>(); List<SitePdu> sitePduList = new ArrayList<>();
for (AccessEntity accessEntity : accessEntities) { for (AccessEntity accessEntity : accessEntities) {
if (ObjectUtils.isEmpty(accessEntity.getSiteId())) continue;
if(ObjectUtils.isEmpty(accessEntity.getSiteId())) continue;
if (accessEntity.getSiteId() == 1L) { if (accessEntity.getSiteId() == 1L) {
SitePdu site = new SitePdu(); SitePdu site = new SitePdu();
site.setId(accessEntity.getSiteId()); site.setId(accessEntity.getSiteId());
......
package com.mortals.xhx.module.access.web; package com.mortals.xhx.module.access.web;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol; import com.mortals.framework.model.OrderCol;
import com.mortals.framework.util.ThreadPool;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.common.code.StatTypeEnum;
import com.mortals.xhx.common.code.TypeEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.thread.StatThread;
import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.service.AccessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context; import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.service.AccessService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
import com.mortals.xhx.common.code.*;
/** /**
* *
* 区域接入 * 区域接入
...@@ -34,10 +37,10 @@ import com.mortals.xhx.common.code.*; ...@@ -34,10 +37,10 @@ import com.mortals.xhx.common.code.*;
*/ */
@RestController @RestController
@RequestMapping("access") @RequestMapping("access")
@Slf4j
public class AccessController extends BaseCRUDJsonBodyMappingController<AccessService,AccessEntity,Long> { public class AccessController extends BaseCRUDJsonBodyMappingController<AccessService,AccessEntity,Long> {
@Autowired @Autowired
private ParamService paramService; private AccessService accessService;
public AccessController(){ public AccessController(){
super.setModuleDesc( "区域接入"); super.setModuleDesc( "区域接入");
...@@ -55,4 +58,38 @@ public class AccessController extends BaseCRUDJsonBodyMappingController<AccessSe ...@@ -55,4 +58,38 @@ public class AccessController extends BaseCRUDJsonBodyMappingController<AccessSe
super.doListBefore(query, model, context); super.doListBefore(query, model, context);
} }
@PostMapping(value = "/stat")
@UnAuth
public Rest<String> stat(@RequestBody AccessQuery accessQuery) {
Rest<String> ret = new Rest();
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "查询" + this.getModuleDesc();
int code = 1;
try {
//天数区间分段计算
DateTime attendStart = DateUtil.parseDate(accessQuery.getAccessTimeStart());
DateTime attendEnd = DateUtil.parseDate(accessQuery.getAccessTimeEnd());
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList();
for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context,
Arrays.asList(StatTypeEnum.STAT_PH.getValue(),StatTypeEnum.STAT_PJ.getValue(),StatTypeEnum.STAT_ALL.getValue()));
ThreadPool.getInstance().execute(statThread);
}
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
code = -1;
this.doException(this.request, busiDesc, model, e);
model.put("message_info", e.getMessage());
}
this.init(model, context);
ret.setCode(code);
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
} }
\ No newline at end of file
package com.mortals.xhx.module.ph.service; package com.mortals.xhx.module.ph.service;
import cn.hutool.core.date.DateTime;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.module.ph.model.PhQueueStatEntity; import com.mortals.xhx.module.ph.model.PhQueueStatEntity;
import com.mortals.xhx.module.ph.dao.PhQueueStatDao; import com.mortals.xhx.module.ph.dao.PhQueueStatDao;
import com.mortals.xhx.module.ph.model.PhQueueStatQuery; import com.mortals.xhx.module.ph.model.PhQueueStatQuery;
import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity; import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity;
import org.springframework.util.StopWatch;
import java.util.List; import java.util.List;
...@@ -30,4 +33,7 @@ public interface PhQueueStatService extends ICRUDService<PhQueueStatEntity, Long ...@@ -30,4 +33,7 @@ public interface PhQueueStatService extends ICRUDService<PhQueueStatEntity, Long
void saveUpdatePhStatList(List<PhQueueStatEntity> saveAndUpdatelist); void saveUpdatePhStatList(List<PhQueueStatEntity> saveAndUpdatelist);
void updateSitePhStatLog(DateTime attendStart, Long compare, StopWatch stopWatch, SitePdu site, Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.ph.service.impl; package com.mortals.xhx.module.ph.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.OrderCol; import com.mortals.framework.model.OrderCol;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result; import com.mortals.framework.model.Result;
import com.mortals.xhx.common.code.AccessTypeEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.model.AccessStatLogEntity;
import com.mortals.xhx.module.access.service.AccessService;
import com.mortals.xhx.module.access.service.AccessStatLogService;
import com.mortals.xhx.module.ph.model.PhQueueEntity; import com.mortals.xhx.module.ph.model.PhQueueEntity;
import com.mortals.xhx.module.ph.model.PhQueueQuery; import com.mortals.xhx.module.ph.model.PhQueueQuery;
import com.mortals.xhx.module.ph.model.PhQueueStatQuery; import com.mortals.xhx.module.ph.model.PhQueueStatQuery;
...@@ -21,6 +31,7 @@ import com.mortals.xhx.module.ph.model.PhQueueStatEntity; ...@@ -21,6 +31,7 @@ import com.mortals.xhx.module.ph.model.PhQueueStatEntity;
import com.mortals.xhx.module.ph.service.PhQueueStatService; import com.mortals.xhx.module.ph.service.PhQueueStatService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -39,6 +50,10 @@ public class PhQueueStatServiceImpl extends AbstractCRUDServiceImpl<PhQueueStatD ...@@ -39,6 +50,10 @@ public class PhQueueStatServiceImpl extends AbstractCRUDServiceImpl<PhQueueStatD
@Autowired @Autowired
private PhQueueService phQueueService; private PhQueueService phQueueService;
@Autowired
private AccessService accessService;
@Autowired
private AccessStatLogService accessStatLogService;
@Override @Override
...@@ -62,7 +77,7 @@ public class PhQueueStatServiceImpl extends AbstractCRUDServiceImpl<PhQueueStatD ...@@ -62,7 +77,7 @@ public class PhQueueStatServiceImpl extends AbstractCRUDServiceImpl<PhQueueStatD
// log.info("更新站点排队统计数据,站点ID:{},站点名称:{},日期:{},排队数量:{}", entity.getSiteId(), entity.getSiteName(), currentDate, phQueueEntities.size()); // log.info("更新站点排队统计数据,站点ID:{},站点名称:{},日期:{},排队数量:{}", entity.getSiteId(), entity.getSiteName(), currentDate, phQueueEntities.size());
updateSitePhCount(entity, phQueueEntities); updateSitePhCount(entity, phQueueEntities);
List<PhQueueStatEntity> saveOrUpdateList=new ArrayList<>(); List<PhQueueStatEntity> saveOrUpdateList = new ArrayList<>();
//部门 //部门
List<PhQueueStatEntity> phQueueStatEntities = updateSiteSectionNamePhCount(currentDate, entity, phQueueEntities); List<PhQueueStatEntity> phQueueStatEntities = updateSiteSectionNamePhCount(currentDate, entity, phQueueEntities);
...@@ -382,6 +397,57 @@ public class PhQueueStatServiceImpl extends AbstractCRUDServiceImpl<PhQueueStatD ...@@ -382,6 +397,57 @@ public class PhQueueStatServiceImpl extends AbstractCRUDServiceImpl<PhQueueStatD
} }
} }
public void updateSitePhStatLog(DateTime attendStart, Long compare, StopWatch stopWatch, SitePdu site, Context context) {
log.info("统计站点:{}", site.getSiteName());
stopWatch.start("站点排号统计开始");
AccessStatLogEntity statLogEntity = new AccessStatLogEntity();
statLogEntity.initAttrValue();
statLogEntity.setStatStartTime(new Date());
statLogEntity.setType(AccessTypeEnum.排队机.getValue());
statLogEntity.setCreateUserId(1L);
statLogEntity.setCreateTime(new Date());
statLogEntity.setSiteId(site.getId());
statLogEntity.setSiteCode(site.getSiteCode());
statLogEntity.setSiteName(site.getSiteName());
AccessQuery accessQuery = new AccessQuery();
accessQuery.setSiteId(site.getId() == null ? 0L : site.getId());
AccessEntity accessEntity = accessService.selectOne(accessQuery);
if (!ObjectUtils.isEmpty(accessEntity)) {
statLogEntity.setAccessId(accessEntity.getId());
}
List<PhQueueStatEntity> saveOrUpdateList = new ArrayList<>();
for (int i = 0; i <= compare.intValue(); i++) {
DateTime curDate = DateUtil.offsetDay(attendStart, i);
// log.info("记录日期:{}", curDate.toDateStr());
PhQueueStatEntity sitestatEntity = new PhQueueStatEntity();
sitestatEntity.initAttrValue();
sitestatEntity.setSiteId(site.getId());
sitestatEntity.setSiteName(site.getSiteName());
sitestatEntity.setSiteCode(site.getSiteCode());
sitestatEntity.setYear(curDate.year());
sitestatEntity.setMonth(curDate.month() + 1);
sitestatEntity.setDay(curDate.dayOfMonth());
//设置年月日
Rest<List<PhQueueStatEntity>> listRest = this.updateSitePhStat(sitestatEntity, context);
saveOrUpdateList.addAll(listRest.getData());
}
List<List<PhQueueStatEntity>> partition = Lists.partition(saveOrUpdateList, 1000);
for (List<PhQueueStatEntity> phQueueStatEntities : partition) {
this.saveUpdatePhStatList(phQueueStatEntities);
}
stopWatch.stop();
statLogEntity.setStatEndTime(new Date());
statLogEntity.setDuration(stopWatch.getLastTaskTimeMillis());
accessStatLogService.save(statLogEntity, context);
}
public static void main(String[] args) { public static void main(String[] args) {
String str = "adbc&&"; String str = "adbc&&";
List<String> split = StrUtil.split(str, "&"); List<String> split = StrUtil.split(str, "&");
......
package com.mortals.xhx.module.pj.service; package com.mortals.xhx.module.pj.service;
import cn.hutool.core.date.DateTime;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity; import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity;
import com.mortals.xhx.module.pj.dao.PjEvaluateStatDao; import com.mortals.xhx.module.pj.dao.PjEvaluateStatDao;
import com.mortals.xhx.module.pj.model.PjEvaluateStatQuery; import com.mortals.xhx.module.pj.model.PjEvaluateStatQuery;
import org.springframework.util.StopWatch;
import java.util.List; import java.util.List;
...@@ -33,4 +36,6 @@ public interface PjEvaluateStatService extends ICRUDService<PjEvaluateStatEntity ...@@ -33,4 +36,6 @@ public interface PjEvaluateStatService extends ICRUDService<PjEvaluateStatEntity
List<PjEvaluateStatEntity> getBillInfos(PjEvaluateStatQuery query, PageInfo pageInfo, Context context); List<PjEvaluateStatEntity> getBillInfos(PjEvaluateStatQuery query, PageInfo pageInfo, Context context);
void saveUpdatePjEvaluateStatList(List<PjEvaluateStatEntity> saveAndUpdatelist); void saveUpdatePjEvaluateStatList(List<PjEvaluateStatEntity> saveAndUpdatelist);
void updateSitePjStatLog(DateTime attendStart, Long compare, StopWatch stopWatch, SitePdu site, Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.pj.service.impl; package com.mortals.xhx.module.pj.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.OrderCol; import com.mortals.framework.model.OrderCol;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result; import com.mortals.framework.model.Result;
import com.mortals.xhx.common.code.AccessTypeEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.model.AccessStatLogEntity;
import com.mortals.xhx.module.access.service.AccessService;
import com.mortals.xhx.module.access.service.AccessStatLogService;
import com.mortals.xhx.module.pj.model.PjEvaluateEntity; import com.mortals.xhx.module.pj.model.PjEvaluateEntity;
import com.mortals.xhx.module.pj.model.PjEvaluateQuery; import com.mortals.xhx.module.pj.model.PjEvaluateQuery;
import com.mortals.xhx.module.pj.model.PjEvaluateStatQuery; import com.mortals.xhx.module.pj.model.PjEvaluateStatQuery;
...@@ -21,6 +31,7 @@ import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity; ...@@ -21,6 +31,7 @@ import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity;
import com.mortals.xhx.module.pj.service.PjEvaluateStatService; import com.mortals.xhx.module.pj.service.PjEvaluateStatService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -39,7 +50,10 @@ public class PjEvaluateStatServiceImpl extends AbstractCRUDServiceImpl<PjEvaluat ...@@ -39,7 +50,10 @@ public class PjEvaluateStatServiceImpl extends AbstractCRUDServiceImpl<PjEvaluat
@Autowired @Autowired
private PjEvaluateService pjEvaluateService; private PjEvaluateService pjEvaluateService;
@Autowired
private AccessService accessService;
@Autowired
private AccessStatLogService accessStatLogService;
@Override @Override
public Result<PjEvaluateStatEntity> find(PjEvaluateStatEntity entity, PageInfo pageInfo, Context context) throws AppException { public Result<PjEvaluateStatEntity> find(PjEvaluateStatEntity entity, PageInfo pageInfo, Context context) throws AppException {
...@@ -379,5 +393,56 @@ public class PjEvaluateStatServiceImpl extends AbstractCRUDServiceImpl<PjEvaluat ...@@ -379,5 +393,56 @@ public class PjEvaluateStatServiceImpl extends AbstractCRUDServiceImpl<PjEvaluat
} }
} }
@Override
public void updateSitePjStatLog(DateTime attendStart, Long compare, StopWatch stopWatch, SitePdu site, Context context) {
stopWatch.start("站点评价统计开始");
AccessStatLogEntity statLogEntity = new AccessStatLogEntity();
statLogEntity.initAttrValue();
statLogEntity.setStatStartTime(new Date());
statLogEntity.setType(AccessTypeEnum.排队机.getValue());
statLogEntity.setCreateUserId(1L);
statLogEntity.setCreateTime(new Date());
statLogEntity.setSiteId(site.getId());
statLogEntity.setSiteCode(site.getSiteCode());
statLogEntity.setSiteName(site.getSiteName());
AccessQuery accessQuery = new AccessQuery();
accessQuery.setSiteId(site.getId() == null ? 0L : site.getId());
AccessEntity accessEntity = accessService.selectOne(accessQuery);
if (!ObjectUtils.isEmpty(accessEntity)) {
statLogEntity.setAccessId(accessEntity.getId());
}
List<PjEvaluateStatEntity> saveAndUpdatelist = new ArrayList<>();
for (int i = 0; i <= compare.intValue(); i++) {
DateTime curDate = DateUtil.offsetDay(attendStart, i);
//log.info("记录日期:{}", curDate.toDateStr());
PjEvaluateStatEntity sitestatEntity = new PjEvaluateStatEntity();
sitestatEntity.initAttrValue();
sitestatEntity.setSiteId(site.getId());
sitestatEntity.setSiteName(site.getSiteName());
sitestatEntity.setSiteCode(site.getSiteCode());
sitestatEntity.setYear(curDate.year());
sitestatEntity.setMonth(curDate.month() + 1);
sitestatEntity.setDay(curDate.dayOfMonth());
//设置年月日
Rest<List<PjEvaluateStatEntity>> rest = this.updateSitePjStat(sitestatEntity, context);
saveAndUpdatelist.addAll(rest.getData());
}
List<List<PjEvaluateStatEntity>> partition = Lists.partition(saveAndUpdatelist, 1000);
for (List<PjEvaluateStatEntity> pjEvaluateStatEntities : partition) {
this.saveUpdatePjEvaluateStatList(pjEvaluateStatEntities);
}
stopWatch.stop();
statLogEntity.setStatEndTime(new Date());
statLogEntity.setDuration(stopWatch.getLastTaskTimeMillis());
accessStatLogService.save(statLogEntity, context);
}
} }
\ No newline at end of file
...@@ -3,7 +3,6 @@ package com.mortals.xhx.module.pj.web; ...@@ -3,7 +3,6 @@ package com.mortals.xhx.module.pj.web;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
...@@ -12,8 +11,8 @@ import com.mortals.framework.service.ICacheService; ...@@ -12,8 +11,8 @@ import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.ThreadPool; import com.mortals.framework.util.ThreadPool;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.common.key.RedisKey; import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.site.SitePdu; import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.thread.StatThread;
import com.mortals.xhx.feign.site.ISiteFeign; import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.access.model.AccessEntity; import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery; import com.mortals.xhx.module.access.model.AccessQuery;
...@@ -22,7 +21,6 @@ import com.mortals.xhx.module.access.model.AccessSystemEntity; ...@@ -22,7 +21,6 @@ import com.mortals.xhx.module.access.model.AccessSystemEntity;
import com.mortals.xhx.module.access.service.AccessService; import com.mortals.xhx.module.access.service.AccessService;
import com.mortals.xhx.module.access.service.AccessStatLogService; import com.mortals.xhx.module.access.service.AccessStatLogService;
import com.mortals.xhx.module.pj.model.PjEvaluateQuery; import com.mortals.xhx.module.pj.model.PjEvaluateQuery;
import com.mortals.xhx.module.pj.model.PjEvaluateStatQuery;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -181,97 +179,15 @@ public class PjEvaluateStatController extends BaseCRUDJsonBodyMappingController< ...@@ -181,97 +179,15 @@ public class PjEvaluateStatController extends BaseCRUDJsonBodyMappingController<
String busiDesc = "查询" + this.getModuleDesc(); String busiDesc = "查询" + this.getModuleDesc();
int code = 1; int code = 1;
try { try {
Runnable runnable = new Runnable() {
@Override
public void run() {
//天数区间分段计算
DateTime attendStart = DateUtil.parseDate(pjEvaluateQuery.getPjTimeStart()); DateTime attendStart = DateUtil.parseDate(pjEvaluateQuery.getPjTimeStart());
DateTime attendEnd = DateUtil.parseDate(pjEvaluateQuery.getPjTimeEnd()); DateTime attendEnd = DateUtil.parseDate(pjEvaluateQuery.getPjTimeEnd());
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY); Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
StopWatch stopWatch = new StopWatch("stopwatch");
log.info("计算天数区间:{}", compare); log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList();
AccessQuery accessQuery = new AccessQuery(); for (SitePdu site : statSiteList) {
// accessQuery.setTagNotList(Arrays.asList("")); StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_PJ.getValue()));
// List<AccessEntity> accessEntities = accessService.find(accessQuery); ThreadPool.getInstance().execute(statThread);
List<AccessEntity> accessEntities = accessService.find(accessQuery).stream().filter(item -> {
List<AccessSystemEntity> accessSystemList = item.getAccessSystemList();
//判断排队机或者评价系统是否开通
if(ObjectUtils.isEmpty(accessSystemList))return false;
List<AccessSystemEntity> collect = accessSystemList.stream().filter(f -> f.getEnabled() == YesNoEnum.YES.getValue()).collect(Collectors.toList());
if(ObjectUtils.isEmpty(collect)){return false;}
return true;
}).collect(Collectors.toList());
List<SitePdu> sitePduList=new ArrayList<>();
for (AccessEntity accessEntity : accessEntities) {
if(ObjectUtils.isEmpty(accessEntity.getSiteId()))continue;
if(accessEntity.getSiteId()==1L){
SitePdu site = new SitePdu();
site.setId(accessEntity.getSiteId());
site.setSiteName(accessEntity.getSiteName());
site.setSiteCode(accessEntity.getSiteCode());
site.setAreaCode(accessEntity.getAreaCode());
sitePduList.add(site);
continue;
}
SitePdu sitePdu = new SitePdu();
sitePdu.setId(accessEntity.getSiteId());
Rest<List<SitePdu>> sitesRest = siteFeign.getFlatSitesBySiteId(sitePdu);
if(YesNoEnum.YES.getValue()==sitesRest.getCode()){
sitePduList.addAll(sitesRest.getData());
}
}
if(!ObjectUtils.isEmpty(sitePduList)){
sitePduList=sitePduList.stream().collect(
collectingAndThen(
toCollection(() -> new TreeSet<>(Comparator.comparing(SitePdu::getId))), ArrayList::new));
for (SitePdu site : sitePduList) {
updateSitePjStat(attendStart, compare, stopWatch, site, context);
}
}
/*
for (AccessEntity accessEntity : accessEntities) {
//根据当前站点获取子站点
SitePdu sitePdu = new SitePdu();
sitePdu.setId(accessEntity.getId());
Rest<List<SitePdu>> sitesRest = siteFeign.getFlatSitesBySiteId(sitePdu);
if(YesNoEnum.YES.getValue()==sitesRest.getCode()){
List<SitePdu> sitePduList = sitesRest.getData();
for (SitePdu site : sitePduList) {
updateSitePjStat(attendStart, compare, stopWatch, site, context);
}
}
}*/
/* for (AccessEntity accessEntity : accessEntities) {
SitePdu site = new SitePdu();
site.setId(accessEntity.getSiteId());
site.setSiteName(accessEntity.getSiteName());
site.setSiteCode(accessEntity.getSiteCode());
site.setAreaCode(accessEntity.getAreaCode());
updateSitePjStat(attendStart, compare, stopWatch, site, context);
}*/
/* SitePdu sitePdu = new SitePdu();
sitePdu.setSize(-1);
Rest<RespData<List<SitePdu>>> resp = siteFeign.list(sitePdu);
List<SitePdu> sitePduList = resp.getData().getData();
log.info("site resp:{}", JSON.toJSONString(resp));
if (resp.getCode() == 1) {
for (SitePdu site : sitePduList) {
updateSitePjStat(attendStart, compare, stopWatch, site, context);
} }
//log.info("日期:{} 完成,耗时:{}ms", curDate.toDateStr(), stopWatch.getLastTaskTimeMillis());
}*/
}
};
ThreadPool.getInstance().execute(runnable);
model.put("message_info", busiDesc + "成功"); model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) { } catch (Exception e) {
...@@ -287,55 +203,5 @@ public class PjEvaluateStatController extends BaseCRUDJsonBodyMappingController< ...@@ -287,55 +203,5 @@ public class PjEvaluateStatController extends BaseCRUDJsonBodyMappingController<
} }
private void updateSitePjStat(DateTime attendStart, Long compare, StopWatch stopWatch, SitePdu site, Context context) {
stopWatch.start("站点评价统计开始");
AccessStatLogEntity statLogEntity = new AccessStatLogEntity();
statLogEntity.initAttrValue();
statLogEntity.setStatStartTime(new Date());
statLogEntity.setType(AccessTypeEnum.排队机.getValue());
statLogEntity.setCreateUserId(1L);
statLogEntity.setCreateTime(new Date());
statLogEntity.setSiteId(site.getId());
statLogEntity.setSiteCode(site.getSiteCode());
statLogEntity.setSiteName(site.getSiteName());
AccessQuery accessQuery = new AccessQuery();
accessQuery.setSiteId(site.getId() == null ? 0L : site.getId());
AccessEntity accessEntity = accessService.selectOne(accessQuery);
if (!ObjectUtils.isEmpty(accessEntity)) {
statLogEntity.setAccessId(accessEntity.getId());
}
List<PjEvaluateStatEntity> saveAndUpdatelist = new ArrayList<>();
for (int i = 0; i <= compare.intValue(); i++) {
DateTime curDate = DateUtil.offsetDay(attendStart, i);
//log.info("记录日期:{}", curDate.toDateStr());
PjEvaluateStatEntity sitestatEntity = new PjEvaluateStatEntity();
sitestatEntity.initAttrValue();
sitestatEntity.setSiteId(site.getId());
sitestatEntity.setSiteName(site.getSiteName());
sitestatEntity.setSiteCode(site.getSiteCode());
sitestatEntity.setYear(curDate.year());
sitestatEntity.setMonth(curDate.month() + 1);
sitestatEntity.setDay(curDate.dayOfMonth());
//设置年月日
Rest<List<PjEvaluateStatEntity>> rest = pjEvaluateStatService.updateSitePjStat(sitestatEntity, context);
saveAndUpdatelist.addAll(rest.getData());
}
List<List<PjEvaluateStatEntity>> partition = Lists.partition(saveAndUpdatelist, 1000);
for (List<PjEvaluateStatEntity> pjEvaluateStatEntities : partition) {
this.service.saveUpdatePjEvaluateStatList(pjEvaluateStatEntities);
}
stopWatch.stop();
statLogEntity.setStatEndTime(new Date());
statLogEntity.setDuration(stopWatch.getLastTaskTimeMillis());
accessStatLogService.save(statLogEntity, context);
}
} }
\ No newline at end of file
package com.mortals.xhx.module.stat.service; package com.mortals.xhx.module.stat.service;
import cn.hutool.core.date.DateTime;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity; import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity;
import com.mortals.xhx.module.stat.model.StatEntity; import com.mortals.xhx.module.stat.model.StatEntity;
import com.mortals.xhx.module.stat.dao.StatDao; import com.mortals.xhx.module.stat.dao.StatDao;
import org.springframework.util.StopWatch;
/** /**
* StatService * StatService
* *
...@@ -27,4 +31,6 @@ public interface StatService extends ICRUDService<StatEntity,Long>{ ...@@ -27,4 +31,6 @@ public interface StatService extends ICRUDService<StatEntity,Long>{
Rest<Void> updateSiteStat(StatEntity entity, Context context); Rest<Void> updateSiteStat(StatEntity entity, Context context);
void updateSiteStatLog(DateTime attendStart, Long compare, StopWatch stopWatch, SitePdu site, Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.stat.service.impl; package com.mortals.xhx.module.stat.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.OrderCol; import com.mortals.framework.model.OrderCol;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result; import com.mortals.framework.model.Result;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.access.service.AccessStatLogService;
import com.mortals.xhx.module.ph.model.PhQueueStatEntity; import com.mortals.xhx.module.ph.model.PhQueueStatEntity;
import com.mortals.xhx.module.ph.model.PhQueueStatQuery; import com.mortals.xhx.module.ph.model.PhQueueStatQuery;
import com.mortals.xhx.module.ph.service.PhQueueStatService; import com.mortals.xhx.module.ph.service.PhQueueStatService;
...@@ -24,6 +28,7 @@ import com.mortals.xhx.module.stat.model.StatEntity; ...@@ -24,6 +28,7 @@ import com.mortals.xhx.module.stat.model.StatEntity;
import com.mortals.xhx.module.stat.service.StatService; import com.mortals.xhx.module.stat.service.StatService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
...@@ -46,6 +51,8 @@ public class StatServiceImpl extends AbstractCRUDServiceImpl<StatDao, StatEntity ...@@ -46,6 +51,8 @@ public class StatServiceImpl extends AbstractCRUDServiceImpl<StatDao, StatEntity
private PjEvaluateStatService pjEvaluateStatService; private PjEvaluateStatService pjEvaluateStatService;
@Autowired @Autowired
private PhQueueStatService phQueueStatService; private PhQueueStatService phQueueStatService;
@Autowired
private AccessStatLogService accessStatLogService;
@Override @Override
...@@ -124,4 +131,23 @@ public class StatServiceImpl extends AbstractCRUDServiceImpl<StatDao, StatEntity ...@@ -124,4 +131,23 @@ public class StatServiceImpl extends AbstractCRUDServiceImpl<StatDao, StatEntity
} }
return Rest.ok(); return Rest.ok();
} }
@Override
public void updateSiteStatLog(DateTime attendStart, Long compare, StopWatch stopWatch, SitePdu site, Context context) {
for (int i = 0; i <= compare.intValue(); i++) {
DateTime curDate = DateUtil.offsetDay(attendStart, i);
StatEntity statEntity = new StatEntity();
statEntity.initAttrValue();
statEntity.setSiteId(site.getId());
statEntity.setSiteName(site.getSiteName());
statEntity.setSiteCode(site.getSiteCode());
statEntity.setYear(curDate.year());
statEntity.setMonth(curDate.month() + 1);
statEntity.setDay(curDate.dayOfMonth());
//设置年月日
this.updateSiteStat(statEntity, context);
}
}
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; ...@@ -11,6 +11,7 @@ import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.pdu.RespData; import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.site.SitePdu; import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.thread.StatThread;
import com.mortals.xhx.feign.site.ISiteFeign; import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.access.model.AccessEntity; import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery; import com.mortals.xhx.module.access.model.AccessQuery;
...@@ -94,96 +95,15 @@ public class StatController extends BaseCRUDJsonBodyMappingController<StatServic ...@@ -94,96 +95,15 @@ public class StatController extends BaseCRUDJsonBodyMappingController<StatServic
String busiDesc = "查询" + this.getModuleDesc(); String busiDesc = "查询" + this.getModuleDesc();
int code = 1; int code = 1;
try { try {
Runnable runnable = new Runnable() {
@Override
public void run() {
//天数区间分段计算
DateTime attendStart = DateUtil.parseDate(query.getCreateTimeStart()); DateTime attendStart = DateUtil.parseDate(query.getCreateTimeStart());
DateTime attendEnd = DateUtil.parseDate(query.getCreateTimeEnd()); DateTime attendEnd = DateUtil.parseDate(query.getCreateTimeEnd());
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY); Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
StopWatch stopWatch = new StopWatch("stopwatch");
log.info("计算天数区间:{}", compare); log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList();
AccessQuery accessQuery = new AccessQuery(); for (SitePdu site : statSiteList) {
/* accessQuery.setTagNotList(Arrays.asList("")); StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_ALL.getValue()));
List<AccessEntity> accessEntities = accessService.find(accessQuery);*/ ThreadPool.getInstance().execute(statThread);
List<AccessEntity> accessEntities = accessService.find(accessQuery).stream().filter(item -> {
List<AccessSystemEntity> accessSystemList = item.getAccessSystemList();
//判断排队机或者评价系统是否开通
if(ObjectUtils.isEmpty(accessSystemList))return false;
List<AccessSystemEntity> collect = accessSystemList.stream().filter(f -> f.getEnabled() == YesNoEnum.YES.getValue()).collect(Collectors.toList());
if(ObjectUtils.isEmpty(collect)){return false;}
return true;
}).collect(Collectors.toList());
List<SitePdu> sitePduList = new ArrayList<>();
for (AccessEntity accessEntity : accessEntities) {
SitePdu sitePdu = new SitePdu();
sitePdu.setId(accessEntity.getId());
Rest<List<SitePdu>> sitesRest = siteFeign.getFlatSitesBySiteId(sitePdu);
if (YesNoEnum.YES.getValue() == sitesRest.getCode()) {
sitePduList.addAll(sitesRest.getData());
}
}
if (!ObjectUtils.isEmpty(sitePduList)) {
sitePduList = sitePduList.stream().collect(
collectingAndThen(
toCollection(() -> new TreeSet<>(Comparator.comparing(SitePdu::getId))), ArrayList::new));
for (SitePdu site : sitePduList) {
for (int i = 0; i <= compare.intValue(); i++) {
DateTime curDate = DateUtil.offsetDay(attendStart, i);
StatEntity statEntity = new StatEntity();
statEntity.initAttrValue();
statEntity.setSiteId(site.getId());
statEntity.setSiteName(site.getSiteName());
statEntity.setSiteCode(site.getSiteCode());
statEntity.setYear(curDate.year());
statEntity.setMonth(curDate.month() + 1);
statEntity.setDay(curDate.dayOfMonth());
//设置年月日
statService.updateSiteStat(statEntity, context);
} }
}
}
/*
SitePdu sitePdu = new SitePdu();
sitePdu.setSize(-1);
Rest<RespData<List<SitePdu>>> resp = siteFeign.list(sitePdu);
for (int i = 0; i <= compare.intValue(); i++) {
DateTime curDate = DateUtil.offsetDay(attendStart, i);
log.info("记录日期:{}", curDate.toDateStr());
stopWatch.start("执行本地方法");
if (resp.getCode() == 1) {
List<SitePdu> sitePduList = resp.getData().getData();
sitePduList.stream().forEach(site -> {
StatEntity statEntity = new StatEntity();
statEntity.initAttrValue();
statEntity.setSiteId(site.getId());
statEntity.setSiteName(site.getSiteName());
statEntity.setSiteCode(site.getSiteCode());
statEntity.setYear(curDate.year());
statEntity.setMonth(curDate.month() + 1);
statEntity.setDay(curDate.dayOfMonth());
//设置年月日
statService.updateSiteStat(statEntity, context);
});
}
stopWatch.stop();
log.info("日期:{} 完成,耗时:{}ms", curDate.toDateStr(), stopWatch.getLastTaskTimeMillis());
}*/
}
};
ThreadPool.getInstance().execute(runnable);
model.put("message_info", busiDesc + "成功"); model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment