Commit 585f84ff authored by 张大伟's avatar 张大伟

1.ZnksServer完成,接受客户端解码未完成

parent c6939b12
...@@ -5,6 +5,7 @@ public class ZnksConstants { ...@@ -5,6 +5,7 @@ public class ZnksConstants {
/** /**
* 天津所有的地区 * 天津所有的地区
**/ **/
public static final String[] TIANJIN_AREAS = {"市辖区", "和平区", "河东区", "河西区", public static final String[] TIANJIN_AREAS = {"和平区", "河东区", "河西区",
"南开区", "河北区", "红桥区", "塘沽区", "汉沽区", "大港区", "东丽区", "西青区", "北辰区", "津南区", "武清区", "宝坻区"}; "南开区", "河北区", "红桥区", "塘沽区", "汉沽区", "大港区", "东丽区",
"西青区", "北辰区", "津南区", "武清区", "宝坻区","静海区", "蓟州区"};
} }
...@@ -4,10 +4,13 @@ import com.adc.da.base.web.BaseController; ...@@ -4,10 +4,13 @@ import com.adc.da.base.web.BaseController;
import com.adc.da.util.http.ResponseMessage; import com.adc.da.util.http.ResponseMessage;
import com.adc.da.util.http.Result; import com.adc.da.util.http.Result;
import com.adc.da.util.utils.CollectionUtils; import com.adc.da.util.utils.CollectionUtils;
import com.adc.da.znks.contants.ZnksConstants;
import com.adc.da.znks.dao.PositionDao;
import com.adc.da.znks.entity.ResponseEntity; import com.adc.da.znks.entity.ResponseEntity;
import com.adc.da.znks.entity.User; import com.adc.da.znks.entity.User;
import com.adc.da.znks.service.LockRecordService; import com.adc.da.znks.service.LockRecordService;
import com.adc.da.znks.service.UserService; import com.adc.da.znks.service.UserService;
import com.adc.da.znks.util.DateTimeUtil;
import com.adc.da.znks.util.GenResponse; import com.adc.da.znks.util.GenResponse;
import com.adc.da.znks.vo.UserCountVO; import com.adc.da.znks.vo.UserCountVO;
import com.adc.da.znks.vo.UserSearch; import com.adc.da.znks.vo.UserSearch;
...@@ -16,14 +19,14 @@ import com.github.pagehelper.PageHelper; ...@@ -16,14 +19,14 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap; import java.util.*;
import java.util.List;
/** /**
* @author David * @author David
...@@ -143,4 +146,44 @@ public class UserController extends BaseController<User> { ...@@ -143,4 +146,44 @@ public class UserController extends BaseController<User> {
return GenResponse.success(String.valueOf(HttpStatus.OK.value()), "统计用户信息成功", userService.getUserCountVO()); return GenResponse.success(String.valueOf(HttpStatus.OK.value()), "统计用户信息成功", userService.getUserCountVO());
} }
@Autowired
private PositionDao positionDao;
@ApiOperation(value = "|User|统计信息")
@PostMapping("/countInfo")
public ResponseEntity<Map<String, Object>> countInfo() {
Map<String, Object> map = new HashMap<>(4);
map.put("userCount", String.valueOf(userService.getUserCount()));
map.put("currentDayUsers", String.valueOf(userService.getCurrentDayUsers()));
List<String> tianJinAreas = org.springframework.util.CollectionUtils.arrayToList(ZnksConstants.TIANJIN_AREAS);
List<Map<String, String>> areaCountList = new ArrayList<>();
for(String area : tianJinAreas) {
int c = userService.getUserCountInTianJinPerArea(area);
Map<String, String> map1 = new HashMap<>();
map1.put(area, String.valueOf(c));
areaCountList.add(map1);
}
map.put("areaCountList", areaCountList);
Date currentTime = new Date(System.currentTimeMillis());
String currentDateStr = com.adc.da.util.utils.DateUtils.dateToString(currentTime,
"yyyy-MM-dd");
List<String> timeCountList = new ArrayList<>();
for (int i = 0; i < 24; i++) {
String startTime = currentDateStr + " " + i + ":00:00";
String endTime;
if(i == 23) {
endTime = currentDateStr + " 23:59:59";
} else {
endTime = currentDateStr + " " + (i + 1) + ":00:00";
}
timeCountList.add(String.valueOf(positionDao.getUserCountByPerHour(startTime, endTime)));
}
map.put("timeCountList", timeCountList);
return GenResponse.success(String.valueOf(HttpStatus.OK.value()), "统计用户信息成功", map);
}
} }
...@@ -25,11 +25,8 @@ public interface PositionDao extends BaseDao<Position> { ...@@ -25,11 +25,8 @@ public interface PositionDao extends BaseDao<Position> {
/** /**
* 获得天津每个地区的人数,每1小时统计一次 * 获得天津每个地区的人数,每1小时统计一次
* *
* @param tianJinArea 天津区域
* @param recordTime1 当前时间的前1个小时
* @param currentTime 当前时间
**/ **/
Integer getUserCountInTianJinPerArea(@Param("area") String tianJinArea, @Param("recordTime1") String recordTime1, @Param("currentTime") String currentTime); int getUserCountInTianJinPerArea(@Param("area") String area);
/** /**
......
package com.adc.da.znks.service; package com.adc.da.znks.service;
import com.adc.da.base.service.BaseService; import com.adc.da.base.service.BaseService;
import com.adc.da.util.utils.CollectionUtils; import com.adc.da.util.utils.CollectionUtils;
import com.adc.da.util.utils.UUID; import com.adc.da.util.utils.UUID;
...@@ -42,7 +41,6 @@ public class UserService extends BaseService<User, String> { ...@@ -42,7 +41,6 @@ public class UserService extends BaseService<User, String> {
@Autowired(required = false) @Autowired(required = false)
private UserDao dao; private UserDao dao;
@Autowired(required = false) @Autowired(required = false)
private PositionDao positionDao; private PositionDao positionDao;
...@@ -93,7 +91,6 @@ public class UserService extends BaseService<User, String> { ...@@ -93,7 +91,6 @@ public class UserService extends BaseService<User, String> {
} }
} }
/** /**
* user login or register * user login or register
**/ **/
...@@ -129,7 +126,6 @@ public class UserService extends BaseService<User, String> { ...@@ -129,7 +126,6 @@ public class UserService extends BaseService<User, String> {
} }
} }
/** /**
* user password encrypt list,list.get(0) is encryptKey,list.get(0) is encrypt password * user password encrypt list,list.get(0) is encryptKey,list.get(0) is encrypt password
**/ **/
...@@ -143,7 +139,6 @@ public class UserService extends BaseService<User, String> { ...@@ -143,7 +139,6 @@ public class UserService extends BaseService<User, String> {
return encryptList; return encryptList;
} }
public List<Map<String, Object>> queryMacByPhone(String phone) { public List<Map<String, Object>> queryMacByPhone(String phone) {
return dao.getGateWayByPhoneNumber(phone); return dao.getGateWayByPhoneNumber(phone);
} }
...@@ -156,7 +151,6 @@ public class UserService extends BaseService<User, String> { ...@@ -156,7 +151,6 @@ public class UserService extends BaseService<User, String> {
return dao.queryClientByMac(macAddress); return dao.queryClientByMac(macAddress);
} }
/** /**
* 获取用户列表记录 * 获取用户列表记录
**/ **/
...@@ -195,6 +189,18 @@ public class UserService extends BaseService<User, String> { ...@@ -195,6 +189,18 @@ public class UserService extends BaseService<User, String> {
return false; return false;
} }
public int getUserCount() {
UserPage userPage = new UserPage();
return dao.queryByCount(userPage);
}
public int getCurrentDayUsers() {
return positionDao.getCurrentDayUsers(new Date(System.currentTimeMillis()));
}
public int getUserCountInTianJinPerArea(String area) {
return positionDao.getUserCountInTianJinPerArea(area);
}
public UserCountVO getUserCountVO() { public UserCountVO getUserCountVO() {
UserPage userPage = new UserPage(); UserPage userPage = new UserPage();
...@@ -203,7 +209,7 @@ public class UserService extends BaseService<User, String> { ...@@ -203,7 +209,7 @@ public class UserService extends BaseService<User, String> {
userCountVO.setUserCount(userCount); userCountVO.setUserCount(userCount);
double clickRate = positionDao.getCurrentDayUsers(new Date(System.currentTimeMillis())) / userCount; double clickRate = positionDao.getCurrentDayUsers(new Date(System.currentTimeMillis())) / userCount;
userCountVO.setClickRate(clickRate); userCountVO.setClickRate(clickRate);
userCountVO.setDistributeVOS(ZnksTaskService.getDistributeVOS()); //userCountVO.setDistributeVOS(ZnksTaskService.getDistributeVOS());
return userCountVO; return userCountVO;
} }
} }
package com.adc.da.znks.service;
import com.adc.da.znks.contants.ZnksConstants;
import com.adc.da.znks.dao.PositionDao;
import com.adc.da.znks.util.DateTimeUtil;
import com.adc.da.znks.vo.MainDistributeVO;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
@Component
public class ZnksTaskService {
private static final Logger logger = LoggerFactory.getLogger(ZnksTaskService.class);
private static List<MainDistributeVO> distributeVOS = new ArrayList<>();
private static final String DEFAULT_MAX_COUNT_TIANJIN_AREA = "西青区";
private static final String DEFAULT_MAX_TIME_QUANTUM = "10:00-11:00";
@Autowired
private PositionDao positionDao;
/**
* 定时统计主要分布问题
**/
@Scheduled(cron = "* * */1 * * *")
public void scheduleMainDistribute() {
//选择当天的所有位置记录
List<String> tianJinAreas = CollectionUtils.arrayToList(ZnksConstants.TIANJIN_AREAS);
TreeMap<Integer, String> tianJinPerAreaUserMap = new TreeMap<>();
Date currentTime = new Date(System.currentTimeMillis());
String currentTimeStr = com.adc.da.util.utils.DateUtils.dateToString(currentTime,
"yyyy-MM-dd HH:mm:ss");
Date recordTime1 = DateUtils.addHours(new Date(System.currentTimeMillis()), -1);
String recordTime1Str = com.adc.da.util.utils.DateUtils.dateToString(recordTime1,
"yyyy-MM-dd HH:mm:ss");
for (String tianJinSArea : tianJinAreas) {
tianJinPerAreaUserMap.put(positionDao.getUserCountInTianJinPerArea(tianJinSArea, recordTime1Str, currentTimeStr), tianJinSArea);
}
String maxUserCountTianJinArea = null;
if (tianJinPerAreaUserMap.lastEntry().getKey() == 0) {
maxUserCountTianJinArea = ZnksTaskService.DEFAULT_MAX_COUNT_TIANJIN_AREA;
} else {
maxUserCountTianJinArea = tianJinPerAreaUserMap.lastEntry().getValue();
}
logger.info("tianJinPerAreaUserMap: {}", tianJinPerAreaUserMap);
TreeMap<Integer, String> mainUserDistributeTime = new TreeMap<>();
Date currentDayEndTime = DateTimeUtil.getCurrentDayEndTime();
long currentTimeLong = currentTime.getTime();
long currentDayEndTimeLong = currentDayEndTime.getTime();
if (currentTimeLong <= currentDayEndTimeLong) {
int hours = (int) DateTimeUtil.getHoursFromCurrentDayStartTime(currentTime);
for (int i = 0; i < hours; i++) {
String timeQuantum = com.adc.da.util.utils.DateUtils.dateToString(recordTime1,
"HH:mm") + "-" + com.adc.da.util.utils.DateUtils.dateToString(currentTime,
"HH:mm"); //获取前一个小时到当前时间的时间段
logger.info("timeQuantum: {}", timeQuantum);
mainUserDistributeTime.put(positionDao.getUserCountByPerHour(recordTime1Str, currentTimeStr), timeQuantum);
}
}
String mainUserTimeQuantum = null;
if (mainUserDistributeTime.lastEntry().getKey() == 0) {
mainUserTimeQuantum = ZnksTaskService.DEFAULT_MAX_TIME_QUANTUM;
} else {
mainUserTimeQuantum = mainUserDistributeTime.lastEntry().getValue();
}
MainDistributeVO mainDistributeVO = new MainDistributeVO();
mainDistributeVO.setMainDistributePosition(maxUserCountTianJinArea);
mainDistributeVO.setMainDistributeTime(mainUserTimeQuantum);
distributeVOS.add(mainDistributeVO);
logger.info("distributeVOS: {}", distributeVOS);
logger.info("maxUserCountTianJinArea: {},userCount: {}", maxUserCountTianJinArea);
logger.info("mainUserDistributeTime: {}", mainUserDistributeTime);
}
public static List<MainDistributeVO> getDistributeVOS() {
return distributeVOS;
}
}
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.datasource.driverClassName = com.mysql.jdbc.Driver
#数据库服务器外网ip221.239.111.146 内网10.10.0.3 #数据库服务器外网ip221.239.111.146 内网10.10.0.3
#智能定损数据库(测试数据库) #智能定损数据库(测试数据库)
spring.datasource.url = jdbc:mysql://106.2.13.200:3306/smarthome spring.datasource.url = jdbc:mysql://47.92.206.131:3306/smarthome?characterEncoding=utf-8
spring.datasource.username = root spring.datasource.username = root
#spring.datasource.password = root spring.datasource.password = root
#spring.datasource.driverClassName = com.mysql.jdbc.Driver #spring.datasource.driverClassName = com.mysql.jdbc.Driver
#spring.datasource.url = jdbc:mysql://localhost:3406/adc?characterEncoding=utf-8&&zeroDateTimeBehavior=convertToNull #spring.datasource.url = jdbc:mysql://localhost:3406/adc?characterEncoding=utf-8&&zeroDateTimeBehavior=convertToNull
......
...@@ -178,14 +178,14 @@ SELECT SEQ_tb_position.NEXTVAL FROM DUAL ...@@ -178,14 +178,14 @@ SELECT SEQ_tb_position.NEXTVAL FROM DUAL
</select> </select>
<select id="getUserCountInTianJinPerArea" resultType="java.lang.Integer" parameterType="string"> <select id="getUserCountInTianJinPerArea" resultType="java.lang.Integer">
SELECT COUNT(user_id) AS CURRENT_USER_COUNT SELECT COUNT(DISTINCT user_id) AS usercount
FROM tb_position FROM tb_position
WHERE position_name LIKE #{area} AND record_time>=#{recordTime1} AND record_time &lt;= #{currentTime} WHERE position_name LIKE CONCAT('%',#{area},'%')
</select> </select>
<select id="getUserCountByPerHour" resultType="java.lang.Integer" parameterType="string"> <select id="getUserCountByPerHour" resultType="java.lang.Integer" parameterType="string">
SELECT COUNT(user_id) AS CURRENT_USER_COUNT SELECT COUNT(DISTINCT user_id) AS CURRENT_USER_COUNT
FROM tb_position FROM tb_position
WHERE record_time>=#{recordTime1} AND record_time &lt;= #{currentTime} WHERE record_time>=#{recordTime1} AND record_time &lt;= #{currentTime}
</select> </select>
......
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