Ver código fonte

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 2 anos atrás
pai
commit
7f2a89efb1

+ 5 - 0
src/main/java/com/template/api/SmartAccessControllerAPI.java

@@ -25,4 +25,9 @@ public interface SmartAccessControllerAPI {
     CommonResult getAccessPage(@RequestParam Integer currentPage, @RequestParam Integer pageCount,String keyWord,Integer gradeId,Integer classId,String resultStatus,String inOut,String startTime,String endTime);
 
 
+    @GetMapping("/totalCount")
+    @ApiOperation(value = "驾驶舱——数量汇总", notes = "驾驶舱——数量汇总", httpMethod = "GET")
+    CommonResult totalCount();
+
+
 }

+ 3 - 6
src/main/java/com/template/api/SmartRelationControllerAPI.java

@@ -5,16 +5,13 @@ import com.template.model.result.CommonResult;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
-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.RequestParam;
+import org.springframework.web.bind.annotation.*;
 
 @RequestMapping("/api/smartRelation")
 public interface SmartRelationControllerAPI {
 
-    @PostMapping(value = "/getList")
+    @GetMapping(value = "/getList")
     @ApiOperation(value = "个人亲密度展示", notes = "个人亲密度展示", httpMethod = "GET")
-    CommonResult getList(@RequestParam int currentPage, @RequestParam int pageCount,@RequestParam Integer userId);
+    CommonResult getList(@RequestParam int currentPage, @RequestParam int pageCount,@RequestParam Integer userId,String startTime,String endTime);
 
 }

+ 21 - 0
src/main/java/com/template/controller/SmartAccessController.java

@@ -1,16 +1,21 @@
 package com.template.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.template.annotation.DESRespondSecret;
 import com.template.api.SmartAccessControllerAPI;
 import com.template.common.utils.ExcelUtils;
 import com.template.model.pojo.SmartAccess;
+import com.template.model.pojo.SmartCarAccess;
 import com.template.model.result.CommonResult;
 import com.template.model.result.PageUtils;
 import com.template.model.vo.SmartAccessVo;
 import com.template.model.vo.SmartAttendanceVo;
+import com.template.model.vo.TotalCountVo;
 import com.template.services.SmartAccessService;
+import com.template.services.SmartCarAccessService;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -40,6 +45,9 @@ public class SmartAccessController implements SmartAccessControllerAPI {
     @Autowired
     SmartAccessService smartAccessService;
 
+    @Autowired
+    SmartCarAccessService smartCarAccessService;
+
     @Override
     @DESRespondSecret(validated = true)
     public CommonResult getPage(Integer currentPage, Integer pageCount, String keyWord,Integer gradeId, Integer classId, Integer departmentId,String openType,String resultStatus,String startTime,String endTime) {
@@ -137,5 +145,18 @@ public class SmartAccessController implements SmartAccessControllerAPI {
         PageUtils<SmartAccessVo> pageUtils=smartAccessService.getAccessPage(currentPage,pageCount,keyWord,gradeId,classId,resultStatus,inOut,startTime,endTime);
         return CommonResult.ok(pageUtils);
     }
+
+    @Override
+    @DESRespondSecret(validated = true)
+    public CommonResult totalCount() {
+        Wrapper<SmartAccess> wrapperAccess=new LambdaQueryWrapper<>();
+        int countAccess = smartAccessService.count(wrapperAccess);
+        Wrapper<SmartCarAccess> wrapperCar=new LambdaQueryWrapper<>();
+        int countCar = smartCarAccessService.count(wrapperCar);
+        TotalCountVo totalCountVo = new TotalCountVo();
+        totalCountVo.setAccessCount(countAccess);
+        totalCountVo.setCarCount(countCar);
+        return CommonResult.ok(totalCountVo);
+    }
 }
 

+ 8 - 5
src/main/java/com/template/controller/SmartRelationController.java

@@ -6,12 +6,16 @@ import com.template.api.SmartRelationControllerAPI;
 import com.template.model.pojo.SmartRelation;
 import com.template.model.result.CommonResult;
 import com.template.model.result.PageUtils;
+import com.template.model.vo.SmartRelationVo;
 import com.template.services.SmartRelationService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * <p>
  *  前端控制器
@@ -27,14 +31,13 @@ public class SmartRelationController implements SmartRelationControllerAPI {
     @Autowired
     SmartRelationService smartRelationService;
 
-
     @Override
-    public CommonResult getList(int currentPage, int pageCount, Integer userId) {
-        PageUtils<SmartRelation> pageUtils=smartRelationService.getPage(currentPage,pageCount,userId);
+    @DESRespondSecret(validated = true)
+    public CommonResult getList(int currentPage,int pageCount,Integer userId, String startTime, String endTime) {
+
+        PageUtils<SmartRelationVo> pageUtils =smartRelationService.getList(currentPage,pageCount,userId,startTime,endTime);
 
         return CommonResult.ok(pageUtils);
     }
-
-
 }
 

+ 7 - 0
src/main/java/com/template/mapper/SmartRelationMapper.java

@@ -1,9 +1,15 @@
 package com.template.mapper;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.template.model.pojo.SmartRelation;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.template.model.vo.SmartRelationVo;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -15,4 +21,5 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface SmartRelationMapper extends BaseMapper<SmartRelation> {
 
+    IPage<SmartRelationVo> getList(Page<SmartRelationVo> page, @Param("userId") Integer userId, @Param("startTime") String startTime, @Param("endTime") String endTime);
 }

+ 21 - 0
src/main/java/com/template/model/vo/SmartRelationVo.java

@@ -0,0 +1,21 @@
+package com.template.model.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class SmartRelationVo {
+    @ApiModelProperty(value = "关联人id")
+    private Integer relationId;
+
+    @ApiModelProperty(value = "关联人名称")
+    private String relationName;
+
+    private String gradeName;
+
+    private String className;
+
+    //次数
+    private Integer count;
+
+}

+ 9 - 0
src/main/java/com/template/model/vo/TotalCountVo.java

@@ -0,0 +1,9 @@
+package com.template.model.vo;
+
+import lombok.Data;
+
+@Data
+public class TotalCountVo {
+    private Integer carCount;
+    private Integer accessCount;
+}

+ 5 - 1
src/main/java/com/template/services/SmartRelationService.java

@@ -3,6 +3,9 @@ package com.template.services;
 import com.template.model.pojo.SmartRelation;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.template.model.result.PageUtils;
+import com.template.model.vo.SmartRelationVo;
+
+import java.util.List;
 
 /**
  * <p>
@@ -14,5 +17,6 @@ import com.template.model.result.PageUtils;
  */
 public interface SmartRelationService extends IService<SmartRelation> {
 
-    PageUtils<SmartRelation> getPage(int currentPage, int pageCount, Integer userId);
+
+    PageUtils<SmartRelationVo> getList(int currentPage,int pageCount,Integer userId, String startTime, String endTime);
 }

+ 68 - 62
src/main/java/com/template/services/impl/SmartRelationServiceImpl.java

@@ -13,6 +13,7 @@ import com.template.model.pojo.SmartRelation;
 import com.template.mapper.SmartRelationMapper;
 import com.template.model.pojo.SmartUser;
 import com.template.model.result.PageUtils;
+import com.template.model.vo.SmartRelationVo;
 import com.template.model.vo.UserVo;
 import com.template.services.SmartAccessService;
 import com.template.services.SmartFaceDiscernService;
@@ -56,7 +57,8 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
     SmartRelationMapper smartRelationMapper;
 
     @Async
-    @Scheduled(cron = "0 0 1 * * ? ")//每天凌晨一点
+    @Scheduled(cron = "0 20 0 * * ? ")//每天凌晨一点
+//    @Scheduled(cron = "0 10 14 * * ? ")//每天凌晨一点
     public void getAccessSmartRelation() {
         if (scheduleConfig.getIsOpen().equals("1")) {
             DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -70,8 +72,8 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
             for (SmartAccess smartAccess : accessList) {
                 String dateTime = smartAccess.getDateTime();
                 LocalDateTime date = LocalDateTime.parse(dateTime, pattern);
-                LocalDateTime startTime = date.minusSeconds(10);
-                LocalDateTime endTime = date.plusSeconds(10);
+                LocalDateTime startTime = date.minusSeconds(5);
+                LocalDateTime endTime = date.plusSeconds(5);
                 Integer userId = smartAccess.getUserId();
                 SmartUser smartUser = smartUserService.getSmartById(userId);
                 List<SmartAccess> accesses = smartAccessService.toDatelist(startTime, endTime);
@@ -79,33 +81,35 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
 
                     for (SmartAccess access : accesses) {
                         Integer userId1 = access.getUserId();
-                        SmartUser smartById = smartUserService.getSmartById(userId1);
+                        if (!userId.equals(userId1) && userId != 0 && userId1 != 0) {
+                            SmartUser smartById = smartUserService.getSmartById(userId1);
 //                        判断是否已添加,有的话则加1
-                        LambdaQueryWrapper<SmartRelation> wrapper = new LambdaQueryWrapper<>();
-                        wrapper.eq(SmartRelation::getUserId, userId)
-                                .eq(SmartRelation::getRelationId, userId1)
-                                .eq(SmartRelation::getDateTime,format);
-                        SmartRelation one = this.getOne(wrapper);
-                        if (ObjectUtils.isEmpty(one)) {
-                            SmartRelation smartRelation = new SmartRelation();
-                            smartRelation.setUserId(userId);
-                            smartRelation.setRelationId(userId1);
-                            if (ObjectUtils.isNotEmpty(smartUser)) {
-                                smartRelation.setName(smartUser.getName());
+                            LambdaQueryWrapper<SmartRelation> wrapper = new LambdaQueryWrapper<>();
+                            wrapper.eq(SmartRelation::getUserId, userId)
+                                    .eq(SmartRelation::getRelationId, userId1)
+                                    .eq(SmartRelation::getDateTime, format);
+                            SmartRelation one = this.getOne(wrapper);
+                            if (ObjectUtils.isEmpty(one)) {
+                                SmartRelation smartRelation = new SmartRelation();
+                                smartRelation.setUserId(userId);
+                                smartRelation.setRelationId(userId1);
+                                if (ObjectUtils.isNotEmpty(smartUser)) {
+                                    smartRelation.setName(smartUser.getName());
+                                }
+                                if (ObjectUtils.isNotEmpty(smartById)) {
+                                    smartRelation.setRelationName(smartById.getName());
+                                }
+                                smartRelation.setCount(1);
+                                smartRelation.setDateTime(format);
+                                this.save(smartRelation);
+                            } else {
+                                Integer count = one.getCount();
+                                count = count + 1;
+                                one.setCount(count);
+                                this.updateById(one);
                             }
-                            if (ObjectUtils.isNotEmpty(smartById)) {
-                                smartRelation.setRelationName(smartById.getName());
-                            }
-                            smartRelation.setCount(0);
-                            smartRelation.setDateTime(format);
-                            this.save(smartRelation);
-                        } else {
-                            Integer count = one.getCount();
-                            count = count + 1;
-                            one.setCount(count);
-                            this.updateById(one);
-                        }
 
+                        }
                     }
 
                 }
@@ -116,7 +120,8 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
     }
 
     @Async
-    @Scheduled(cron = "0 0 2 * * ? ")//每天凌晨一点
+    @Scheduled(cron = "0 40 2 * * ? ")//每天凌晨两点
+//    @Scheduled(cron = "0 25` * * * ? ")//每天凌晨两点
     public void getFaceDiscernListSmartRelation() {
         if (scheduleConfig.getIsOpen().equals("1")) {
             DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -132,8 +137,8 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
             for (SmartFaceDiscern faceDiscern : faceDiscernList) {
                 String dateTime = faceDiscern.getDateTime();
                 LocalDateTime date = LocalDateTime.parse(dateTime, pattern);
-                LocalDateTime startTime = date.minusSeconds(10);
-                LocalDateTime endTime = date.plusSeconds(10);
+                LocalDateTime startTime = date.minusSeconds(5);
+                LocalDateTime endTime = date.plusSeconds(5);
                 Integer userId = faceDiscern.getUserId();
                 SmartUser smartUser = smartUserService.getSmartById(userId);
                 List<SmartFaceDiscern> faceDiscerns = smartFaceDiscernService.toDateList(startTime, endTime);
@@ -141,35 +146,36 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
 
                     for (SmartFaceDiscern faceDiscern1 : faceDiscerns) {
                         Integer userId1 = faceDiscern1.getUserId();
-                        SmartUser smartById = smartUserService.getSmartById(userId1);
+                        if (!userId.equals(userId1) && userId != 0 && userId1 != 0) {
+                            SmartUser smartById = smartUserService.getSmartById(userId1);
 //                        判断是否已添加,有的话则加1
-                        LambdaQueryWrapper<SmartRelation> wrapper = new LambdaQueryWrapper<>();
-                        wrapper.eq(SmartRelation::getUserId, userId)
-                                .eq(SmartRelation::getRelationId, userId1)
-                                .eq(SmartRelation::getDateTime,format);
-                        SmartRelation one = this.getOne(wrapper);
-                        if (ObjectUtils.isEmpty(one)) {
-                            SmartRelation smartRelation = new SmartRelation();
-                            smartRelation.setUserId(userId);
-                            smartRelation.setRelationId(userId1);
-                            if (ObjectUtils.isNotEmpty(smartUser)) {
-                                smartRelation.setName(smartUser.getName());
-                            }
-                            if (ObjectUtils.isNotEmpty(smartById)) {
-                                smartRelation.setRelationName(smartById.getName());
+                            LambdaQueryWrapper<SmartRelation> wrapper = new LambdaQueryWrapper<>();
+                            wrapper.eq(SmartRelation::getUserId, userId)
+                                    .eq(SmartRelation::getRelationId, userId1)
+                                    .eq(SmartRelation::getDateTime, format);
+                            SmartRelation one = this.getOne(wrapper);
+                            if (ObjectUtils.isEmpty(one)) {
+                                SmartRelation smartRelation = new SmartRelation();
+                                smartRelation.setUserId(userId);
+                                smartRelation.setRelationId(userId1);
+                                if (ObjectUtils.isNotEmpty(smartUser)) {
+                                    smartRelation.setName(smartUser.getName());
+                                }
+                                if (ObjectUtils.isNotEmpty(smartById)) {
+                                    smartRelation.setRelationName(smartById.getName());
+                                }
+                                smartRelation.setDateTime(format);
+                                smartRelation.setCount(1);
+                                this.save(smartRelation);
+                            } else {
+                                Integer count = one.getCount();
+                                count = count + 1;
+                                one.setCount(count);
+                                this.updateById(one);
                             }
-                            smartRelation.setDateTime(format);
-                            smartRelation.setCount(0);
-                            this.save(smartRelation);
-                        } else {
-                            Integer count = one.getCount();
-                            count = count + 1;
-                            one.setCount(count);
-                            this.updateById(one);
-                        }
 
+                        }
                     }
-
                 }
 
             }
@@ -179,12 +185,12 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
 
 
     @Override
-    public PageUtils<SmartRelation> getPage(int currentPage, int pageCount, Integer userId) {
-//        Page<UserVo> page = new Page<>();
-//        page.setCurrent(currentPage);
-//        page.setSize(pageCount);
-//        IPage<WarningUserDto> result = smartUserMapper.warningUserList(page, name);
-//        return new PageUtils(result);
-        return null;
+    public PageUtils<SmartRelationVo> getList(int currentPage,int pageCount,Integer userId, String startTime, String endTime) {
+        Page<SmartRelationVo> page = new Page<>();
+        page.setCurrent(currentPage);
+        page.setSize(pageCount);
+        IPage<SmartRelationVo> result =smartRelationMapper.getList(page,userId,startTime,endTime);
+
+        return new PageUtils(result);
     }
 }

+ 27 - 0
src/main/resources/mapper/template/SmartRelationMapper.xml

@@ -2,4 +2,31 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.template.mapper.SmartRelationMapper">
 
+    <select id="getList" resultType="com.template.model.vo.SmartRelationVo">
+        SELECT
+        (SELECT SUM(count)
+        FROM `smart_relation`
+        WHERE user_id = sr.user_id
+        and relation_id = sr.relation_id
+        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+            and date_time &gt;= #{startTime} and date_time &lt; #{endTime}
+        </if>
+        ) as count,
+        sr.relation_id as relationId,
+        sr.relation_name as relationName,
+        sc.`name` as className,
+        sg.`name` as gradeName
+        FROM
+        `smart_relation` sr
+        LEFT JOIN smart_user su
+        on su.id=sr.relation_id
+        LEFT JOIN smart_class sc on su.school_class=sc.id
+        LEFT JOIN smart_grade sg on sc.grade_id=sg.id
+        WHERE sr.user_id=#{userId}
+        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+            and sr.date_time &gt;= #{startTime} and sr.date_time &lt; #{endTime}
+        </if>
+        ORDER BY count DESC
+
+    </select>
 </mapper>

+ 1 - 0
src/main/resources/mapper/template/SmartVisitorParentsConfigMapper.xml

@@ -40,6 +40,7 @@
                svpc.screen_push_config   as screenPushConfig,
                svpc.screen_cancel_config as screenCancelConfig,
                svpc.access_config        as accessConfig,
+               svpc.car_config           as carConfig,
                svpc.create_time          as createTime,
                sc.`name`                 as className,
                sg.`name`                 as gradeName