liu 2 лет назад
Родитель
Сommit
86c5d22a68

+ 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);
 
 }

+ 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;
+
+}

+ 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);
 }

+ 11 - 10
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,8 +57,8 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
     SmartRelationMapper smartRelationMapper;
 
     @Async
-    @Scheduled(cron = "0 0 1 * * ? ")//每天凌晨一点
-//    @Scheduled(cron = "0 41 10 * * ? ")//每天凌晨一点
+    @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");
@@ -119,7 +120,7 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
     }
 
     @Async
-    @Scheduled(cron = "0 0 3 * * ? ")//每天凌晨两点
+    @Scheduled(cron = "0 40 2 * * ? ")//每天凌晨两点
 //    @Scheduled(cron = "0 25` * * * ? ")//每天凌晨两点
     public void getFaceDiscernListSmartRelation() {
         if (scheduleConfig.getIsOpen().equals("1")) {
@@ -184,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>