Explorar el Código

优化

tags/正式3.2.0
王宁 hace 2 años
padre
commit
493fd7a2b9
Se han modificado 26 ficheros con 978 adiciones y 26 borrados
  1. 0
    1
      sapi/pom.xml
  2. 0
    1
      sapi/src/main/java/com/xhkjedu/sapi/SapiApplication.java
  3. 52
    0
      sapi/src/main/java/com/xhkjedu/sapi/config/RabbitConfig.java
  4. 30
    0
      sapi/src/main/java/com/xhkjedu/sapi/config/ScheduledConfig.java
  5. 2
    2
      sapi/src/main/java/com/xhkjedu/sapi/controller/analyze/SchoolResourceController.java
  6. 68
    0
      sapi/src/main/java/com/xhkjedu/sapi/controller/space/ResourceController.java
  7. 52
    0
      sapi/src/main/java/com/xhkjedu/sapi/listener/MessageConsumer.java
  8. 19
    0
      sapi/src/main/java/com/xhkjedu/sapi/mapper/space/ResourceDirectorMapper.java
  9. 11
    0
      sapi/src/main/java/com/xhkjedu/sapi/mapper/space/ResourceFileMapper.java
  10. 33
    0
      sapi/src/main/java/com/xhkjedu/sapi/mapper/space/ResourceMapper.java
  11. 13
    0
      sapi/src/main/java/com/xhkjedu/sapi/mapper/subjectbook/SubjectBookMapper.java
  12. 4
    5
      sapi/src/main/java/com/xhkjedu/sapi/model/space/TResource.java
  13. 1
    1
      sapi/src/main/java/com/xhkjedu/sapi/model/space/TResourceDirector.java
  14. 51
    0
      sapi/src/main/java/com/xhkjedu/sapi/model/space/TResourceFile.java
  15. 168
    0
      sapi/src/main/java/com/xhkjedu/sapi/service/space/ResourceService.java
  16. 39
    0
      sapi/src/main/java/com/xhkjedu/sapi/task/ClassReportTask.java
  17. 29
    0
      sapi/src/main/java/com/xhkjedu/sapi/task/CloudSyncTask.java
  18. 87
    0
      sapi/src/main/java/com/xhkjedu/sapi/utils/ConvertUtil.java
  19. 28
    5
      sapi/src/main/resources/application.properties
  20. 3
    3
      sapi/src/main/resources/mapper/cloud/CloudSyncMapper.xml
  21. 106
    0
      sapi/src/main/resources/mapper/space/ResourceMapper.xml
  22. 53
    0
      sstudy/src/main/java/com/xhkjedu/sstudy/config/RabbitConfig.java
  23. 30
    0
      sstudy/src/main/java/com/xhkjedu/sstudy/config/ScheduledConfig.java
  24. 62
    0
      sstudy/src/main/java/com/xhkjedu/sstudy/config/ThreadPoolTaskExecutorConfig.java
  25. 29
    0
      sstudy/src/main/java/com/xhkjedu/sstudy/task/PaperStudentTask.java
  26. 8
    8
      sstudy/src/main/resources/application.properties

+ 0
- 1
sapi/pom.xml Ver fichero

@@ -30,7 +30,6 @@
30 30
             <groupId>org.springframework.cloud</groupId>
31 31
             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
32 32
         </dependency>
33
-
34 33
         <dependency>
35 34
             <groupId>mysql</groupId>
36 35
             <artifactId>mysql-connector-java</artifactId>

+ 0
- 1
sapi/src/main/java/com/xhkjedu/sapi/SapiApplication.java Ver fichero

@@ -2,7 +2,6 @@ package com.xhkjedu.sapi;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 5
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
7 6
 import tk.mybatis.spring.annotation.MapperScan;
8 7
 

+ 52
- 0
sapi/src/main/java/com/xhkjedu/sapi/config/RabbitConfig.java Ver fichero

@@ -0,0 +1,52 @@
1
+package com.xhkjedu.sapi.config;
2
+
3
+import org.springframework.amqp.core.Queue;
4
+import org.springframework.beans.factory.annotation.Value;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.context.annotation.Configuration;
7
+
8
+/**
9
+ * @author ywx
10
+ * @classname RabbitConfig
11
+ * @description
12
+ * @date 2021/6/18 12:51
13
+ **/
14
+@Configuration
15
+public class RabbitConfig {
16
+    @Value("${rabbitmq.resourceToPdfQueue}")
17
+    private String resourceToPdfQueue;
18
+    @Value("${rabbitmq.resourceTransferQueue}")
19
+    private String resourceTransferQueue;
20
+    @Value("${rabbitmq.resourceUnZipQueue}")
21
+    private String resourceUnZipQueue;
22
+    @Value("${rabbitmq.resourceDelQueue}")
23
+    private String resourceDelQueue;
24
+    @Value("${rabbitmq.resourceHandleQueue}")
25
+    private String resourceHandleQueue;
26
+
27
+    @Bean
28
+    public Queue resourceToPdfQueue() {
29
+        return new Queue(resourceToPdfQueue);
30
+    }
31
+
32
+    @Bean
33
+    public Queue resourceTransferQueue() {
34
+        return new Queue(resourceTransferQueue);
35
+    }
36
+
37
+    @Bean
38
+    public Queue resourceUnZipQueue() {
39
+        return new Queue(resourceUnZipQueue);
40
+    }
41
+
42
+    @Bean
43
+    public Queue resourceDelQueue() {
44
+        return new Queue(resourceDelQueue);
45
+    }
46
+
47
+    @Bean
48
+    public Queue resourceHandleQueue() {
49
+        return new Queue(resourceHandleQueue);
50
+    }
51
+
52
+}

+ 30
- 0
sapi/src/main/java/com/xhkjedu/sapi/config/ScheduledConfig.java Ver fichero

@@ -0,0 +1,30 @@
1
+package com.xhkjedu.sapi.config;
2
+
3
+import org.springframework.context.annotation.*;
4
+import org.springframework.core.type.AnnotatedTypeMetadata;
5
+import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
6
+
7
+/**
8
+ * @author ywx
9
+ * @className ScheduledConfig
10
+ * @description @Scheduled 注解,是被一个叫做 ScheduledAnnotationBeanPostProcessor 的类所拦截的,
11
+ * 所以我们可以根据配置,决定是否创建这个 bean,如果没有这个 bean,@Scheduled 就不会被拦截,那么定时任务肯定不会执行了,
12
+ * 需要注意的是:这种方式,启动类上面的 @EnableScheduling 需要去掉。
13
+ * @date 2021/5/18 9:15
14
+ **/
15
+@Configuration
16
+public class ScheduledConfig {
17
+    @Conditional(ScheduledCondition.class)
18
+    @Bean
19
+    public ScheduledAnnotationBeanPostProcessor processor(){
20
+        return new ScheduledAnnotationBeanPostProcessor();
21
+    }
22
+}
23
+
24
+class ScheduledCondition implements Condition {
25
+
26
+    @Override
27
+    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
28
+        return Boolean.valueOf(context.getEnvironment().getProperty("enable.scheduled"));
29
+    }
30
+}

+ 2
- 2
sapi/src/main/java/com/xhkjedu/sapi/controller/analyze/SchoolResourceController.java Ver fichero

@@ -2,7 +2,7 @@ package com.xhkjedu.sapi.controller.analyze;
2 2
 
3 3
 import com.github.pagehelper.PageHelper;
4 4
 import com.github.pagehelper.PageInfo;
5
-import com.xhkjedu.sapi.model.subjectbook.TResource;
5
+import com.xhkjedu.sapi.model.space.TResource;
6 6
 import com.xhkjedu.sapi.service.analyze.SchoolResourceService;
7 7
 import com.xhkjedu.utils.N_Utils;
8 8
 import com.xhkjedu.utils.PageUtil;
@@ -38,7 +38,7 @@ public class SchoolResourceController {
38 38
      * @return com.xhkjedu.vo.ResultVo
39 39
      */
40 40
     @PostMapping("/allnum")
41
-    public ResultVo getSchoolAllNum(@RequestBody TResource  tResource){
41
+    public ResultVo getSchoolAllNum(@RequestBody TResource tResource){
42 42
         N_Utils.validation(new Object[]{tResource.getSchoolid(),"学校id",1});
43 43
         SchoolResourceNumVo sr = schoolResourceService.getSchoolResourceNum(tResource.getSchoolid());
44 44
         return  new ResultVo(0,"",sr);

+ 68
- 0
sapi/src/main/java/com/xhkjedu/sapi/controller/space/ResourceController.java Ver fichero

@@ -0,0 +1,68 @@
1
+package com.xhkjedu.sapi.controller.space;
2
+
3
+import com.github.pagehelper.PageHelper;
4
+import com.github.pagehelper.PageInfo;
5
+import com.xhkjedu.sapi.model.space.TResource;
6
+import com.xhkjedu.sapi.service.space.ResourceService;
7
+import com.xhkjedu.sapi.vo.subjectbook.ResourceVo;
8
+import com.xhkjedu.utils.N_Utils;
9
+import com.xhkjedu.utils.PageUtil;
10
+import com.xhkjedu.vo.PageResult;
11
+import com.xhkjedu.vo.ResultVo;
12
+import org.springframework.util.CollectionUtils;
13
+import org.springframework.web.bind.annotation.PostMapping;
14
+import org.springframework.web.bind.annotation.RequestBody;
15
+import org.springframework.web.bind.annotation.RequestMapping;
16
+import org.springframework.web.bind.annotation.RestController;
17
+
18
+import javax.annotation.Resource;
19
+import java.util.List;
20
+
21
+/**
22
+ * @ClassName ResourceController
23
+ * Description 个人空间
24
+ * Author WN
25
+ * Date 2022/2/22 15:48
26
+ **/
27
+@RestController
28
+@RequestMapping("/spr")
29
+public class ResourceController {
30
+    @Resource
31
+    private ResourceService resourceService;
32
+
33
+    //我的空间--网页端
34
+    @PostMapping("/list")
35
+    public ResultVo myList(@RequestBody TResource tResource) {
36
+        Integer page = tResource.getPage();
37
+        Integer pageSize = tResource.getPageSize();
38
+        Integer createid = tResource.getCreateid();
39
+        Integer level = tResource.getLevel();
40
+        N_Utils.validation(new Object[]{page,"显示页码",1,pageSize,"显示条数",1,createid,"教师id",1
41
+                ,level,"资源级别",1});
42
+        PageHelper.startPage(page, pageSize);
43
+        List<TResource> list = resourceService.listMyResource(tResource);
44
+        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
45
+        return new ResultVo(0,"获取教师备课资源列表成功",pageResult);
46
+    }
47
+
48
+    //分享到校本资源
49
+    @PostMapping("/share_school")
50
+    public ResultVo shareSchool(@RequestBody TResource tResource) {
51
+        String resourceid = tResource.getResourceid();
52
+        String lsbid = tResource.getLsbid();
53
+        String directorid = tResource.getDirectorid();
54
+        Integer resourcetype = tResource.getResourcetype();
55
+        Integer createid = tResource.getCreateid();
56
+        N_Utils.validation(new Object[]{resourceid,"资源id",2,lsbid,"教材关系表id",2,directorid,"章节id",2
57
+                ,resourcetype,"资源归类",1,createid,"教师id",1});
58
+        tResource.setLevel(1);//资源级别1校本
59
+        String id = resourceService.share(tResource);
60
+        if(id.equals("99")){
61
+            return new ResultVo(0,"该资源已分享过校本");
62
+        }else{
63
+            return new ResultVo(0,"分享成功",id);
64
+        }
65
+    }
66
+
67
+
68
+}

+ 52
- 0
sapi/src/main/java/com/xhkjedu/sapi/listener/MessageConsumer.java Ver fichero

@@ -0,0 +1,52 @@
1
+package com.xhkjedu.sapi.listener;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.xhkjedu.sapi.mapper.research.ResearchMapper;
5
+import com.xhkjedu.sapi.model.research.TResearch;
6
+import com.xhkjedu.sapi.model.space.TResource;
7
+import com.xhkjedu.sapi.service.space.ResourceService;
8
+import com.xhkjedu.sapi.vo.subjectbook.ResourceVo;
9
+import com.xhkjedu.utils.N_Utils;
10
+import lombok.extern.slf4j.Slf4j;
11
+import org.springframework.amqp.core.Message;
12
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
13
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
14
+import org.springframework.stereotype.Component;
15
+
16
+import javax.annotation.Resource;
17
+import java.time.LocalDateTime;
18
+
19
+/**
20
+ * 消息到达消费者监听类
21
+ */
22
+@Component
23
+@Slf4j
24
+public class MessageConsumer {
25
+
26
+    @Resource
27
+    private ResearchMapper researchMapper;
28
+
29
+    //资源转换完处理资源文件
30
+    @RabbitHandler
31
+    @RabbitListener(queues = "${rabbitmq.resourceHandleQueue}")
32
+    public void resourceHandleQueue(Message message) {
33
+        try {
34
+            String msg = new String(message.getBody(), "UTF-8");
35
+            System.out.println(LocalDateTime.now()+" 资源处理接收消息内容:"+msg);
36
+            TResource resource = JSON.parseObject(msg, TResource.class);
37
+            String resourceid = resource.getResourceid();
38
+            String resourceurl = resource.getResourceurl();
39
+            String mp4code = resource.getMp4code();
40
+            String source = resource.getSource();
41
+            if ("research".equals(source)) {
42
+                TResearch research = new TResearch();
43
+                research.setResearchid(N_Utils.str2Int(resourceid));
44
+                research.setResearchpath(resourceurl);
45
+                research.setMp4code(mp4code);
46
+                researchMapper.updateResourceMp4code(research);
47
+            }
48
+        } catch (Exception e) {
49
+            log.error("资源转换失败:"+e.getMessage());
50
+        }
51
+    }
52
+}

+ 19
- 0
sapi/src/main/java/com/xhkjedu/sapi/mapper/space/ResourceDirectorMapper.java Ver fichero

@@ -0,0 +1,19 @@
1
+package com.xhkjedu.sapi.mapper.space;
2
+
3
+import com.xhkjedu.sapi.base.TkMapper;
4
+import com.xhkjedu.sapi.model.space.TResourceDirector;
5
+import org.apache.ibatis.annotations.Param;
6
+import org.springframework.stereotype.Repository;
7
+
8
+import java.util.List;
9
+
10
+/**
11
+ * @ClassName ResourceDirectorMapper
12
+ * Description TODO 资源教材章节关系
13
+ * Author WN
14
+ * Date 2021/1/4 16:49
15
+ **/
16
+@Repository
17
+public interface ResourceDirectorMapper extends TkMapper<TResourceDirector> {
18
+    void batchSave(@Param("list") List<TResourceDirector> directors);
19
+}

+ 11
- 0
sapi/src/main/java/com/xhkjedu/sapi/mapper/space/ResourceFileMapper.java Ver fichero

@@ -0,0 +1,11 @@
1
+package com.xhkjedu.sapi.mapper.space;
2
+
3
+import com.xhkjedu.sapi.base.TkMapper;
4
+import com.xhkjedu.sapi.model.space.TResourceFile;
5
+
6
+import java.util.List;
7
+import java.util.Map;
8
+
9
+public interface ResourceFileMapper extends TkMapper<TResourceFile> {
10
+    List<Map> listFile(String resourceid);
11
+}

+ 33
- 0
sapi/src/main/java/com/xhkjedu/sapi/mapper/space/ResourceMapper.java Ver fichero

@@ -0,0 +1,33 @@
1
+package com.xhkjedu.sapi.mapper.space;
2
+
3
+
4
+import com.xhkjedu.sapi.base.TkMapper;
5
+import com.xhkjedu.sapi.model.space.TResource;
6
+import com.xhkjedu.sapi.model.space.TResourceDirector;
7
+import com.xhkjedu.sapi.vo.subjectbook.ResourceVo;
8
+import org.apache.ibatis.annotations.Param;
9
+
10
+import java.util.List;
11
+
12
+public interface ResourceMapper extends TkMapper<TResource> {
13
+    //详情
14
+    ResourceVo findById(@Param("resourceid") String resourceid);
15
+
16
+//    ResourceVo findById2(@Param("resourceid") String resourceid);
17
+
18
+
19
+    //判断资源是否已经分享到校本
20
+    Integer getLevelResourceForxb(@Param("resource") TResource resource);
21
+
22
+    /**
23
+     * 个人空间
24
+     * @Param [resource]
25
+     * @Author ywx
26
+     * @Date 2020/7/9 11:44
27
+     * @return java.util.List<com.xhkjedu.model.resource.TResource>
28
+     **/
29
+    List<TResource> listMyResource(@Param("resource") TResource resource);
30
+
31
+    void batchSaveResourceDirector(@Param("list") List<TResourceDirector> directors);
32
+
33
+}

+ 13
- 0
sapi/src/main/java/com/xhkjedu/sapi/mapper/subjectbook/SubjectBookMapper.java Ver fichero

@@ -0,0 +1,13 @@
1
+package com.xhkjedu.sapi.mapper.subjectbook;
2
+
3
+import com.xhkjedu.sapi.base.TkMapper;
4
+import com.xhkjedu.sapi.model.subjectbook.TSubjectBook;
5
+
6
+/**
7
+ * @ClassName SubjectBookMapper
8
+ * Description 教材
9
+ * Author WN
10
+ * Date 2022/2/22 15:55
11
+ **/
12
+public interface SubjectBookMapper extends TkMapper<TSubjectBook> {
13
+}

sapi/src/main/java/com/xhkjedu/sapi/model/subjectbook/TResource.java → sapi/src/main/java/com/xhkjedu/sapi/model/space/TResource.java Ver fichero

@@ -1,4 +1,4 @@
1
-package com.xhkjedu.sapi.model.subjectbook;
1
+package com.xhkjedu.sapi.model.space;
2 2
 
3 3
 import com.xhkjedu.sapi.model.BaseBean;
4 4
 import lombok.Data;
@@ -104,10 +104,6 @@ public class TResource extends BaseBean {
104 104
     //备注
105 105
     private String comm;
106 106
 
107
-    //班级id
108
-    @Transient
109
-    private Integer classid;
110
-
111 107
     //科目id
112 108
     private String subjectid;
113 109
 
@@ -115,6 +111,9 @@ public class TResource extends BaseBean {
115 111
     //状态0全部1未查看1已查看
116 112
     private Integer costtime;
117 113
 
114
+
118 115
     @Transient
119 116
     private List<TResourceDirector> directors;//资源教材章节
117
+    @Transient
118
+    private List<TResourceFile> files;//资源附件
120 119
 }

sapi/src/main/java/com/xhkjedu/sapi/model/subjectbook/TResourceDirector.java → sapi/src/main/java/com/xhkjedu/sapi/model/space/TResourceDirector.java Ver fichero

@@ -1,4 +1,4 @@
1
-package com.xhkjedu.sapi.model.subjectbook;
1
+package com.xhkjedu.sapi.model.space;
2 2
 
3 3
 import com.xhkjedu.sapi.model.BaseBean;
4 4
 import lombok.Data;

+ 51
- 0
sapi/src/main/java/com/xhkjedu/sapi/model/space/TResourceFile.java Ver fichero

@@ -0,0 +1,51 @@
1
+package com.xhkjedu.sapi.model.space;
2
+
3
+import com.xhkjedu.sapi.model.BaseBean;
4
+import lombok.Data;
5
+
6
+import javax.persistence.Id;
7
+import javax.persistence.Table;
8
+
9
+@Table(name = "t_resource_file")
10
+@Data
11
+public class TResourceFile extends BaseBean {
12
+    @Id
13
+    //资源附件表
14
+    private Integer rfid;
15
+
16
+    //资源表
17
+    private String resourceid;
18
+
19
+    //资源名称
20
+    private String resourcename;
21
+
22
+    //资源分类1word,2ppt,3pdf,4图片,5视频,6音频,7压缩包,10其他
23
+    private Integer resourceclass;
24
+
25
+    //资源地址
26
+    private String resourceurl;
27
+
28
+    //封面图地址
29
+    private String resourcecover;
30
+
31
+    //是否转换0未转换1已转换2转换失败3加密
32
+    private Integer converted;
33
+
34
+    //转换失败原因
35
+    private String convertmsg;
36
+
37
+    //转换后的pdf文件地址
38
+    private String pdfurl;
39
+
40
+    //文件后缀
41
+    private String suffix;
42
+
43
+    //文件大小
44
+    private Integer resourcesize;
45
+
46
+    //视频时长(秒)
47
+    private Integer duration;
48
+
49
+    //创建时间
50
+    private Integer createtime;
51
+}

+ 168
- 0
sapi/src/main/java/com/xhkjedu/sapi/service/space/ResourceService.java Ver fichero

@@ -0,0 +1,168 @@
1
+package com.xhkjedu.sapi.service.space;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.xhkjedu.sapi.mapper.space.ResourceDirectorMapper;
5
+import com.xhkjedu.sapi.mapper.space.ResourceFileMapper;
6
+import com.xhkjedu.sapi.mapper.space.ResourceMapper;
7
+import com.xhkjedu.sapi.mapper.subjectbook.SubjectBookMapper;
8
+import com.xhkjedu.sapi.model.space.TResource;
9
+import com.xhkjedu.sapi.model.space.TResourceDirector;
10
+import com.xhkjedu.sapi.model.space.TResourceFile;
11
+import com.xhkjedu.sapi.model.subjectbook.TSubjectBook;
12
+import com.xhkjedu.sapi.utils.ApiUtil;
13
+import com.xhkjedu.sapi.utils.ConvertUtil;
14
+import com.xhkjedu.sapi.vo.subjectbook.ResourceVo;
15
+import com.xhkjedu.utils.N_Utils;
16
+import org.springframework.beans.factory.annotation.Autowired;
17
+import org.springframework.stereotype.Service;
18
+import org.springframework.transaction.annotation.Transactional;
19
+import javax.annotation.Resource;
20
+import java.util.ArrayList;
21
+import java.util.List;
22
+
23
+/**
24
+ * @author ywx
25
+ * @classname ResourceService
26
+ * @description 
27
+ * @date 2020/6/5 9:50
28
+ **/
29
+@Service
30
+public class ResourceService {
31
+    @Resource
32
+    private ResourceMapper resourceMapper;
33
+    @Resource
34
+    private ResourceFileMapper resourceFileMapper;
35
+    @Resource
36
+    private ResourceDirectorMapper resourceDirectorMapper;
37
+    @Resource
38
+    private SubjectBookMapper subjectBookMapper;
39
+    @Autowired
40
+    private ConvertUtil convertUtil;
41
+
42
+    @Transactional
43
+    public String save(TResource model) {
44
+        model.setReadcount(0);
45
+        model.setDowncount(0);
46
+        model.setResourcestate(1);
47
+        model.setCreatetime(N_Utils.getSecondTimestamp());
48
+        String directorid = model.getDirectorid();
49
+        if (directorid != null && (directorid.equals("0") || directorid.equals(""))) {
50
+            model.setDirectorid(null);
51
+        }
52
+        String resourceid = ApiUtil.getId();
53
+        model.setResourceid(resourceid);
54
+        if (N_Utils.isEmpty(model.getSubjectid())) {//科目为空根据教材id取科目
55
+            TSubjectBook book = subjectBookMapper.selectByPrimaryKey(model.getLsbid());
56
+            model.setSubjectid(book.getSubjectid());
57
+        }
58
+
59
+        List<TResourceFile> ziplist = new ArrayList<>();
60
+        if(model.getResourceclass()==7 && model.getCosttime()!=null && model.getCosttime()==7){
61
+            ziplist = JSON.parseArray(model.getPdfurl(),TResourceFile.class);
62
+            for(TResourceFile rf : ziplist){
63
+                rf.setResourceid(resourceid);
64
+            }
65
+
66
+            model.setPdfurl(null);
67
+        }
68
+
69
+        resourceMapper.insertSelective(model);//保存资源
70
+
71
+        List<TResourceDirector> directors = model.getDirectors();
72
+        if(N_Utils.isListEmpty(directors)){//兼容以前添加单个章节模式
73
+            directors = new ArrayList<>();
74
+            TResourceDirector rd = new TResourceDirector();
75
+            rd.setLsbid(model.getLsbid());
76
+            rd.setDirectorid(model.getDirectorid());
77
+            directors.add(rd);
78
+        }
79
+        for(TResourceDirector rd : directors){
80
+            rd.setRdid(ApiUtil.getId());
81
+            rd.setResourceid(resourceid);
82
+            rd.setCreateid(model.getCreateid());
83
+            rd.setCreatetime(model.getCreatetime());
84
+        }
85
+
86
+        //如果是分享的压缩包并且已经解压
87
+        if(model.getResourceclass()==7 && model.getCosttime()!=null && model.getCosttime()==7 && ziplist!=null && ziplist.size()>0){
88
+            resourceFileMapper.insertList(ziplist);//批量保存压缩文件的集合
89
+        }
90
+
91
+        resourceMapper.batchSaveResourceDirector(directors);//保存资源教材章节关系
92
+
93
+        convertUtil.convertResource(model);
94
+        return resourceid;
95
+    }
96
+    //获取详情
97
+    public ResourceVo findById(String resourceid) {
98
+        ResourceVo resource = resourceMapper.findById(resourceid);
99
+        convertUtil.getResourceUrl(resource);
100
+        return resource;
101
+    }
102
+
103
+    //分享
104
+    public String share(TResource model) {
105
+        String resourceid = model.getResourceid();
106
+
107
+        //判断该资源是否已经分享过该章节,如果已经分享过直接返回
108
+        Integer count = resourceMapper.getLevelResourceForxb(model);
109
+        if(count>0){
110
+            return "99";
111
+        }else{
112
+            return saveShare(model, resourceid);
113
+        }
114
+    }
115
+
116
+    /**
117
+     * 分享资源保存
118
+     * @Param [model, resourceid]
119
+     * @Author ywx
120
+     * @Date 2020/7/1 10:18
121
+     * @return java.lang.Integer
122
+     **/
123
+    private String saveShare(TResource model, String resourceid) {
124
+        if (N_Utils.isNotEmpty(resourceid)) {
125
+            ResourceVo r = findById(resourceid);
126
+            model.setResourcename(r.getResourcename());
127
+            model.setResourceclass(r.getResourceclass());
128
+            model.setResourceurl(r.getResourceurl());
129
+            model.setSuffix(r.getSuffix());
130
+            model.setResourcesize(r.getResourcesize());
131
+            model.setResourcecover(r.getResourcecover());
132
+            model.setConverted(r.getConverted());
133
+            model.setPdfurl(r.getPdfurl());
134
+            model.setComm(r.getComm());
135
+            model.setDuration(r.getDuration());
136
+            model.setMp4code(r.getMp4code());
137
+            if(model.getLevel()==1){
138
+                model.setBelong(3);
139
+            }else{
140
+                model.setBelong(r.getBelong());
141
+            }
142
+
143
+            if (model.getResourcetype() == null) {
144
+                model.setResourcetype(r.getResourcetype());
145
+            }
146
+
147
+            if(r.getResourceclass()==7 && N_Utils.isNotEmpty(r.getPdfurl())){
148
+                //压缩包,用costtime替代分享时的压缩包,设置为7
149
+                model.setCosttime(7);
150
+            }
151
+        }
152
+        save(model);
153
+        //需要条用资源内保存方法
154
+        return "";
155
+    }
156
+
157
+
158
+    /**
159
+     *功能描述 我的空间列表
160
+     * @author WN
161
+     * @date 2022/2/22
162
+     * @param  * @param resource
163
+     * @return java.util.List<com.xhkjedu.sapi.model.space.TResource>
164
+     */
165
+    public List<TResource> listMyResource(TResource resource) {
166
+        return resourceMapper.listMyResource(resource);
167
+    }
168
+}

+ 39
- 0
sapi/src/main/java/com/xhkjedu/sapi/task/ClassReportTask.java Ver fichero

@@ -0,0 +1,39 @@
1
+package com.xhkjedu.sapi.task;
2
+
3
+import com.xhkjedu.sapi.model.classreport.TReportClasstype;
4
+import com.xhkjedu.sapi.service.classreport.ClassReportService;
5
+import org.springframework.scheduling.annotation.Scheduled;
6
+import org.springframework.stereotype.Component;
7
+
8
+import javax.annotation.Resource;
9
+
10
+/**
11
+ * @author ywx
12
+ * @classname ClassReportTask
13
+ * @description 班级报告定时任务
14
+ * @date 2021/5/31 16:23
15
+ **/
16
+@Component
17
+public class ClassReportTask {
18
+
19
+    @Resource
20
+    private ClassReportService classReportService;
21
+
22
+    //生成上周班级报告
23
+    @Scheduled(cron = "${cron.classReportWeek}")
24
+    public void classReportWeek(){
25
+        TReportClasstype type = new TReportClasstype();
26
+        type.setReporttype(1);
27
+        type.setBasenum(1);
28
+        classReportService.generateClassReport(type);
29
+    }
30
+
31
+    //生成上月班级报告
32
+    @Scheduled(cron = "${cron.classReportMonth}")
33
+    public void classReportMonth(){
34
+        TReportClasstype type = new TReportClasstype();
35
+        type.setReporttype(2);
36
+        type.setBasenum(1);
37
+        classReportService.generateClassReport(type);
38
+    }
39
+}

+ 29
- 0
sapi/src/main/java/com/xhkjedu/sapi/task/CloudSyncTask.java Ver fichero

@@ -0,0 +1,29 @@
1
+package com.xhkjedu.sapi.task;
2
+
3
+import com.xhkjedu.sapi.config.ConfigKey;
4
+import com.xhkjedu.sapi.model.cloud.TCloudSync;
5
+import com.xhkjedu.sapi.service.cloud.CloudSyncService;
6
+import org.springframework.scheduling.annotation.Scheduled;
7
+import org.springframework.stereotype.Component;
8
+
9
+import javax.annotation.Resource;
10
+
11
+/**
12
+ * @author ywx
13
+ * @className CloudSyncTask
14
+ * @description
15
+ * @date 2021/6/5 14:13
16
+ **/
17
+@Component
18
+public class CloudSyncTask {
19
+    @Resource
20
+    private CloudSyncService cloudSyncService;
21
+
22
+    //生成上周班级报告
23
+    @Scheduled(cron = "${cron.synctime}")
24
+    public void classReportWeek(){
25
+        TCloudSync sync = cloudSyncService.getCloudInfo();
26
+        sync.setSyncnum(ConfigKey.syncnum);
27
+        cloudSyncService.sync(sync);
28
+    }
29
+}

+ 87
- 0
sapi/src/main/java/com/xhkjedu/sapi/utils/ConvertUtil.java Ver fichero

@@ -0,0 +1,87 @@
1
+package com.xhkjedu.sapi.utils;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.xhkjedu.sapi.listener.MessageSender;
5
+import com.xhkjedu.sapi.mapper.space.ResourceFileMapper;
6
+import com.xhkjedu.sapi.model.space.TResource;
7
+import com.xhkjedu.sapi.vo.subjectbook.ResourceVo;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.stereotype.Component;
10
+
11
+import javax.annotation.Resource;
12
+import java.util.Arrays;
13
+import java.util.List;
14
+import java.util.Map;
15
+
16
+/**
17
+ * @author ywx
18
+ * @classname ConvertUtil
19
+ * @description 文件转换工具类
20
+ * @date 2021/10/27 9:32
21
+ **/
22
+@Component
23
+public class ConvertUtil {
24
+    @Resource
25
+    private ResourceFileMapper resourceFileMapper;
26
+    @Autowired
27
+    private MessageSender messageSender;
28
+    private static Integer[] CLASS = {1,2,5,7};//资源分类1word,2ppt,3pdf,4图片,5视频,6音频,7压缩包,10其他
29
+
30
+    //资源转换(word或ppt转为pdf,视频非h264编码转码,压缩包解压)
31
+    public void convertResource(TResource model) {
32
+        Integer resourceclass = model.getResourceclass();
33
+        //flv的视频不转换
34
+        if ("flv".equals(model.getSuffix())) return;
35
+        if (Arrays.asList(CLASS).contains(resourceclass) && model.getConverted() == 0) {
36
+            ResourceVo resource = new ResourceVo();
37
+            resource.setResourceid(model.getResourceid());
38
+            resource.setResourceclass(resourceclass);
39
+            resource.setResourceurl(model.getResourceurl());
40
+            resource.setSuffix(model.getSuffix());
41
+            messageSender.convertResource(resource);
42
+        }
43
+    }
44
+
45
+    //获取资源预览路径
46
+    public String getResourceUrl(ResourceVo resource) {
47
+        String pdfurl = resource.getPdfurl();
48
+        Integer resourceclass = resource.getResourceclass();
49
+        Integer converted = resource.getConverted();
50
+        if ((resourceclass == 1 || resourceclass == 2) && converted == 0) {
51
+            //需要把word或ppt转为pdf
52
+            pdfurl = messageSender.convertResource(resource);
53
+        } else if (resourceclass == 5) {
54
+            pdfurl = videoTransfer(resource);
55
+        } else if (resourceclass == 7) {
56
+            pdfurl = unzip(resource);
57
+        }
58
+        resource.setPdfurl(pdfurl);
59
+        return pdfurl;
60
+    }
61
+
62
+    //视频转换
63
+    public String videoTransfer(ResourceVo resource) {
64
+        String resourceurl = resource.getResourceurl();
65
+        String suffix = resource.getSuffix();
66
+        if (suffix.equals("mp4") && !resource.getMp4code().equals("h264")) {
67
+            resourceurl = messageSender.convertResource(resource);
68
+        }
69
+        return resourceurl;
70
+    }
71
+
72
+    //解压zip
73
+    public String unzip(ResourceVo resource) {
74
+        String resourceid = resource.getResourceid();
75
+        String pdfurl = null;
76
+        Integer converted = resource.getConverted();
77
+        if (converted == 0) {
78
+            //获取压缩包文件
79
+            pdfurl = messageSender.convertResource(resource);
80
+        } else {
81
+            List<Map> files = resourceFileMapper.listFile(resourceid);
82
+            pdfurl = JSON.toJSONString(files);
83
+        }
84
+        return pdfurl;
85
+    }
86
+
87
+}

+ 28
- 5
sapi/src/main/resources/application.properties Ver fichero

@@ -59,6 +59,15 @@ nummax=50000
59 59
 numadd=100000000
60 60
 #一次同步数量
61 61
 cron.syncnum=100
62
+#默认为false,不开启定时任务
63
+enable.scheduled=false
64
+#周一的凌晨2:00触发生成班级周报
65
+cron.classReportWeek=0 0 2 ? * MON
66
+#1号的凌晨3:00触发生成班级月报
67
+cron.classReportMonth=0 0 3 1 * ?
68
+#周日的凌晨3:00同步基础信息
69
+cron.synctime=0 0 3 ? * SUN
70
+#一次同步数量
62 71
 
63 72
 #云平台接口地址
64 73
 cloudapi=http://scapitest.xhkjedu.com/
@@ -77,9 +86,23 @@ lc.lc_app_id=xinghuodashuju_qa_20210524
77 86
 lc.lc_security_key=d802d29c7e0c79bdecea3a10c419231a
78 87
 lc.lc_school_prefix=henanxinghuoliaoyuankejiyouxiangongsi_
79 88
 
80
-rabbitmq.queue=xhkjedu.xhschool.livequeue_dev_bd
81
-rabbitmq.resourceToPdfQueue=xhkjedu.xhschool.resourceToPdfQueue
82
-rabbitmq.resourceTransferQueue=xhkjedu.xhschool.resourceTransferQueue
83
-rabbitmq.resourceUnZipQueue=xhkjedu.xhschool.resourceUnZipQueue
84
-rabbitmq.resourceDelQueue=xhkjedu.xhschool.resourceDelQueue
89
+rabbitmq.resourceToPdfQueue=xhkjedu.xhschool.resourceToPdfQueue_dev
90
+rabbitmq.resourceTransferQueue=xhkjedu.xhschool.resourceTransferQueue_dev
91
+rabbitmq.resourceUnZipQueue=xhkjedu.xhschool.resourceUnZipQueue_dev
92
+rabbitmq.resourceDelQueue=xhkjedu.xhschool.resourceDelQueue_dev
85 93
 rabbitmq.resourceHandleQueue=xhkjedu.xhschool.resourceHandleQueue_dev
94
+spring.rabbitmq.host=116.63.199.166
95
+spring.rabbitmq.port=5672
96
+spring.rabbitmq.username=xhkjedu
97
+spring.rabbitmq.password=xhkjedud07
98
+spring.rabbitmq.connection-timeout=15000
99
+#rabbitmq自动签收
100
+spring.rabbitmq.listener.simple.acknowledge-mode=auto
101
+# 是否开启消费者重试(为false时关闭消费者重试)
102
+spring.rabbitmq.listener.simple.retry.enabled=true
103
+# 最大重试重新投递消息次数
104
+spring.rabbitmq.listener.simple.retry.max-attempts=3
105
+# 重试重新投递消息的间隔时间(单位毫秒)
106
+spring.rabbitmq.listener.simple.retry.initial-interval=30000ms
107
+#重试次数超过上面的设置之后,是否丢弃(消费者listener抛出异常,是否重回队列(默认true:重回队列,false:不重回队列(可结合死信交换机))
108
+spring.rabbitmq.listener.simple.default-requeue-rejected=false

+ 3
- 3
sapi/src/main/resources/mapper/cloud/CloudSyncMapper.xml Ver fichero

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
-<mapper namespace="com.xhkjedu.mapper.sapi.cloud.CloudSyncMapper">
3
+<mapper namespace="com.xhkjedu.sapi.mapper.cloud.CloudSyncMapper">
4 4
   <!--列表-->
5 5
   <resultMap id="syncResult" type="java.util.Map">
6 6
     <id column="csid" property="csid"></id>
@@ -125,7 +125,7 @@
125 125
       </foreach>
126 126
   </insert>
127 127
   <!--同步资源-->
128
-  <insert id="syncResource" parameterType="com.xhkjedu.sapi.model.subjectbook.TResource">
128
+  <insert id="syncResource" parameterType="com.xhkjedu.sapi.model.space.TResource">
129 129
       INSERT INTO t_resource (resourceid,resourcename,subjectid,resourceclass,resourcetype,level
130 130
       ,resourceurl,resourcecover,converted,pdfurl,resourcestate,suffix,mp4code,resourcesize,duration,comm
131 131
       ,createtime,timeunix,resourcegrade,source,year,region,schoolname,belong)
@@ -136,7 +136,7 @@
136 136
       ON DUPLICATE KEY UPDATE resourcename=#{m.resourcename},resourcestate=#{m.resourcestate},comm=#{m.comm}
137 137
   </insert>
138 138
   <!--同步资源章节-->
139
-  <insert id="syncResourceDirector" parameterType="com.xhkjedu.sapi.model.subjectbook.TResourceDirector">
139
+  <insert id="syncResourceDirector" parameterType="com.xhkjedu.sapi.model.space.TResourceDirector">
140 140
       <foreach collection ="list" item="m" index= "index" separator =";">
141 141
       INSERT INTO t_resource_director (rdid,resourceid,lsbid,directorid,createtime,timeunix)
142 142
       VALUES (#{m.rdid},#{m.resourceid},#{m.lsbid},#{m.directorid},#{m.handletime},UNIX_TIMESTAMP(now()))

+ 106
- 0
sapi/src/main/resources/mapper/space/ResourceMapper.xml Ver fichero

@@ -0,0 +1,106 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.xhkjedu.sapi.mapper.space.ResourceMapper">
4
+
5
+    <!--2020.11.16 教师备课只获取自己上传到个人空间文件-->
6
+    <select id="listMyResource" resultType="com.xhkjedu.sapi.model.space.TResource">
7
+        select r.resourceid,r.resourcename,r.createtime,r.suffix,u.username createname,r.resourceurl,rd.lsbid,
8
+        rd.directorid,r.resourceclass,r.resourcetype,r.readcount,r.downcount,r.pdfurl,r.converted,r.resourcecover
9
+        ,r.comm,r.duration,r.resourcesize,r.mp4code
10
+        from t_resource r left join t_user u on u.userid=r.createid
11
+        left join t_resource_director rd on r.resourceid=rd.resourceid
12
+        where r.resourcestate=1 and r.level=2 and r.createid=#{resource.createid}
13
+        <if test="resource.resourcename!=null and resource.resourcename!=''">
14
+            and r.resourcename like '%${resource.resourcename}%'
15
+        </if>
16
+        <if test="resource.resourceclass!=null and resource.resourceclass!=0">
17
+            and r.resourceclass=#{resource.resourceclass}
18
+        </if>
19
+        <if test="resource.subjectid!=null and resource.subjectid!='0'.toString() and resource.subjectid!=''">
20
+            and r.subjectid=#{resource.subjectid}
21
+        </if>
22
+        <if test="resource.lsbid!=null and resource.lsbid!='0'.toString() and resource.lsbid!=''">
23
+            and rd.lsbid=#{resource.lsbid}
24
+        </if>
25
+        <if test="resource.directorid!=null and resource.directorid!='0'.toString() and resource.directorid!=''">
26
+            and rd.directorid=#{resource.directorid}
27
+        </if>
28
+        order by r.createtime desc,r.resourcename asc,r.resourceid asc
29
+    </select>
30
+    <!--详情-->
31
+    <resultMap id="resourceResult" type="com.xhkjedu.sapi.vo.subjectbook.ResourceVo">
32
+        <result property="resourceid" column="resourceid"></result>
33
+        <result property="resourcename" column="resourcename"></result>
34
+        <result property="readcount" column="readcount"></result>
35
+        <result property="downcount" column="downcount"></result>
36
+        <result property="resourceclass" column="resourceclass"></result>
37
+        <result property="resourcetype" column="resourcetype"></result>
38
+        <result property="belong" column="belong"></result>
39
+        <result property="resourcegrade" column="resourcegrade"></result>
40
+        <result property="source" column="source"></result>
41
+        <result property="year" column="year"></result>
42
+        <result property="region" column="region"></result>
43
+        <result property="schoolname" column="schoolname"></result>
44
+        <result property="converted" column="converted"></result>
45
+        <result property="pdfurl" column="pdfurl"></result>
46
+        <result property="resourceurl" column="resourceurl"></result>
47
+        <result property="resourcecover" column="resourcecover"></result>
48
+        <result property="suffix" column="suffix"></result>
49
+        <result property="mp4code" column="mp4code"></result>
50
+        <result property="resourcesize" column="resourcesize"></result>
51
+        <result property="duration" column="duration"></result>
52
+        <result property="createid" column="createid"></result>
53
+        <result property="createname" column="createname"></result>
54
+        <result property="createtime" column="createtime"></result>
55
+        <result property="comm" column="comm"></result>
56
+        <result property="lsbnum" column="lsbnum"></result>
57
+        <result property="directornum" column="directornum"></result>
58
+        <result property="areaall" column="areaall"></result>
59
+        <collection property="directors" ofType="com.xhkjedu.sapi.vo.subjectbook.DirectorVo" javaType="java.util.List">
60
+            <result property="lsbid" column="lsbid"></result>
61
+            <result property="directorid" column="directorid"></result>
62
+            <result property="directorname" column="directorname"></result>
63
+            <result property="level" column="level"></result>
64
+            <result property="subjectid" column="subjectid"></result>
65
+            <result property="subjectname" column="subjectname"></result>
66
+            <result property="versionname" column="versionname"></result>
67
+            <result property="lsbname" column="lsbname"></result>
68
+        </collection>
69
+    </resultMap>
70
+    <select id="findById" resultMap="resourceResult">
71
+        select r.*,u.username createname,rd.lsbid,rd.directorid,d.directorall directorname
72
+        ,sb.level,sb.subjectid,s.subjectname,v.versionname,sb.lsbname
73
+        ,(select a.areaall from t_areazone a where a.areacode=r.region)areaall
74
+        from t_resource r left join t_user u on u.userid=r.createid
75
+        left join t_resource_director rd on r.resourceid = rd.resourceid
76
+        left join t_director d on rd.directorid = d.directorid
77
+        left join t_subject_book sb on d.lsbid = sb.lsbid
78
+        left join t_subject s on sb.subjectid = s.subjectid
79
+        left join t_version v on sb.versionid = v.versionid
80
+        where r.resourceid=#{resourceid};
81
+        update t_resource r set r.readcount=r.readcount+1 where r.resourceid=#{resourceid}
82
+    </select>
83
+    <!--<select id="findById2" resultType="com.xhkjedu.sapi.vo.subjectbook.ResourceVo">
84
+        select r.resourceid,r.resourceclass,r.resourceurl,r.pdfurl,r.converted,r.suffix,r.mp4code
85
+        from t_resource r where r.resourceid=#{resourceid}
86
+    </select>-->
87
+
88
+    <!-- 获取资源是否已经分享到校本 -->
89
+    <select id="getLevelResourceForxb" resultType="java.lang.Integer">
90
+        SELECT COUNT(*) FROM t_resource r left join t_resource_director rd on r.resourceid=rd.resourceid
91
+        LEFT JOIN t_resource r2 ON r.resourceurl=r2.resourceurl
92
+        left join t_resource_director rd2 on r2.resourceid=rd2.resourceid and rd.lsbid=rd2.lsbid
93
+        WHERE r2.resourceid=#{resource.resourceid} AND r.level=1 AND rd.directorid=#{resource.directorid} and r.resourcestate=1
94
+        AND (r.belong IN(1,2) OR r.schoolid=#{resource.schoolid})
95
+    </select>
96
+
97
+    <!--批量添加-->
98
+    <insert id="batchSaveResourceDirector" parameterType="com.xhkjedu.sapi.model.space.TResourceDirector">
99
+        INSERT INTO t_resource_director (rdid,resourceid,lsbid,directorid,createid,createtime)
100
+        VALUES
101
+        <foreach collection ="list" item="d" index= "index" separator =",">
102
+            (#{d.rdid},#{d.resourceid},#{d.lsbid},#{d.directorid},#{d.createid},#{d.createtime})
103
+        </foreach>
104
+    </insert>
105
+
106
+</mapper>

+ 53
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/config/RabbitConfig.java Ver fichero

@@ -0,0 +1,53 @@
1
+package com.xhkjedu.sstudy.config;
2
+
3
+import org.springframework.amqp.core.Queue;
4
+import org.springframework.beans.factory.annotation.Value;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.context.annotation.Configuration;
7
+
8
+/**
9
+ * @author ywx
10
+ * @classname RabbitConfig
11
+ * @description
12
+ * @date 2021/6/18 12:51
13
+ **/
14
+@Configuration
15
+public class RabbitConfig {
16
+
17
+    @Value("${rabbitmq.resourceToPdfQueue}")
18
+    private String resourceToPdfQueue;
19
+    @Value("${rabbitmq.resourceTransferQueue}")
20
+    private String resourceTransferQueue;
21
+    @Value("${rabbitmq.resourceUnZipQueue}")
22
+    private String resourceUnZipQueue;
23
+    @Value("${rabbitmq.resourceDelQueue}")
24
+    private String resourceDelQueue;
25
+    @Value("${rabbitmq.resourceHandleQueue}")
26
+    private String resourceHandleQueue;
27
+
28
+    @Bean
29
+    public Queue resourceToPdfQueue() {
30
+        return new Queue(resourceToPdfQueue);
31
+    }
32
+
33
+    @Bean
34
+    public Queue resourceTransferQueue() {
35
+        return new Queue(resourceTransferQueue);
36
+    }
37
+
38
+    @Bean
39
+    public Queue resourceUnZipQueue() {
40
+        return new Queue(resourceUnZipQueue);
41
+    }
42
+
43
+    @Bean
44
+    public Queue resourceDelQueue() {
45
+        return new Queue(resourceDelQueue);
46
+    }
47
+
48
+    @Bean
49
+    public Queue resourceHandleQueue() {
50
+        return new Queue(resourceHandleQueue);
51
+    }
52
+
53
+}

+ 30
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/config/ScheduledConfig.java Ver fichero

@@ -0,0 +1,30 @@
1
+package com.xhkjedu.sstudy.config;
2
+
3
+import org.springframework.context.annotation.*;
4
+import org.springframework.core.type.AnnotatedTypeMetadata;
5
+import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
6
+
7
+/**
8
+ * @author ywx
9
+ * @className ScheduledConfig
10
+ * @description @Scheduled 注解,是被一个叫做 ScheduledAnnotationBeanPostProcessor 的类所拦截的,
11
+ * 所以我们可以根据配置,决定是否创建这个 bean,如果没有这个 bean,@Scheduled 就不会被拦截,那么定时任务肯定不会执行了,
12
+ * 需要注意的是:这种方式,启动类上面的 @EnableScheduling 需要去掉。
13
+ * @date 2021/5/18 9:15
14
+ **/
15
+@Configuration
16
+public class ScheduledConfig {
17
+    @Conditional(ScheduledCondition.class)
18
+    @Bean
19
+    public ScheduledAnnotationBeanPostProcessor processor(){
20
+        return new ScheduledAnnotationBeanPostProcessor();
21
+    }
22
+}
23
+
24
+class ScheduledCondition implements Condition {
25
+
26
+    @Override
27
+    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
28
+        return Boolean.valueOf(context.getEnvironment().getProperty("enable.scheduled"));
29
+    }
30
+}

+ 62
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/config/ThreadPoolTaskExecutorConfig.java Ver fichero

@@ -0,0 +1,62 @@
1
+package com.xhkjedu.sstudy.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
6
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
7
+
8
+import java.util.concurrent.ThreadPoolExecutor;
9
+
10
+/**
11
+ * @描述 :配置线程池
12
+ * @创建人 :zj
13
+ * @创建时间 2019/9/30
14
+ * @修改人和其它信息
15
+ */
16
+@Configuration
17
+public class ThreadPoolTaskExecutorConfig {
18
+    /**
19
+     * 配置执行任务线程池
20
+     * 应用此池: @Async("asyncPoolTaskExecutor")
21
+     *
22
+     * @return
23
+     */
24
+    @Bean(name = "asyncPoolTaskExecutor")
25
+    public ThreadPoolTaskExecutor getAsyncThreadPoolTaskExecutor() {
26
+        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
27
+        taskExecutor.setCorePoolSize(20);
28
+        taskExecutor.setMaxPoolSize(200);
29
+        taskExecutor.setQueueCapacity(25);
30
+        taskExecutor.setKeepAliveSeconds(200);
31
+        //定义线程池名字
32
+        taskExecutor.setThreadNamePrefix("asyncPoolTaskExecutor。");
33
+        //该方法就是这里的关键,用来设置线程池关闭的时候等待所有任务都完成再继续销毁其他的Bean,这样这些异步任务的销毁就会先于Redis线程池的销毁。
34
+        // 同时,这里还设置了setAwaitTerminationSeconds(60),该方法用来设置线程池中任务的等待时间,如果超过这个时候还没有销毁就强制销毁,
35
+        // 以确保应用最后能够被关闭,而不是阻塞住。
36
+        taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
37
+        taskExecutor.setAwaitTerminationSeconds(60);
38
+        // 线程池对拒绝任务(无线程可用)的处理策略,目前只支持AbortPolicy、CallerRunsPolicy;默认为后者
39
+        taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
40
+        taskExecutor.initialize();
41
+        return taskExecutor;
42
+    }
43
+
44
+    /** 
45
+    * @Description: 配置调度任务线程池
46
+    * @Author: lgq 
47
+    * @Date: 2020-03-11 16:15:27
48
+    */ 
49
+    @Bean
50
+    public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
51
+        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
52
+        threadPoolTaskScheduler.setPoolSize(500);
53
+        threadPoolTaskScheduler.setThreadNamePrefix("taskExecutor-");
54
+        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
55
+        threadPoolTaskScheduler.setRemoveOnCancelPolicy(true);
56
+        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
57
+        threadPoolTaskScheduler.setAwaitTerminationSeconds(60);
58
+        threadPoolTaskScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
59
+        return threadPoolTaskScheduler;
60
+    }
61
+
62
+}

+ 29
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/task/PaperStudentTask.java Ver fichero

@@ -0,0 +1,29 @@
1
+package com.xhkjedu.sstudy.task;
2
+
3
+import com.xhkjedu.sstudy.service.paperstudent.PaperStudentService;
4
+import lombok.extern.slf4j.Slf4j;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.scheduling.annotation.Async;
7
+import org.springframework.scheduling.annotation.Scheduled;
8
+import org.springframework.stereotype.Component;
9
+
10
+/**
11
+ * @ClassName PaperStudentTask
12
+ * Description 学生作业,如果是截至时间到时显示答案,定时任务处理
13
+ * Author WN
14
+ * Date 2020/10/13 15:32
15
+ **/
16
+@Slf4j
17
+@Component
18
+public class PaperStudentTask {
19
+
20
+    @Autowired
21
+    private PaperStudentService paperStudentService;
22
+
23
+    @Async("threadPoolTaskScheduler")
24
+    @Scheduled(cron = "${cron.updatePaperStuShowanswer}")
25
+    public void updatePaperStuShowanswer(){
26
+        paperStudentService.updateShowanswer();
27
+    }
28
+
29
+}

+ 8
- 8
sstudy/src/main/resources/application.properties Ver fichero

@@ -58,12 +58,12 @@ secretKey=nanhuakaizhangjianwangni
58 58
 nummin=10000
59 59
 nummax=50000
60 60
 numadd=100000000
61
-#默认为false,不开启定时任务
62
-enable.scheduled=false
63
-#周日的凌晨3:00同步基础信息
64
-cron.synctime=0 0 3 ? * SUN
65 61
 #一次同步数量
66 62
 cron.syncnum=100
63
+#默认为false,不开启定时任务
64
+enable.scheduled=false
65
+#每隔1分钟修改学生作业是否显示答案
66
+cron.updatePaperStuShowanswer=* */1 * * * ?
67 67
 
68 68
 #云平台接口地址
69 69
 cloudapi=http://scapitest.xhkjedu.com/
@@ -77,10 +77,10 @@ file.showurl=http://schoolstatictest.xhkjedu.com/static/
77 77
 dbname=xhkjedu_school_test
78 78
 
79 79
 
80
-rabbitmq.resourceToPdfQueue=xhkjedu.xhschool.resourceToPdfQueue
81
-rabbitmq.resourceTransferQueue=xhkjedu.xhschool.resourceTransferQueue
82
-rabbitmq.resourceUnZipQueue=xhkjedu.xhschool.resourceUnZipQueue
83
-rabbitmq.resourceDelQueue=xhkjedu.xhschool.resourceDelQueue
80
+rabbitmq.resourceToPdfQueue=xhkjedu.xhschool.resourceToPdfQueue_dev
81
+rabbitmq.resourceTransferQueue=xhkjedu.xhschool.resourceTransferQueue_dev
82
+rabbitmq.resourceUnZipQueue=xhkjedu.xhschool.resourceUnZipQueue_dev
83
+rabbitmq.resourceDelQueue=xhkjedu.xhschool.resourceDelQueue_dev
84 84
 rabbitmq.resourceHandleQueue=xhkjedu.xhschool.resourceHandleQueue_dev
85 85
 spring.rabbitmq.host=116.63.199.166
86 86
 spring.rabbitmq.port=5672

Loading…
Cancelar
Guardar