wulianwei 1 год назад
Родитель
Сommit
78c9aa0d14
24 измененных файлов с 568 добавлено и 11 удалено
  1. 10 0
      pom.xml
  2. 1 0
      src/main/java/com/tuoren/forward/aspect/HandleLogAspect.java
  3. 38 2
      src/main/java/com/tuoren/forward/config/amqp/AmqpClient1.java
  4. 38 2
      src/main/java/com/tuoren/forward/config/amqp/AmqpClient2.java
  5. 21 0
      src/main/java/com/tuoren/forward/controller/DeviceController.java
  6. 37 0
      src/main/java/com/tuoren/forward/controller/SatasticDayController.java
  7. 13 1
      src/main/java/com/tuoren/forward/entity/Device.java
  8. 21 0
      src/main/java/com/tuoren/forward/entity/SatasticDay.java
  9. 18 0
      src/main/java/com/tuoren/forward/entity/req/SatasticDayReq.java
  10. 15 0
      src/main/java/com/tuoren/forward/entity/resp/CountCategoryResp.java
  11. 13 0
      src/main/java/com/tuoren/forward/entity/resp/CountResp.java
  12. 16 0
      src/main/java/com/tuoren/forward/entity/resp/SatasticResp.java
  13. 6 0
      src/main/java/com/tuoren/forward/mapper/DeviceMapper.java
  14. 2 0
      src/main/java/com/tuoren/forward/mapper/LogMapper.java
  15. 25 0
      src/main/java/com/tuoren/forward/mapper/SatasticDayMapper.java
  16. 21 0
      src/main/java/com/tuoren/forward/service/DeviceService.java
  17. 23 0
      src/main/java/com/tuoren/forward/service/SatasticDayService.java
  18. 28 2
      src/main/java/com/tuoren/forward/service/UserService.java
  19. 21 0
      src/main/resources/application.yml
  20. 14 0
      src/main/resources/db/migration/V1.0.0_satasitc_init.sql
  21. 1 1
      src/main/resources/generatorConfig.xml
  22. 76 3
      src/main/resources/mapper/DeviceMapper.xml
  23. 7 0
      src/main/resources/mapper/LogMapper.xml
  24. 103 0
      src/main/resources/mapper/SatasticDayMapper.xml

+ 10 - 0
pom.xml

@@ -131,6 +131,16 @@
 		    <groupId>com.squareup.okhttp3</groupId>
 		    <artifactId>okhttp</artifactId>
 		</dependency>
+		<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-core -->
+		<dependency>
+		    <groupId>org.flywaydb</groupId>
+		    <artifactId>flyway-core</artifactId>
+		</dependency>
+		<dependency>
+		    <groupId>org.flywaydb</groupId>
+		    <artifactId>flyway-mysql</artifactId>
+		</dependency>
+
         <!--<dependency>
         	<groupId>com.demo</groupId>
         	<artifactId>forward</artifactId>

+ 1 - 0
src/main/java/com/tuoren/forward/aspect/HandleLogAspect.java

@@ -85,6 +85,7 @@ public class HandleLogAspect {
 			request.setAttribute(CommonConstant.REQUEST_LOG_ATTR, handleLog);
 	        request.setAttribute(CommonConstant.REQUEST_TIME_ATTR, time);
 		}
+		
         Object result = joinPoint.proceed();
         
         long wastetime = System.currentTimeMillis() - time;

+ 38 - 2
src/main/java/com/tuoren/forward/config/amqp/AmqpClient1.java

@@ -35,8 +35,10 @@ import com.alibaba.fastjson2.JSONObject;
 import com.tuoren.forward.config.mqtt.MqttUtil;
 import com.tuoren.forward.constant.CommonConstant;
 import com.tuoren.forward.entity.Device;
+import com.tuoren.forward.entity.SatasticDay;
 import com.tuoren.forward.entity.User;
 import com.tuoren.forward.mapper.DeviceMapper;
+import com.tuoren.forward.mapper.SatasticDayMapper;
 import com.tuoren.forward.mapper.UserMapper;
 import com.tuoren.forward.util.RemoteUtil;
 import com.tuoren.forward.util.UUIDUtil;
@@ -79,6 +81,9 @@ public class AmqpClient1 {
     @Autowired
     UserMapper userMapper;
     
+    @Autowired
+    SatasticDayMapper satasticDayMapper;
+    
     @Autowired
     MongoTemplate mongoTemplate;
     
@@ -168,6 +173,7 @@ public class AmqpClient1 {
             String productKey = json.getString("productKey");
             String hospitalCode = "";
             JSONObject items = json.getJSONObject("items");
+            JSONObject localJson = null;
             long ci = 0;
             long lac = 0;
             if(items.containsKey("userId")) {
@@ -181,7 +187,8 @@ public class AmqpClient1 {
             }
             if(ci > 0 && lac>0) {
             	String location = remoteUtil.localtion(String.valueOf(ci), String.valueOf(lac));
-            	items.put("location", JSONObject.parseObject(location));
+            	localJson =  JSONObject.parseObject(location);
+            	items.put("location", localJson);
             }
             if(StringUtils.isEmpty(hospitalCode)) {
 //            	String sql = "SELECT h.code FROM bus_hospital h  inner join bus_device d on d.tenant_id = h.tenant_id where device_id=? limit 1";
@@ -202,22 +209,37 @@ public class AmqpClient1 {
         			return;
         		}
         		JSONObject mongoJson = new JSONObject();
+        		Date date = new Date();
         		Device exist = deviceMapper.selectByMac(deviceName);
         		if(exist == null) {
         			Device record = new Device();
         			String deviceId = UUIDUtil.get32UUID();
         			record.setId(deviceId);
-        			record.setCreatetime(new Date());
+        			record.setCreatetime(date);
+        			record.setModifytime(date);
         			record.setMac(deviceName);
         			record.setProductId(productKey);
         			record.setTenantId(owner.getId());
+        			if(localJson != null) {
+        				record.setLat(localJson.getString("lat"));
+        				record.setLat(localJson.getString("lng"));
+        				record.setLat(localJson.getString("address"));
+        				record.setLat(localJson.getString("radius"));
+        			}
         			record.setData(items.toString());
         			deviceMapper.insertSelective(record);
         			mongoJson.put("deviceId", deviceId);
         		}else {
         			Device record = new Device();
         			record.setId(exist.getId());
+        			record.setModifytime(date);
         			record.setTenantId(owner.getId());
+        			if(localJson != null) {
+        				record.setLat(localJson.getString("lat"));
+        				record.setLat(localJson.getString("lng"));
+        				record.setLat(localJson.getString("address"));
+        				record.setLat(localJson.getString("radius"));
+        			}
         			record.setData( items.toString());
         			deviceMapper.updateByPrimaryKeySelective2(record);
         			mongoJson.put("deviceId", exist.getId());
@@ -228,6 +250,20 @@ public class AmqpClient1 {
         		mongoJson.put("items", items);
         		mongoTemplate.insert(mongoJson, CommonConstant.MONGO_COLLECTION_DEVICE_RECORD);
         		
+        		String sataType = "forward";
+        		SatasticDay existSata = satasticDayMapper.selectSataTodayByType(sataType);
+        		if(existSata == null) {
+        			SatasticDay record = new SatasticDay();
+        			record.setId(UUIDUtil.get32UUID());
+        			record.setType(sataType);
+        			record.setNum(1);
+        			record.setCreatedate(date);
+        			satasticDayMapper.insert(record);
+        		}else {
+        			existSata.setNum(existSata.getNum()+1);
+        			satasticDayMapper.updateByPrimaryKey(existSata);
+        		}
+        		
         		if(mqttUtil != null) {
         			log.info("mqtt publish1:"+  json.toString());
         			mqttUtil.pub(CommonConstant.MQTT_PUBLISH_PREFIX+hospitalCode, json.toString());

+ 38 - 2
src/main/java/com/tuoren/forward/config/amqp/AmqpClient2.java

@@ -35,8 +35,10 @@ import com.alibaba.fastjson2.JSONObject;
 import com.tuoren.forward.config.mqtt.MqttUtil;
 import com.tuoren.forward.constant.CommonConstant;
 import com.tuoren.forward.entity.Device;
+import com.tuoren.forward.entity.SatasticDay;
 import com.tuoren.forward.entity.User;
 import com.tuoren.forward.mapper.DeviceMapper;
+import com.tuoren.forward.mapper.SatasticDayMapper;
 import com.tuoren.forward.mapper.UserMapper;
 import com.tuoren.forward.util.RemoteUtil;
 import com.tuoren.forward.util.UUIDUtil;
@@ -79,6 +81,9 @@ public class AmqpClient2 {
     @Autowired
     UserMapper userMapper;
     
+    @Autowired
+    SatasticDayMapper satasticDayMapper;
+    
     @Autowired
     MongoTemplate mongoTemplate;
     
@@ -168,6 +173,7 @@ public class AmqpClient2 {
             String productKey = json.getString("productKey");
             String hospitalCode = "";
             JSONObject items = json.getJSONObject("items");
+            JSONObject localJson = null;
             long ci = 0;
             long lac = 0;
             if(items.containsKey("userId")) {
@@ -181,7 +187,8 @@ public class AmqpClient2 {
             }
             if(ci > 0 && lac>0) {
             	String location = remoteUtil.localtion(String.valueOf(ci), String.valueOf(lac));
-            	items.put("location", JSONObject.parseObject(location));
+            	localJson =  JSONObject.parseObject(location);
+            	items.put("location", localJson);
             }
             if(StringUtils.isEmpty(hospitalCode)) {
 //            	String sql = "SELECT h.code FROM bus_hospital h  inner join bus_device d on d.tenant_id = h.tenant_id where device_id=? limit 1";
@@ -202,22 +209,37 @@ public class AmqpClient2 {
         			return;
         		}
         		JSONObject mongoJson = new JSONObject();
+        		Date date = new Date();
         		Device exist = deviceMapper.selectByMac(deviceName);
         		if(exist == null) {
         			Device record = new Device();
         			String deviceId = UUIDUtil.get32UUID();
         			record.setId(deviceId);
-        			record.setCreatetime(new Date());
+        			record.setCreatetime(date);
+        			record.setModifytime(date);
         			record.setMac(deviceName);
         			record.setProductId(productKey);
         			record.setTenantId(owner.getId());
+        			if(localJson != null) {
+        				record.setLat(localJson.getString("lat"));
+        				record.setLat(localJson.getString("lng"));
+        				record.setLat(localJson.getString("address"));
+        				record.setLat(localJson.getString("radius"));
+        			}
         			record.setData(items.toString());
         			deviceMapper.insertSelective(record);
         			mongoJson.put("deviceId", deviceId);
         		}else {
         			Device record = new Device();
         			record.setId(exist.getId());
+        			record.setModifytime(date);
         			record.setTenantId(owner.getId());
+        			if(localJson != null) {
+        				record.setLat(localJson.getString("lat"));
+        				record.setLat(localJson.getString("lng"));
+        				record.setLat(localJson.getString("address"));
+        				record.setLat(localJson.getString("radius"));
+        			}
         			record.setData( items.toString());
         			deviceMapper.updateByPrimaryKeySelective2(record);
         			mongoJson.put("deviceId", exist.getId());
@@ -228,6 +250,20 @@ public class AmqpClient2 {
         		mongoJson.put("items", items);
         		mongoTemplate.insert(mongoJson, CommonConstant.MONGO_COLLECTION_DEVICE_RECORD);
         		
+        		String sataType = "forward";
+        		SatasticDay existSata = satasticDayMapper.selectSataTodayByType(sataType);
+        		if(existSata == null) {
+        			SatasticDay record = new SatasticDay();
+        			record.setId(UUIDUtil.get32UUID());
+        			record.setType(sataType);
+        			record.setNum(1);
+        			record.setCreatedate(date);
+        			satasticDayMapper.insert(record);
+        		}else {
+        			existSata.setNum(existSata.getNum()+1);
+        			satasticDayMapper.updateByPrimaryKey(existSata);
+        		}
+        		
         		if(mqttUtil != null) {
         			log.info("mqtt publish2:"+  json.toString());
         			mqttUtil.pub(CommonConstant.MQTT_PUBLISH_PREFIX+hospitalCode, json.toString());

+ 21 - 0
src/main/java/com/tuoren/forward/controller/DeviceController.java

@@ -15,9 +15,12 @@ import com.tuoren.forward.entity.req.DeviceAddReq;
 import com.tuoren.forward.entity.req.DeviceRecordSearchReq;
 import com.tuoren.forward.entity.req.DeviceSearchReq;
 import com.tuoren.forward.entity.req.IdReq;
+import com.tuoren.forward.entity.resp.CountCategoryResp;
+import com.tuoren.forward.entity.resp.CountResp;
 import com.tuoren.forward.entity.resp.DeviceResp;
 import com.tuoren.forward.service.DeviceService;
 import com.tuoren.forward.util.Result;
+import com.tuoren.forward.util.ResultData;
 import com.tuoren.forward.util.ResultPage;
 
 import io.swagger.v3.oas.annotations.Operation;
@@ -93,4 +96,22 @@ public class DeviceController {
 		return deviceService.searchRecord(req);
 	}
 	
+	@PostMapping("countProvinceDevice")
+    @ResponseBody
+    @Operation(summary = "统计各省设备数")
+	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
+	public ResultData<CountCategoryResp> countProvinceDevice(){
+		log.info("searchRecord>>");
+		return deviceService.countProvinceDevice();
+	}
+	
+	@PostMapping("countOnlineDevice")
+    @ResponseBody
+    @Operation(summary = "统计在线设备数")
+	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
+	public ResultData<CountResp> countOnlineDevice(){
+		log.info("countOnlineDevice>>");
+		return deviceService.countOnlineDevice();
+	}
+	
 }

+ 37 - 0
src/main/java/com/tuoren/forward/controller/SatasticDayController.java

@@ -0,0 +1,37 @@
+package com.tuoren.forward.controller;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+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.ResponseBody;
+
+import com.tuoren.forward.entity.req.SatasticDayReq;
+import com.tuoren.forward.entity.resp.SatasticResp;
+import com.tuoren.forward.service.SatasticDayService;
+import com.tuoren.forward.util.ResultData;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Controller
+@RequestMapping("satasticDayController")
+@Tag(name="统计接口")
+public class SatasticDayController {
+	
+	@Autowired
+	SatasticDayService satasticDayService;
+	
+	@PostMapping("sataDays")
+    @ResponseBody
+    @Operation(summary = "近日统计")
+	public ResultData<List<SatasticResp>> sataDays(@RequestBody SatasticDayReq req){
+		log.info("sataDays>>:{}",req);
+		return satasticDayService.sataDays(req);
+	}
+}

+ 13 - 1
src/main/java/com/tuoren/forward/entity/Device.java

@@ -33,7 +33,19 @@ public class Device {
 
     @Schema(description = "租户ID")
     private String tenantId;
-
+    
+    @Schema(description = "纬度")
+    private String lat;
+    
+    @Schema(description = "经度")
+    private String lng;
+    
+    @Schema(description = "地址")
+    private String address;
+    
+    @Schema(description = "误差半径,单位:米")
+    private String radius;
+    
     @Schema(description = "当前数据")
     private String data;
 }

+ 21 - 0
src/main/java/com/tuoren/forward/entity/SatasticDay.java

@@ -0,0 +1,21 @@
+package com.tuoren.forward.entity;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import java.util.Date;
+import lombok.Data;
+
+@Data
+@Schema(description = "日统计量")
+public class SatasticDay {
+    @Schema(description = "ID")
+    private String id;
+
+    @Schema(description = "统计量")
+    private Integer num;
+
+    @Schema(description = "统计类型, forward:转发,login:登录,alarm:报警")
+    private String type;
+
+    @Schema(description = "创建日期")
+    private Date createdate;
+}

+ 18 - 0
src/main/java/com/tuoren/forward/entity/req/SatasticDayReq.java

@@ -0,0 +1,18 @@
+package com.tuoren.forward.entity.req;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+@Schema(description="统计请求")
+public class SatasticDayReq {
+	
+
+	  @Schema(description = "统计类型, forward:转发,login:登录,alarm:报警")
+	  private String type;
+	   
+	  @Schema(description = "最近天数")
+	  private Integer days;
+	   
+
+}

+ 15 - 0
src/main/java/com/tuoren/forward/entity/resp/CountCategoryResp.java

@@ -0,0 +1,15 @@
+package com.tuoren.forward.entity.resp;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+@Schema(description = "分类统计数据")
+public class CountCategoryResp {
+	
+	@Schema(description = "统计名称")
+	private String title;
+	
+	@Schema(description = "统计数字")
+	private Integer num;
+}

+ 13 - 0
src/main/java/com/tuoren/forward/entity/resp/CountResp.java

@@ -0,0 +1,13 @@
+package com.tuoren.forward.entity.resp;
+
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+@Schema(description = "统计数据")
+public class CountResp {
+	
+	@Schema(description = "统计数字")
+	private Integer num;
+}

+ 16 - 0
src/main/java/com/tuoren/forward/entity/resp/SatasticResp.java

@@ -0,0 +1,16 @@
+package com.tuoren.forward.entity.resp;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+@Schema(description = "统计量")
+public class SatasticResp {
+	
+	@Schema(description = "统计量")
+    private Integer num;
+
+    @Schema(description = "统计类型, forward:转发,login:登录,alarm:报警")
+    private String type;
+    
+}

+ 6 - 0
src/main/java/com/tuoren/forward/mapper/DeviceMapper.java

@@ -5,6 +5,8 @@ import java.util.List;
 import com.tuoren.forward.annotation.SqlLimit;
 import com.tuoren.forward.entity.Device;
 import com.tuoren.forward.entity.dto.DeviceDto;
+import com.tuoren.forward.entity.resp.CountCategoryResp;
+import com.tuoren.forward.entity.resp.CountResp;
 import com.tuoren.forward.entity.resp.DeviceResp;
 
 @SqlLimit
@@ -30,6 +32,10 @@ public interface DeviceMapper {
     @SqlLimit(alis = "d")
     List<DeviceResp> select(DeviceDto row);
 
+    CountCategoryResp countProviceDevice();
+    
+    CountResp countOnlineDevice();
+    
     int updateByPrimaryKeySelective(Device row);
     
     @SqlLimit(isWork = false)

+ 2 - 0
src/main/java/com/tuoren/forward/mapper/LogMapper.java

@@ -16,6 +16,8 @@ public interface LogMapper {
 
     List<Log> select(LogDto row);
     
+    Integer existLoginTodayByUseid(String userid);
+    
     int updateByPrimaryKeySelective(Log row);
 
     int updateByPrimaryKey(Log row);

+ 25 - 0
src/main/java/com/tuoren/forward/mapper/SatasticDayMapper.java

@@ -0,0 +1,25 @@
+package com.tuoren.forward.mapper;
+
+import java.util.List;
+
+import com.tuoren.forward.entity.SatasticDay;
+import com.tuoren.forward.entity.req.SatasticDayReq;
+import com.tuoren.forward.entity.resp.SatasticResp;
+
+public interface SatasticDayMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(SatasticDay row);
+
+    int insertSelective(SatasticDay row);
+
+    SatasticDay selectByPrimaryKey(String id);
+    
+    SatasticDay selectSataTodayByType(String type);
+    
+    List<SatasticResp> satasticDays(SatasticDayReq req);
+
+    int updateByPrimaryKeySelective(SatasticDay row);
+
+    int updateByPrimaryKey(SatasticDay row);
+}

+ 21 - 0
src/main/java/com/tuoren/forward/service/DeviceService.java

@@ -22,10 +22,13 @@ import com.tuoren.forward.entity.dto.DeviceDto;
 import com.tuoren.forward.entity.req.DeviceAddReq;
 import com.tuoren.forward.entity.req.DeviceRecordSearchReq;
 import com.tuoren.forward.entity.req.DeviceSearchReq;
+import com.tuoren.forward.entity.resp.CountCategoryResp;
+import com.tuoren.forward.entity.resp.CountResp;
 import com.tuoren.forward.entity.resp.DeviceResp;
 import com.tuoren.forward.mapper.DeviceMapper;
 import com.tuoren.forward.util.AccessTokenUtil;
 import com.tuoren.forward.util.Result;
+import com.tuoren.forward.util.ResultData;
 import com.tuoren.forward.util.ResultPage;
 import com.tuoren.forward.util.UUIDUtil;
 
@@ -127,4 +130,22 @@ public class DeviceService {
 		List<JSONObject> results = mongoTemplate.find(query, JSONObject.class, "device_record");
 		return ResultPage.success(results, totol);
 	}
+	
+	/**
+	 * @title 统计各省设备数
+	 * @return
+	 */
+	public ResultData<CountCategoryResp> countProvinceDevice(){
+		CountCategoryResp resp = deviceMapper.countProviceDevice();
+		return ResultData.success(resp);
+	}
+	
+	/**
+	 * @title 统计在线设备数
+	 * @return
+	 */
+	public ResultData<CountResp> countOnlineDevice(){
+		CountResp resp = deviceMapper.countOnlineDevice();
+		return ResultData.success(resp);
+	}
 }

+ 23 - 0
src/main/java/com/tuoren/forward/service/SatasticDayService.java

@@ -0,0 +1,23 @@
+package com.tuoren.forward.service;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.tuoren.forward.entity.req.SatasticDayReq;
+import com.tuoren.forward.entity.resp.SatasticResp;
+import com.tuoren.forward.mapper.SatasticDayMapper;
+import com.tuoren.forward.util.ResultData;
+
+@Service
+public class SatasticDayService {
+	
+	@Autowired
+	SatasticDayMapper satasticDayMapper;
+	
+	public ResultData<List<SatasticResp>> sataDays(SatasticDayReq req){
+		List<SatasticResp> resp = satasticDayMapper.satasticDays(req);
+		return ResultData.success(resp);
+	}
+}

+ 28 - 2
src/main/java/com/tuoren/forward/service/UserService.java

@@ -13,17 +13,20 @@ import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import com.tuoren.forward.constant.CommonConstant;
+import com.tuoren.forward.entity.SatasticDay;
 import com.tuoren.forward.entity.User;
 import com.tuoren.forward.entity.UserRole;
 import com.tuoren.forward.entity.dto.UserDto;
 import com.tuoren.forward.entity.req.LoginReq;
 import com.tuoren.forward.entity.req.UserAddOpenReq;
 import com.tuoren.forward.entity.req.UserAddReq;
-import com.tuoren.forward.entity.req.UserSearchReq;
 import com.tuoren.forward.entity.req.UserEditSelfReq;
+import com.tuoren.forward.entity.req.UserSearchReq;
 import com.tuoren.forward.entity.resp.LoginResp;
 import com.tuoren.forward.entity.resp.UserResp;
+import com.tuoren.forward.mapper.LogMapper;
 import com.tuoren.forward.mapper.RoleMapper;
+import com.tuoren.forward.mapper.SatasticDayMapper;
 import com.tuoren.forward.mapper.UserMapper;
 import com.tuoren.forward.mapper.UserRoleMapper;
 import com.tuoren.forward.util.AccessTokenUtil;
@@ -51,6 +54,12 @@ public class UserService {
 	@Autowired
 	UserRoleMapper userRoleMapper;
 	
+	@Autowired
+	LogMapper logMapper;
+	
+	@Autowired
+	SatasticDayMapper satasticDayMapper;
+	
 	/**
 	 * @title 登录
 	 * @param req
@@ -74,6 +83,7 @@ public class UserService {
 		if(loginUser == null || !MD5Util.encode32(req.getPassword()).equals(loginUser.getPassword())) {
 			return ResultData.failNull("用户名或密码错误");
 		}
+		Date date= new Date();
 		List<String> roleIds = roleMapper.selectIdByUserId(loginUser.getId());
 		loginUser.setRoleIds(roleIds);
 		StpUtil.login(loginUser.getId());
@@ -83,9 +93,25 @@ public class UserService {
 		//跟新登录时间
 		User user = new User();
 		user.setId(loginUser.getId());
-		user.setLasttime(new Date());
+		user.setLasttime(date);
 		userMapper.updateByPrimaryKeySelective(user);
 		
+		if(logMapper.existLoginTodayByUseid(user.getId()) == null) {
+			String sataType = "login";
+			SatasticDay existSata = satasticDayMapper.selectSataTodayByType(sataType);
+    		if(existSata == null) {
+    			SatasticDay record = new SatasticDay();
+    			record.setId(UUIDUtil.get32UUID());
+    			record.setType(sataType);
+    			record.setNum(1);
+    			record.setCreatedate(date);
+    			satasticDayMapper.insert(record);
+    		}else {
+    			existSata.setNum(existSata.getNum()+1);
+    			satasticDayMapper.updateByPrimaryKey(existSata);
+    		}
+		}
+		
 		//返回登录结果
 		LoginResp resp = new LoginResp();
 		BeanUtils.copyProperties(loginUser, resp);

+ 21 - 0
src/main/resources/application.yml

@@ -9,6 +9,7 @@ spring:
     time-zone: GMT+8
     date-format: yyyy-MM-dd HH:mm:ss
 
+
     
 mybatis:
   configuration:
@@ -61,6 +62,16 @@ spring:
         maximum-pool-size: 5
         idle-timeout: 600000
         pool-name: HikariCP
+  flyway:
+    #是否启用
+    enabled: false
+    # flyway 的 clean 命令会删除指定 schema 下的所有 table, 生产务必禁掉
+    clean-disabled: true
+    locations: classpath:db/migration
+    #迁移时是否校验,默认为true.
+    validate-on-migrate: true
+    # 如果数据库不是空表,需要设置成 true,否则启动报错
+    baseline-on-migrate: true
   redis:
     database: 2
     host: 127.0.0.1
@@ -149,6 +160,16 @@ spring:
         maximum-pool-size: 10
         idle-timeout: 600000
         pool-name: HikariCP-nb
+  flyway:
+    #是否启用
+    enabled: true
+    # flyway 的 clean 命令会删除指定 schema 下的所有 table, 生产务必禁掉
+    clean-disabled: true
+    locations: classpath:db/migration
+    #迁移时是否校验,默认为true.
+    validate-on-migrate: true
+    # 如果数据库不是空表,需要设置成 true,否则启动报错
+    baseline-on-migrate: true
   redis:
     database: 2
     host: 192.168.100.115

+ 14 - 0
src/main/resources/db/migration/V1.0.0_satasitc_init.sql

@@ -0,0 +1,14 @@
+ALTER TABLE `forward`.`device` 
+ADD COLUMN `lat` VARCHAR(45) NULL AFTER `tenant_id`,
+ADD COLUMN `lng` VARCHAR(45) NULL AFTER `lat`,
+ADD COLUMN `address` VARCHAR(200) NULL AFTER `lng`,
+ADD COLUMN `radius` VARCHAR(10) NULL AFTER `address`;
+
+
+CREATE TABLE `satastic_day` (
+  `id` varchar(45) NOT NULL COMMENT 'ID',
+  `num` int DEFAULT NULL COMMENT '统计量',
+  `type` varchar(10) DEFAULT NULL COMMENT '统计类型, forward:转发,login:登录,alarm:报警',
+  `createdate` date DEFAULT NULL COMMENT '创建日期',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='日统计量'

+ 1 - 1
src/main/resources/generatorConfig.xml

@@ -34,6 +34,6 @@
             <property name="enableSubPackages" value="true"/>
         </javaClientGenerator>
         <!--生成对应表及类名-->
-        <table tableName="log" domainObjectName="Log" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
+        <table tableName="satastic_day" domainObjectName="SatasticDay" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
     </context>
 </generatorConfiguration>

+ 76 - 3
src/main/resources/mapper/DeviceMapper.xml

@@ -11,6 +11,10 @@
     <result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
     <result column="modifytime" jdbcType="TIMESTAMP" property="modifytime" />
     <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
+    <result column="lat" jdbcType="VARCHAR" property="lat" />
+    <result column="lng" jdbcType="VARCHAR" property="lng" />
+    <result column="address" jdbcType="VARCHAR" property="address" />
+    <result column="radius" jdbcType="VARCHAR" property="radius" />
   </resultMap>
   <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tuoren.forward.entity.Device">
     <result column="data" jdbcType="LONGVARCHAR" property="data" />
@@ -47,7 +51,7 @@
   	and tenant_id = #{owner}
   	limit 1
   </select>
-  <select id="existByMacOwner" parameterType="java.lang.Integer"  resultMap="BaseResultMap">
+  <select id="existByMacOwner" parameterType="java.lang.Integer"  resultType="java.lang.Integer" >
   	select 1
   	from device
   	where mac = #{mac,jdbcType=VARCHAR}
@@ -79,6 +83,17 @@
 	</if>
   </select>
   
+  <select id="countProviceDevice" resultType="com.tuoren.forward.entity.resp.CountCategoryResp">
+  	select pro title,count(1) num from 
+	(SELECT left(address,2) pro FROM forward.device where address is not null) pro_device
+	group by pro
+  </select>
+  
+  <select id="countOnlineDevice" resultType="com.tuoren.forward.entity.resp.CountResp">
+  	select  count(1) num
+  	from device where timestampdiff(MINUTE,modifytime,now()) &lt; 60
+  </select>
+  
   <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
     delete from device
     where id = #{id,jdbcType=VARCHAR}
@@ -87,11 +102,13 @@
     insert into device (id, mac, name, 
       is_delete, product_id, description, 
       createtime, modifytime, tenant_id, 
+      lat,lng,address,radius,
       data)
     values (#{id,jdbcType=VARCHAR}, #{mac,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
       #{isDelete,jdbcType=CHAR}, #{productId,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, 
       #{createtime,jdbcType=TIMESTAMP}, #{modifytime,jdbcType=TIMESTAMP}, #{tenantId,jdbcType=VARCHAR}, 
-      #{data,jdbcType=LONGVARCHAR})
+      #{lat,jdbcType=VARCHAR},#{lng,jdbcType=VARCHAR},#{address,jdbcType=VARCHAR},
+      #{radius,jdbcType=VARCHAR},#{data,jdbcType=LONGVARCHAR})
   </insert>
   <insert id="insertSelective" parameterType="com.tuoren.forward.entity.Device">
     insert into device
@@ -123,6 +140,18 @@
       <if test="tenantId != null">
         tenant_id,
       </if>
+      <if test="lat != null">
+        lat,
+      </if>
+      <if test="lng != null">
+        lng,
+      </if>
+      <if test="address != null">
+        address,
+      </if>
+      <if test="radius != null">
+        radius,
+      </if>
       <if test="data != null">
         data,
       </if>
@@ -155,6 +184,18 @@
       <if test="tenantId != null">
         #{tenantId,jdbcType=VARCHAR},
       </if>
+      <if test="lat != null">
+        #{lat,jdbcType=VARCHAR},
+      </if>
+      <if test="lng != null">
+        #{lng,jdbcType=VARCHAR},
+      </if>
+      <if test="address != null">
+        #{address,jdbcType=VARCHAR},
+      </if>
+      <if test="radius != null">
+        #{radius,jdbcType=VARCHAR},
+      </if>
       <if test="data != null">
         #{data,jdbcType=LONGVARCHAR},
       </if>
@@ -187,6 +228,18 @@
       <if test="tenantId != null">
         tenant_id = #{tenantId,jdbcType=VARCHAR},
       </if>
+      <if test="lat != null">
+        lat = #{lat,jdbcType=VARCHAR},
+      </if>
+      <if test="lng != null">
+        lng = #{lng,jdbcType=VARCHAR},
+      </if>
+      <if test="address != null">
+        address = #{address,jdbcType=VARCHAR},
+      </if>
+      <if test="radius != null">
+        radius = #{radius,jdbcType=VARCHAR},
+      </if>
       <if test="data != null">
         data = #{data,jdbcType=LONGVARCHAR},
       </if>
@@ -220,6 +273,18 @@
       <if test="tenantId != null">
         tenant_id = #{tenantId,jdbcType=VARCHAR},
       </if>
+      <if test="lat != null">
+        lat = #{lat,jdbcType=VARCHAR},
+      </if>
+      <if test="lng != null">
+        lng = #{lng,jdbcType=VARCHAR},
+      </if>
+      <if test="address != null">
+        address = #{address,jdbcType=VARCHAR},
+      </if>
+      <if test="radius != null">
+        radius = #{radius,jdbcType=VARCHAR},
+      </if>
       <if test="data != null">
         data = #{data,jdbcType=LONGVARCHAR},
       </if>
@@ -236,6 +301,10 @@
       createtime = #{createtime,jdbcType=TIMESTAMP},
       modifytime = #{modifytime,jdbcType=TIMESTAMP},
       tenant_id = #{tenantId,jdbcType=VARCHAR},
+      lat = #{lat,jdbcType=VARCHAR},
+      lng = #{lng,jdbcType=VARCHAR},
+      address = #{address,jdbcType=VARCHAR},
+      radius = #{radius,jdbcType=VARCHAR},
       data = #{data,jdbcType=LONGVARCHAR}
     where id = #{id,jdbcType=VARCHAR}
   </update>
@@ -248,7 +317,11 @@
       description = #{description,jdbcType=VARCHAR},
       createtime = #{createtime,jdbcType=TIMESTAMP},
       modifytime = #{modifytime,jdbcType=TIMESTAMP},
-      tenant_id = #{tenantId,jdbcType=VARCHAR}
+      tenant_id = #{tenantId,jdbcType=VARCHAR},
+      lat = #{lat,jdbcType=VARCHAR},
+      lng = #{lng,jdbcType=VARCHAR},
+      address = #{address,jdbcType=VARCHAR},
+      radius = #{radius,jdbcType=VARCHAR}
     where id = #{id,jdbcType=VARCHAR}
   </update>
 </mapper>

+ 7 - 0
src/main/resources/mapper/LogMapper.xml

@@ -54,6 +54,13 @@
 			<if test="order != null "> ${order}</if>
 	</if>
   </select>
+  <select id="existLoginTodayByUseid" parameterType="java.lang.String"  resultType="java.lang.Integer" >
+  	select 1
+  	from log
+  	where operation='登录' and userid=#{userid,jdbcType=VARCHAR}
+  		and DATEDIFF(current_date(),createtime) =0
+  	limit 1
+  </select>
   <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
     delete from log
     where id = #{id,jdbcType=VARCHAR}

+ 103 - 0
src/main/resources/mapper/SatasticDayMapper.xml

@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.tuoren.forward.mapper.SatasticDayMapper">
+  <resultMap id="BaseResultMap" type="com.tuoren.forward.entity.SatasticDay">
+    <id column="id" jdbcType="VARCHAR" property="id" />
+    <result column="num" jdbcType="INTEGER" property="num" />
+    <result column="type" jdbcType="VARCHAR" property="type" />
+    <result column="createdate" jdbcType="DATE" property="createdate" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    id, num, type, createdate
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from satastic_day
+    where id = #{id,jdbcType=VARCHAR}
+  </select>
+  <select id="selectSataTodayByType" parameterType="java.lang.String"  resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from satastic_day
+    where type = #{type,jdbcType=VARCHAR} and createdate = current_date()
+    limit 1
+  </select>
+  <select id="satasticDays" parameterType="com.tuoren.forward.entity.req.SatasticDayReq"  resultType="com.tuoren.forward.entity.resp.SatasticResp">
+    select type, sum(num) num
+    from satastic_day
+    <where>
+    	<if test="type != null and type !=''">
+    		type = #{type,jdbcType=VARCHAR}
+    	</if>
+    	<if test="days != null">
+    		and DATEDIFF(current_date(),createdate) &lt; #{days,jdbcType=INTEGER}
+    	</if>
+    </where>
+    group by type
+  </select>
+  
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+    delete from satastic_day
+    where id = #{id,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.tuoren.forward.entity.SatasticDay">
+    insert into satastic_day (id, num, type, 
+      createdate)
+    values (#{id,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, 
+      #{createdate,jdbcType=DATE})
+  </insert>
+  <insert id="insertSelective" parameterType="com.tuoren.forward.entity.SatasticDay">
+    insert into satastic_day
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="num != null">
+        num,
+      </if>
+      <if test="type != null">
+        type,
+      </if>
+      <if test="createdate != null">
+        createdate,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=VARCHAR},
+      </if>
+      <if test="num != null">
+        #{num,jdbcType=INTEGER},
+      </if>
+      <if test="type != null">
+        #{type,jdbcType=VARCHAR},
+      </if>
+      <if test="createdate != null">
+        #{createdate,jdbcType=DATE},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.tuoren.forward.entity.SatasticDay">
+    update satastic_day
+    <set>
+      <if test="num != null">
+        num = #{num,jdbcType=INTEGER},
+      </if>
+      <if test="type != null">
+        type = #{type,jdbcType=VARCHAR},
+      </if>
+      <if test="createdate != null">
+        createdate = #{createdate,jdbcType=DATE},
+      </if>
+    </set>
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.tuoren.forward.entity.SatasticDay">
+    update satastic_day
+    set num = #{num,jdbcType=INTEGER},
+      type = #{type,jdbcType=VARCHAR},
+      createdate = #{createdate,jdbcType=DATE}
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+</mapper>