From 03ff6ba5af6cb8aa1ab03a12a258cb834ac34c16 Mon Sep 17 00:00:00 2001 From: Administrator Date: Wed, 1 Dec 2021 19:03:40 +0800 Subject: [PATCH] 压测工具 --- src/main/java/com/subsidy/common/configure/MyTomcat.java | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/subsidy/controller/AdministerController.java | 8 ++++++++ src/main/java/com/subsidy/controller/ClassHourDictController.java | 8 ++++---- src/main/java/com/subsidy/controller/MemberController.java | 2 +- src/main/java/com/subsidy/controller/VodPlayHistoryController.java | 10 ++++++++-- src/main/java/com/subsidy/model/ClassHourDictDO.java | 2 ++ src/main/java/com/subsidy/service/ClassHourDictService.java | 2 +- src/main/java/com/subsidy/service/VodPlayHistoryService.java | 1 + src/main/java/com/subsidy/service/impl/ClassHourDictServiceImpl.java | 26 ++++++++++++++++++++------ src/main/java/com/subsidy/service/impl/MemberServiceImpl.java | 50 +++++++++++++++++++++++++------------------------- src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java | 5 +++++ src/main/java/com/subsidy/util/SecretUtils.java | 6 +++--- src/main/resources/application-dev.properties | 8 ++++---- src/main/resources/application-prod.properties | 3 --- src/main/resources/application.properties | 39 +++++++++++++++++++++++---------------- src/main/resources/mapper/MemberMapper.xml | 2 +- 16 files changed, 195 insertions(+), 66 deletions(-) create mode 100644 src/main/java/com/subsidy/common/configure/MyTomcat.java diff --git a/src/main/java/com/subsidy/common/configure/MyTomcat.java b/src/main/java/com/subsidy/common/configure/MyTomcat.java new file mode 100644 index 0000000..52d1ac7 --- /dev/null +++ b/src/main/java/com/subsidy/common/configure/MyTomcat.java @@ -0,0 +1,89 @@ +package com.subsidy.common.configure; + +import org.apache.catalina.connector.Connector; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.MultipartConfigFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.servlet.MultipartConfigElement; + +@Configuration +public class MyTomcat { + + + @Value("${spring.server.port}") + private String port; + @Value("${spring.server.acceptorThreadCount}") + private String acceptorThreadCount; + @Value("${spring.server.minSpareThreads}") + private String minSpareThreads; + @Value("${spring.server.maxSpareThreads}") + private String maxSpareThreads; + @Value("${spring.server.maxThreads}") + private String maxThreads; + @Value("${spring.server.maxConnections}") + private String maxConnections; + @Value("${spring.server.protocol}") + private String protocol; + @Value("${spring.server.redirectPort}") + private String redirectPort; + @Value("${spring.server.compression}") + private String compression; + @Value("${spring.server.connectionTimeout}") + private String connectionTimeout; + + @Value("${spring.server.MaxFileSize}") + private String MaxFileSize; + @Value("${spring.server.MaxRequestSize}") + private String MaxRequestSize; + + @Bean + public ServletWebServerFactory servletContainer() { + TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); + tomcat.addConnectorCustomizers(new GwsTomcatConnectionCustomizer()); + return tomcat; + } + + @Bean + public MultipartConfigElement multipartConfigElement() { + MultipartConfigFactory factory = new MultipartConfigFactory(); + // 单个数据大小 + factory.setMaxFileSize(MaxFileSize); // KB,MB + /// 总上传数据大小 + factory.setMaxRequestSize(MaxRequestSize); + return factory.createMultipartConfig(); + } + + /** + * + * 默认http连接 + * + * @version + * @author liuyi 2016年7月20日 下午7:59:41 + * + */ + public class GwsTomcatConnectionCustomizer implements TomcatConnectorCustomizer { + + public GwsTomcatConnectionCustomizer() { + } + + @Override + public void customize(Connector connector) { + connector.setPort(Integer.valueOf(port)); + connector.setAttribute("connectionTimeout", connectionTimeout); + connector.setAttribute("acceptorThreadCount", acceptorThreadCount); + connector.setAttribute("minSpareThreads", minSpareThreads); + connector.setAttribute("maxSpareThreads", maxSpareThreads); + connector.setAttribute("maxThreads", maxThreads); + connector.setAttribute("maxConnections", maxConnections); + connector.setAttribute("protocol", protocol); + connector.setAttribute("redirectPort", "redirectPort"); + connector.setAttribute("compression", "compression"); + } + } + +} diff --git a/src/main/java/com/subsidy/controller/AdministerController.java b/src/main/java/com/subsidy/controller/AdministerController.java index 66d69d2..4077c35 100644 --- a/src/main/java/com/subsidy/controller/AdministerController.java +++ b/src/main/java/com/subsidy/controller/AdministerController.java @@ -24,6 +24,7 @@ import io.swagger.annotations.Api; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.net.InetAddress; import java.util.Arrays; import java.util.List; @@ -43,6 +44,13 @@ public class AdministerController { @Autowired private AdministerService administerService; + @GetMapping("getIp") + public String getIp()throws Exception{ + InetAddress addr = InetAddress.getLocalHost(); + System.out.println("Local HostAddress:"+addr.getHostAddress()); + return addr.getHostAddress(); + } + @PostMapping("/login") @ApiOperation("登录接口 accountName password") public ResponseVO login(@RequestBody AdministerDO administerDO){ diff --git a/src/main/java/com/subsidy/controller/ClassHourDictController.java b/src/main/java/com/subsidy/controller/ClassHourDictController.java index 19fb9ee..cdb8982 100644 --- a/src/main/java/com/subsidy/controller/ClassHourDictController.java +++ b/src/main/java/com/subsidy/controller/ClassHourDictController.java @@ -31,14 +31,14 @@ public class ClassHourDictController { private ClassHourDictService classHourDictService; @PostMapping("getSetting") - @ApiOperation("查看当天设置的最大学习时长") + @ApiOperation("查看当天设置的最大学习时长 companyId") @LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) - public ResponseVO getSetting(){ - return ResponseData.generateCreatedResponse(0,classHourDictService.getSetting()); + public ResponseVO getSetting(@RequestBody ClassHourDictDO classHourDictDO){ + return ResponseData.generateCreatedResponse(0,classHourDictService.getSetting(classHourDictDO)); } @PostMapping("updateSetting") - @ApiOperation("修改当天设置时长 id classHour status") + @ApiOperation("修改当天设置时长 id 主键 classHour status") @LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) public ResponseVO updateSetting(@RequestBody ClassHourDictDO classHourDictDO){ return ResponseData.generateCreatedResponse(0,classHourDictService.updateSetting(classHourDictDO)); diff --git a/src/main/java/com/subsidy/controller/MemberController.java b/src/main/java/com/subsidy/controller/MemberController.java index 1a3d061..c74af9e 100644 --- a/src/main/java/com/subsidy/controller/MemberController.java +++ b/src/main/java/com/subsidy/controller/MemberController.java @@ -40,7 +40,7 @@ public class MemberController { @PostMapping("getAll") @ApiOperation("查询某部门成员 pageNum pageSize departmentId userName status") - @LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) + //@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) public ResponseVO getAll(@RequestBody GetAllDTO getAllDTO){ return ResponseData.generateCreatedResponse(0,memberService.getAll(getAllDTO)); } diff --git a/src/main/java/com/subsidy/controller/VodPlayHistoryController.java b/src/main/java/com/subsidy/controller/VodPlayHistoryController.java index 9d9b44d..22fad72 100644 --- a/src/main/java/com/subsidy/controller/VodPlayHistoryController.java +++ b/src/main/java/com/subsidy/controller/VodPlayHistoryController.java @@ -1,6 +1,7 @@ package com.subsidy.controller; +import com.alibaba.fastjson.JSON; import com.subsidy.common.ResponseData; import com.subsidy.common.ResponseVO; import com.subsidy.model.VodPlayHistoryDO; @@ -31,10 +32,15 @@ public class VodPlayHistoryController { private VodPlayHistoryService vodPlayHistoryService; @PostMapping("insertHistory") - @ApiOperation("记录学生看视频位置 classId班级id vodId 视频id memberId 成员id playLength 播放时长 playRecord 位点") + @ApiOperation("记录学生看视频位置 ajax请求 classId班级id vodId 视频id memberId 成员id playLength 播放时长 playRecord 位点") public ResponseVO insertHistory(@RequestBody VodPlayHistoryDO vodPlayHistoryDO){ return ResponseData.generateCreatedResponse(0,vodPlayHistoryService.insertHistory(vodPlayHistoryDO)); } - + @RequestMapping("insertHistoryNew") + @ApiOperation("记录学生看视频位置 classId班级id vodId 视频id memberId 成员id playLength 播放时长 playRecord 位点") + public ResponseVO insertHistoryNew(@RequestBody String param){ + VodPlayHistoryDO vodPlayHistoryDO = JSON.parseObject(param,VodPlayHistoryDO.class); + return ResponseData.generateCreatedResponse(0,vodPlayHistoryService.insertHistoryNew(vodPlayHistoryDO)); + } } diff --git a/src/main/java/com/subsidy/model/ClassHourDictDO.java b/src/main/java/com/subsidy/model/ClassHourDictDO.java index 2ea9e58..b346cd3 100644 --- a/src/main/java/com/subsidy/model/ClassHourDictDO.java +++ b/src/main/java/com/subsidy/model/ClassHourDictDO.java @@ -25,6 +25,8 @@ public class ClassHourDictDO extends BaseModel { @TableId(value = "id", type = IdType.AUTO) private Long id; + private Long companyId; + /** * 课时 */ diff --git a/src/main/java/com/subsidy/service/ClassHourDictService.java b/src/main/java/com/subsidy/service/ClassHourDictService.java index 078e6c1..6196c30 100644 --- a/src/main/java/com/subsidy/service/ClassHourDictService.java +++ b/src/main/java/com/subsidy/service/ClassHourDictService.java @@ -15,7 +15,7 @@ import com.subsidy.vo.hour.PollingGetVO; */ public interface ClassHourDictService extends IService { - ClassHourDictDO getSetting(); + ClassHourDictDO getSetting(ClassHourDictDO classHourDictDO); String updateSetting(ClassHourDictDO classHourDictDO); diff --git a/src/main/java/com/subsidy/service/VodPlayHistoryService.java b/src/main/java/com/subsidy/service/VodPlayHistoryService.java index 3b850e3..a355a19 100644 --- a/src/main/java/com/subsidy/service/VodPlayHistoryService.java +++ b/src/main/java/com/subsidy/service/VodPlayHistoryService.java @@ -15,4 +15,5 @@ public interface VodPlayHistoryService extends IService { String insertHistory(VodPlayHistoryDO vodPlayHistoryDO); + String insertHistoryNew(VodPlayHistoryDO vodPlayHistoryDO); } diff --git a/src/main/java/com/subsidy/service/impl/ClassHourDictServiceImpl.java b/src/main/java/com/subsidy/service/impl/ClassHourDictServiceImpl.java index 661ee81..f617547 100644 --- a/src/main/java/com/subsidy/service/impl/ClassHourDictServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/ClassHourDictServiceImpl.java @@ -32,9 +32,19 @@ public class ClassHourDictServiceImpl extends ServiceImpl() + .lambda() + .eq(ClassHourDictDO::getCompanyId,classHourDictDO.getCompanyId())); + if (null==classHourDictDO){ + ClassHourDictDO classHourDictDO2 = new ClassHourDictDO(); + classHourDictDO2.setCompanyId(classHourDictDO.getCompanyId()); + classHourDictDO2.setStatus(0); + classHourDictDO2.setClassHour(6); + this.baseMapper.insert(classHourDictDO2); + return classHourDictDO2; + } + return classHourDictDO1; } public String updateSetting(ClassHourDictDO classHourDictDO){ @@ -68,10 +78,14 @@ public class ClassHourDictServiceImpl extends ServiceImpl imple studyPageVO.setTotalMember(classMemberMappingDOS.size()); //多少人完成 - int completedCnt = 0; - for (ClassMemberMappingDO cmmd : classMemberMappingDOS) { - - Boolean flag = true; - - for (VodDictDO vodDictDO : vodDictDOS) { - List vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper() - .lambda() - .eq(VodPlayHistoryDO::getVodId, vodDictDO.getId()) - .eq(VodPlayHistoryDO::getMemberId, cmmd.getMemberId()) - .orderByDesc(VodPlayHistoryDO::getPlayRecord)); - if (vodPlayHistoryDOS.size() > 0) { - if (vodPlayHistoryDOS.get(0).getPlayRecord() < vodDictDO.getVodLength()) { - flag = false; - //break; - } - } else { - flag = false; - } - } - if (flag) { - completedCnt++; - } - } - studyPageVO.setDoneMember(completedCnt); + //int completedCnt = 0; + //for (ClassMemberMappingDO cmmd : classMemberMappingDOS) { + // + // Boolean flag = true; + // + // for (VodDictDO vodDictDO : vodDictDOS) { + // List vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper() + // .lambda() + // .eq(VodPlayHistoryDO::getVodId, vodDictDO.getId()) + // .eq(VodPlayHistoryDO::getMemberId, cmmd.getMemberId()) + // .orderByDesc(VodPlayHistoryDO::getPlayRecord)); + // if (vodPlayHistoryDOS.size() > 0) { + // if (vodPlayHistoryDOS.get(0).getPlayRecord() < vodDictDO.getVodLength()) { + // flag = false; + // //break; + // } + // } else { + // flag = false; + // } + // } + // if (flag) { + // completedCnt++; + // } + //} + //studyPageVO.setDoneMember(completedCnt); } memberStudyPageVO.setStudyPageVOS(studyPageVOS); diff --git a/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java b/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java index b29fe46..db73e96 100644 --- a/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java @@ -23,4 +23,9 @@ public class VodPlayHistoryServiceImpl extends ServiceImpl + and t2.user_name like concat('%',#{userName} ,'%') -- libgit2 0.25.0