diff --git a/pom.xml b/pom.xml index b090d6f..a7f7e15 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ gson 2.8.5 - + com.github.binarywang weixin-java-mp @@ -69,24 +69,174 @@ spring-boot-starter-websocket + - com.alibaba - fastjson - 1.2.47 + org.springframework.boot + spring-boot-starter-aop + 1.5.9.RELEASE + + + com.zaxxer + HikariCP + 3.4.1 + + + org.apache.logging.log4j log4j-core 2.10.0 - + + + org.springframework.boot + spring-boot-starter-test + + junit junit 4.12 test + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.1 + + + + tk.mybatis + mapper-spring-boot-starter + 1.2.4 + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.2.3 + + + + org.mybatis.generator + mybatis-generator-core + 1.3.2 + compile + true + + + + io.springfox + springfox-swagger2 + 2.7.0 + + + io.springfox + springfox-swagger-ui + 2.7.0 + + + + + com.alibaba + fastjson + 1.2.16 + + + + + + + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.apache.commons + commons-pool2 + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + com.github.binarywang + java-emoji-converter + 0.0.1 + + + + + + + + + + + + + org.apache.poi + poi-ooxml + 3.17 + + + + + org.apache.poi + poi-scratchpad + 3.17 + + + + + + com.google.code.gson + gson + 2.8.5 + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + org.docx4j + docx4j + 6.0.1 + + + + org.slf4j + slf4j-log4j12 + + + + + + + + + + + + + + + diff --git a/src/main/java/com/zgczx/Application.java b/src/main/java/com/zgczx/Application.java index 8c052dc..f051c5b 100644 --- a/src/main/java/com/zgczx/Application.java +++ b/src/main/java/com/zgczx/Application.java @@ -2,12 +2,16 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import tk.mybatis.spring.annotation.MapperScan; + +@MapperScan(basePackages = "com.zgczx.mapper") @SpringBootApplication -public class Application { +//@EnableCaching +public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } - } diff --git a/src/main/java/com/zgczx/aop/RequestLogAspect.java b/src/main/java/com/zgczx/aop/RequestLogAspect.java new file mode 100644 index 0000000..281d59b --- /dev/null +++ b/src/main/java/com/zgczx/aop/RequestLogAspect.java @@ -0,0 +1,80 @@ +package com.zgczx.aop; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +import org.aspectj.lang.annotation.*; +import org.aspectj.lang.reflect.MethodSignature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.text.SimpleDateFormat; +import java.util.Arrays; + +/** + * 编写了一个aop简单使用 + * 管切入到指定类指定方法的代码片段称为切面,而切入到哪些类、哪些方法则叫切入点。 + * 如果几个或更多个逻辑过程中,有重复的操作行为,AOP就可以将其提取出来,运用代理机制, + * 实现程序功能的统一维护,这么说来可能太含蓄,如果说到权限判断,日志记录等,可能就明白了。 + * + * 使用@Aspect注解将一个java类定义为切面类 + * 使用@Pointcut定义一个切入点,可以是一个规则表达式,比如下例中某个package下的所有函数,也可以是一个注解等。 + * 根据需要在切入点不同位置的切入内容 + * 使用@Before在切入点开始处切入内容 + * 使用@After在切入点结尾处切入内容 + * 使用@AfterReturning在切入点return内容之后切入内容(可以用来对处理返回值做一些加工处理) + * 使用@Around在切入点前后切入内容,并自己控制何时执行切入点自身的内容 + * 使用@AfterThrowing用来处理当切入内容部分抛出异常之后的处理逻辑 + * @author aml + * @date 2019/10/8 21:42 + */ +@Aspect +@Component +public class RequestLogAspect { + private static final Logger logger = LoggerFactory.getLogger(RequestLogAspect.class); + + @Pointcut("execution(public * com.zgczx.controller..*.*(..)) && !execution(public * com.zgczx.controller.exam.ExamController.findExamQuestionInfo(..) ) ") + public void webLog(){ + + } + @Before(("webLog()")) + public void doBefor(JoinPoint joinPoint){ + //接收到请求, 记录请求内容 + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + + // 记录下请求的内容 + logger.info("URL: " + request.getRequestURI().toString()); + logger.info("HTTP method: "+ request.getMethod()); + logger.info("IP:" + request.getRemoteAddr()); + logger.info("CLASS_method: "+ joinPoint.getSignature().getDeclaringTypeName() + "." + + joinPoint.getSignature().getName()); + // 获取参数名 + Signature signature = joinPoint.getSignature(); + MethodSignature methodSignature = (MethodSignature) signature; + logger.info("parameterName: "+ Arrays.toString(methodSignature.getParameterNames())); + logger.info("parameterValue: "+ Arrays.toString(joinPoint.getArgs())); + + } + + @AfterReturning(returning = "ret", pointcut = "webLog()") + public void doAfterReturning(Object ret){ + // 处理完请求, 返回内容 + logger.info("RESPONSE: "+ ret); + + } + + @Around("webLog()") + public Object doAround(ProceedingJoinPoint pip) throws Throwable{ + long startTime = System.currentTimeMillis(); + Object object = pip.proceed(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + logger.info("currentTime: " + dateFormat.format(startTime)); + logger.info("Time : "+ (System.currentTimeMillis() - startTime)); + return object; + } +} diff --git a/src/main/java/com/zgczx/aop/UserAuthorizeAspect.java b/src/main/java/com/zgczx/aop/UserAuthorizeAspect.java new file mode 100644 index 0000000..5954c38 --- /dev/null +++ b/src/main/java/com/zgczx/aop/UserAuthorizeAspect.java @@ -0,0 +1,73 @@ +package com.zgczx.aop; + +import com.zgczx.constans.CookieConstant; +import com.zgczx.constans.RedisConstans; +import com.zgczx.exception.UserAuthorizeException; +import com.zgczx.utils.CookieUtil; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + +/** + * explain:权限认证的切面 + * 不能直接访问某个接口的url,只有登录成功后才能访问接口 + * @author aml + * @date 2019/11/9 13:35 + */ +//TODO 暂时屏蔽 能够登录后需要放开,也就是有开放平台登录账号 +// 2019年11.9号,先不放开,看需求再说 + // 微信端没必要使用权限认证,因为用户根本就不知道接口的url + //但是PC端得需要,因为用户可以从 浏览器的窗口地址栏中看到具体的url +//@Aspect +//@Component +@Slf4j +public class UserAuthorizeAspect { + + @Autowired + private StringRedisTemplate stringRedisTemplate; + + /** + * 定义切面方法 + * com.zgczx.controller.score:包名 + * Score*: 所有以Score开头的java文件 + * 例如:ScoreController + */ + @Pointcut("execution(public * com.zgczx.controller.score.Score*.*(..))"+ //这些方法都要经过切面 + //"&& execution(public * com.zgczx.controller.user.UserController.login())" + + "&& !execution(public * com.zgczx.controller.user.UserController.*(..))")//排除UserController中的方法,包含登录登出 + public void verify(){} + + @Before("verify()") + public void doVerify(){ + //接收到请求, 记录请求内容 + ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = requestAttributes.getRequest();//获取HttpServletRequest + //1.查询cookie + Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN); + if (cookie == null){ + log.warn("【登录校验】 Cookie中查不到token"); + //这里抛出异常,在handler中处理异常让其跳转到授权页面 + throw new UserAuthorizeException(); + } + //2.去Redis中查询cookie + String redisTokenValue = stringRedisTemplate.opsForValue().get(String.format(RedisConstans.TOKEN_PREFIX, cookie.getValue())); + if (redisTokenValue == null){ + log.warn("【登录校验】 Redis中查不到token"); + //这里抛出异常,在handler中处理异常让其跳转到授权页面 + throw new UserAuthorizeException(); + } + + } + + +} diff --git a/src/main/java/com/zgczx/config/datasoucreconfig/DataSourceConfig.java b/src/main/java/com/zgczx/config/datasoucreconfig/DataSourceConfig.java new file mode 100644 index 0000000..d815f64 --- /dev/null +++ b/src/main/java/com/zgczx/config/datasoucreconfig/DataSourceConfig.java @@ -0,0 +1,38 @@ +package com.zgczx.config.datasoucreconfig; + +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import javax.sql.DataSource; + + +@Configuration // 显式配置了多个数据源 +public class DataSourceConfig { + + @Bean(name = "db1DataSource") + @Qualifier("db1DataSource") + @Primary // 设置 主数据源 + @ConfigurationProperties(prefix = "spring.datasource.db1")// 指定配置文件中的数据源前缀 + public DataSource db1DataSource(){ + return DataSourceBuilder.create().type(HikariDataSource.class).build(); + } + + @Bean(name = "db2DataSource") + @Qualifier("db2DataSource") + @ConfigurationProperties(prefix = "spring.datasource.db2")// 指定配置文件中的数据源前缀 + public DataSource db2DataSource(){ + return DataSourceBuilder.create().type(HikariDataSource.class).build(); + } + + @Bean(name = "db3DataSource") + @Qualifier("db3DataSource") + @ConfigurationProperties(prefix = "spring.datasource.db3")// 指定配置文件中的数据源前缀 + public DataSource db3DataSource(){ + return DataSourceBuilder.create().type(HikariDataSource.class).build(); + } +} diff --git a/src/main/java/com/zgczx/config/datasoucreconfig/Db1Config.java b/src/main/java/com/zgczx/config/datasoucreconfig/Db1Config.java new file mode 100644 index 0000000..ee77d33 --- /dev/null +++ b/src/main/java/com/zgczx/config/datasoucreconfig/Db1Config.java @@ -0,0 +1,64 @@ +package com.zgczx.config.datasoucreconfig; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManager; +import javax.sql.DataSource; +import java.util.Map; + + + +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "entityManagerFactoryDb1", + transactionManagerRef = "transactionManagerDb1", + basePackages = {"com.zgczx.repository.mysql1"}) //设置Repository所在位置 +public class Db1Config { + + @Autowired + @Qualifier("db1DataSource") + private DataSource db1DataSource; + + @Primary + @Bean(name = "entityManagerDb1") + public EntityManager entityManager(EntityManagerFactoryBuilder builder) { + return entityManagerFactoryDb1(builder).getObject().createEntityManager(); + } + + @Primary + @Bean(name = "entityManagerFactoryDb1") + public LocalContainerEntityManagerFactoryBean entityManagerFactoryDb1(EntityManagerFactoryBuilder builder) { + return builder + .dataSource(db1DataSource) + .properties(getVendorProperties(db1DataSource)) + .packages("com.zgczx.repository.mysql1") //设置实体类所在位置 + .persistenceUnit("db1PersistenceUnit") + .build(); + } + + @Autowired + private JpaProperties jpaProperties; + + private Map getVendorProperties(DataSource dataSource) { + return jpaProperties.getHibernateProperties(dataSource); + } + + @Primary + @Bean(name = "transactionManagerDb1") + public PlatformTransactionManager transactionManagerDb1(EntityManagerFactoryBuilder builder) { + return new JpaTransactionManager(entityManagerFactoryDb1(builder).getObject()); + } + +} diff --git a/src/main/java/com/zgczx/config/datasoucreconfig/Db2Config.java b/src/main/java/com/zgczx/config/datasoucreconfig/Db2Config.java new file mode 100644 index 0000000..1b5fcbe --- /dev/null +++ b/src/main/java/com/zgczx/config/datasoucreconfig/Db2Config.java @@ -0,0 +1,81 @@ +package com.zgczx.config.datasoucreconfig; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManager; +import javax.sql.DataSource; +import java.util.Map; +import java.util.Properties; + +/** + * 第二数据源的具体配置 + * 这种配置是 1.多版本的 + * @author aml + * @date 2019/10/10 10:45 + */ +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "entityManagerFactoryDb2", + transactionManagerRef = "transactionManagerDb2", + basePackages = {"com.zgczx.repository.mysql2.scoretwo.dao"}) // 指定该数据源操作的DAO接口包 +public class Db2Config { + + @Autowired + @Qualifier("db2DataSource") + private DataSource db2DataSource; + + //@Primary//指定主数据源 + @Bean(name = "entityManagerDb2") + public EntityManager entityManager(EntityManagerFactoryBuilder builder) { + return entityManagerFactoryDb2(builder).getObject().createEntityManager(); + } + + //@Primary + @Bean(name = "entityManagerFactoryDb2") + public LocalContainerEntityManagerFactoryBean entityManagerFactoryDb2(EntityManagerFactoryBuilder builder) { + return builder + .dataSource(db2DataSource) + .properties(getVendorProperties(db2DataSource)) + .packages("com.zgczx.repository.mysql2.scoretwo.model") //设置实体类所在位置 + .persistenceUnit("db2PersistenceUnit") + .build(); + + //设置数据源的方言 +// LocalContainerEntityManagerFactoryBean entityManagerFactory = builder.dataSource(db2DataSource) +// .packages("com.zgczx.repository.mysql2.scoretwo.model").build(); +// Properties jpaProperties = new Properties(); +// jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); +// jpaProperties.put("hibernate.physical_naming_strategy", "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy"); +// jpaProperties.put("hibernate.connection.charSet", "utf-8"); +// jpaProperties.put("hibernate.show_sql", "false"); +// entityManagerFactory.setJpaProperties(jpaProperties); +// return entityManagerFactory; + + } + + @Autowired + private JpaProperties jpaProperties; + + private Map getVendorProperties(DataSource dataSource) { + return jpaProperties.getHibernateProperties(dataSource); + } + + //@Primary + @Bean(name = "transactionManagerDb2") + public PlatformTransactionManager transactionManagerDb2(EntityManagerFactoryBuilder builder) { + return new JpaTransactionManager(entityManagerFactoryDb2(builder).getObject()); + } + +} \ No newline at end of file diff --git a/src/main/java/com/zgczx/config/datasoucreconfig/Db3Config.java b/src/main/java/com/zgczx/config/datasoucreconfig/Db3Config.java new file mode 100644 index 0000000..0cb690c --- /dev/null +++ b/src/main/java/com/zgczx/config/datasoucreconfig/Db3Config.java @@ -0,0 +1,69 @@ +package com.zgczx.config.datasoucreconfig; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManager; +import javax.sql.DataSource; +import java.util.Map; +import java.util.Properties; + +/** + * 第三数据源的具体配置 + * 这种配置是 1.多版本的 + * @author aml + * @date 2019/10/10 10:45 + */ +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "entityManagerFactoryDb3", + transactionManagerRef = "transactionManagerDb3", + basePackages = {"com.zgczx.repository.mysql3.unifiedlogin.dao"}) // 指定该数据源操作的DAO接口包 +public class Db3Config { + + @Autowired + @Qualifier("db3DataSource") + private DataSource db3DataSource; + + //@Primary//指定主数据源 + @Bean(name = "entityManagerDb3") + public EntityManager entityManager(EntityManagerFactoryBuilder builder) { + return entityManagerFactoryDb3(builder).getObject().createEntityManager(); + } + + //@Primary + @Bean(name = "entityManagerFactoryDb3") + public LocalContainerEntityManagerFactoryBean entityManagerFactoryDb3(EntityManagerFactoryBuilder builder) { + return builder + .dataSource(db3DataSource) + .properties(getVendorProperties(db3DataSource)) + .packages("com.zgczx.repository.mysql3.unifiedlogin.model") //设置实体类所在位置 + .persistenceUnit("db3PersistenceUnit") + .build(); + } + + @Autowired + private JpaProperties jpaProperties; + + private Map getVendorProperties(DataSource dataSource) { + return jpaProperties.getHibernateProperties(dataSource); + } + + //@Primary + @Bean(name = "transactionManagerDb3") + public PlatformTransactionManager transactionManagerDb3(EntityManagerFactoryBuilder builder) { + return new JpaTransactionManager(entityManagerFactoryDb3(builder).getObject()); + } + +} \ No newline at end of file diff --git a/src/main/java/com/zgczx/config/wechatconfig/ProjectUrlConfig.java b/src/main/java/com/zgczx/config/wechatconfig/ProjectUrlConfig.java new file mode 100644 index 0000000..ef67240 --- /dev/null +++ b/src/main/java/com/zgczx/config/wechatconfig/ProjectUrlConfig.java @@ -0,0 +1,46 @@ +package com.zgczx.config.wechatconfig; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @author aml + * @date 2019/10/12 20:05 + */ +@Data +@ConfigurationProperties(prefix = "projectUrl") +@Component +public class ProjectUrlConfig { + + /** + * 微信公众平台授权url + */ + public String wechatMpAuthorize; + + /** + * 微信开放平台授权url + */ + public String wechatOpenAuthorize; + + /** + * 成绩分析系统 + */ + public String score_analysis; + + /** + * 获取公众号的AccessToken 的 URL + */ + public String AccessToken; + + /** + * 获取jsApi-ticket + */ + public String getticket; + + /** + * 用户已备案的url + */ + public String userWebURL; + +} diff --git a/src/main/java/com/zgczx/config/wechatconfig/WeChatAccountConfig.java b/src/main/java/com/zgczx/config/wechatconfig/WeChatAccountConfig.java new file mode 100644 index 0000000..5c9a233 --- /dev/null +++ b/src/main/java/com/zgczx/config/wechatconfig/WeChatAccountConfig.java @@ -0,0 +1,63 @@ +package com.zgczx.config.wechatconfig; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @author aml + * @date 2019/10/12 19:58 + */ +@Data +@Component +@ConfigurationProperties(prefix = "wechat") +public class WeChatAccountConfig { + + /** + * 公众平台id + */ + private String mpAppId; + + /** + * 公众平台密钥 + */ + private String mpAppSecret; + + /** + * 开放平台id + */ + private String openAppId; + + /** + * 开放平台密钥 + */ + private String openAppSecret; + + /** + * 商户号 + */ + private String mchId; + + /** + * 商户密钥 + */ + private String mchKey; + + /** + * 商户证书路径 + */ + private String keyPath; + + /** + * 微信支付异步通知地址 + */ + private String notifyUrl; + + /** + * 微信模版id + */ + private Map templateId; + +} diff --git a/src/main/java/com/zgczx/config/wechatconfig/WechatMpConfig.java b/src/main/java/com/zgczx/config/wechatconfig/WechatMpConfig.java new file mode 100644 index 0000000..60c7fd5 --- /dev/null +++ b/src/main/java/com/zgczx/config/wechatconfig/WechatMpConfig.java @@ -0,0 +1,36 @@ +package com.zgczx.config.wechatconfig; + +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +/** + * @author aml + * @date 2019/10/12 19:54 + */ +@Component +public class WechatMpConfig { + + @Autowired + private WeChatAccountConfig weChatAccountConfig; + + @Bean + public WxMpService wxMpService(){ + WxMpService wxMpService = new WxMpServiceImpl(); + wxMpService.setWxMpConfigStorage(wxMpConfigStorage()); + return wxMpService; + } + + public WxMpConfigStorage wxMpConfigStorage(){ + WxMpInMemoryConfigStorage wxMpInMemoryConfigStorage = new WxMpInMemoryConfigStorage(); + wxMpInMemoryConfigStorage.setAppId(weChatAccountConfig.getMpAppId()); + wxMpInMemoryConfigStorage.setSecret(weChatAccountConfig.getMpAppSecret()); + return wxMpInMemoryConfigStorage; + + } + +} diff --git a/src/main/java/com/zgczx/constans/CookieConstant.java b/src/main/java/com/zgczx/constans/CookieConstant.java new file mode 100644 index 0000000..3836bde --- /dev/null +++ b/src/main/java/com/zgczx/constans/CookieConstant.java @@ -0,0 +1,19 @@ +package com.zgczx.constans; + +/** + * Explain: cookie常量 + * @author aml + * @date 2019/11/8 21:46 + */ +public interface CookieConstant { + + /** + * token的Cookie name + */ + String TOKEN = "token"; + /** + * 过期时间 + * 单位:s + */ + Integer EXPIPE = 7200; +} diff --git a/src/main/java/com/zgczx/constans/RedisConstans.java b/src/main/java/com/zgczx/constans/RedisConstans.java new file mode 100644 index 0000000..9df2e03 --- /dev/null +++ b/src/main/java/com/zgczx/constans/RedisConstans.java @@ -0,0 +1,20 @@ +package com.zgczx.constans; + +/** + * Explain(解释):Redis常量配置 + * 过期时间等 + * @author aml + * @date 2019/11/8 21:02 + */ +public interface RedisConstans { + + /** + * token 前缀 + */ + String TOKEN_PREFIX = "token_%s"; + + /** + * 过期时间 + */ + Integer EXPIPE = 7200;// 单位:s +} diff --git a/src/main/java/com/zgczx/controller/exam/ExamController.java b/src/main/java/com/zgczx/controller/exam/ExamController.java new file mode 100644 index 0000000..fac4314 --- /dev/null +++ b/src/main/java/com/zgczx/controller/exam/ExamController.java @@ -0,0 +1,572 @@ +package com.zgczx.controller.exam; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.zgczx.VO.ResultVO; +import com.zgczx.repository.mysql1.exam.dto.*; +import com.zgczx.repository.mysql1.exam.model.Question; +import com.zgczx.repository.mysql1.exam.model.UserCollect; +import com.zgczx.repository.mysql1.exam.model.UserPaperRecord; +import com.zgczx.repository.mysql1.exam.model.UserQuestionRecord; +import com.zgczx.service.exam.ExamService; +import com.zgczx.utils.ResultVOUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.List; +import java.util.Map; + +/** + * 在线题库第一个controller + * @author aml + * @date 2019/12/11 15:40 + */ + +@Api(description = "第一个exam模块") +@RestController +@RequestMapping("/exam") +@Slf4j +public class ExamController { + + @Autowired + private ExamService examService; + + @ApiOperation(value = "一、 读取Word中的内容并生成json串处理") + @PostMapping("/parseWord") + public ResultVO parseWord( + @ApiParam(value = "file文件", required = true) + @RequestParam("filename")MultipartFile file, + HttpSession session, HttpServletRequest request){ + + String text = examService.parseWord(file,session,request); + + return ResultVOUtil.success(text); + } + + @ApiOperation(value = "二、 获取此科目此年级的所有章目") + @GetMapping("/getAllChapter") + public ResultVO getAllChapter( + @ApiParam(value = "levelName年级水平", required = true) + @RequestParam("levelName") String levelName, + @ApiParam(value = "subject科目名称", required = true) + @RequestParam("subject") String subject + ){ + List list = examService.getAllChapter(levelName,subject); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "三、 获取此科目此年级所有的 小节名称") + @GetMapping("/getAllSection") + public ResultVO getAllSection( + @ApiParam(value = "levelName年级水平", required = true) + @RequestParam("levelName") String levelName, + @ApiParam(value = "chapter具体章名称", required = true) + @RequestParam("chapter") String chapter, + @ApiParam(value = "subject科目名称", required = true) + @RequestParam("subject") String subject + ){ + List list = examService.getAllSection(levelName,chapter,subject); + + return ResultVOUtil.success(list); + } + + + @ApiOperation(value = "四、 将一试卷切分为一道道题存入题库表中") + @GetMapping("/splitExam") + public ResultVO splitExam( + @ApiParam(value = "试卷全称", required = true) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject + ){ + List list = examService.splitExam(examName,subject); + + return ResultVOUtil.success(list); + } + + + @ApiOperation(value = "# 2.8 模拟考试、章节练习 + 年级,五、 根据科目和考试名称返回所有题的信息数据") + @GetMapping("/findExamQuestionInfo") + public ResultVO findExamQuestionInfo( + @ApiParam(value = "试卷全称", required = true) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel + ){ + List list = examService.findExamQuestionInfo(examName,subject,studentNumber,openid,gradeLevel); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "#2.8 章节、模拟:六、【属于做一道题后,做题记录跟着变化】动态实时呈现用户做题详情 并记录用户所有的做题情况") + @GetMapping("/doQuestionInfo") + public ResultVO doQuestionInfo( + @ApiParam(value = "哪道题:题库表的主键id", required = true) + @RequestParam("id") int id, + @ApiParam(value = "studentNumber用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户学号", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "commitString一道题提交的内容", required = true) + @RequestParam("commitString") String commitString, + @ApiParam(value = "试卷全称", required = true) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "试卷id", required = true) + @RequestParam("sourcePaperId") int sourcePaperId, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel, + @ApiParam(value = "做题时间",required = true) + @RequestParam("doTime") String doTime + ){ + DoQuestionInfoDTO list = examService.judgeQuestionRight(id,studentNumber,openid,commitString,examName,subject,sourcePaperId,gradeLevel,doTime); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "七、记录用户的收藏情况 ") + @GetMapping("/insertCollect") + public ResultVO insertCollect( + @ApiParam(value = "哪道题:题库表的主键id", required = true) + @RequestParam("id") int id, + @ApiParam(value = "studentNumber用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户学号", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "分类名称", required = true) + @RequestParam("classification") String classification +// @ApiParam(value = "这道题提交的内容", required = true) +// @RequestParam("commitString") String commitString +// @ApiParam(value = "试卷全称", required = true) +// @RequestParam("paperName") String examName, +// @ApiParam(value = "科目名称", required = true) +// @RequestParam("subject") String subject + ){ + //UserCollect list = examService.insertCollect(id,studentNumber,openid,classification,commitString);//,examName,subject + UserCollect list = examService.insertCollect(id,studentNumber,openid,classification); + return ResultVOUtil.success(list); + } + //3.29 此接口暂时无用 + @ApiOperation(value = "八、【不做题时查看】用户做题详情;需求:点击类似做题页面的键盘,出现的正确、错误、未做数量 ") + @GetMapping("/getDoQuestionInfo") + public ResultVO getDoQuestionInfo( + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户学号", required = true) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "试卷id", required = true) + @RequestParam("sourcePaperId") int sourcePaperId + ){ + + DoQuestionInfoDTO list = examService.getDoQuestionInfo(studentNumber,examName,subject,sourcePaperId); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "九、回显这个用户最近做的章节练习情况 ") + @GetMapping("/echoDoQuestionInfo") + public ResultVO echoDoQuestionInfo( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "试卷名称", required = true) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject + ){ + + List list = examService.echoDoQuestionInfo(studentNumber,examName,subject); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "#2.1 兼容错题本中没有试卷名称情况:十、取消收藏 ") + @GetMapping("/cancelCollect") + public ResultVO cancelCollect( + @ApiParam(value = "哪道题:题库表的主键id", required = true) + @RequestParam("id") int id, + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "试卷名称", required = false) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "取消收藏传值为 2", required = true) + @RequestParam("cancel") int cancel + ){ + + UserCollect list = examService.cancelCollect(id,studentNumber,openid,examName,subject,cancel); + + return ResultVOUtil.success(list); + } + + + @ApiOperation(value = "十一、 用户整套试卷(一节题)的记录") + @PostMapping("/fullPaperRecord") + public ResultVO fullPaperRecord( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "试卷名称", required = true) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "此试卷的所有内容(为了记录此时每道题的选项内容)", required = true) + @RequestParam("examPaperContent") String examPaperContent, + @ApiParam(value = "此时卷用户的答题信息", required = true) + @RequestParam("examPaperAnwer") String examPaperAnwer + ){ + + UserPaperRecord userPaperRecord = examService.fullPaperRecord(studentNumber,openid,examName,subject,examPaperContent,examPaperAnwer); + return ResultVOUtil.success(userPaperRecord); + } + + @ApiOperation(value = "十二、点击练习错题(考试错题)时,展现已掌握和未掌握的章名称和对应错题数(已掌握和未掌握的考试错题数) ") + @GetMapping("/getChapterErrNumber") + public ResultVO getChapterErrNumber( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "试卷类型 1:练习;2:考试", required = true) + @RequestParam("examCategory") String examCategory + ){ + + JSONObject list = examService.getChapterErrNumber(studentNumber,openid,subject, examCategory); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "十三、将用户最近做的此试卷信息回显给用户 ") + @GetMapping("/echoPaperInfo") + public ResultVO echoPaperInfo( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "试卷名称", required = true) + @RequestParam("paperName") String examName + ){ + + List list = examService.echoPaperInfo(studentNumber,openid,subject,examName); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "十四、查询某个用户是否收藏过某道题 ") + @GetMapping("findCollectInfo") + public ResultVO findCollectInfo( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "哪道题:题库表的主键id", required = true) + @RequestParam("question_id") int questionId + ){ + FindCollectDTO list = examService.findCollectInfo(studentNumber,subject,questionId); + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "十五、获取此章下面的所有节的名称和对应的错题数量 ") + @GetMapping("/getSectionErrNumber") + public ResultVO getSectionErrNumber( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "章的名称", required = true) + @RequestParam("chapterName") String chapterName, + @ApiParam(value = "是否已掌握",required = true) + @RequestParam("ifMastered") String ifMastered + ){ + + SectionErrNumberDTO list = examService.getSectionErrNumber(studentNumber,openid,subject,chapterName, ifMastered); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "# 1.14 十六、错题本:获取某类别所有未掌握(已经掌握)题的所有情况 ") + @GetMapping("/getNotMasteredInfo") + public ResultVO getNotMasteredInfo( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "分类:章节练习", required = true) + @RequestParam("examCategory") String examCategory, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel, + @ApiParam(value = "掌握还是未掌握:1为掌握;2为未掌握",required = true) + @RequestParam("master") int master + ){ + + JSONObject jsonArray = examService.getNotMasteredInfo(studentNumber,openid,subject,examCategory,gradeLevel,master); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "# 1.15 十七、错题本中的 下面的分类详情 ") + @GetMapping("/getClassification") + public ResultVO getClassification( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "分类:章节练习", required = true) + @RequestParam("examCategory") String examCategory, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel, + @ApiParam(value = "掌握还是未掌握:1为掌握;2为未掌握",required = true) + @RequestParam("master") int master + ){ + JSONObject jsonArray = examService.getClassification(studentNumber,openid,subject,examCategory,gradeLevel,master); + return ResultVOUtil.success(jsonArray); + } + + + @ApiOperation(value = "# 1.14 十八、错题本:统计分类中 未掌握或已掌握的 各分类的数量 ") + @GetMapping("/getClassificationQuantity") + public ResultVO getClassificationQuantity( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel, + @ApiParam(value = "掌握还是未掌握:1为掌握;2为未掌握",required = true) + @RequestParam("master") int master + ){ + + JSONObject jsonArray = examService.getClassificationQuantity(studentNumber,openid,subject,gradeLevel,master); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "# 1. 31十九、错题本:根据题库id获取此题的所有信息 ") + @GetMapping("/getQuestionInfo") + public ResultVO getQuestionInfo( + @ApiParam(value = "题库主键id", required = true) + @RequestParam("id") int id, + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid +// @ApiParam(value = "科目名称", required = true) +// @RequestParam("subject") String subject, +// @ApiParam(value = "年级",required = true) +// @RequestParam("gradeLevel") String gradeLevel + ){ + + JSONObject jsonArray = examService.getQuestionInfo(id,studentNumber,openid); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "# 2.3 二十、专项练习:获取此年级、科目的所有知识点 ") + @GetMapping("/getAllKnowledge") + public ResultVO getAllKnowledge( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel + ){ + + JSONObject jsonArray = examService.getAllKnowledge(studentNumber,openid,subject,gradeLevel); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "# 2.3 二十一、专项练习:根据知识点获取所有相关的题 ") + @GetMapping("/getAllQuestionByPoint") + public ResultVO getAllQuestionByPoint( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel, + @ApiParam(value = "知识点", required = true) + @RequestParam("knowledgePoint") String knowledgePoint + ){ + + JSONArray jsonArray = examService.getAllQuestionByPoint(studentNumber,openid,subject,gradeLevel,knowledgePoint); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "# 2.4 二十二、专项练习:记录用户此题到 用户记录表中 ") + @PostMapping("/specialRecordId") + public ResultVO specialRecordId( + @ApiParam(value = "哪道题:题库表的主键id", required = true) + @RequestParam("id") int id, + @ApiParam(value = "studentNumber用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户学号", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "commitString一道题提交的内容", required = true) + @RequestParam("commitString") String commitString, + @ApiParam(value = "专项练习", required = true) + @RequestParam("examCategory") String examCategory, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, +// @ApiParam(value = "试卷id", required = true) +// @RequestParam("sourcePaperId") int sourcePaperId, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel, + @ApiParam(value = "做题时间",required = true) + @RequestParam("doTime") String doTime + ){ + JSONObject list = examService.specialRecordId(id,studentNumber,openid,commitString,examCategory,subject,gradeLevel,doTime); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "# 2.7 二十三、历年真题、模拟考试:获取此年级、科目的分類的各个考试名称和题数 ") + @GetMapping("/getAllExamName") + public ResultVO getAllExamName( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel, + @ApiParam(value = "模拟考试、历年真题", required = true) + @RequestParam("examCategory") String examCategory + ){ + + JSONObject jsonArray = examService.getAllExamName(studentNumber,openid,subject,gradeLevel,examCategory); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "二十四、首页面中继续学习-仅章节练习 ") + @GetMapping("/continueLearn") + public ResultVO continueLearn( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject + ){ + + JSONObject list = examService.continueLearn(studentNumber,openid,subject); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "# 2.23 英语四六级套卷(真题、模拟)二十五、 根据科目和考试名称+年级返回所有题(套卷)的信息数据") + @GetMapping("/findCoiliInfo") + public ResultVO findCoiliInfo( + @ApiParam(value = "试卷全称", required = true) + @RequestParam("paperName") String examName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel + ){ + JSONObject list = examService.findCoiliInfo(examName,subject,studentNumber,openid,gradeLevel); + + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "# 3.3 二十六、“我的收藏”:统计分类中 各分类的数量 ") + @GetMapping("/getcollectClassifyQuantity") + public ResultVO getcollectClassifyQuantity( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel + ){ + + JSONObject jsonArray = examService.getcollectClassifyQuantity(studentNumber,openid,subject,gradeLevel); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "# 3.3 二十七、“我的收藏”:获取某类别所有题的所有情况 ") + @GetMapping("/getcollectMasteredInfo") + public ResultVO getcollectMasteredInfo( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "分类:章节练习", required = true) + @RequestParam("examCategory") String examCategory, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel + ){ + + JSONObject jsonArray = examService.getcollectMasteredInfo(studentNumber,openid,subject,examCategory,gradeLevel); + + return ResultVOUtil.success(jsonArray); + } + + @ApiOperation(value = "# 3.9 二十八、“生物学号校验”:校验能做中关村生物的学生 ") + @GetMapping("/checkStudentNumber") + public ResultVO checkStudentNumber( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("gradeLevel") String gradeLevel + ){ + + JSONObject jsonArray = examService.checkStudentNumber(studentNumber,openid,subject,gradeLevel); + + return ResultVOUtil.success(jsonArray); + } +} diff --git a/src/main/java/com/zgczx/controller/exam/ExamTwoController.java b/src/main/java/com/zgczx/controller/exam/ExamTwoController.java new file mode 100644 index 0000000..7358fce --- /dev/null +++ b/src/main/java/com/zgczx/controller/exam/ExamTwoController.java @@ -0,0 +1,358 @@ +package com.zgczx.controller.exam; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.zgczx.VO.ResultVO; +import com.zgczx.service.exam.ExamTwoService; +import com.zgczx.utils.ResultVOUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 在线题库第二个controller + * @author lxj + * @date 2019/12/29 + */ + +@Api(description = "第二个exam模块") +@RestController +@RequestMapping("/exam-two") +@Slf4j +public class ExamTwoController { + + @Autowired + private ExamTwoService examTwoService; + + @ApiOperation(value = "一、统计错题数") + @GetMapping("/getErrorProblemsNum") + public ResultVO getErrorProblemsNum( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称",required = true) + @RequestParam("subject") String subject + ){ + Map errorProblemsNum=examTwoService.getErrorProblemsNum(studentNumber,openid,subject); + return ResultVOUtil.success(errorProblemsNum); + } + + @ApiOperation(value="二、统计收藏题数") + @GetMapping("/getCollectProblemsNum") + public ResultVO getCollectProblemsNum( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称",required = true) + @RequestParam("subject") String subject + ){ + Map collectProblemsNum=examTwoService.getCollectProblemsNum(studentNumber,openid,subject); + return ResultVOUtil.success(collectProblemsNum); + } + + @ApiOperation(value = "三、我的收藏页面中,默认选择练习题收藏(包括章 和对应的收藏题数),选择考试题收藏时,显示考试名称和对应收藏题数 ") + @GetMapping("/getChapterCollectNumber") + public ResultVO getCollectNumber( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value="题来源",required=true) + @RequestParam("category") String category + ){ + Map getCollectNums=examTwoService.getCollectProblemsNum(studentNumber,openid,subject,category); + return ResultVOUtil.success(getCollectNums); + } + + @ApiOperation(value = "四、 练习题收藏:点击某一章,查询该章包含的节的名称 和对应收藏题数") + @GetMapping("/getSectionCollectNumber") + public ResultVO getSectionsCollectNum( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value="章节名称",required=true) + @RequestParam("chapter") String chapter + ){ + Map getSectionsAndCollectNum=examTwoService.getCollectProblemsNumByChapter(studentNumber,openid,subject,chapter); + return ResultVOUtil.success(getSectionsAndCollectNum); + } + + @ApiOperation(value="五、 练习题收藏:点击章、节显示 此小节收藏题的详细信息") + @GetMapping("/getChapterCollectProblems") + public ResultVO getChapterCollectProblems( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value="章节名称",required=true) + @RequestParam("chapter") String chapter, + @ApiParam(value="小节名称",required=true) + @RequestParam("section") String section + ){ + JSONArray sectionCollectProblems=examTwoService.getSectionCollectProblems(studentNumber, openid, subject, chapter, section); + return ResultVOUtil.success(sectionCollectProblems); + } + + @ApiOperation(value = "六、 考试题收藏:点击某次考试,显示收藏的本次考试题的详细信息") + @GetMapping("/getExamCollectProblems") + public ResultVO getExamCollectProblems( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value="考试名称",required=true) + @RequestParam("examName") String examName + ){ + JSONArray examCollectProblems=examTwoService.getExamCollectProblems(studentNumber,openid,subject,examName); + return ResultVOUtil.success(examCollectProblems); + } + + @ApiOperation(value = "七、 练习错题:点击章、节显示 此小节错题的详细信息") + @GetMapping("/getSectionErrorProblems") + public ResultVO getSectionErrorProblems( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value="章名称",required=true) + @RequestParam("chapter") String chapter, + @ApiParam(value="节名称",required=true) + @RequestParam("section") String section, + @ApiParam(value = "是否掌握(已掌握/未掌握)",required = true) + @RequestParam("ifMastered") String ifMastered + ){ + JSONArray examErrorProblems=examTwoService.getErrorProblemsByChapterAndSection(studentNumber,openid,subject,chapter,section,ifMastered); + return ResultVOUtil.success(examErrorProblems); + } + + @ApiOperation(value = "八、 考试错题:点击某次考试,显示本次考试错题的详细信息") + @GetMapping("/getExamErrorProblems") + public ResultVO getExamErrorProblems( + @ApiParam(value = "用户学号", required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject, + @ApiParam(value="考试名称",required=true) + @RequestParam("examName") String examName, + @ApiParam(value = "是否掌握(已掌握/未掌握)",required = true) + @RequestParam("ifMastered") String ifMastered + ){ + JSONArray examErrorProblems=examTwoService.getErrorProblemsByExamName(studentNumber,openid,subject,examName,ifMastered); + return ResultVOUtil.success(examErrorProblems); + } + + @ApiOperation(value="九、 删除已掌握错题中的某道题") + @PostMapping("/deleteMasteredQuestions") + public ResultVO deleteMasteredQuestions( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "删除题号id",required = true) + @RequestParam("questionId") int questionId, + @ApiParam(value = "删除题来源(1.练习错题,2.考试错题)",required = false) + @RequestParam("questionSource") String questionSource + ){ + Map deleteMasterQuesiotns=examTwoService.deleteMasteredQuestions(studentNumber, openid,subject, questionId, questionSource); + return ResultVOUtil.success(deleteMasterQuesiotns); + } + + @ApiOperation(value="十、 做错题中未掌握的题,正确进入已掌握") + @PostMapping("/doNotMasteredQuestions") + public ResultVO doNotMasteredQuestions( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "题号(针对所有题)",required = true) + @RequestParam("questionId") int questionId, + @ApiParam(value = "题来源(1.练习错题,2.考试错题)",required = true) + @RequestParam("questionSource") String questionSource, + @ApiParam(value = "用户答案",required = true) + @RequestParam("userAnswer") String userAnswer, + @ApiParam(value = "试卷id",required = true) + @RequestParam("examPaperId") int examId, + @ApiParam(value = "试卷名称",required = true) + @RequestParam("examPaperName") String examName + ){ + Map map=examTwoService.doNotMasteredQuestions(studentNumber, openid, subject, questionId, questionSource, userAnswer, examId, examName); + return ResultVOUtil.success(map); + } + + @ApiOperation(value = "十一、 专项练习:知识点中根据年级和科目统计每章的题数") + @GetMapping("/getQuestionsNumsByChapter") + public ResultVO getQuestionsNumsByChapter( + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName + ){ + Map map=examTwoService.getQuestionsByChapterAndSubject(subject,levelName); + return ResultVOUtil.success(map); + } + + @ApiOperation(value = "十二、 专项练习:知识点中每章下所有知识点及对应的题数") + @GetMapping("/getQuestionsNumsByAttributr") + public ResultVO getQuestionsNumsByAttributr( + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName, + @ApiParam(value = "章名称",required = true) + @RequestParam("chapter") String chapter + ){ + Map map=examTwoService.getQuestionsNumsByAttribute(subject, levelName, chapter); + return ResultVOUtil.success(map); + } + + @ApiOperation(value = "十三、 专项练习:根据章名称 和知识点查看题的详细信息") + @GetMapping("/getQuestionsByQuestionsAttribute") + public ResultVO getQuestionsByQuestionsAttribute( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "章名称",required = true) + @RequestParam("chapter") String chapter, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName, + @ApiParam(value = "知识点",required = true) + @RequestParam("questionAttribute") String questionAttribute + ){ + JSONArray arr=examTwoService.getQuestionsByQuestionsAttribute(studentNumber, openid, subject, levelName, chapter, questionAttribute); + return ResultVOUtil.success(arr); + } + + @ApiOperation(value = "#1.27 十四、 根据学科和年级统计用户做题记录") + @GetMapping("/getDoQuestionRecord") + public ResultVO getDoQuestionRecord( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName, + @ApiParam(value = "筛选的开始时间",required = false) + @RequestParam("starTime") String starTime, + @ApiParam(value = "筛选的截止时间",required = false) + @RequestParam("endTime") String endTime + + ){ + JSONArray array = examTwoService.getDoQUestionRecord(studentNumber, openid,subject,levelName,starTime,endTime); + return ResultVOUtil.success(array); + } + + @ApiOperation(value = "#1.27 十五、 做题记录:关于某一份试卷/章节/知识点做题详情(做题时间、题难易度等)") + @GetMapping("/getDoQuestionRecordDetail") + public ResultVO getDoQuestionRecordDetail( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName, + @ApiParam(value = "试卷名称(章节名称/知识点)",required = true) + @RequestParam("examName") String examName, + @ApiParam(value = "来源:章节练习、模拟考试、专项练习等",required = true) + @RequestParam("source") String source + ){ + JSONArray arr=examTwoService.getDoQuestionRecordDetail(studentNumber,openid,subject,levelName,examName, source); + + return ResultVOUtil.success(arr); + } + + @ApiOperation(value = "十六、 学习记录:统计做题数") + @GetMapping("getDoQuestionsCount") + public ResultVO getDoQuestionsCount( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName + ){ + JSONArray arr=examTwoService.getDoQuestionsCount(studentNumber,openid,subject,levelName); + return ResultVOUtil.success(arr); + } + + @ApiOperation(value = "十七、 学习记录:统计错题和收藏总数") + @GetMapping("/getWrongCollectQuestionsCount") + public ResultVO getWrongCollectQuestionsCount( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName + ){ + Map map=examTwoService.getWrongCollectQuestionsCount(studentNumber,openid,subject,levelName); + return ResultVOUtil.success(map); + } + + @ApiOperation(value="#3.3 十八、 学习记录:按天统计做题正确率和做题时长") + @GetMapping("/getRightRateAndClassHours") + public ResultVO getRightRateAndClassHours( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName + ){ + JSONArray arr=examTwoService.getRightRateAndClassHours(studentNumber,openid,subject,levelName); + return ResultVOUtil.success(arr); + } + + @ApiOperation(value="十九、 学习记录:上面三个数的统计") + @GetMapping("/getPracticeRecord") + public ResultVO getPracticeRecord( + @ApiParam(value = "用户学号",required = true) + @RequestParam("studentNumber") String studentNumber, + @ApiParam(value = "用户openid",required = true) + @RequestParam("openid") String openid, + @ApiParam(value = "学科",required = true) + @RequestParam("subject") String subject, + @ApiParam(value = "年级",required = true) + @RequestParam("levelName") String levelName + ){ + JSONObject json=examTwoService.getPracticeRecord(studentNumber,openid,subject,levelName); + return ResultVOUtil.success(json); + } +} diff --git a/src/main/java/com/zgczx/controller/exam/PaperSplitController.java b/src/main/java/com/zgczx/controller/exam/PaperSplitController.java new file mode 100644 index 0000000..0ea8324 --- /dev/null +++ b/src/main/java/com/zgczx/controller/exam/PaperSplitController.java @@ -0,0 +1,306 @@ +package com.zgczx.controller.exam; + +import com.alibaba.fastjson.JSONObject; +import com.zgczx.VO.ResultVO; +import com.zgczx.repository.mysql1.exam.dao.*; +import com.zgczx.repository.mysql1.exam.model.Chapter; +import com.zgczx.repository.mysql1.exam.model.ExamContent; +import com.zgczx.repository.mysql1.exam.model.ExamPaper; +import com.zgczx.repository.mysql1.exam.model.Question; +import com.zgczx.repository.mysql3.unifiedlogin.dao.UserLoginDao; +import com.zgczx.service.exam.PaperSplitService; +import com.zgczx.utils.Excel2BeanList; +import com.zgczx.utils.ResultVOUtil; +import io.swagger.annotations.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static com.zgczx.utils.FilterStringUtil.filterChineseAndMath; +import static com.zgczx.utils.FilterStringUtil.filterspecial; +import static com.zgczx.utils.WordRedUtil.readWord; + +/** + * @author aml + * @date 2019/12/27 15:31 + */ +@Api(description = "word解析为题库模块") +@RestController +@RequestMapping("/word") +@Slf4j +public class PaperSplitController { + + @Autowired + private ChapterDao chapterDao; + + @Autowired + private QuestionDao questionDao; + + @Autowired + private ExamPaperDao examPaperDao; + + @Autowired + private UserQuestionRecordDao userQuestionRecordDao; + + @Autowired + private UserCollectDao userCollectDao; + + @Autowired + private ExamContentDao examContentDao; + + @Autowired + private UserPaperRecordDao userPaperRecordDao; + + @Autowired + private UserLoginDao userLoginDao; + + @Autowired + private PaperSplitService paperSplitService; + + private String info; + + + @ApiOperation(value = "一、 读取Word中的内容并生成json串处理") + @PostMapping("/parseWord2") + public ResultVO parseWord2( + @ApiParam(value = "file文件", required = true) + @RequestParam("filename") MultipartFile file, + HttpSession session, HttpServletRequest request) throws Exception{ + + String text = null; + + JSONObject docJson = readWord(file); + text = String.valueOf(docJson.get("doctext")); + String title = filterChineseAndMath(String.valueOf(docJson.get("title"))); + String imgList = String.valueOf(docJson.get("imgList")); + + +// 1. 将试卷读进去 + ExamContent examContent = new ExamContent(); + examContent.setContent(text); + examContent.setExamName(title); + examContent.setSubject("生物"); + ExamContent save = examContentDao.save(examContent); + String[] split = save.getContent().split("#");// + for (String string : split) { + + } +// // 2. 将答案读进去 +// ExamContent examContent = examContentDao.findOne(2); +// examContent.setAnswer(text); +// examContentDao.save(examContent); + System.out.println("打印text: " + text); + + ResultVO resultVO = splitPaper(save.getExamName(), save.getSubject()); + log.info("【打印出结果:】{}",resultVO.getData()); + + + return ResultVOUtil.success(text); + } + + + @ApiOperation(value = " 将一试卷切分为一道道题存入题库表中") + @GetMapping("/splitPaper") + @Transactional + public ResultVO splitPaper( + @ApiParam(value = "试卷全称", required = true) + @RequestParam("paperName") String paperName, + @ApiParam(value = "科目名称", required = true) + @RequestParam("subject") String subject + ) { + ExamContent examContent = examContentDao.findByExamNameAndSubject(paperName, subject); +// String[] split = examContent.getContent().split("#"); + + // 1. 获取使用年级 + String content = examContent.getContent();//获取Word中的所有数据 + int gradeStartIndex = content.indexOf("【适用年级】"); + int gradeEndIndex = content.indexOf("一、选择题"); + String gradeLevel = content.substring(gradeStartIndex + 6, gradeEndIndex); + + String[] split = content.split("#"); + log.info("[split: ]{}", split); + // 2. 确定此Word是章节练习还是模拟考试 + String wordType = split[0]; + String paperType = null; + if (wordType.contains("节")) { + paperType = "章节练习"; + } else { + paperType = "模拟练习"; + } + + List idList = new ArrayList<>(); + for (int i = 1; i < split.length; i++) { + Question question = new Question(); + String s = filterspecial(split[i]);//过滤下\t,\n等字符 + log.info("【去除t,n等字符的每道题的内容】: {}", s); + int anwerIndex = s.indexOf("【答案】");//此题的答案索引位置 + String itemOption = s.substring(0, anwerIndex);//题干+选项 + question.setQuestionContext(itemOption); + int analysisIndex = s.indexOf("【解析】");// 此题的解析索引位置 + String anwerOption = s.substring(analysisIndex - 1, analysisIndex);// 答案选项 + question.setCorrectOption(anwerOption); + //正确的答案文本 + /* int i1 = s.indexOf("A."); + int i2 = s.indexOf("B."); + int i3 = s.indexOf("C."); + int i4 = s.indexOf("D.");*/ + int i1 = -1; + if (s.indexOf("A.") != -1) { + i1 = s.indexOf("A."); + } else { + i1 = s.indexOf("A."); + } + int i2 = -1; + if (s.indexOf("B.") != -1) { + i2 = s.indexOf("B."); + } else { + i2 = s.indexOf("B."); + } + int i3 = -1; + if (s.indexOf("C.") != -1) { + i3 = s.indexOf("C."); + } else { + i3 = s.indexOf("C."); + } + int i4 = -1; + if (s.indexOf("D.") != -1) { + i4 = s.indexOf("D."); + } else { + i4 = s.indexOf("D."); + } + String contentA = s.substring(i1 + 2, i2);//A选项 + String contentB = s.substring(i2 + 2, i3);//B选项 + String contentC = s.substring(i3 + 2, i4);//C选项 + String contentD = s.substring(i4 + 2, anwerIndex);//D选项 + if (anwerOption.trim().equals("A")) { + question.setCorrectText(contentA);//正确答案的文本 + } else if (anwerOption.trim().equals("B")) { + question.setCorrectText(contentB);//正确答案的文本 + } else if (anwerOption.trim().equals("C")) { + question.setCorrectText(contentC);//正确答案的文本 + } else { + question.setCorrectText(contentD);//正确答案的文本 + } + + int knowledgePointsIndex = s.indexOf("【知识点】");// 知识点索引位置 + String analysisText = s.substring(analysisIndex, knowledgePointsIndex);//此题的解析文本 + question.setCorrectAnalysis(analysisText); + int difficultyIndex = s.indexOf("【难易程度】");// 难易程度索引位置 + String knowledgePoint = s.substring(knowledgePointsIndex + 5, difficultyIndex);//此题的知识点属性 + question.setQuestionAttribute(knowledgePoint); + int cognition = s.indexOf("【认知层次】");// 认知层次索引位置 + String difficultyText = s.substring(difficultyIndex + 6, cognition);//此题的难易程度 + question.setQuestionDifficult(difficultyText); + String cognitionText = s.substring(cognition + 6, s.length());//此题的认知层次 + question.setCognitiveLevel(cognitionText); + + // 还剩下一个 图片的字段没存了 + + question.setExamLocation("北京"); + question.setQuestionType("单选"); + question.setQuestionSource(paperType); + question.setExamName(examContent.getExamName()); + question.setSubject(examContent.getSubject()); + question.setValid(1); + question.setLevelName(gradeLevel);// 适用年级: 例如:高1 + + Question save = questionDao.save(question); + + idList.add(save.getId());// 将每个题 在题库表的主键id存放到list中去 + } + // 将数据存到 exampaer中,试卷中 + ExamPaper examPaper = new ExamPaper(); + String examName = examPaper.getExamName(); +// String[] split1 = examName.split(","); + String[] split1 = null; + if (wordType.contains(",")){ + split1 = wordType.split(","); + }else if (wordType.contains(",")){ + split1 = wordType.split(","); + } + + String string = split1[1]; + int gradeIndex = string.indexOf("【适用年级】"); + String sectionString = string.substring(0, gradeIndex); + + // 将数据存入chapter中,章节中 + Chapter chapter = new Chapter(); + chapter.setSubject("生物"); + chapter.setSubjectId(6); + chapter.setChapter(split1[0]); + chapter.setSection(sectionString); + chapter.setLevelName(gradeLevel); + Chapter chapterSave = chapterDao.save(chapter); + + examPaper.setExamName(sectionString); + examPaper.setQuestionList(String.valueOf(idList)); + examPaper.setExamSource(paperType); + examPaper.setExamLocation("北京"); + examPaper.setSubject("生物"); + examPaper.setSubjectId(6); + examPaper.setQuestionCount(idList.size()); + examPaper.setExamContentId(examContent.getId()); + examPaper.setExamContent(content); + examPaper.setGradeLevel(gradeLevel); + examPaper.setChapterId(chapterSave.getId()); + examPaper.setValid(1); + + ExamPaper examPaperSave = examPaperDao.save(examPaper); + + int ids = questionDao.updateByIds(idList, examPaperSave.getId()); + log.info("【共修改的条数:】{}", ids); +// examPaper.setExamName(); + + + return ResultVOUtil.success(idList); + } + + @ApiOperation(value = "用户信息批量录入", notes = "根据excel文件进行用户信息批量录入") + @ApiImplicitParams({ + @ApiImplicitParam(name = "file_url", value = " 文件服务器地址 ", required = true, dataType = "__file", paramType = "form")//不是 file,而是双下划线“__file”:原因是版本不一样:dataType = "__file" + }) + @RequestMapping(value = "/batchAddUser", method = RequestMethod.POST) + public JSONObject batchAddUser(HttpServletResponse response, HttpServletRequest request) throws Exception { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; // 将普通请求转换为文件请求 + Map fileMap = multipartRequest.getFileMap(); // 获取所有上传的文献集合,数量不限 + List> content = new ArrayList<>(); + for (Map.Entry entity : fileMap.entrySet()) { // 遍历单个文件 + MultipartFile mf = entity.getValue(); + try { + content = Excel2BeanList.readExcel(mf, 33); // 33指excel中的最大列数,可以根据需要调整 + + } catch (IOException e) { + e.printStackTrace(); + JSONObject json_store = new JSONObject(); + json_store.put("errno", "001"); + json_store.put("errmsg", "批量插入用户信息失败!"); + return json_store; + } + } + JSONObject jsonRespond = paperSplitService.batchAddUser(content); + + return jsonRespond; + } + + @ApiOperation(value = "#3.9 批量更新,根据学校提供的数据 更新统一登录中的相同姓名 学号") + @GetMapping("/updateAll") + public ResultVO updateAll(){ + + JSONObject list = paperSplitService.updateAll(); + + return ResultVOUtil.success(0); + } + + +} diff --git a/src/main/java/com/zgczx/controller/exam/WordToQuestionController.java b/src/main/java/com/zgczx/controller/exam/WordToQuestionController.java new file mode 100644 index 0000000..fba6bf2 --- /dev/null +++ b/src/main/java/com/zgczx/controller/exam/WordToQuestionController.java @@ -0,0 +1,152 @@ +package com.zgczx.controller.exam; + +import com.zgczx.VO.ResultVO; +import com.zgczx.repository.mysql1.exam.dao.*; +import com.zgczx.repository.mysql3.unifiedlogin.dao.UserLoginDao; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.docx4j.openpackaging.packages.WordprocessingMLPackage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author aml + * @date 2020/1/3 14:18 + */ +@Api(description = "word解析为题库模块二") +@RestController +@RequestMapping("/word2") +@Slf4j +public class WordToQuestionController { + + @Autowired + private ChapterDao chapterDao; + + @Autowired + private QuestionDao questionDao; + + @Autowired + private ExamPaperDao examPaperDao; + + @Autowired + private UserQuestionRecordDao userQuestionRecordDao; + + @Autowired + private UserCollectDao userCollectDao; + + @Autowired + private ExamContentDao examContentDao; + + @Autowired + private UserPaperRecordDao userPaperRecordDao; + + @Autowired + private UserLoginDao userLoginDao; + + private String info; + + + @ApiOperation(value = "一、 读取Word中的内容并生成json串处理") + @PostMapping("/parseWord2") + public ResultVO parseWord2( + @ApiParam(value = "file文件", required = true) + @RequestParam("filename") MultipartFile file, + HttpSession session, HttpServletRequest request) throws Exception { + + InputStream in = file.getInputStream();//将Word文件转换为字节流 + +// InputStream in = new FileInputStream(file.getOriginalFilename());//将Word文件转换为字节流 + + WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(in); + //获取word所有内容 + List list = wordMLPackage.getMainDocumentPart().getContent(); + //将文件中的内容分隔成每一道题 + List> questionMapList = getSubjectList(list); + + log.info("【打印:】{}", questionMapList); + return null; + } + + /** + * 将word中的题目分割成list放入List + * + * @param list + * @return + */ + private List> getSubjectList(List list) { + List> subjectList = new ArrayList>(); + List stringList = new ArrayList<>(); + StringBuffer subjectItem = new StringBuffer(); + int count = 0; + int qNum = 0; + //划分题目 + //以数字开头并且包含.表示一个新的题目开始 + String regex = "^\\d{1,100}\\."; + Pattern pattern = Pattern.compile(regex); + Matcher m = null; + Map tempMap = new HashMap(); + String qtype = ""; + String oldQtype = ""; + String line = ""; + int titleNumber = 0; + for (int i = 0; i < list.size(); i++) { + line = list.get(i).toString(); + m = pattern.matcher(line); + if (m.find()) {//题干 + count++; + + if (qNum > 0) {//不是文件文件第一个题干,将之前的buffer保存 + + tempMap = new HashMap(); +// tempMap.put("qtype", oldQtype);//这个是这道题的类型:单选、多选等 + tempMap.put(String.valueOf(qNum), subjectItem.toString()); + subjectList.add(tempMap); + + subjectItem = new StringBuffer(); + subjectItem.append(line); + + } else {//文件第一个题干,创建新的buffer,并将题干放入buffer +// if (subjectItem != null){ +// tempMap = new HashMap(); +//// tempMap.put("qtype", oldQtype);//这个是这道题的类型:单选、多选等 +// tempMap.put(String.valueOf(0), subjectItem.toString()); +// subjectList.add(tempMap); +// }else { + subjectItem = new StringBuffer(); + subjectItem.append(line); +// } + } + qNum++; + + }else { + + subjectItem.append(line); + + } + + + + } + return subjectList; + } + + +} diff --git a/src/main/java/com/zgczx/controller/score/ScoreController.java b/src/main/java/com/zgczx/controller/score/ScoreController.java index 57320b0..534c275 100644 --- a/src/main/java/com/zgczx/controller/score/ScoreController.java +++ b/src/main/java/com/zgczx/controller/score/ScoreController.java @@ -1,20 +1,22 @@ package com.zgczx.controller.score; import com.zgczx.VO.ResultVO; -import com.zgczx.dataobject.score.ExamCoversionTotal; -import com.zgczx.dataobject.score.ExamInfo; -import com.zgczx.dto.ExamCoversionTotalDTO; -import com.zgczx.dto.ExamCoversionTotalSectionDTO; -import com.zgczx.dto.ExamCoversionTotalSingleDTO; -import com.zgczx.dto.SixRateDTO; +import com.zgczx.repository.mysql1.score.dto.*; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalSectionDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalSingleDTO; +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import com.zgczx.repository.mysql1.score.model.ExamInfo; import com.zgczx.service.score.ScoreService; import com.zgczx.utils.ResultVOUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; import java.util.List; /** @@ -22,6 +24,7 @@ * @date 2019/9/10 14:44 * 成绩相关的路由皆由此转发 */ +@Api(description = "第一个score分析模块") @RestController @RequestMapping("/score") //@CrossOrigin(origins = "*", maxAge = 3600) @@ -38,6 +41,7 @@ public class ScoreController { * @param examType 具体哪次考试 * @return ResultVOUtil中的code、msg、data */ + @ApiOperation(value = "一、 获取学生的所有成绩,根据学号id和考试名称") @GetMapping("/getExamCoversionTotal") public ResultVO getExamCoversionTotal(@RequestParam(value = "userId") Integer userId, @RequestParam(value = "examType") String examType){ @@ -47,7 +51,7 @@ public ResultVO getExamCoversionTotal(@RequestParam(value = "userId") Integer return ResultVOUtil.success(examCoversionTotal); } - + @ApiOperation(value = "二、 查询所有的考试名称") @GetMapping(value = "/getListExamInfols", name = "查询所有的考试名称") public ResultVO getListExamInfols(){ @@ -62,6 +66,7 @@ public ResultVO getListExamInfols(){ * @param examType 具体某次考试名称 * @return VO类中的data数据返回 */ + @ApiOperation(value = "三、 旭日图中的中心,主要是对年级和班级的进退名次的实现") @GetMapping(value = "/getExamCoversionTotalInfo") public ResultVO getExamCoversionTotalInfo(@RequestParam(value = "stuNumber") String stuNumber, @RequestParam(value = "examType") String examType ){ @@ -71,11 +76,13 @@ public ResultVO getExamCoversionTotalInfo(@RequestParam(value = "stuNumber") } /** - * 旭日图第三层,获取各单科的班排、年排、进退名次 + * 旭日图第三层,获取各单科的班排、年排、进退名次,班级年级人数 + * 总分标准,各单科满分标准 * @param stuNumber 学生学号 * @param examType 具体某次考试名称 * @return VO类中的data数据返回 */ + @ApiOperation(value = "四、旭日图第三层,获取各单科的班排、年排、进退名次,班级年级人数,总分标准,各单科满分标准") @GetMapping(value = "/getExamCoversionTotalSingleInfo") public ResultVO getExamCoversionTotalSingleInfo(@RequestParam(value = "stuNumber") String stuNumber, @RequestParam(value = "examType") String examType, @@ -92,6 +99,8 @@ public ResultVO getExamCoversionTotalSingleInfo(@RequestParam(value = "stuNum * @param examType 某次考试 * @return 返回DTO */ +// @CrossOrigin(origins = "*", maxAge = 3600) + @ApiOperation(value = "五、旭日图的第二层, 获取三科和综合(6选3)的分值,三科班排、年排;综合班排、年排") @GetMapping(value = "/getExamCoversionTotalSectionInfo") public ResultVO getExamCoversionTotalSectionInfo(@RequestParam(value = "stuNumber") String stuNumber, @RequestParam(value = "examType") String examType){ @@ -102,16 +111,114 @@ public ResultVO getExamCoversionTotalSectionInfo(@RequestParam(value = "stuNu /** + * 作为定位对比一图: * 获取六率信息,高分率、优秀率、良好率、及格率、低分率、超均率,当前学生所处率值 * @param stuNumber 学生学号 * @param examType 某次考试 * @return 返回具体的DTO */ + @ApiOperation(value = "六、定位对比,获取此用户所在班级的高分、低分、良好、及格、低分人数和自己所处位置") @GetMapping(value = "/getSixRateInfo") - public ResultVO getSixRateInfo(@RequestParam(value = "stuNumber") String stuNumber, - @RequestParam(value = "examType") String examType){ + public ResultVO getSixRateInfo( + @ApiParam(value = "用户学号:stuNumber", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "考试名称:examType", required = true) + @RequestParam(value = "examType") String examType){ List sixRateInfo = scoreService.getSixRateInfo(stuNumber, examType); return ResultVOUtil.success(sixRateInfo); } + + /** + * 学科分析,各学科贡献率和各学科均衡差值,都是和年级值对比 + * @param stuNumber 学生学号 + * @param examType 具体的考试名称 + * @return 返回DTO对象 + */ + @ApiOperation(value = "七、学科分析,各学科贡献率和各学科均衡差值,都是和年级值对比") + @GetMapping(value = "/getSubjectAnalysisInfo") + public ResultVO getSubjectAnalysisInfo(@RequestParam(value = "stuNumber") String stuNumber, + @RequestParam(value = "examType") String examType){ + List subjectAnalysisInfo = scoreService.getSubjectAnalysisInfo(stuNumber, examType); + + return ResultVOUtil.success(subjectAnalysisInfo); + } + + /** + * 历史分析中的-01 :总分分析,包含总分、班排、年排、班均分 + * 年均分, 以上五个值的标准化(百分率) + * @param stuNumber 学生学号 + * @param examType 具体的考试名称 + * @return 返回DTO对象 + */ + @ApiOperation(value = "八、历史分析中的-01 :总分分析,包含总分、班排、年排、班均分,年均分, 以上五个值的标准化(百分率)") + @GetMapping(value = "/getHistoricalAnalysisTotalInfo") + public ResultVO getHistoricalAnalysisTotalInfo(@RequestParam(value = "stuNumber") String stuNumber, + @RequestParam(value = "examType") String examType, + @RequestParam(value = "openid") String openid){ + List historicalAnalysisTotalInfo = scoreService.getHistoricalAnalysisTotalInfo(stuNumber,examType,openid); + + return ResultVOUtil.success(historicalAnalysisTotalInfo); + } + + /** + * 历史分析中的-02 :单科分数分析,包含单科分值、班排、年排、班均分 + * 年均分, 以上五个值的标准化(百分率) + * @param stuNumber 学号 + * @param examType 考试名称 + * @param subject 具体科目 + * @return 返回dto对象 + */ + @ApiOperation(value = "九、历史分析中的-02 :单科分数分析,包含单科分值、班排、年排、班均分,年均分, 以上五个值的标准化(百分率)") + @GetMapping(value = "/getHistoricalAnalysisSingleInfo") + public ResultVO getHistoricalAnalysisSingleInfo(@RequestParam(value = "stuNumber") String stuNumber, + @RequestParam(value = "examType") String examType, + @RequestParam(value = "subject") String subject, + @RequestParam(value = "openid") String openid){ + List historicalAnalysisSingleInfo = scoreService.getHistoricalAnalysisSingleInfo(stuNumber, examType, subject,openid); + + return ResultVOUtil.success(historicalAnalysisSingleInfo); + } + + + /** + * 旭日图中总分、三科、综合、各单科的率值 + * 率值 = 所得分 / 各标准总分 + * @param stuNumber 学号 + * @param examType 考试名称 + * @return 返回DTO对象 + */ + @ApiOperation(value = "十、旭日图中总分、三科、综合、各单科的率值;率值 = 所得分 / 各标准总分") + @GetMapping(value = "/getAsahiChartAllRate") + public ResultVO getAsahiChartAllRate(@RequestParam(value = "stuNumber") String stuNumber, + @RequestParam(value = "examType") String examType){ + List asahiChartAllRate = scoreService.getAsahiChartAllRate(stuNumber, examType); + + return ResultVOUtil.success(asahiChartAllRate); + } + + + /** + * 成绩单接口:获取总分的班排、年排,各具体单科的分数、班排、年排 + * @param stuNumber 学号 + * @param examType 考试名称 + * @return DTO对象 + */ + @ApiOperation(value = "十一、成绩单接口:获取总分的班排、年排,各具体单科的分数、班排、年排") + @GetMapping(value = "/getScoreReportInfo") + public ResultVO getScoreReportInfo(@RequestParam(value = "stuNumber") String stuNumber, + @RequestParam(value = "examType") String examType){ + List scoreReportDTOList = scoreService.getScoreReport(stuNumber, examType); + + return ResultVOUtil.success(scoreReportDTOList); + } + + + @RequestMapping({"MP_verify_Sb3I1Dr7zM3OCTYc.txt"}) + @ResponseBody + private String returnConfigFile() { + //把MP_verify_xxxxxx.txt中的内容返回 + return "Sb3I1Dr7zM3OCTYc"; + } + } diff --git a/src/main/java/com/zgczx/controller/score/ScoreTwoController.java b/src/main/java/com/zgczx/controller/score/ScoreTwoController.java new file mode 100644 index 0000000..6882356 --- /dev/null +++ b/src/main/java/com/zgczx/controller/score/ScoreTwoController.java @@ -0,0 +1,320 @@ +package com.zgczx.controller.score; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.zgczx.VO.ResultVO; +import com.zgczx.repository.mysql1.score.dto.ManuallyEnterGradesDTO; +import com.zgczx.repository.mysql1.score.dto.MonthByYearListDTO; +import com.zgczx.repository.mysql1.score.model.GoalSet; +import com.zgczx.repository.mysql1.score.model.ManuallyEnterGrades; +import com.zgczx.repository.mysql1.user.model.StudentInfo; +import com.zgczx.repository.mysql2.scoretwo.dto.CommentValueDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.LocationComparisonDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.SingleContrastInfoDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.TotalScoreInfoDTO; +import com.zgczx.service.scoretwo.ScoreTwoService; +import com.zgczx.utils.Param; +import com.zgczx.utils.ResultVOUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + +/** + * 承接ScoreController剩下的接口 + * 因为 ScoreController中的实现类达到了2000千行 + * @author aml + * @date 2019/10/29 12:27 + */ +@Api(description = "第二个scoreTwo分析模块") +@RestController +@RequestMapping("/scoreTwo") +@Slf4j +public class ScoreTwoController { + + @Autowired + ScoreTwoService scoreTwoService; + + /** + * 插入操作 + * @param wechatOpenid openid + * @param studentNumber 学号 + * @param subject 科目名称 或 “全科” + * @param score 分数 + * @param classRank 班级排名 + * @param gradeRank 年级排名 + * @param examName 考试名称 + * @return ManualGradeEntry对象 + */ + @PostMapping("/save") + public ResultVO save(@RequestParam(value = "wechat_openid") String wechatOpenid, + @RequestParam(value = "student_number") String studentNumber, + @RequestParam(value = "subject") String subject, + @RequestParam(value = "score") String score, + @RequestParam(value = "class_rank") String classRank, + @RequestParam(value = "grade_rank") String gradeRank, + @RequestParam(value = "exam_name") String examName){ + ManuallyEnterGrades manuallyEnterGrades = scoreTwoService.saveEntity(wechatOpenid,studentNumber,subject,score,classRank,gradeRank,examName); + return ResultVOUtil.success(manuallyEnterGrades); + } + + /** + * 注意: 前端用Vue直接传不了,list中包含类似json串的格式, + * 前端只能传string,后端用fastjson.JSON处理一下,封装成list数组形式 + * @RequestBody是把整个HttpServletRequest的输入(request.getInputStream()), + * 转换成一个对象,常用的转换是采用json方式, + * 在spring中是RequestResponseBodyMethodProcessor利用HttpMessageConventer做的。 + * @param list + * @return + * + */ + //用户手动录入成绩自己各科成绩,暂时没用,用的 "一、 录入成绩,可批量录入" + @ApiOperation(value = "一、 录入成绩,可批量录入") + @PostMapping("/saveList") + public ResultVO saveList(@RequestBody @ApiParam(name="用户Model对象 传参名称为 list",value="传入json格式",required=true) String list){ + List enterGradesList = JSON.parseObject(list, new TypeReference>() { + }); + log.info("【打印出传参情况:】{}",enterGradesList); + List list1 = scoreTwoService.saveList(enterGradesList); + + return ResultVOUtil.success(list1); + } + //用户手动录入成绩自己各科成绩 + @ApiOperation(value = "一、 录入成绩,可批量录入") + @PostMapping("/saveList2") + public ResultVO saveList2(HttpServletRequest request, HttpServletResponse response){ + String list = request.getParameter("0"); + log.info("【打印没映射的参数情况:】{}",list); + List enterGradesList = JSON.parseObject(list, new TypeReference>() { + }); + log.info("【打印出传参情况:】{}",enterGradesList); + List list1 = scoreTwoService.saveList(enterGradesList); + + return ResultVOUtil.success(list1); + } + + + /** + * 获取此用户录入数据的所有年份 + * @param openid 用户openid + * @return StringList 对象 + */ + @ApiOperation(value = "二、录入统计1) 获取此用户录入数据的所有年份") + @GetMapping("/getYearList") + public ResultVO getYearList( + @ApiParam(value = "openid", required = true) + @RequestParam(value = "openid") String openid){ + + List stringList = scoreTwoService.getYearList(openid); + + return ResultVOUtil.success(stringList); + } + + /** + * 根据年份获取对应的数据中的月份 + * @param openid + * @param year + * @return + */ + @ApiOperation(value = "三、录入统计2) 根据年份和openid获取对应的数据中的月份信息") + @GetMapping(value = "getMonthByYearList") + public ResultVO getMonthByYearList( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "year", required = true) + @RequestParam(value = "year") String year){ + + List stringList = scoreTwoService.getMonthByYearList(openid,year); + return ResultVOUtil.success(stringList); + } + + /** + * 根据年份和月份获取对应的数据中的考试名称,例如2018年08月月考,此接口就是获取 “月考” + * @param openid + * @param yearMonth + * @return + */ + @ApiOperation(value = "四、录入统计3) 根据年份和月份获取对应的数据中的考试名称") + @GetMapping(value = "getExamNameByYearMonthList") + public ResultVO getExamNameByYearMonthList( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "年月参数名称",required = true) + @RequestParam(value = "yearMonth") String yearMonth){ + + List stringList = scoreTwoService.getExamNameByYearMonthList(openid,yearMonth); + return ResultVOUtil.success(stringList); + } + + //获取此用户录入本次考试的所有信息 + @ApiOperation(value = "#12.9: 五、录入统计4) 根据考试名称和openid获取对应的数据") + @GetMapping(value = "/findAll") + public ResultVO findAll( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "exam_name全称",required = true) + @RequestParam(value = "examName") String examName + ){ + List list = scoreTwoService.findAll(openid,examName); + return ResultVOUtil.success(list); + } + + + //根据学号验证 学校是否提供数据了 + @ApiOperation(value = "六、暂时无用,验证目前从统一登录那块验证的;登录模块:根据学号验证 学校是否提供数据了;") + @GetMapping(value = "/verifyStudentId") + public ResultVO verifyStudentCode( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "学生学号",required = true) + @RequestParam(value = "verifyStudentId") String verifyStudentId + ){ + StudentInfo list = scoreTwoService.verifyStudentCode(openid,verifyStudentId); + return ResultVOUtil.success(list); + } + + //定位对比二图: 和前排人的差距 + @ApiOperation(value = "七、定位对比二图: 和前排人的差距") + @GetMapping(value = "/getGapValue") + public ResultVO getGapValue( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "用户学号", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "exam_name全称",required = true) + @RequestParam(value = "examName") String examName + ){ + List list = scoreTwoService.getGapValue(openid,stuNumber,examName); + return ResultVOUtil.success(list); + } + + //定位对比三图一: 评语中的各个值 + @ApiOperation(value = "八、 定位对比三:图一上评语中的各个值") + @GetMapping(value = "/getCommentValue") + public ResultVO getCommentValue( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "用户学号", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "考试全称",required = true) + @RequestParam(value = "examName") String examName + ){ + List list = scoreTwoService.getCommentValue(openid,stuNumber,examName); + return ResultVOUtil.success(list); + } + + //九 定位对比: 1。 总分的 自己排名、目标排名、自己分数、目标分数、差值 + @ApiOperation(value = "(定位对比从这个开始)九 定位对比: 1。 总分的 自己排名、目标排名、自己分数、目标分数、差值 ") + @GetMapping(value = "/getTotalScoreInfo") + public ResultVO getTotalScoreInfo( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "用户学号", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "考试全称",required = true) + @RequestParam(value = "examName") String examName, + @ApiParam(value = "总分的目标排名",required = true) + @RequestParam(value = "targetRank") String targetRank + ){ + List list = scoreTwoService.getTotalScoreInfo(openid,stuNumber,examName,targetRank); + return ResultVOUtil.success(list); + } + + //十、定位对比: 2。 此用户所选的科目集合 + @ApiOperation(value = "十、(无用) 定位对比: 此用户所选的科目集合 ") + @GetMapping(value = "/getSubjectCollection") + public ResultVO getSubjectCollection( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "用户学号", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "考试全称",required = true) + @RequestParam(value = "examName") String examName + ){ + List list = scoreTwoService.getSubjectCollection(openid,stuNumber,examName); + return ResultVOUtil.success(list); + } + + //十一、定位对比:1. 单科的 自己排名、目标排名、自己分数、目标分数、差值 + @ApiOperation(value = "十一、定位对比:2. 单科的 自己排名、目标排名、自己分数、目标分数、差值") + @GetMapping("/getSingleContrastInfo") + public ResultVO getSingleContrastInfo( +// @ApiParam(value = "用户openid", required = true) +// @RequestParam(value = "openid") String openid, +// @ApiParam(value = "用户学号", required = true) +// @RequestParam(value = "stuNumber") String stuNumber, +// @ApiParam(value = "考试全称",required = true) +// @RequestParam(value = "examName") String examName, + HttpServletRequest request, HttpServletResponse response){ + + Map param = Param.getParam(request); + //JSONObject singleContrastInfo = scoreTwoService.getSingleContrastInfo(param); + List singleContrastInfo = scoreTwoService.getSingleContrastInfo(param); + +// // 取出json串 +// String list = request.getParameter("0"); +//// List singleContrastInfo = scoreTwoService.getSingleContrastInfo(openid, stuNumber, examName, list); +// +// // json串处理;暂无用放到,impl +// List enterGradesList = JSON.parseObject(list, new TypeReference>() { +// }); +// List list1 = scoreTwoService.saveList(enterGradesList); + + return ResultVOUtil.success(singleContrastInfo); + } + + //定位中查询之前各科设定的目标值 + @ApiOperation(value = "十二、 定位中查询之前各科设定的目标值") + @GetMapping(value = "/findTargetValue") + public ResultVO findTargetValue( + @ApiParam(value = "用户学号", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "考试全称",required = true) + @RequestParam(value = "examName") String examName + ){ + GoalSet list = scoreTwoService.findTargetValue(stuNumber,examName); + return ResultVOUtil.success(list); + } + + + @ApiOperation(value = "#12.9: 十三、 录入统计中的 删除 功能") + @GetMapping(value = "/deleteManuallyEnter") + public ResultVO deleteManuallyEnter( + @ApiParam(value = "用户学号", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "考试全称",required = true) + @RequestParam(value = "examName") String examName, + @ApiParam(value = "subject科目名称", required = true) + @RequestParam(value = "subject") String subject + ){ + int list = scoreTwoService.deleteManuallyEnter(stuNumber,openid,examName,subject); + return ResultVOUtil.success(list); + } + + @ApiOperation(value = "#12.9: 十四、 录入统计中的 更新 功能") + @PostMapping(value = "/updateManuallyEnter") + public ResultVO updateManuallyEnter( + @ApiParam(value = "用户学号", required = true) + @RequestParam(value = "stuNumber") String stuNumber, + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid") String openid, + @ApiParam(value = "考试全称",required = true) + @RequestParam(value = "oldexamName") String oldexamName, + @ApiParam(value = "subject科目名称", required = true) + @RequestParam(value = "subject") String subject, + ManuallyEnterGrades manuallyEnterGrades + ){ + ManuallyEnterGrades list = scoreTwoService.updateManuallyEnter(stuNumber,openid,oldexamName,subject,manuallyEnterGrades); + return ResultVOUtil.success(list); + } +} diff --git a/src/main/java/com/zgczx/controller/user/UserController.java b/src/main/java/com/zgczx/controller/user/UserController.java new file mode 100644 index 0000000..86c0eec --- /dev/null +++ b/src/main/java/com/zgczx/controller/user/UserController.java @@ -0,0 +1,97 @@ +package com.zgczx.controller.user; + +import com.zgczx.VO.ResultVO; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.repository.mysql1.user.model.UserFeedBack; +import com.zgczx.repository.mysql1.user.model.WechatStudent; +import com.zgczx.service.user.UserService; +import com.zgczx.utils.ResultVOUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import javax.xml.transform.Result; +import java.util.List; + +/** + * @author aml + * @date 2019/11/8 19:32 + */ +@Api(description = "用户模块") +@RestController +@RequestMapping("/user") +@Slf4j +public class UserController { + + @Autowired + UserService userService; + + private String info = null; + + @ApiOperation(value = "用户登录") + @GetMapping("/login") + public ResultVO login( + @ApiParam(value = "openid", required = true) + @RequestParam(value = "openid") String openid, + HttpServletRequest request, + HttpServletResponse response){ + + WechatStudent wechatStudent = userService.login(openid,request,response); + + return ResultVOUtil.success(wechatStudent); + } + + @ApiOperation(value = "用户登出") + @GetMapping("/logout") + public ResultVO logout(HttpServletRequest request, + HttpServletResponse response){ + String logout = userService.logout(request, response); + return ResultVOUtil.success(logout); + } + +// @PostMapping("/registerWechatStudent") +// public ResultVO registerWechatStudent( +// @Valid WechatStudent wechatStudent, BindingResult bindingResult +// // ,@RequestParam(value = "openid") String openid +// ){ +// if (bindingResult.hasErrors()){ +// info = "【学生注册】参数验证不正确," + wechatStudent.toString(); +// log.error(info); +// // throw new ScoreException(错误code,错误message) +// throw new ScoreException(ResultEnum.PARAM_EXCEPTION.getCode(), +// bindingResult.getFieldError().getDefaultMessage()); +// } +// +// WechatStudent wechatStudent1 = userService.registerWechatStudent(wechatStudent); +// return ResultVOUtil.success(wechatStudent1); +// } + + @ApiOperation(value = "用户注册") + @PostMapping("/registerWechatStudent") + public ResultVO registerWechatStudent( + @ApiParam(value = "用户openid", required = true) + @RequestParam(value = "openid")String openid, + @ApiParam(value = "统一登录的主键",required = true) + @RequestParam(value = "foreignKeId")String foreignKeId){ + + WechatStudent wechatStudent1 = userService.registerWechatStudent(openid,foreignKeId); + return ResultVOUtil.success(wechatStudent1); + } + + @ApiOperation(value = "用户反馈") + @PostMapping("/addUserFeedBack") + @ResponseBody + public ResultVO addUserFeedBack(UserFeedBack userFeedBack) { + + UserFeedBack rsUserFeedBack = userService.addUserFeedBack(userFeedBack); + return ResultVOUtil.success(rsUserFeedBack); + } +} diff --git a/src/main/java/com/zgczx/controller/wechat/WeChatController.java b/src/main/java/com/zgczx/controller/wechat/WeChatController.java new file mode 100644 index 0000000..638974d --- /dev/null +++ b/src/main/java/com/zgczx/controller/wechat/WeChatController.java @@ -0,0 +1,296 @@ +package com.zgczx.controller.wechat; + +import com.alibaba.fastjson.JSONObject; +import com.zgczx.VO.ResultVO; +import com.zgczx.config.wechatconfig.ProjectUrlConfig; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.service.wechat.WeChatService; +import com.zgczx.utils.ResultVOUtil; +import io.swagger.annotations.*; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpUser; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.*; +import java.util.UUID; + +/** + * @author aml + * @date 2019/10/12 19:50 + */ +@Api(description = "微信相关模块") +@Controller +//@RestController +@RequestMapping("/wechat") +@Slf4j +public class WeChatController { + + @Autowired + private WxMpService wxMpService; + + @Autowired + private WeChatService weChatService; + + @Autowired + private ProjectUrlConfig projectUrlConfig; + + /** + * 描述请求微信API接口,获取code等参数 + * + *

请求微信服务器获取用户个人信息时需要用到code等参数 + * + * @param returnUrl + * @param path 此参数为前端要求添加的,此参数返回给前端后,由前端再获取此参数,拼接组成下一步请求的url + * 可以不传此参数,接口中去掉path即可 + * @return + */ + @CrossOrigin(origins = "*", maxAge = 3600) + @GetMapping("/authorize") + public String authorize(@RequestParam("returnUrl") String returnUrl, + @RequestParam("path") String path) { + + return "redirect:" + weChatService.getAuthorizeFromWechat(returnUrl,path); + } + + + /** + * 经过授权接口(authorize)后拿到code等参数,把code作为参数,请求此接口获取用户openid,姓名,头像等参数 + * + *

流程: code -> access token -> 微信用户信息(wechatOpenid,名称,头像等) + * + * @param code + * @param returnUrl + * @param path 前端传给后台的字段,由前端自己定义,基于Vue开发的话,一般设置 path 为 "menu",前端获取path值,然后拼接请求地址,访问首页 + * 可以不传此参数,接口中去掉path即可 + * @return + */ + @CrossOrigin(origins = "*", maxAge = 3600) + @GetMapping("/userInfo") + public String userInfo(@RequestParam("code") String code, + @RequestParam("state") String returnUrl, + @RequestParam("path") String path) { + + return "redirect:"+weChatService.getUserInfoFromWechat(code,returnUrl,path); + } + + + /*@ApiOperation(value = "授权") + @GetMapping("/authorize") + public String authorize(@RequestParam("returnUrl") String returnUrl) {//returnUrl:本项目的首页面访问路径 + //1. 配置 + //2. 调用 + //url:http://zhongkeruitong.top/score_analysis/wechat/userInfo : 直接跳转到这个接口获取其他信息 + //拼接这个访问url去调用这个“/userInfo”接口,去获取token,然后获取openid、头像等信息 +// String url = projectUrlConfig.getWechatMpAuthorize() + "/show/score_analysis/wechat/userInfo"; + String url = "http://zhongkeruitong.top/score_analysis/wechat/userInfo"; // 跳转请求下面接口的全路径url + // 占位符使用,切记“,”,不是直接拼接“+” + log.info("url= {}", url); + String redirectUrl = wxMpService.oauth2buildAuthorizationUrl(url, WxConsts.OAUTH2_SCOPE_USER_INFO, URLEncoder.encode(returnUrl)); + log.info("【微信网页授权】 获取code,redirectUrl= {}", redirectUrl); + //return "redirectUrl: " + redirectUrl; // redirectUrl:这个不是java的跳转关键字 + return "redirect:" + redirectUrl; //跳转的下面userInfo接口,请求这个接口获取信息数据 + } + + *//** + * 按照开发文档获取用户token, + * 1 第一步:用户同意授权,获取code + * 2 第二步:通过code换取网页授权access_token + * 3 第三步:刷新access_token(如果需要) + * 4 第四步:拉取用户信息(需scope为 snsapi_userinfo) + * 5 附:检验授权凭证(access_token)是否有效 + * 获取code后,请求以下链接获取access_token: https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code + * + * @param code 请求一个微信的url获取所需要的code + * @param returnUrl state=STAT,可随意写 + * @return 获取用户的token,从token获取用户openid + *//* + @GetMapping("/userInfo") + public String userInfo(@RequestParam("code") String code, + @RequestParam("state") String returnUrl) { + WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken(); + WxMpUser wxMpUser = new WxMpUser(); + try { + wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code); + wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);//从这里获取用户各种信息,例如昵称了等 + } catch (WxErrorException e) { + log.error("【微信网页授权】{}", e); + throw new ScoreException(ResultEnum.WECHAT_MP_ERROR.getCode(), e.getError().getErrorMsg()); + + } + //获取当前用户的openid,昵称、微信头像,直接存放到数据库中 + String openId = wxMpOAuth2AccessToken.getOpenId(); // 用户的openid + String nickname = wxMpUser.getNickname(); // 用户昵称 + String headImgUrl = wxMpUser.getHeadImgUrl();//用户头像 + log.info("openid= {}", openId); + log.info("【昵称】 {}", nickname); + log.info("【头像】 {}", headImgUrl); + return "redirect:" + returnUrl + "?openid=" + openId; + } +*/ + /** + * 获取 appid, timestamp,nonceStr,signature, + * 目的 获取微信的js通行证,来调用微信的一些方法,例如微信上传图片等 + * + * @param url + * @param session + * @return + */ + @ApiOperation(value = "获取js通行证的各种参数") + @ResponseBody + @GetMapping("/getSign") + public ResultVO getSign(@RequestParam("url") String url, HttpSession session) { + log.info("【打印参数url:】{}", url); + JSONObject sign = weChatService.getSign(url, session); + return ResultVOUtil.success(sign); + } + + /** + * 从微信服务器上保存图片到自己指定位置 + * @param serverIds 微信返回给端的图片id + * @param session + * @param request + * @param response + * @return + */ + @ApiOperation(value = "将微信服务器上的图片下载到指定的图片服务器上") + @PostMapping("/savePicture") + @ResponseBody + public static String savePicture( + @ApiParam(value = "serverIds", required = true) + @RequestParam("serverIds")String serverIds, + HttpSession session, + HttpServletRequest request, + HttpServletResponse response){ + String filename = null; + log.info("【打印serversIds: 】{}",serverIds); + if (StringUtils.isNoneBlank(serverIds)){ + filename = saveImageToDisk(serverIds, session , response, request); + } + String string = "http://zhongkeruitong.top/image/" + filename; + log.info("【返回前端的url地址:】{}",string); + return string; + } + + + // 将字节流中的文件上传到自己指定的 图片服务器上 + private static String saveImageToDisk(String serverIds, HttpSession session, HttpServletResponse response, HttpServletRequest request){ + String filename = null; + //根据mediaId去微信服务器上下载图片到指定的文件夹中 + InputStream inputStream = getMedia(serverIds, response, session); + byte[] data = new byte[1024]; + int len = 0; + FileOutputStream fileOutputStream = null; + + //指定图片服务的地址 + String savePath = "/home/bigdata/application/score-img/"; + //图片命名,以UUID来给文件命名 + filename = UUID.randomUUID() + ".jpa"; + try { + fileOutputStream = new FileOutputStream(savePath+filename); + //当字节流读取不到最后字节,就 一直读取文件 + while ((len = inputStream.read(data)) != -1){ + //从data中,将0~len 长度的字节写到输出流中 + fileOutputStream.write(data,0,len); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (inputStream != null){ + try { + //关闭输入流 + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (fileOutputStream != null){ + try { + //关闭输出流 + fileOutputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + log.info("【输出上传到图片服务器上的文件名:】{}",filename); + return filename; + } + + //将从微信服务器上下载的文件转化为字节流 + private static InputStream getMedia(String serverIds, HttpServletResponse response, HttpSession session){ + //1. 微信的get请求链接 + String url = "https://api.weixin.qq.com/cgi-bin/media/get"; + //2. 从session中获取token + String accessToken = (String) session.getAttribute("accessToken"); + log.info("【打印从session中获取的token:】{}",accessToken); + //拼接请求微信get链接的 参数值 + String params = "access_token=" + accessToken + "&media_id=" + serverIds; + InputStream inputStream = null; + String urlNameString = url + "?" + params; + log.info("【打印出完整的get链接: 】{}",urlNameString); + + try { + //请求微信的get链接,获取所需的值 + URL urlGet = new URL(urlNameString); + HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); + http.setRequestMethod("GET");//必须是get方式请求 + http.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); + http.setDoOutput(true); + http.setDoInput(true); + http.connect(); + + //判断文件是什么格式的,jpg还是MP4等 + String fileexpandedName = getFileexpandedName(http.getHeaderField("Content-Type")); + log.info("【输出文件的类型格式: 】{}",fileexpandedName); + + //将获取的微信的文件转化为byte流 + inputStream = http.getInputStream(); + + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return inputStream; + } + + /** + * 根据内容类型判断文件扩展名, + * 文件头类型 content-type + * @param contentType 内容类型 + * @return + */ + public static String getFileexpandedName(String contentType) { + + String fileEndWitsh = ""; + if ("image/jpeg".equals(contentType)){ + fileEndWitsh = ".jpg"; + } else if ("audio/mpeg".equals(contentType)){ + fileEndWitsh = ".mp3"; + } else if ("audio/amr".equals(contentType)){ + fileEndWitsh = ".amr"; + } else if ("video/mp4".equals(contentType)){ + fileEndWitsh = ".mp4"; + } else if ("video/mpeg4".equals(contentType)){ + fileEndWitsh = ".mp4"; + } + return fileEndWitsh; + } +} diff --git a/src/main/java/com/zgczx/dataobject/score/ExamInfo.java b/src/main/java/com/zgczx/dataobject/score/ExamInfo.java index 0793026..4423bf5 100644 --- a/src/main/java/com/zgczx/dataobject/score/ExamInfo.java +++ b/src/main/java/com/zgczx/dataobject/score/ExamInfo.java @@ -1,5 +1,6 @@ package com.zgczx.dataobject.score; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import javax.persistence.*; @@ -17,6 +18,8 @@ public class ExamInfo { private long id; private String examName; private String examGrade; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Timestamp examDate; private String paperId; diff --git a/src/main/java/com/zgczx/dataobject/score/ImportConversionScore.java b/src/main/java/com/zgczx/dataobject/score/ImportConversionScore.java new file mode 100644 index 0000000..608fb5b --- /dev/null +++ b/src/main/java/com/zgczx/dataobject/score/ImportConversionScore.java @@ -0,0 +1,220 @@ +package com.zgczx.dataobject.score; + +import lombok.Data; + +import javax.persistence.*; +import java.util.Objects; + +/** + * @author aml + * @date 2019/9/22 16:28 + */ +@Entity +@Data +@Table(name = "import_conversion_score", schema = "score_ananlysis_dev", catalog = "") +public class ImportConversionScore { + private int id; + private String studentMachineCard; + private String username; + private String yuwenScore; + private String shuxueScore; + private String yingyuScore; + private String wuliConverscore; + private String huaxueConverscore; + private String shengwuConverscore; + private String lishiConverscore; + private String diliConverscore; + private String zhengzhiConverscore; + private String totalScore; + private String classIndex; + private String schoolIndex; + private String examType; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Basic + @Column(name = "student_machine_card") + public String getStudentMachineCard() { + return studentMachineCard; + } + + public void setStudentMachineCard(String studentMachineCard) { + this.studentMachineCard = studentMachineCard; + } + + @Basic + @Column(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @Basic + @Column(name = "yuwen_score") + public String getYuwenScore() { + return yuwenScore; + } + + public void setYuwenScore(String yuwenScore) { + this.yuwenScore = yuwenScore; + } + + @Basic + @Column(name = "shuxue_score") + public String getShuxueScore() { + return shuxueScore; + } + + public void setShuxueScore(String shuxueScore) { + this.shuxueScore = shuxueScore; + } + + @Basic + @Column(name = "yingyu_score") + public String getYingyuScore() { + return yingyuScore; + } + + public void setYingyuScore(String yingyuScore) { + this.yingyuScore = yingyuScore; + } + + @Basic + @Column(name = "wuli_converscore") + public String getWuliConverscore() { + return wuliConverscore; + } + + public void setWuliConverscore(String wuliConverscore) { + this.wuliConverscore = wuliConverscore; + } + + @Basic + @Column(name = "huaxue_converscore") + public String getHuaxueConverscore() { + return huaxueConverscore; + } + + public void setHuaxueConverscore(String huaxueConverscore) { + this.huaxueConverscore = huaxueConverscore; + } + + @Basic + @Column(name = "shengwu_converscore") + public String getShengwuConverscore() { + return shengwuConverscore; + } + + public void setShengwuConverscore(String shengwuConverscore) { + this.shengwuConverscore = shengwuConverscore; + } + + @Basic + @Column(name = "lishi_converscore") + public String getLishiConverscore() { + return lishiConverscore; + } + + public void setLishiConverscore(String lishiConverscore) { + this.lishiConverscore = lishiConverscore; + } + + @Basic + @Column(name = "dili_converscore") + public String getDiliConverscore() { + return diliConverscore; + } + + public void setDiliConverscore(String diliConverscore) { + this.diliConverscore = diliConverscore; + } + + @Basic + @Column(name = "zhengzhi_converscore") + public String getZhengzhiConverscore() { + return zhengzhiConverscore; + } + + public void setZhengzhiConverscore(String zhengzhiConverscore) { + this.zhengzhiConverscore = zhengzhiConverscore; + } + + @Basic + @Column(name = "total_score") + public String getTotalScore() { + return totalScore; + } + + public void setTotalScore(String totalScore) { + this.totalScore = totalScore; + } + + @Basic + @Column(name = "class_index") + public String getClassIndex() { + return classIndex; + } + + public void setClassIndex(String classIndex) { + this.classIndex = classIndex; + } + + @Basic + @Column(name = "school_index") + public String getSchoolIndex() { + return schoolIndex; + } + + public void setSchoolIndex(String schoolIndex) { + this.schoolIndex = schoolIndex; + } + + @Basic + @Column(name = "exam_type") + public String getExamType() { + return examType; + } + + public void setExamType(String examType) { + this.examType = examType; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ImportConversionScore that = (ImportConversionScore) o; + return id == that.id && + Objects.equals(studentMachineCard, that.studentMachineCard) && + Objects.equals(username, that.username) && + Objects.equals(yuwenScore, that.yuwenScore) && + Objects.equals(shuxueScore, that.shuxueScore) && + Objects.equals(yingyuScore, that.yingyuScore) && + Objects.equals(wuliConverscore, that.wuliConverscore) && + Objects.equals(huaxueConverscore, that.huaxueConverscore) && + Objects.equals(shengwuConverscore, that.shengwuConverscore) && + Objects.equals(lishiConverscore, that.lishiConverscore) && + Objects.equals(diliConverscore, that.diliConverscore) && + Objects.equals(zhengzhiConverscore, that.zhengzhiConverscore) && + Objects.equals(totalScore, that.totalScore) && + Objects.equals(classIndex, that.classIndex) && + Objects.equals(schoolIndex, that.schoolIndex) && + Objects.equals(examType, that.examType); + } + + @Override + public int hashCode() { + return Objects.hash(id, studentMachineCard, username, yuwenScore, shuxueScore, yingyuScore, wuliConverscore, huaxueConverscore, shengwuConverscore, lishiConverscore, diliConverscore, zhengzhiConverscore, totalScore, classIndex, schoolIndex, examType); + } +} diff --git a/src/main/java/com/zgczx/dataobject/score/ManuallyEnterGrades.java b/src/main/java/com/zgczx/dataobject/score/ManuallyEnterGrades.java new file mode 100644 index 0000000..49f5ab7 --- /dev/null +++ b/src/main/java/com/zgczx/dataobject/score/ManuallyEnterGrades.java @@ -0,0 +1,130 @@ +package com.zgczx.dataobject.score; + +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author aml + * @date 2019/10/29 19:10 + */ +@Entity +@Data +@Table(name = "manually_enter_grades", schema = "score_ananlysis_dev", catalog = "") +public class ManuallyEnterGrades { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + private String wechatOpenid; + private String studentNumber; + private String subjectName; + private String score; + private String classRank; + private String gradeRank; + private String examName; + private Timestamp inserttime; + private Timestamp updatetime; + +// @Id +// @Column(name = "id") +// public int getId() { +// return id; +// } +// +// public void setId(int id) { +// this.id = id; +// } +// +// @Basic +// @Column(name = "wechat_openid") +// public String getWechatOpenid() { +// return wechatOpenid; +// } +// +// public void setWechatOpenid(String wechatOpenid) { +// this.wechatOpenid = wechatOpenid; +// } +// +// @Basic +// @Column(name = "student_number") +// public String getStudentNumber() { +// return studentNumber; +// } +// +// public void setStudentNumber(String studentNumber) { +// this.studentNumber = studentNumber; +// } +// +// @Basic +// @Column(name = "subject_name") +// public String getSubjectName() { +// return subjectName; +// } +// +// public void setSubjectName(String subjectName) { +// this.subjectName = subjectName; +// } +// +// @Basic +// @Column(name = "score") +// public String getScore() { +// return score; +// } +// +// public void setScore(String score) { +// this.score = score; +// } +// +// @Basic +// @Column(name = "class_rank") +// public String getClassRank() { +// return classRank; +// } +// +// public void setClassRank(String classRank) { +// this.classRank = classRank; +// } +// +// @Basic +// @Column(name = "grade_rank") +// public String getGradeRank() { +// return gradeRank; +// } +// +// public void setGradeRank(String gradeRank) { +// this.gradeRank = gradeRank; +// } +// +// @Basic +// @Column(name = "exam_name") +// public String getExamName() { +// return examName; +// } +// +// public void setExamName(String examName) { +// this.examName = examName; +// } +// +// @Basic +// @Column(name = "inserttime") +// public Timestamp getInserttime() { +// return inserttime; +// } +// +// public void setInserttime(Timestamp inserttime) { +// this.inserttime = inserttime; +// } +// +// @Basic +// @Column(name = "updatetime") +// public Timestamp getUpdatetime() { +// return updatetime; +// } +// +// public void setUpdatetime(Timestamp updatetime) { +// this.updatetime = updatetime; +// } + +} diff --git a/src/main/java/com/zgczx/dto/AsahiChartAllRateDTO.java b/src/main/java/com/zgczx/dto/AsahiChartAllRateDTO.java new file mode 100644 index 0000000..5a2bce9 --- /dev/null +++ b/src/main/java/com/zgczx/dto/AsahiChartAllRateDTO.java @@ -0,0 +1,45 @@ +package com.zgczx.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * @author aml + * @date 2019/9/26 10:50 + */ +@Data +public class AsahiChartAllRateDTO { + + // 总分率值,即所得总分 / 总分满分标准 + private String totalScoreRate; + + // 三科分数之和率值,三科得分数和/ 三科总分 + private String threeSubjectsRate; + + // 6选3综合率值, 6选3综合得分 / 6选3综合满分标准分 + private String comprehensiveRate; + + // 所有真实科目的率值,k: 科目名称;v:所对应的率值 + private Map allSubjectRateMap; + +// +// // 语文率值, 语文得分 / 语文总分 +// private int languageScoreRate; +// // 数学率值, 数学得分 / 数学总分 +// private int mathScoreRate; +// // 英语率值, 英语得分 / 英语总分 +// private int englishScoreRate; +// // 物理率值, 物理得分 / 物理总分 +// private int physicalScoreRate; +// // 化学率值, 化学得分 / 化学总分 +// private int chemistryScoreRate; +// // 生物率值, 生物得分 / 生物总分 +// private int biologicalScoreRate; +// // 政治率值, 政治得分 / 政治总分 +// private int politicalScoreRate; +// // 历史率值, 历史得分 / 历史总分 +// private int historyScoreRate; +// // 地理率值, 地理得分 / 地理总分 +// private int geographyScoreRate; +} diff --git a/src/main/java/com/zgczx/dto/ExamCoversionTotalSectionDTO.java b/src/main/java/com/zgczx/dto/ExamCoversionTotalSectionDTO.java index 80dca86..5ab3ac1 100644 --- a/src/main/java/com/zgczx/dto/ExamCoversionTotalSectionDTO.java +++ b/src/main/java/com/zgczx/dto/ExamCoversionTotalSectionDTO.java @@ -26,10 +26,20 @@ public class ExamCoversionTotalSectionDTO { //综合年级排名 private int complexGradeRank; - // 年级排名进退名次 - private int waveGrade; - // 班级排名进退名次 - private int waveClass; +// // 年级排名进退名次 +// private int waveGrade; +// // 班级排名进退名次 +// private int waveClass; //存放某学生的6选3的具体科目 private List list; + + //三科班级进退名次 + private int threeWaveClass; + //三科年级进退名次 + private int threeWaveGrade; + //综合班级进退名次 + private int complexWaveClass; + //综合年级进退名次 + private int complexWaveGrade; + } diff --git a/src/main/java/com/zgczx/dto/ExamCoversionTotalSingleDTO.java b/src/main/java/com/zgczx/dto/ExamCoversionTotalSingleDTO.java index 3ff0ab7..fa981ff 100644 --- a/src/main/java/com/zgczx/dto/ExamCoversionTotalSingleDTO.java +++ b/src/main/java/com/zgczx/dto/ExamCoversionTotalSingleDTO.java @@ -3,6 +3,8 @@ import com.zgczx.dataobject.score.ExamCoversionTotal; import lombok.Data; +import java.util.List; + /** * @author aml * @date 2019/9/16 14:08 @@ -18,4 +20,30 @@ public class ExamCoversionTotalSingleDTO { private int waveGrade; // 班级排名进退名次 private int waveClass; + // 班级人数 + private int classNumber; + //年级人数 + private int gradeNumber; + //本此考试的总分标准 + private int sumScore; + // 语文总分标准 + private int languageScore; + // 数学满分标准 + private int mathScore; + // 英语满分标准 + private int englishScore; + // 物理满分标准 + private int physicalScore; + // 化学满分标准 + private int chemistryScore; + // 生物满分标准 + private int biologicalScore; + // 政治满分标准 + private int politicalScore; + // 历史满分标准 + private int historyScore; + // 地理满分标准 + private int geographyScore; + // subject此科目的对应分数 + private String score; } diff --git a/src/main/java/com/zgczx/dto/HistoricalAnalysisSingleDTO.java b/src/main/java/com/zgczx/dto/HistoricalAnalysisSingleDTO.java new file mode 100644 index 0000000..4c5cb1a --- /dev/null +++ b/src/main/java/com/zgczx/dto/HistoricalAnalysisSingleDTO.java @@ -0,0 +1,32 @@ +package com.zgczx.dto; + +import com.zgczx.dataobject.score.ExamCoversionTotal; +import lombok.Data; + +/** + * @author aml + * @date 2019/9/24 20:30 + */ +@Data +public class HistoricalAnalysisSingleDTO { + + private ExamCoversionTotal examCoversionTotal; + //单科班级排名 + private int classRank; + //单科年级排名 + private int gradeRank; + // 班级平均分 + private String classAverage; + // 年级平均分 + private String gradeAverage; + // 年级排名的百分率 + private String gradePercentage; + // 班级排名的百分率 + private String classPercentage; + // 班级平均分百分率 + private String classAveragePercentage; + // 年级平均分百分率 + private String gradeAveragePercentage; + // 单科分数的百分率 + private String singleScorePercentage; +} diff --git a/src/main/java/com/zgczx/dto/HistoricalAnalysisTotalDTO.java b/src/main/java/com/zgczx/dto/HistoricalAnalysisTotalDTO.java new file mode 100644 index 0000000..d2f10a3 --- /dev/null +++ b/src/main/java/com/zgczx/dto/HistoricalAnalysisTotalDTO.java @@ -0,0 +1,33 @@ +package com.zgczx.dto; + +import com.zgczx.dataobject.score.ExamCoversionTotal; +import lombok.Data; + +/** + * @author aml + * @date 2019/9/24 16:08 + */ +@Data +public class HistoricalAnalysisTotalDTO { + + private ExamCoversionTotal examCoversionTotal; +// //班级排名 +// private int classRank; +// //年级排名 +// private int gradeRank; + // 班级平均分 + private String classAverage; + // 年级平均分 + private String gradeAverage; + // 年级排名的百分率 + private String gradePercentage; + // 班级排名的百分率 + private String classPercentage; + // 班级平均分百分率 + private String classAveragePercentage; + // 年级平均分百分率 + private String gradeAveragePercentage; + // 总分的百分率 + private String totalScorePercentage; + +} diff --git a/src/main/java/com/zgczx/dto/ScoreReportDTO.java b/src/main/java/com/zgczx/dto/ScoreReportDTO.java new file mode 100644 index 0000000..2abbb67 --- /dev/null +++ b/src/main/java/com/zgczx/dto/ScoreReportDTO.java @@ -0,0 +1,53 @@ +package com.zgczx.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * @author aml + * @date 2019/9/27 12:12 + */ +@Data +public class ScoreReportDTO { + // 总分分数 + private String totalScore; + // 总分的年级排名 + private int totalScoreGradeRank; + // 总分的班级排名 + private int totalScoreClassRank; + + //总分的年级平均分 + private String totalAverage; + + private Map> map; + + //总分满分数值 + private String totalScoreStandard; + //班级总人数 + private int totalClassNumber; + // 年级总人数 + private int totalGradeNumber; + +// // 具体科目的分数map,k: 科目名称,V:对应的分数 +// private Map subjectScoreMap; +// // 具体科目的年级排名,K:科目名称,V:对应的年级排名 +// private Map subjectGradeRankMap; +// // 具体科目的班级排名,K:科目名称,V:对应的班级排名 +// private Map subjectClassRankMap; +// // 总分满分标准、各科满分标准 +// private Map subjectStandardMap; +// + + +// //语文map,一个map中存放,分数、年排、班排、满分标准 +// private Map yuwenMap; +// private Map shuxueMap; +// private Map yingyuMap; +// private Map wuliMap; +// private Map huaxueMap; +// private Map shengwuMap; +// private Map diliMap; +// private Map lishiMap; +// private Map zhengzhiMap; +} diff --git a/src/main/java/com/zgczx/dto/SubjectAnalysisDTO.java b/src/main/java/com/zgczx/dto/SubjectAnalysisDTO.java new file mode 100644 index 0000000..6c9ae41 --- /dev/null +++ b/src/main/java/com/zgczx/dto/SubjectAnalysisDTO.java @@ -0,0 +1,36 @@ +package com.zgczx.dto; + +import com.zgczx.dataobject.score.ExamCoversionTotal; +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author aml + * @date 2019/9/23 11:17 + */ +@Data +public class SubjectAnalysisDTO { + + private ExamCoversionTotal examCoversionTotal; + + // 学科贡献率,各单科贡献率,各科分数和总分的比值 + private Map contributionRate; + + // 学科均衡差值,即各科年排排名和总分年级排名的差值 + private Map equilibriumDifference; + + // 年级的标准率值,即年级排名 / 年级总人数 + private String gradeRate; + +// // 上次考试的 学科贡献率,各单科贡献率,各科分数和总分的比值 +// private Map oldcontributionRate; +// +// // 前三次 学科贡献率的平均值 +// private Map avgcontributionRate; + + // 此map中九门科目的map,每一个map中最多能放 + // 本次、上次、平均、差值(本次 - 平均) 率值 + private Map> map; +} diff --git a/src/main/java/com/zgczx/dto/SubjectDTO.java b/src/main/java/com/zgczx/dto/SubjectDTO.java new file mode 100644 index 0000000..d2cec5b --- /dev/null +++ b/src/main/java/com/zgczx/dto/SubjectDTO.java @@ -0,0 +1,32 @@ +package com.zgczx.dto; + +import com.zgczx.dataobject.score.ExamCoversionTotal; +import lombok.Data; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; + +import javax.persistence.Entity; +import javax.persistence.Id; +import java.util.UUID; + +/** + * @author aml + * @date 2019/10/23 14:14 + */ +@Data +@Entity +public class SubjectDTO { + + @Id + int id; + private String yuwen; + private String shuxue; + private String yingyu; + private String wuli; + private String huaxue; + private String shengwu; + private String zhengzhi; + private String lishi; + private String dili; + +} diff --git a/src/main/java/com/zgczx/enums/ResultEnum.java b/src/main/java/com/zgczx/enums/ResultEnum.java index 9fdb969..8201ef6 100644 --- a/src/main/java/com/zgczx/enums/ResultEnum.java +++ b/src/main/java/com/zgczx/enums/ResultEnum.java @@ -34,7 +34,7 @@ public enum ResultEnum { /** * 微信公众账号方面错误 */ - WECHAT_MP_ERROR(504, "微信公众账号方面错误"), + // WECHAT_MP_ERROR(504, "微信公众账号方面错误"), /** * 课程冲突 */ @@ -47,11 +47,14 @@ public enum ResultEnum { + + /* 参数错误:10001-19999 */ PARAM_IS_INVALID(10001, "参数无效"), PARAM_IS_BLANK(10002, "参数为空"), PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"), PARAM_NOT_COMPLETE(10004, "参数缺失"), + PARAM_STRING_EXCEPTION(10005,"字符串格式异常"), /* 用户错误:20001-29999*/ USER_NOT_LOGGED_IN(20001, "用户未登录"), @@ -62,6 +65,8 @@ public enum ResultEnum { /* 业务错误:30001-39999 */ SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "某业务出现问题"), + SPECIFIED_QUESTIONED_BULK_INSERT_FAILED(30002, "批量插入出错"), + NEVER_DID_THIS_PAPER(30003,"您从未做过此试卷"), /* 系统错误:40001-49999 */ SYSTEM_INNER_ERROR(40001, "系统繁忙,请稍后重试"), @@ -70,6 +75,7 @@ public enum ResultEnum { RESULE_DATA_NONE(50001, "数据未找到"), DATA_IS_WRONG(50002, "数据有误"), DATA_ALREADY_EXISTED(50003, "数据已存在"), + DATA_OUT_RANGE(50004,"数据超出范围"), /* 接口错误:60001-69999 */ INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"), @@ -80,7 +86,15 @@ public enum ResultEnum { INTERFACE_EXCEED_LOAD(60006, "接口负载过高"), /* 权限错误:70001-79999 */ - PERMISSION_NO_ACCESS(70001, "无访问权限"); + PERMISSION_NO_ACCESS(70001, "无访问权限"), + + + /* 微信公众号有关的错误: 80001-89999*/ + WECHAT_MP_ERROR(80001, "微信公众账号方面错误"), + + + + ; diff --git a/src/main/java/com/zgczx/exception/UserAuthorizeException.java b/src/main/java/com/zgczx/exception/UserAuthorizeException.java new file mode 100644 index 0000000..f80e7e8 --- /dev/null +++ b/src/main/java/com/zgczx/exception/UserAuthorizeException.java @@ -0,0 +1,9 @@ +package com.zgczx.exception; + +/** + * explain: 用户权限认证 + * @author aml + * @date 2019/11/9 13:51 + */ +public class UserAuthorizeException extends RuntimeException { +} diff --git a/src/main/java/com/zgczx/handler/ScoreExceptionHandler.java b/src/main/java/com/zgczx/handler/ScoreExceptionHandler.java new file mode 100644 index 0000000..fc15156 --- /dev/null +++ b/src/main/java/com/zgczx/handler/ScoreExceptionHandler.java @@ -0,0 +1,25 @@ +package com.zgczx.handler; + +import com.zgczx.VO.ResultVO; +import com.zgczx.exception.ScoreException; +import com.zgczx.utils.ResultVOUtil; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +/** + * 异常拦截器,异常统一返回格式 + * @author aml + * @date 2019/10/23 21:47 + */ +@RestControllerAdvice +public class ScoreExceptionHandler { + + @ExceptionHandler(value = ScoreException.class) +// @ResponseStatus(HttpStatus.FORBIDDEN) //控制返回的status != 200 + public ResultVO handlerScoreException(ScoreException e){ + return ResultVOUtil.error(e.getCode(), e.getMessage(),e.data); + } + +} diff --git a/src/main/java/com/zgczx/handler/UserAuthorizeExceptionHandler.java b/src/main/java/com/zgczx/handler/UserAuthorizeExceptionHandler.java new file mode 100644 index 0000000..702eb5b --- /dev/null +++ b/src/main/java/com/zgczx/handler/UserAuthorizeExceptionHandler.java @@ -0,0 +1,42 @@ +package com.zgczx.handler; + +import com.zgczx.config.wechatconfig.ProjectUrlConfig; +import com.zgczx.exception.UserAuthorizeException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.servlet.ModelAndView; + +/** + * explain:user授权异常捕获处理 + * + * @author aml + * @date 2019/11/9 13:58 + */ +@ControllerAdvice +public class UserAuthorizeExceptionHandler { + + @Autowired + private ProjectUrlConfig projectUrlConfig; + + /** + * 处理UserAuthorizeException.class这个类抛出的异常, + * 并且跳转到指定的url。 + * 拦截登录异常 + * 例如:重定向至登录页面 - 也就是微信扫码登录 + * + * @return + */ + @ExceptionHandler(value = UserAuthorizeException.class)//处理此类抛出的异常 + public ModelAndView handlerUserAuthorizeException() { + return new ModelAndView("redirect:" + .concat(projectUrlConfig.wechatOpenAuthorize)//微信开放平台登录授权地址 + .concat("/wechat/qrAuthorize") + .concat("?returnUrl=") + // .concat(projectUrlConfig.score_analysis())//服务器访问的地址 + .concat("/seller/login")); + + } + + +} diff --git a/src/main/java/com/zgczx/mapper/ManuallyEnterGradesMapper.java b/src/main/java/com/zgczx/mapper/ManuallyEnterGradesMapper.java new file mode 100644 index 0000000..7f615be --- /dev/null +++ b/src/main/java/com/zgczx/mapper/ManuallyEnterGradesMapper.java @@ -0,0 +1,24 @@ +package com.zgczx.mapper; + +import com.zgczx.repository.mysql1.score.model.ManuallyEnterGrades; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 这个实体类的mapper接口,主要查询此类中的所有数据接口方法 + * @author aml + * @date 2019/11/6 13:51 + */ +public interface ManuallyEnterGradesMapper { + + List getManuallyEnterGrades(); + + ManuallyEnterGrades getManuallyEnterGradesById(int id); + + // 获取此用户的所有录入数据的年份 + List getYears(String openid); + + // 获取此用户的所有录入数据的年份 + List getMonths(@Param("openid")String openid, @Param("year")String year); +} diff --git a/src/main/java/com/zgczx/repository/basefactory/BaseFactory.java b/src/main/java/com/zgczx/repository/basefactory/BaseFactory.java new file mode 100644 index 0000000..0568e66 --- /dev/null +++ b/src/main/java/com/zgczx/repository/basefactory/BaseFactory.java @@ -0,0 +1,38 @@ +package com.zgczx.repository.basefactory; + +import org.springframework.stereotype.Repository; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceContext; + +/** + * 获取多数据源中的实体管理工厂 + * @author aml + * @date 2019/11/1 11:07 + */ +@Repository +public class BaseFactory { + + /** + * 数据源1 + */ + public EntityManager entityManagerDb1; + + /** + * 数据源2 + */ + public EntityManager entityManagerDb2; + + @PersistenceContext(unitName = "entityManagerFactoryDb1") + public void setEntityManagerDb1(EntityManager entityManagerDb1){ + this.entityManagerDb1 = entityManagerDb1; + } + + // 注入指定数据源的实体管理工厂 + @PersistenceContext(unitName = "entityManagerFactoryDb2") + public void setEntityManagerDb2(EntityManager entityManagerDb2){ + this.entityManagerDb2 = entityManagerDb2; + } + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/ChapterDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/ChapterDao.java new file mode 100644 index 0000000..ae6685e --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/ChapterDao.java @@ -0,0 +1,42 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.Chapter; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 章节表 + * @author aml + * @date 2019/12/11 17:00 + */ +@Repository +public interface ChapterDao extends JpaRepository { + + //1. 获取 此年级的所有的章名称:例如获取高一的所有章 + @Query(value = "select DISTINCT chapter from e_chapter where level_name=?1 and subject=?2 ", nativeQuery = true) + List findByLevelNameAndSubject(String levelName, String subject); + + //2. 获取所有的 节名称,根据 高中 和 章的名称 + @Query(value = "SELECT section FROM e_chapter WHERE level_name=?1 AND chapter=?2 and subject=?3 ", nativeQuery = true) + List findByLevelNameAndChapterAndSubject(String levelName, String chapter, String subject); + + //3. 获取所有章的名称,根据节的名称 +// SELECT DISTINCT chapter FROM e_chapter WHERE section IN('第1节 细胞膜的结构和功能','第2节 细胞','ddd') + @Query(value = "SELECT DISTINCT chapter FROM e_chapter WHERE section IN(?1)", nativeQuery = true) + List findBySectionIn(List sectionList); + + //4. 获取所有节名称,根据章名称 和 科目 + @Query(value = "SELECT section FROM e_chapter WHERE chapter=?1 AND SUBJECT=?2 ", nativeQuery = true) + List findByChapterAndSubject(String chapter,String subject); + + // 5. 根据学科和年级 获取该学科的所有章节(已涉及学科和年级) lxj + @Query(value = "select distinct chapter from e_chapter where `subject`=?1 and level_name= ?2 ",nativeQuery = true) + List findChapterBySubject(String subject,String levelName); + + //6. 根据节的名称获取章的名称 + @Query(value = "SELECT chapter FROM e_chapter WHERE section=?1 ", nativeQuery = true) + List findBySection(String section); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/ExamContentDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/ExamContentDao.java new file mode 100644 index 0000000..9c62915 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/ExamContentDao.java @@ -0,0 +1,15 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.ExamContent; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/12/19 15:10 + */ +@Repository +public interface ExamContentDao extends JpaRepository { + + ExamContent findByExamNameAndSubject(String examName, String subject); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/ExamPaperDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/ExamPaperDao.java new file mode 100644 index 0000000..c684263 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/ExamPaperDao.java @@ -0,0 +1,49 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.ExamPaper; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.keyvalue.repository.config.QueryCreatorType; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 试卷表 + * @author aml + * @date 2019/12/11 20:54 + */ +@Repository +public interface ExamPaperDao extends JpaRepository { + + //1. 获取此试卷的所有信息,根据 试卷名称和科目 + ExamPaper findByExamNameAndSubjectAndValid(String examName, String subject,int deleted); + ExamPaper findByExamNameAndSubjectAndValidAndGradeLevel(String examName, String subject,int deleted,String gradeLevel); + @Query(value = "select * from e_exam_paper where exam_name=?1 and subject=?2 and valid=?3", nativeQuery = true) + ExamPaper getBy(String examName, String subject,int deleted); + + //3. 获取所有的试卷信息,从而判断哪个属于章节练习,根据idList + List findByIdIn(List idList); + + // 4. 获取所有考试名称(不包含专项练习或章节练习) lxj + @Query(value = "select exam_name from e_exam_paper where exam_source='模拟考试' or exam_source='历年真题' ",nativeQuery = true) + List getExamName(); + + // 5. 根据学科和年级查询考试名称和题目总数 + @Query(value = "select * from e_exam_paper where subject=?1 and grade_level=?2 ",nativeQuery = true) + List getExamPaper(String subject,String levelName); + + //6.模拟考试: 获取模拟考试的名称,不包括期中、期末;根据科目、年级、模拟考试、valid=1 + @Query(value = "SELECT * FROM e_exam_paper WHERE SUBJECT=?1 AND grade_level=?2 AND exam_name NOT LIKE ?4 AND exam_name NOT LIKE ?5 AND exam_source=?3 AND valid=1 ", nativeQuery = true) + List getAllBySubjectAndGradeLevelAndExamSource(String subject,String gradeLevel,String examSource,String condition1,String condition2); + //7.模拟考试: 获取 期中 的模拟考试的名称;根据科目、年级、模拟考试、valid=1 + @Query(value = "SELECT * FROM e_exam_paper WHERE SUBJECT=?1 AND grade_level=?2 AND exam_name LIKE ?4 AND exam_source=?3 AND valid=1 ", nativeQuery = true) + List getAllBySubjectAndGradeLevelAndExamSource2(String subject,String gradeLevel,String examSource,String condition1); + + //8. 获取此年级、此科目的所有 试卷信息 + List getBySubjectAndGradeLevelAndValid(String subject,String gradeLevel,int valid); + + //9. 获取有效的 此试卷信息 + @Query(value = "select * from e_exam_paper where id=?1 and valid=?2 ", nativeQuery = true) + ExamPaper findByIdAndValid(int id, int valid); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/QuestionDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/QuestionDao.java new file mode 100644 index 0000000..67a27e3 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/QuestionDao.java @@ -0,0 +1,90 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.Question; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import javax.transaction.Transactional; +import java.util.List; + +/** + * 题库表 + * @author aml + * @date 2019/12/11 20:47 + */ +@Repository +public interface QuestionDao extends JpaRepository { + + //1. 获取相同考试名的所有题 + List findByExamName(String examName); + + //2. 获取此试卷中的所有题的信息,根据idList:题库的主键id列表 + List findByIdIn(List idList); + + // 3. 获取此道题的 科目名称 : 根据 question中的主键id + @Query(value = "SELECT SUBJECT FROM e_exam_paper WHERE id=(SELECT exam_id FROM e_question WHERE id =?1 )", nativeQuery = true) + String getSubjectName(int id); + //3.1 获取此题的 科目名称:兼容直接录入专项的题,exam_paper没有此录入专项的数据 + @Query(value = "select subject from e_question where id =?1 ", nativeQuery = true) + String getSubject(int id); + + // 4. 根据章节名称查询收藏的题的详细信息 lxj + @Query(value = "select * from e_question where id in (select distinct question_id from e_user_collect as euc,e_exam_paper as eep,e_chapter as ec \n" + + "where ec.chapter=?3 and ec.section=?4 \n" + + "and ec.section=eep.exam_name and eep.id=euc.exam_paper_id and euc.valid=1 and euc.student_number=?1 and euc.subject=?2) ",nativeQuery = true) + List getSectionCollectProblems(String stuNumber,String subject,String chapter,String section); + + // 5. 根据考试名称查询收藏的题的详细信息 lxj + @Query(value = "select * from e_question where id in (select distinct question_id from e_user_collect as euc,e_exam_paper as eep\n" + + "where eep.exam_name=?3 \n" + + "and eep.id=euc.exam_paper_id and euc.valid=1 and euc.student_number=?1 and euc.subject=?2) ",nativeQuery = true) + public List getExamCollectProblems(String stuNumber,String subject,String examName); + + // 6. 根据question_id查询题的详细信息 lxj + @Query(value = "select * from e_question where id=?1 and subject=?2 ",nativeQuery = true) + public List getQuestionInfoById(int id,String subject); + + // 7. 根据章名称获取本章对应的题数 lxj + @Query(value = "select count(distinct eq.id) from e_chapter as ec,e_question as eq,e_exam_paper as eep where ec.`subject`=?1 and ec.level_name=?2 and \n" + + "ec.chapter=?3 and ec.section=eep.exam_name and eep.id=eq.exam_id ",nativeQuery = true) + public int getQuestionsNumByChapter(String subject,String levelName,String chapter); + + // 8. 根据科目、章的名称、知识点得到对应的题的详细信息(已涉及学科和年级) lxj + @Query(value = "select ec.chapter,eq.* from e_question as eq,e_chapter as ec,e_exam_paper as eep where ec.`subject`=?1 and ec.level_name=?2 and \n" + + "ec.chapter=?3 and ec.section=eep.exam_name and eep.id=eq.exam_id and eq.question_attribute=?4 ",nativeQuery = true) + public List getQuestionsBySubjectAndChapterAndAttribute(String subject,String levelName,String chapter,String attribute); + + // 9. 根据章节 获取知识点和对应的题数(已涉及学科和年级) lxj + @Query(value = "select distinct eq.question_attribute from e_question as eq,e_chapter as ec,e_exam_paper as eep where ec.`subject`=?1 and ec.level_name=?2 and \n" + + "ec.chapter=?3 and ec.section=eep.exam_name and eep.id=eq.exam_id ",nativeQuery = true) + public List getAttributesByChapter(String subject,String levelName,String chapter); + + // 10. 根据知识点获取对应的题数(已涉及学科和年级) lxj + @Query(value = "select count(distinct id) from e_question as eq where find_in_set(?1,question_attribute) " ,nativeQuery = true) + int getQuestionsNumsByAttribute(String attribute); + + // 11. 根据年级和学科查询对应的知识点 + @Query(value = "select distinct question_attribute from e_question where `subject`=?1 and level_name=?2 and valid=1",nativeQuery = true) + List getQUestionAttribute(String subject,String levelName); + + + + + // 批量修改,用于解析Word并存库 + @Modifying + @Transactional + @Query(value = "update e_question as a set a.exam_id=?2 where a.id in (?1) ", nativeQuery = true) + int updateByIds(List idList,int examId); + + // 获取此题 有效的所有数据 + Question getByIdAndValid(int id, int valid); + + //14. 专项练习: 根据知识点、年级、科目 获取相关的所有题 + @Query(value = "SELECT * FROM e_question WHERE SUBJECT=?1 AND level_name=?2 AND FIND_IN_SET(?3,question_attribute) and valid=1 ", nativeQuery = true) + List getAllSubjectAndLevelNameByQuestionAndAttribute(String subject,String levelName,String point); + //14.2 专项练习:根据 全部、年级、科目 获取所有题目 + @Query(value = "SELECT * FROM e_question WHERE SUBJECT=?1 AND level_name=?2 AND valid=1", nativeQuery = true) + List getAllSubjectAndLevelName(String subject,String levelName); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserCollectDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserCollectDao.java new file mode 100644 index 0000000..878c848 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserCollectDao.java @@ -0,0 +1,95 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.UserCollect; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Map; + +/** + * 用户收藏 表 + * @author aml + * @date 2019/12/17 16:52 + */ +@Repository +public interface UserCollectDao extends JpaRepository { + + //1. 获取此用户 -> 此科目 -> 此试卷 -> 此题 是否收藏 + @Query(value = "SELECT * FROM e_user_collect WHERE student_number=?1 AND SUBJECT=?2 AND exam_paper_id=?3 AND question_id=?4 AND valid=?5", nativeQuery = true) + UserCollect getByStudentNumberAndSubjectAndExamPaperIdAndQuestionId(String stuNumber,String subject,int paperId,int questionId,int valid); + //1.2 获取此用户、此科目、此题是否收藏 + UserCollect getByStudentNumberAndSubjectAndQuestionId(String stuNumber,String subject,int questionId); + //2. 查询此题是否收藏 + UserCollect findByQuestionIdAndValid(int id, int valid); + + // 3. 统计用户收藏总题数 lxj + @Query(value="select count(distinct question_id) from e_user_collect where student_number=?1 and subject=?2 and valid=1 ",nativeQuery = true) + int getCollectProblemsNum(String stuNumber,String subject); + + // 3. 按年级统计用户收藏总题数 lxj + @Query(value = "select count(distinct question_id) from e_user_collect as euc,e_exam_paper as eep where eep.grade_level=?2 and eep.id=euc.exam_paper_id \n" + + "and euc.student_number=?1 and euc.subject=?3 and euc.valid=1 ",nativeQuery = true) + int getCollectCountByGradeLevel(String stuNumber,String levelName,String subject); + + // 4. 统计用户收藏练习题数 lxj + @Query(value = "select count(distinct euc.question_id) from e_user_collect euc,e_question eq where euc.student_number=?1 and euc.`subject`=?2 and euc.valid=1 and euc.question_id=eq.id and eq.question_source='章节练习' ",nativeQuery = true) + int getCollectChapterProblemsNum(String stuNumber,String subject); + + // 5. 统计用户收藏考试题数 lxj + @Query(value="select count(distinct euc.question_id) from e_user_collect euc,e_question eq where euc.student_number=?1 and euc.`subject`=?2 and euc.valid=1 and euc.question_id=eq.id and (eq.question_source='模拟考试' or eq.question_source='历年真题') ",nativeQuery = true) + int getCollectExamProblemsNum(String stuNumber,String subject); + + // 6. 统计用户每一章收藏的题数 lxj + @Query(value = "select count(distinct euc.question_id) from e_exam_paper as eep,e_user_collect as euc,e_chapter as ec where eep.chapter_id=ec.id and ec.chapter=?3 and eep.id=euc.exam_paper_id and euc.valid=1 and euc.student_number=?1 and euc.subject=?2 ",nativeQuery = true) + int getCollectProblemsByChapter(String stuNumber, String subject,String chapter); + + // 7. 统计用户每次考试收藏的题数 lxj + @Query(value = "select count(distinct euc.question_id) from e_exam_paper as eep,e_user_collect as euc where euc.exam_paper_id=eep.id \n" + + "and exam_name=?3 and euc.valid=1 and euc.student_number=?1 and euc.subject=?2 ",nativeQuery = true) + int getCollectProblemsByExam(String stuNumber,String subject,String examName); + + // 8. 根据节的名称获取对应的收藏题数 lxj + @Query(value = "select count(distinct euc.question_id) from e_exam_paper as eep,e_user_collect as euc,e_chapter as ec \n" + + "where eep.chapter_id=ec.id and ec.section=?3 \n" + + "and eep.id=euc.exam_paper_id and euc.valid=1 and euc.student_number=?1 and euc.subject=?2 ",nativeQuery = true) + int getCollectProblemsBySection(String stuNumber,String subject,String section); + // 9. 查询此用户此题是否插入收藏库表中 aml + UserCollect findByStudentNumberAndQuestionId(String sutNumber,int questionId); + + // 10. 查看某道题某个用户是否收藏了 lxj + @Query(value = "select count(*) from e_user_collect where student_number=?1 and `subject`=?2 and valid=1 and question_id=?3 ",nativeQuery = true) + int getIfCollectByStuNumAndQuestionId(String stuNumber,String subject,int questionId); + + //11. 我的收藏:传来“全部”时,获取所有 用户的、科目、年级、所有数量 + @Query(value = "SELECT * FROM e_user_collect AS euc \n" + + "INNER JOIN e_question AS q ON euc.`question_id`=q.id \n" + + "INNER JOIN e_exam_paper AS ep \n" + + "ON euc.`exam_paper_id`=ep.`id`\n" + + "WHERE euc.student_number=?1 AND euc.`subject`=?2 AND q.level_name=?3 AND euc.valid=1 ", nativeQuery = true) + List totalNum(String stuNumber, String subject, String gradeLevel); + + //12. 我的收藏:获取收藏表中某用户-》某年级-》某科目 某类(章节练习) 的所有数量 + @Query(value = "SELECT * FROM e_user_collect AS euc \n" + + "INNER JOIN e_question AS q \n" + + "ON euc.`question_id`=q.`id`\n" + + "INNER JOIN e_exam_paper AS ep \n" + + "ON euc.`exam_paper_id`=ep.`id` \n" + + "WHERE euc.student_number=?1 AND ep.`grade_level`=?2 AND euc.`subject`=?3 AND ep.`exam_source`=?4 AND euc.valid=1 ", nativeQuery = true) + List getAllInfo(String stuNumber,String gradeLevel,String subject,String examCategory); + + //13. 我的收藏:获取收藏表中某用户-》某年级-》某科目 所有类别(章节练习、专项、模拟、真题) 的所有数量 + @Query(value = "SELECT * FROM e_user_collect AS euc \n" + + "INNER JOIN e_question AS q\n" + + "ON euc.`question_id`=q.`id`\n" + + "INNER JOIN e_exam_paper AS ep\n" + + "ON euc.`exam_paper_id`=ep.`id`\n" + + "WHERE euc.student_number=?1 AND ep.`grade_level`=?2 AND euc.`subject`=?3 AND euc.valid=1 \n" + + "GROUP BY euc.`question_id` \n" + + "ORDER BY euc.inserttime ASC", nativeQuery = true) + List getAllByFull(String stuNumber,String gradeLevel,String subject); + + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserPaperRecordDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserPaperRecordDao.java new file mode 100644 index 0000000..4d8df43 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserPaperRecordDao.java @@ -0,0 +1,27 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.UserPaperRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author aml + * @date 2019/12/22 19:15 + */ +@Repository +public interface UserPaperRecordDao extends JpaRepository { + + //1. 获取此用户是否 存在 此套试卷的 记录 按记录的次数 降序返回 + @Query(value = "SELECT * FROM e_user_paper_record WHERE student_number=?1 AND subject=?2 AND exam_paper_id=?3 ORDER BY times DESC", nativeQuery = true) + List getByStudentNumberAndSubjectAndExamPaperId(String stuNumber,String subjectName,int examPaperId); + + //2. 获取此用户的 本次试卷的保存信息,按照times降序获取 + // List getByStudentNumberAndSubjectAndExamPaperId(String stu) + + + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserQuestionRecordDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserQuestionRecordDao.java new file mode 100644 index 0000000..ffd1d23 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserQuestionRecordDao.java @@ -0,0 +1,176 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.UserQuestionRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 用户做题记录表 + * @author aml + * @date 2019/12/16 15:11 + */ +@Repository +public interface UserQuestionRecordDao extends JpaRepository { + + //1. 获取某学生->某科目 -> 某试卷的所有做题记录; 可以统计做对数量和做错数量 + List getByStudentNumberAndSubjectAndExamPaperIdAndTimes(String studentNumber,String subject,int paperId,int times); + + //2. 获取这份试卷中这道题,此用户是否做过,按做过次数的降序排列 + @Query(value = "SELECT * FROM e_user_question_record WHERE student_number=?1 AND exam_paper_id=?2 AND question_id=?3 ORDER BY times DESC", nativeQuery = true) + List getByStudentNumberAndExamPaperIdAndQuestionId(String stuNumber,int sourcePaperId,int questionid); + //2.2 获取这份试卷中这道题,此用户是否做过,按做过次数的降序排列,3.23 + 章节练习这个标签 + @Query(value = "SELECT * FROM e_user_question_record WHERE student_number=?1 AND exam_paper_id=?2 AND question_id=?3 AND exam_category='章节练习' ORDER BY times DESC", nativeQuery = true) + List getByStudentNumberAndExamPaperIdAndQuestionId2(String stuNumber,int sourcePaperId,int questionid); + + // 3. 获取 此用户回显的 做题记录 + @Query(value = "SELECT * FROM e_user_question_record WHERE student_number=?1 AND SUBJECT=?2 AND exam_paper_id=?3 ORDER BY times DESC\n", nativeQuery = true) + List getByStudentNumberAndSubjectAndExamPaperId(String studentNumber,String subject,int sourcePaperId); + // 3.2 获取 此用户回显的 做题记录. 首页面继续学习接口 + @Query(value = "SELECT * FROM e_user_question_record WHERE student_number=?1 AND SUBJECT=?2 AND exam_category='章节练习' ORDER BY times DESC\n", nativeQuery = true) + List getByStudentNumberAndSubjectAndExamPaperId2(String studentNumber,String subject); + + //4. 获取此学生-》此科目-》所有错题的试卷id: exam_paper_id + @Query(value = "SELECT DISTINCT exam_paper_id FROM e_user_question_record WHERE student_number=?1 AND SUBJECT=?2 ", nativeQuery = true) + List getAllExamPaperId(String stuNumber, String subject); + + //5. 获取此用户-》此科目-》章节练习中 所有错的 试卷名称(每节的名称) + @Query(value = "SELECT DISTINCT exam_paper_name FROM e_user_question_record WHERE student_number=?1 AND SUBJECT=?2 AND do_right=?3 AND exam_category IN(?4,?5) ", nativeQuery = true) + List getAllErrInfo(String stuNumber,String subject,int doRight,String examCategory,String examCategory2); + + //6. 获取此用户-》此科目-》章节练习-》所有试卷名称 + @Query(value = "SELECT DISTINCT exam_paper_name FROM e_user_question_record WHERE student_number=?1 AND SUBJECT=?2 AND exam_category=?3 ", nativeQuery = true) + List getAllExamPaperName(String stuNumber,String subject,String examCategory); + + //7. 获取此用户-》此科目-》章节练习中 所有错题的信息 + List getByStudentNumberAndSubjectAndDoRightAndExamCategory(String stuNumber,String subject,int doRight,String examCategory); + + //8. 获取此节的 所有错题数量 lxj + @Query(value = "SELECT COUNT(DISTINCT question_id) FROM e_user_question_record WHERE student_number=?1 AND SUBJECT=?2 AND exam_paper_name=?3",nativeQuery = true) + int getByErrNumber(String stuNumber,String subject,String examPaperName); + + // 9. 查询用户某试卷最新一次做题记录 lxj + @Query(value = "select * from e_user_question_record where student_number=?1 and exam_paper_name=?2 and exam_category=?3 and \n" + + "times=(select max(times) from e_user_question_record where student_number=?1 and exam_paper_name=?2 and exam_category=?3) ",nativeQuery = true) + List getUserQuestionRecord(String stuNumber,String examName,String source); + // 9.2 查询用户某试卷最新一次做题记录 lxj + @Query(value = "select * from e_user_question_record where student_number=?1 and exam_paper_name=?2 and times=(select max(times) \n" + + "from e_user_question_record where student_number=?1 and exam_paper_name=?2) AND inserttime >=?3 AND inserttime <=?4 ",nativeQuery = true) + List getUserQuestionRecord2(String stuNumber,String examName,String starTime,String endTime); + // 9.3 用于十五接口 查询用户某试卷最新一次做题记录 lxj + @Query(value = "select * from e_user_question_record where student_number=?1 and exam_paper_name=?2 and times=(select max(times) \n" + + "from e_user_question_record where student_number=?1 and exam_paper_name=?2) AND exam_category=?3 ",nativeQuery = true) + List getUserQuestionRecord3(String stuNumber,String examName,String source); + + // 9(1). 查询用户专项练习最新一次做题记录 lxj + @Query(value = "select * from e_user_question_record where student_number=?1 and knowledge_points=?2 and exam_category=?3 and \n" + + "times=(select max(times) from e_user_question_record where student_number=?1 and exam_category=?3 \n" + + "and knowledge_points=?2) ",nativeQuery = true) + List getUserQuestionRecordByKnowledgePoints(String stuNumber,String knowledgePoints,String source); + // 3.2号 9(1).2. 查询用户、科目、年级、专项练习最新一次做题记录 lxj + @Query(value = "SELECT * FROM e_user_question_record AS euqr\n" + + "INNER JOIN e_question AS eq\n" + + "ON euqr.question_id=eq.id\n" + + "WHERE euqr.student_number=?1 AND euqr.subject=?2 AND euqr.exam_category=?3 AND eq.level_name=?4 AND \n" + + "euqr.times=(SELECT MAX(times) FROM e_user_question_record WHERE student_number=?1 AND exam_category=?3 \n" + + "AND SUBJECT=?2) ",nativeQuery = true) + List getUserQuestionRecordByKnowledgePoints2(String stuNumber,String subject,String source,String levelName); + + + // 10. 查询用户某份试卷最新一次做题时间 lxj + @Query(value = "select max(updatetime) from e_user_question_record where student_number=?1 and exam_paper_name=?2 \n" + + "and exam_category=?3 and times=(select max(times) from e_user_question_record where student_number=?1 \n" + + "and exam_paper_name=?2 and exam_category=?3)",nativeQuery = true) + String getDoTimeByChapter(String stuNumber,String examName,String category); + // 10.2 查询用户某份试卷最新一次做题时间 lxj + @Query(value = "select max(updatetime) from e_user_question_record where student_number=?1 and exam_paper_name=?2 \n" + + "and exam_category=?3 and times=(select max(times) from e_user_question_record where student_number=?1 \n" + + "and exam_paper_name=?2 and exam_category=?3) AND inserttime >=?4 AND inserttime <=?5 ",nativeQuery = true) + String getDoTimeByChapter2(String stuNumber,String examName,String category,String starTime,String endTime); + // 11. 根据用户学号查询用户做题时间 lxj + @Query(value = "select distinct date_format(euqr.updatetime,'%Y-%m-%d') date FROM e_user_question_record as euqr,e_question as eq,\n" + + "e_exam_paper as eep where euqr.student_number=?1 and euqr.`subject`=?2 and euqr.question_id=eq.id and eq.exam_id=eep.id \n" + + "and eep.grade_level=?3 ",nativeQuery = true) + List getDoQuestionsDate(String stuNumber,String subject,String levelName); + + /* // 12. 根据用户时间统计用户当天做题数 lxj + @Query(value = "select count(id) from e_user_question_record where student_number=?1 and DATE_FORMAT(inserttime,'%Y-%m-%d')=?2 ",nativeQuery = true) + int getDoQUestionsNumsByDate(String stuNumber,String date);*/ + //3.3 修改 12.根据用户时间统计用户当天做题数 lxj + @Query(value = "SELECT COUNT(euqr.id) FROM e_user_question_record AS euqr\n" + + "INNER JOIN e_question AS eq\n" + + "ON euqr.question_id=eq.id\n" + + "WHERE euqr.student_number=?1 AND DATE_FORMAT(euqr.inserttime,'%Y-%m-%d')=?2 AND euqr.subject=?3 AND eq.level_name=?4 ",nativeQuery = true) + int getDoQUestionsNumsByDate(String stuNumber,String date,String subject,String levelName); + +/* // 13. 根据做题时间和用户学号查询用户当天做对题数 lxj + @Query(value = "select count(id) from e_user_question_record where student_number=?1 and DATE_FORMAT(inserttime,'%Y-%m-%d')=?2 and do_right=?3 ",nativeQuery = true) + int getDoQuestionsRightNumsByDate(String stuNumber,String date, int doRight);*/ +// 3.3 修改 13. 根据做题时间和用户学号查询用户当天做对题数 lxj + @Query(value = "SELECT COUNT(euqr.id) FROM e_user_question_record AS euqr\n" + + "INNER JOIN e_question AS eq\n" + + "ON euqr.question_id=eq.id\n" + + "WHERE euqr.student_number=?1 AND DATE_FORMAT(euqr.inserttime,'%Y-%m-%d')=?2 AND euqr.subject=?3 AND eq.level_name=?4 AND euqr.do_right=?5 \n ",nativeQuery = true) + int getDoQuestionsRightNumsByDate(String stuNumber,String date, String subject,String levelName,int doRight); + ////3.22修改,获取具体学科的做题时间 + // 14. 根据做题时间查询用户当天做题情况(用户获取用户做每道题的时间) lxj + @Query(value = "select do_time from e_user_question_record where student_number=?1 and DATE_FORMAT(inserttime,'%Y-%m-%d')=?2 and subject=?3 ",nativeQuery = true) + List getDoQuestionsTimeList(String stuNumber,String date,String subject); + + // 15. 每个知识点最新一次做题时间 + + // 16. 按照知识点统计用户最新一次做题记录 lxj + @Query(value = "select * from e_user_question_record where student_number=?1 and knowledge_points=?2 and exam_category=?3 and \n" + + "times=(select max(times) from e_user_question_record where student_number=?1 and knowledge_points=?2 and exam_category=?3) ",nativeQuery = true) + List getQuestionsRecordByAttribute(String stuNumber, String attribute, String questionCategory); + // 16.2 按照知识点统计用户最新一次做题记录 lxj + @Query(value = "select * from e_user_question_record where student_number=?1 and knowledge_points=?2 and exam_category=?3 and \n" + + "times=(select max(times) from e_user_question_record where student_number=?1 and knowledge_points=?2 and exam_category=?3) AND inserttime >=?4 AND inserttime <=?5 ",nativeQuery = true) + List getQuestionsRecordByAttribute2(String stuNumber, String attribute, String questionCategory,String starTime,String endTime); + // 3.2号 9(1).2. 查询用户、科目、年级、专项练习最新一次做题记录 lxj + @Query(value = "SELECT * FROM e_user_question_record AS euqr\n" + + "INNER JOIN e_question AS eq\n" + + "ON euqr.question_id=eq.id\n" + + "WHERE euqr.student_number=?1 AND euqr.subject=?2 AND euqr.exam_category=?3 AND eq.level_name=?4 AND \n" + + "euqr.times=(SELECT MAX(times) FROM e_user_question_record WHERE student_number=?1 AND exam_category=?3 \n" + + "AND SUBJECT=?2) AND euqr.inserttime >=?5 AND euqr.inserttime <=?6 ",nativeQuery = true) + List getUserQuestionRecordByKnowledgePoints3(String stuNumber,String subject,String source,String levelName,String starTime,String endTime); + + // 17. 查询用户某个知识点最新一次做题时间 + @Query(value = "select max(updatetime) from e_user_question_record where student_number=?1 and knowledge_points=?2 \n" + + "and exam_category=?3 and times=(select max(times) from e_user_question_record where student_number=?1 \n" + + "and knowledge_points=?2 and exam_category=?3) ",nativeQuery = true) + String getDoTimeByAttribute(String stuNumber,String attribute,String category); + // 17.2 查询用户某个知识点最新一次做题时间 + @Query(value = "select max(updatetime) from e_user_question_record where student_number=?1 and knowledge_points=?2 \n" + + "and exam_category=?3 and times=(select max(times) from e_user_question_record where student_number=?1 \n" + + "and knowledge_points=?2 and exam_category=?3) AND inserttime >=?4 AND inserttime <=?5 ",nativeQuery = true) + String getDoTimeByAttribute2(String stuNumber,String attribute,String category,String starTime,String endTime); + + // 18. 十九、 学习记录:上面三个数的统计:用户做题总数 + @Query(value = "select count(*) from e_user_question_record as euqr, e_question as eq where euqr.student_number=?1 and euqr.`subject`=?2 and euqr.question_id=eq.id \n" + + "and eq.level_name=?3 ",nativeQuery = true) + int getDoQuestionCount(String stuNumber,String subject,String levelName); + + // 18(2). 十九、 学习记录:上面三个数的统计:查询用户每道题做题时长 + @Query(value = "select euqr.do_time from e_user_question_record as euqr, e_question as eq where euqr.student_number=?1 and euqr.`subject`=?2 \n" + + "and euqr.question_id=eq.id and eq.level_name=?3 ",nativeQuery = true) + List getDoQUestionTime(String stuNumber,String subject, String levelName); + + // 18(3). 十九、 学习记录:上面三个数的统计:查询用户每道题做题时间 + @Query(value = "select euqr.* from e_user_question_record as euqr, e_question as eq where euqr.student_number=?1 and euqr.`subject`=?2 \n" + + "and euqr.question_id=eq.id and eq.level_name=?3 ",nativeQuery = true) + List getDoQuestionUpdatetime(String stuNumber, String subject, String levelName); + + // 18(4). 十九、 学习记录:此用户、科目、年级 做题天数 + @Query(value = "select COUNT(DISTINCT SUBSTRING(euqr.inserttime,1,10)) from e_user_question_record as euqr, e_question as eq where euqr.student_number=?1 and euqr.`subject`=?2 \n" + + "and euqr.question_id=eq.id and eq.level_name=?3 ",nativeQuery = true) + int getDoQuestionDays(String stuNumber, String subject, String levelName); + + //19. 二十二、专项练习: 获取 专项练习 模块中,此用户是否做过,按做过次数的降序排列 + @Query(value = "SELECT * FROM e_user_question_record WHERE student_number=?1 AND exam_category=?2 AND question_id=?3 AND SUBJECT=?4 ORDER BY times DESC", nativeQuery = true) + List getSpecialRecord(String stuNumber,String examCategory,int questionid,String subject); + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserWrongQustionDao.java b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserWrongQustionDao.java new file mode 100644 index 0000000..2647ea6 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dao/UserWrongQustionDao.java @@ -0,0 +1,225 @@ +package com.zgczx.repository.mysql1.exam.dao; + +import com.zgczx.repository.mysql1.exam.model.UserWrongQustion; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Update; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 用户错题的dao + * @author aml + * @date 2020/1/2 12:46 + */ +@Repository +public interface UserWrongQustionDao extends JpaRepository { + + //1. 获取此来源的此题数据;由学号-科目-试卷来源(章节;模拟;历年真题) + @Query(value = "SELECT * FROM e_user_wrong_qustion WHERE student_number=?1 AND exam_category=?2 AND question_id=?3 AND subject=?4 ", nativeQuery = true) + UserWrongQustion getByStudentNumberAndExamCategoryAndQuestionId(String stuNumber, String examCategory, int questionid,String subject); + + // 2. 获取某个用户所有错题数 lxj + @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 ",nativeQuery = true) + int getErrorProblemsNumber(String stuNumber,String subject); + +// // 3. 获取用户章节练习错题数(未掌握的) lxj +// @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and do_right=2 and exam_category='章节练习' ",nativeQuery = true) +// int getChapterErrProblemsNum(String stuNumber,String subject); +// +// // 4. 获取用户考试错题数(未掌握的) lxj +// @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and do_right=2 and (exam_category='模拟考试' or exam_category='历年真题') ",nativeQuery = true) +// int getExamErrorProblemsNum(String stuNumber,String subject); + + // 5. 获取用户每一章的错题数(已掌握和未掌握,传参决定是否掌握) lxj + @Query(value = "select count(distinct question_id) from e_user_wrong_qustion as euwq,e_exam_paper as eep,e_chapter as ec \n" + + "where eep.chapter_id=ec.id and ec.chapter=?3 \n" + + "and eep.exam_name=euwq.exam_paper_name and euwq.do_right=?4 and euwq.student_number=?1 and euwq.subject=?2 ",nativeQuery = true) + int getErrorNumByChapter(String stuNumber, String subject,String chapter,int doRight); + + // 6. 统计用户每次考试错题数(已掌握和未掌握,传参决定是否掌握) lxj + @Query(value = "select count(distinct question_id) from e_exam_paper as eep,e_user_wrong_qustion as euwq where euwq.exam_paper_name=eep.exam_name \n" + + "and exam_name=?3 and euwq.do_right=?4 and euwq.student_number=?1 and euwq.subject=?2 ",nativeQuery = true) + int getErrorNumByExam(String stuNumber,String subject,String examName,int doRight); + + // 7. 获取此节的 所有错题数量(已掌握和未掌握,传参决定是否掌握) lxj + @Query(value = "SELECT COUNT(DISTINCT question_id) FROM e_user_wrong_qustion WHERE student_number=?1 AND SUBJECT=?2 \n" + + "AND exam_paper_name=?3 and do_right=?4 ",nativeQuery = true) + int getByErrNumber(String stuNumber,String subject,String examPaperName,int doRight); + + // 8. 根据节的名称 获取错题的详细信息 lxj + @Query(value = "select distinct question_id,euwq.id,euwq.student_number,euwq.openid,euwq.`subject`,euwq.do_right,euwq.user_answer,euwq.exam_paper_id,\n" + + "euwq.exam_paper_name,euwq.exam_category,euwq.do_time,euwq.inserttime,euwq.updatetime from e_user_wrong_qustion as euwq,e_exam_paper as eep,e_chapter as ec \n" + + "where ec.chapter=?3 and ec.section=?4 and ec.section=eep.exam_name and eep.exam_name=euwq.exam_paper_name and euwq.do_right=?5 and euwq.student_number=?1 \n" + + "and euwq.subject=?2 ",nativeQuery = true) + public List getErrorProblemsIdByChapterAndSection(String stuNumber,String subject,String chapter,String section,int doRight); + + // 9. 根据考试名称 获取本次考试错题id lxj + @Query(value = "select distinct question_id,euwq.id,euwq.student_number,euwq.openid,euwq.`subject`,euwq.do_right,euwq.user_answer,euwq.exam_paper_id,\n" + + "euwq.exam_paper_name,euwq.exam_category,euwq.do_time,euwq.inserttime,euwq.updatetime from e_user_wrong_qustion as euwq,e_exam_paper as eep \n" + + "where eep.exam_name=?3 and eep.exam_name=euwq.exam_paper_name and euwq.do_right=?4 \n" + + "and euwq.student_number=?1 and euwq.subject=?2 ",nativeQuery = true) + public List getErrorProblemsIdByExamName(String stuNumber,String subject,String examName,int doRight); + +// // 10. 统计用户练习错题数(已掌握的) lxj +// @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and do_right=1 and exam_category='章节练习' ",nativeQuery = true) +// int getChapterErrProblemsNum2(String stuNumber,String subject); +// +// // 11. 统计用户考试错题数(已掌握的) lxj +// @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and do_right=1 and (exam_category='模拟考试' or exam_category='历年真题') ",nativeQuery = true) +// int getExamErrorProblemsNum2(String stuNumber,String subject); + + // 12. 统计用户已掌握错题数 lxj + @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and do_right=1 ",nativeQuery = true) + int getMasteredErrorProblemsNum(String stuNumber,String subject); + + // 12(1). 根据年级统计用户错题数(已掌握和未掌握,已掌握未掌握通过参数传) lxj + @Query(value = "select count(distinct question_id) from e_user_wrong_qustion as euwq,e_exam_paper as eep where eep.grade_level=?2 and eep.id=euwq.exam_paper_id \n" + + "and euwq.`subject`=?3 and euwq.student_number=?1 and euwq.do_right=?4 ",nativeQuery = true) + int getMasteredErrorQuestionsCountByGradeLevel(String stuNumber,String levelName,String subject,int doRight); + + // 13. 统计用户未掌握错题数 lxj + @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and do_right=2 ",nativeQuery = true) + int getNotMasteredErrorProblemsNum(String stuNumber,String subject); + + // 14. 统计用户练习错题数 lxj + @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and (exam_category='章节练习' or exam_category='专项练习') ",nativeQuery = true) + int getPracticeErrorNum(String stuNumber,String subject); + + // 15. 统计用户考试错题数 lxj + @Query(value = "select count(distinct question_id) from e_user_wrong_qustion where `subject`=?2 and student_number=?1 and (exam_category='模拟考试' or exam_category='历年真题') ",nativeQuery = true) + int getExamErrorNum(String stuNumber,String subject); + + // 16. 用户删除已掌握错题中的某道题 lxj + @Query(value="delete from e_user_wrong_qustion where id=?1 ",nativeQuery = true) + @Modifying + @Transactional + void deleteById(int id); + + // 17. 根据学生学号、学科、题号、试题来源、已掌握查询已掌握错题的题号 + @Query(value = "select id from e_user_wrong_qustion where student_number=?1 and subject=?2 and do_right=1 and question_id=?3 and (exam_category=?4 or exam_category=?5) ",nativeQuery = true) + String getIdBySubjectAndQuestionIdAndExamCategory(String stuNumber,String subject,int questionId,String examCategory1,String examCategory2); + // 17.2 根据学生学号、学科、题号、已掌握查询已掌握错题的题号 + @Query(value = "select id from e_user_wrong_qustion where student_number=?1 and subject=?2 and do_right=1 and question_id=?3 ",nativeQuery = true) + String getIdBySubjectAndQuestionId(String stuNumber,String subject,int questionId); + @Query(value = "select * from e_user_wrong_qustion where student_number=?1 and subject=?2 and do_right=1 and question_id=?3 ",nativeQuery = true) + List getIdBySubjectAndQuestionId2(String stuNumber,String subject,int questionId); + + // 18. 错题表中查询同一用户、同一来源、同一道题做题记录 lxj + @Query(value = "select * from e_user_wrong_qustion where student_number=?1 and `subject`=?2 and question_id=?3 and exam_paper_id=?4 \n" + + "and exam_paper_name=?5 and (exam_category=?6 or exam_category=?7) ",nativeQuery = true) + UserWrongQustion getUserWrongQustionByUserAndSubjectAndExamCategory(String stuNumber,String subject,int questionId,int examPaperId,String examPaperName,String examCategory1,String examCategory2); + + //19. 获取错题表中某用户-》某年级-》某科目 某类(章节练习) 未掌握(或已掌握)的所有题,3.29修改:添加AND uwq.`exam_category`='章节练习' + @Query(value = "SELECT * FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_question AS q \n" + + "ON uwq.`question_id`=q.`id` \n" + + "INNER JOIN e_exam_paper AS ep \n" + + "ON uwq.`exam_paper_id`=ep.`id` \n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 AND ep.`exam_source`=?5 AND uwq.`exam_category`='章节练习' ", nativeQuery = true) + List getAllInfo(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory); + + //19.2 获取错题表中某用户-》某年级-》某科目 (专项练习) 未掌握(或已掌握)的所有题 + @Query(value = "SELECT * FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_question AS q \n" + + "ON uwq.`question_id`=q.`id` \n" + + "WHERE student_number=?1 AND q.`level_name`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 AND uwq.exam_category=?5 ", nativeQuery = true) + List getAllInfo2(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory); + + + //20. 获取错题表中 用户-》某年级-》某科目 各分类的 未掌握(或已掌握)的所有题 + @Query(value = "SELECT DISTINCT uwq.question_id,uwq.id,uwq.student_number,uwq.openid,uwq.`subject`,uwq.do_right,uwq.user_answer,uwq.exam_paper_id,uwq.exam_paper_name,uwq.exam_category,uwq.do_time,uwq.inserttime,uwq.updatetime FROM e_user_wrong_qustion AS uwq FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_exam_paper AS ep\n" + + "ON uwq.`exam_paper_id`=ep.`id`\n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 ", nativeQuery = true) + List getClassificationQuantity(String stuNumber,String gradeLevel,String subject,int doRight); + + //21. 获取错题表中 用户 -》 某年级 -》 某科目 全部的 未掌握和已掌握的 所有题 + @Query(value = "SELECT uwq.*\n" + + "FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_question AS q\n" + + "ON uwq.`question_id`=q.`id`\n" + + "INNER JOIN e_exam_paper AS ep\n" + + "ON uwq.`exam_paper_id`=ep.`id`\n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 \n" + + "GROUP BY uwq.`question_id` \n" + + "ORDER BY uwq.inserttime ASC", nativeQuery = true) + List getAllByQuestion(String stuNumber,String gradeLevel,String subject,int doRight); + + //22. 获取获取错题表中 用户 -》 某年级 -》 某科目 -> 某道题 的 未掌握和已掌握的 此题的 来源 + @Query(value = "SELECT DISTINCT uwq.`exam_category` FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_question AS q\n" + + "ON uwq.`question_id`=q.`id`\n" + + "INNER JOIN e_exam_paper AS ep\n" + + "ON uwq.`exam_paper_id`=ep.`id`\n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 AND uwq.`question_id`=?5", nativeQuery = true) + List getallQuestionSource(String stuNumber,String gradeLevel,String subject,int doRight, int questionId); + + + //23. 根据“章节名称” 获取此学号、年级、科目、是否做对 获取 有哪些节有错题 + @Query(value = "SELECT DISTINCT uwq.`exam_paper_name` FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_exam_paper AS ep\n" + + "ON uwq.`exam_paper_id`=ep.`id`\n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 AND ep.`exam_source`=?5 ", nativeQuery = true) + List getSectionName(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory); + + //24. 获取错题中的章节对应关系,根据章的名称获取 去重后的 此节的名称 + @Query(value = "select DISTINCT euwq.exam_paper_name from e_user_wrong_qustion as euwq,e_exam_paper as eep,e_chapter as ec \n" + + "where eep.chapter_id=ec.id and ec.chapter=?3 \n" + + "and eep.exam_name=euwq.exam_paper_name and euwq.do_right=?4 and euwq.student_number=?1 and euwq.subject=?2 ",nativeQuery = true) + List getChapterSection(String stuNumber, String subject,String chapter,int doRight); + + //25. 获取专项练习中的 所有题的知识点属性,根据学号、年级、科目、是否作对 + @Query(value = "SELECT DISTINCT q.`question_attribute` FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_question AS q\n" + + "ON uwq.`question_id`=q.`id`\n" + + "WHERE uwq.student_number=?1 AND uwq.SUBJECT=?3 AND uwq.do_right=?4 AND q.`level_name`=?2 AND uwq.`exam_category`=?5 ", nativeQuery = true) + List getQuestionAttribute(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory); + + //26. 获取专项练习中 某个知识点属性的 数量,根据学号、年级、科目、是否作对、知识点属性 + @Query(value = "SELECT COUNT(*) FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_question AS q\n" + + "ON uwq.`question_id`=q.`id`\n" + + "WHERE uwq.student_number=?1 AND uwq.SUBJECT=?3 AND uwq.do_right=?4 AND q.`level_name`=?2 AND uwq.`exam_category`=?5 AND FIND_IN_SET(?6,q.`question_attribute`) ", nativeQuery = true) + int getQuestionAttributeNum(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory,String attribute); + + //27. 获取错题表中某用户-》某年级-》某科目 章节练习 未掌握(或已掌握)的所有题 + @Query(value = "SELECT * FROM e_user_wrong_qustion AS uwq\n" + + "INNER JOIN e_question AS q\n" + + "ON uwq.`question_id`=q.`id`\n" + + "WHERE uwq.student_number=?1 AND uwq.SUBJECT=?3 AND uwq.do_right=?4 AND q.`level_name`=?2 AND uwq.`exam_category`=?5 ", nativeQuery = true) + List getAllChapterInfo(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory); + + //28. 获取历年真题获取模拟考试的 掌握或未掌握的 试卷名称,根据学号、年级、科目、是否作对,历年真题或模拟考试 + @Query(value = "SELECT DISTINCT uwq.`exam_paper_name` FROM e_user_wrong_qustion AS uwq \n" + + "INNER JOIN e_exam_paper AS ep \n" + + "ON uwq.`exam_paper_id`=ep.`id`\n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 AND ep.`exam_source`= uwq.`exam_category` AND uwq.`exam_category`=?5 ", nativeQuery = true) + List getExamPaperName(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory); + //29. 获取此考试名称的 未掌握或已掌握的 错题数量,根据学号、年级、科目、是否作对,历年真题或模拟考试的试卷名称 + @Query(value = "SELECT COUNT(DISTINCT uwq.`question_id`) FROM e_user_wrong_qustion AS uwq \n" + + "INNER JOIN e_exam_paper AS ep \n" + + "ON uwq.`exam_paper_id`=ep.`id`\n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 AND ep.`exam_source`= uwq.`exam_category` AND uwq.`exam_paper_name`=?5 ", nativeQuery = true) + int getgetExamPaperNameNum(String stuNumber,String gradeLevel,String subject,int doRight,String examPaperName); + + // 30. 获取此 模块的总共未掌握或已掌握的错题数量,根据学号、年级、科目、是否作对,历年真题或模拟考试 + @Query(value = "SELECT COUNT(DISTINCT uwq.`question_id`) FROM e_user_wrong_qustion AS uwq \n" + + "INNER JOIN e_exam_paper AS ep \n" + + "ON uwq.`exam_paper_id`=ep.`id`\n" + + "INNER JOIN e_question AS q ON uwq.`question_id`=q.id \n" + + "WHERE student_number=?1 AND ep.`grade_level`=?2 AND uwq.`subject`=?3 AND uwq.`do_right`=?4 AND ep.`exam_source`= uwq.`exam_category` AND uwq.`exam_category`=?5 AND q.`level_name`=?2 ", nativeQuery = true) + int getTotalExamPaperNum(String stuNumber,String gradeLevel,String subject,int doRight,String examCategory); + + //31. 传来“全部”时,获取所有 用户的、科目、年级、是否掌握 所有数量 + @Query(value = "SELECT * FROM e_user_wrong_qustion AS uwq \n" + + "INNER JOIN e_question AS q\n" + + "ON uwq.`question_id`=q.id\n" + + "WHERE student_number=?1 AND uwq.`subject`=?2 AND q.level_name=?3 AND uwq.`do_right`=?4 ", nativeQuery = true) + List totalNum(String stuNumber,String subject,String gradeLevel,int doRight); + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/ChapterErrNumberDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/ChapterErrNumberDTO.java new file mode 100644 index 0000000..23ef9d9 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/ChapterErrNumberDTO.java @@ -0,0 +1,18 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * 十二、点击练习错题时,展现的章节名称和对应的错题数量 封装类 + * @author aml + * @date 2019/12/23 19:02 + */ +@Data +public class ChapterErrNumberDTO { + + private String gradeLevel;//年级水平 + + private Map chapterNumber;//错题的章节名称 和 对应的数量 +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/DoQuestionInfoDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/DoQuestionInfoDTO.java new file mode 100644 index 0000000..afcf6ff --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/DoQuestionInfoDTO.java @@ -0,0 +1,28 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 六、动态实时呈现用户做题详情 并记录用户所有的做题情况 的封装类 + * @author aml + * @date 2019/12/17 15:46 + */ +@Data +public class DoQuestionInfoDTO { + //总共做题数量 + private int questionCount; +//作对题的数量 + private int doRight; +//作错题的数量 + private int doError; +//未做题的数量 + private int notDo; + + private List doRightList; // 做对的题号 + private List doErrorList; // 做错的题号 + private List notDoList; // 未做的题号 + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoDoQuestionDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoDoQuestionDTO.java new file mode 100644 index 0000000..d58a5e0 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoDoQuestionDTO.java @@ -0,0 +1,18 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import lombok.Data; + +/** + * 回显 用户 的做题情况 + * @author aml + * @date 2019/12/20 12:51 + */ +@Data +public class EchoDoQuestionDTO { + // 题号 + private int questionNo; + + // 对应的当时填写的文本 + private String questionNoText; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperCompleteDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperCompleteDTO.java new file mode 100644 index 0000000..95547fe --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperCompleteDTO.java @@ -0,0 +1,20 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import lombok.Data; + +import java.util.List; + +/** + * 这个是真正的返回给前端的 DTO,里面套了两个dto + * @author aml + * @date 2019/12/24 15:02 + */ +@Data +public class EchoPaperCompleteDTO { + + private List list; + + private int effective;//2此时卷没做完; 1 为时卷做完; + + private String firstNoDoneNum;// 此试卷中第一道未做的 题号 +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperDTO.java new file mode 100644 index 0000000..0787e1f --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperDTO.java @@ -0,0 +1,83 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.List; + +/** + * @author aml + * @date 2019/12/24 11:11 + */ +@Data +@Entity +public class EchoPaperDTO { + + @Id + private int id; + @Column(name = "exam_id") + private int examId; + @Column(name = "question_source") + private String questionSource; + @Column(name = "exam_name") + private String examName; + @Column(name = "exam_type") + private String examType; + @Column(name = "exam_location") + private String examLocation; + @Column(name = "question_id") + private int questionId; + @Column(name = "question_type") + private String questionType; + @Column(name = "question_difficult") + private String questionDifficult; + @Column(name = "question_context") + private String questionContext; + @Column(name = "question_option") + private String questionOption; + @Column(name = "question_score") + private String questionScore; + @Column(name = "question_attribute") + private String questionAttribute; + @Column(name = "correct_option") + private String correctOption; + @Column(name = "correct_text") + private String correctText; + @Column(name = "correct_analysis") + private String correctAnalysis; + @Column(name = "chapter_id") + private int chapterId; + + private String level; + @Column(name = "level_name") + private String levelName; + @Column(name = "create_user") + private String createUser; + @Column(name = "knowledge_module") + private String knowledgeModule; + @Column(name = "cognitive_level") + private String cognitiveLevel; + @Column(name = "core_literacy") + private String coreLiteracy; + + private int valid; + @Column(name = "question_imgs") + private String questionImgs; + + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + + private String randomOption; + + private String rightOption; + private String sourcePaperId; + private int collect; + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperTotalDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperTotalDTO.java new file mode 100644 index 0000000..b6b4a54 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/EchoPaperTotalDTO.java @@ -0,0 +1,29 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @author aml + * @date 2019/12/24 14:19 + */ +@Data +public class EchoPaperTotalDTO { + + private EchoPaperDTO question; + + private List randomOption;//选项列表 + + private int complete; //是否做完这个卷子 + + private String userOption;//用户的每道题的选项 + + private int collect; //这道题是否已经收藏过,1为收藏,2为未收藏 + + private String rightOption;// 正确选项 + + private String sourcePaperId;// 来源试卷id + + private List imgList; //= new LinkedList<>();//2.4 新修改 +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/FindCollectDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/FindCollectDTO.java new file mode 100644 index 0000000..977b317 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/FindCollectDTO.java @@ -0,0 +1,14 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import lombok.Data; + +/** + * @author aml + * @date 2019/12/26 16:12 + */ +@Data +public class FindCollectDTO { + + private int collect;// 此题是否收藏,1为收藏,2为 未收藏 + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/QuestionDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/QuestionDTO.java new file mode 100644 index 0000000..c1d6944 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/QuestionDTO.java @@ -0,0 +1,33 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import com.zgczx.repository.mysql1.exam.model.Question; +import lombok.Data; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * @author aml + * @date 2019/12/13 16:38 + */ +@Data +public class QuestionDTO { + + private Question question; + +// // 选项列表ABCD +// private List option; + + // 选项列表ABCD + private List randomOption; + + // 此题的正确选项,随着答案文本,选项跟着变化 + private String rightOption; + + private int sourcePaperId;// 这个道是在哪个试卷中的题,这个是组卷的id,不是最初录入题库中的id + + private int collect;// 是否收藏, 1为这道题已经收藏,2为未收藏 + + private List imgList; //= new LinkedList<>();//2.4 新修改 +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/dto/SectionErrNumberDTO.java b/src/main/java/com/zgczx/repository/mysql1/exam/dto/SectionErrNumberDTO.java new file mode 100644 index 0000000..ce87fd6 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/dto/SectionErrNumberDTO.java @@ -0,0 +1,17 @@ +package com.zgczx.repository.mysql1.exam.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * 十五、获取此章下面的所有节的名称和对应的错题数量 + * @author aml + * @date 2019/12/29 15:16 + */ +@Data +public class SectionErrNumberDTO { + + private Map sectionNumber;// 节的名称 和 错题数量 + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/Chapter.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/Chapter.java new file mode 100644 index 0000000..5a96ddc --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/Chapter.java @@ -0,0 +1,45 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 章节表 + * @author aml + * @date 2019/12/11 11:23 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Entity +@Data +@Table(name="e_chapter") +public class Chapter { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + @Column(name = "subject_id") + private int subjectId; + + private String subject; + private String chapter; + + private String section; + + private String level; + @Column(name = "level_name") + private String levelName; + + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/ExamContent.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/ExamContent.java new file mode 100644 index 0000000..009dee7 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/ExamContent.java @@ -0,0 +1,43 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 题库中的 试卷内容表,存放学校提供的每一次的考试数据 + * @author aml + * @date 2019/12/11 12:59 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Data +@Entity +@Table(name = "e_exam_content") +public class ExamContent { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + private String subject; + + @Column(name = "exam_name") + private String examName; + + private String content; + + private String answer; + + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/ExamPaper.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/ExamPaper.java new file mode 100644 index 0000000..442caf0 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/ExamPaper.java @@ -0,0 +1,72 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 题库中的 试卷表,存放每一次试卷 + * @author aml + * @date 2019/12/11 14:15 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Data +@Entity +@Table(name = "e_exam_paper") +public class ExamPaper { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + @Column(name = "exam_name") + private String examName; + @Column(name = "exam_source") + private String examSource; + @Column(name = "exam_type") + private String examType; + @Column(name = "exam_location") + private String examLocation; + private String subject; + @Column(name = "subject_id") + private int subjectId; + @Column(name = "chapter_id") + private int chapterId; + @Column(name = "paper_type") + private String paperType; + @Column(name = "exam_score") + private String examScore; + @Column(name = "question_count") + private int questionCount; + @Column(name = "suggest_time") + private String suggestTime; + @Column(name = "limit_star_time") + private String limitStarTime; + @Column(name = "limit_end_time") + private String limitEndTime; + @Column(name = "exam_content_id") + private int examContentId; + @Column(name = "exam_content") + private String examContent; + + @Column(name = "question_list") + private String questionList; + @Column(name = "grade_level") + private String gradeLevel; + @Column(name = "create_user") + private String createUser; + private int valid; + private String rank; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + + private String difficult; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/Question.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/Question.java new file mode 100644 index 0000000..d5b4c37 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/Question.java @@ -0,0 +1,86 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 题库中的 题库表,存放所有的题 + * @author aml + * @date 2019/12/11 14:24 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Data +@Entity +@Table(name = "e_question") +public class Question { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + @Column(name = "exam_id") + private int examId; + @Column(name = "question_source") + private String questionSource; + private String subject; + @Column(name = "exam_name") + private String examName; + @Column(name = "exam_type") + private String examType; + @Column(name = "exam_location") + private String examLocation; + @Column(name = "question_id") + private int questionId; + @Column(name = "question_type") + private String questionType; + @Column(name = "question_difficult") + private String questionDifficult; + @Column(name = "question_context") + private String questionContext; + @Column(name = "question_option") + private String questionOption; + @Column(name = "question_score") + private int questionScore; + @Column(name = "question_attribute") + private String questionAttribute; + @Column(name = "correct_option") + private String correctOption; + @Column(name = "correct_text") + private String correctText; + @Column(name = "correct_analysis") + private String correctAnalysis; + @Column(name = "chapter_id") + private int chapterId; + + private String level; + @Column(name = "level_name") + private String levelName; + @Column(name = "create_user") + private String createUser; + @Column(name = "knowledge_module") + private String knowledgeModule; + @Column(name = "cognitive_level") + private String cognitiveLevel; + @Column(name = "core_literacy") + private String coreLiteracy; + + private int valid; + @Column(name = "question_imgs") + private String questionImgs; + + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + + + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/Subject.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/Subject.java new file mode 100644 index 0000000..8ff4cff --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/Subject.java @@ -0,0 +1,31 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 题库中的 学科表 + * @author aml + * @date 2019/12/11 14:29 + */ +@Data +@Entity +@Table(name = "e_subject") +public class Subject { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + private String subject; + private int termId; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/Term.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/Term.java new file mode 100644 index 0000000..00fa208 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/Term.java @@ -0,0 +1,33 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 题库中的 学期表 + * @author aml + * @date 2019/12/11 14:31 + */ +@Data +@Entity +@Table(name = "e_term") +public class Term { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + private String semester; + private String startime; + private String endtime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/UserCollect.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserCollect.java new file mode 100644 index 0000000..1b35944 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserCollect.java @@ -0,0 +1,50 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 用户 收藏表 + * @author aml + * @date 2019/12/17 16:47 + */ +@DynamicInsert +@Data +@Entity +@Table(name = "e_user_collect") +public class UserCollect { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + @Column(name = "student_number") + private String studentNumber; + + private String openid; + + private String subject; + + @Column(name = "question_id") + private int questionId; + + @Column(name = "exam_paper_id") + private int examPaperId; + + @Column(name = "user_answer") + private String userAnswer; + + private String classification; + + private int valid; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/UserPaperRecord.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserPaperRecord.java new file mode 100644 index 0000000..ba8c2b8 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserPaperRecord.java @@ -0,0 +1,53 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 用户做试卷的记录表 + * 试卷: 将章节中的 每一节也抽象看为 一套试卷 + * @author aml + * @date 2019/12/22 19:11 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Data +@Entity +@Table(name = "e_user_paper_record") +public class UserPaperRecord { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + @Column(name = "student_number") + private String studentNumber; + private String openid; + private String subject; + @Column(name = "exam_paper_id") + private int examPaperId; + @Column(name = "exam_paper_content") + private String examPaperContent; + @Column(name = "exam_paper_anwer") + private String examPaperAnwer; + + private int times; + @Column(name = "customer_score") + private String customerScore; + @Column(name = "do_time") + private String doTime; + + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/UserQuestionRecord.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserQuestionRecord.java new file mode 100644 index 0000000..b5524de --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserQuestionRecord.java @@ -0,0 +1,64 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 题库中的 用户做题记录表,存放用户所有做题记录 + * @author aml + * @date 2019/12/11 14:34 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Data +@Entity +@Table(name = "e_user_question_record") +public class UserQuestionRecord { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + @Column(name = "student_number") + private String studentNumber; + private String openid; + private String subject; + @Column(name = "question_text_content") + private String questionTextContent; + @Column(name = "user_answer") + private String userAnswer; + @Column(name = "do_right") + private int doRight; + @Column(name = "question_id") + private int questionId; + + private int times; + @Column(name = "exam_paper_id") + private int examPaperId; + @Column(name = "exam_paper_name") + private String examPaperName; + @Column(name = "exam_category") + private String examCategory; + + @Column(name = "customer_score") + private String customerScore; + @Column(name = "question_score") + private String questionScore; + @Column(name = "do_time") + private String doTime; + private int status; + @Column(name = "knowledge_points") + private String knowledgePoints; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/exam/model/UserWrongQustion.java b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserWrongQustion.java new file mode 100644 index 0000000..3a86289 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/exam/model/UserWrongQustion.java @@ -0,0 +1,57 @@ +package com.zgczx.repository.mysql1.exam.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 用户错题表 + * @author aml + * @date 2020/1/2 12:44 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Data +@Entity +@Table(name = "e_user_wrong_qustion") +public class UserWrongQustion { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + @Column(name = "student_number") + private String studentNumber; + private String openid; + private String subject; + + @Column(name = "user_answer") + private String userAnswer; + @Column(name = "do_right") + private int doRight; + @Column(name = "question_id") + private int questionId; + + + @Column(name = "exam_paper_id") + private int examPaperId; + @Column(name = "exam_paper_name") + private String examPaperName; + @Column(name = "exam_category") + private String examCategory; + + + @Column(name = "do_time") + private String doTime; + + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dao/ExamFullScoreSetDao.java b/src/main/java/com/zgczx/repository/mysql1/score/dao/ExamFullScoreSetDao.java new file mode 100644 index 0000000..777b2b4 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dao/ExamFullScoreSetDao.java @@ -0,0 +1,22 @@ +package com.zgczx.repository.mysql1.score.dao; + +import com.zgczx.repository.mysql1.score.model.ExamFullScoreSet; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.math.BigInteger; + +/** + * @author aml + * @date 2019/9/19 16:12 + */ +@Repository +public interface ExamFullScoreSetDao extends JpaRepository { + + @Query(value = "select e from ExamFullScoreSet as e where e.examinfoId = ?1") + ExamFullScoreSet findByExaminfoId(int examid); + + @Query(value = "SELECT SUM(sfs.yuwen+sfs.shuxue+sfs.yingyu+sfs.wuli+sfs.huaxue+sfs.shengwu+sfs.zhengzhi+sfs.lishi+sfs.dili) FROM subject_full_score AS sfs WHERE id=(SELECT subject_schame_id FROM exam_full_score_set WHERE examinfo_id=?1)",nativeQuery = true) + BigInteger getSchameTotal(int examId); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dao/ExamInfoDao.java b/src/main/java/com/zgczx/repository/mysql1/score/dao/ExamInfoDao.java new file mode 100644 index 0000000..e2ea945 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dao/ExamInfoDao.java @@ -0,0 +1,34 @@ +package com.zgczx.repository.mysql1.score.dao; + +import com.zgczx.repository.mysql1.score.model.ExamInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author aml + * @date 2019/9/10 15:53 + */ +@Repository +public interface ExamInfoDao extends JpaRepository { + + /** + * 根据具体的 哪次考试获取 此id + * @param examType 具体考试名称 + * @return id + */ + @Query(value = "select e.id from ExamInfo e where e.examName = ?1") + int findByExamName(String examType); + @Query(value = "SELECT id FROM exam_info WHERE exam_name=?1 AND school_name=?2",nativeQuery = true) + int findByExamNameAndSchoolName(String examType, String schoolName); + + + + // @Query(value = "select * from exam_info where exam_name=?1",nativeQuery = true) + ExamInfo getByExamName(String examType); + + @Query(value = "SELECT exam_name FROM exam_info ", nativeQuery = true) + List getAllExamName(); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dao/GoalSetDao.java b/src/main/java/com/zgczx/repository/mysql1/score/dao/GoalSetDao.java new file mode 100644 index 0000000..5c26fec --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dao/GoalSetDao.java @@ -0,0 +1,19 @@ +package com.zgczx.repository.mysql1.score.dao; + +import com.zgczx.repository.mysql1.score.model.GoalSet; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author aml + * @date 2019/11/29 15:45 + */ +@Repository +public interface GoalSetDao extends JpaRepository { + + @Query(value = "SELECT * FROM goal_set WHERE student_number=?1 AND exam_name=?2 ORDER BY id DESC", nativeQuery = true) + List findTargetValue(String studentNumber,String examName); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dao/ImportConversionScoreDao.java b/src/main/java/com/zgczx/repository/mysql1/score/dao/ImportConversionScoreDao.java new file mode 100644 index 0000000..9a3a3ee --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dao/ImportConversionScoreDao.java @@ -0,0 +1,20 @@ +package com.zgczx.repository.mysql1.score.dao; + +import com.zgczx.repository.mysql1.score.model.ImportConversionScore; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/9/22 16:28 + */ +@Repository +public interface ImportConversionScoreDao extends JpaRepository { + /** + * + * @param machine 某此考试的机读号 + * @param examType 具体的考试名称 + * @return ImportConversionScore对象 + */ + ImportConversionScore findByStudentMachineCardAndExamType(String machine, String examType); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dao/ManuallyEnterGradesDao.java b/src/main/java/com/zgczx/repository/mysql1/score/dao/ManuallyEnterGradesDao.java new file mode 100644 index 0000000..fdd6853 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dao/ManuallyEnterGradesDao.java @@ -0,0 +1,50 @@ +package com.zgczx.repository.mysql1.score.dao; + +import com.zgczx.repository.mysql1.score.model.ManuallyEnterGrades; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author aml + * @date 2019/10/29 19:15 + */ +@Repository +public interface ManuallyEnterGradesDao extends JpaRepository { + + @Query(value = "SELECT DISTINCT LEFT(exam_name, 8) FROM manually_enter_grades WHERE wechat_openid =?1 AND exam_name LIKE ?2 ", nativeQuery = true) + List getExamNameByWechatOpenidAndYear(String openid, String year); + + @Query(value = "SELECT COUNT(DISTINCT exam_name) FROM manually_enter_grades WHERE wechat_openid =?1 AND exam_name LIKE ?2", nativeQuery = true) + int countByWechatOpenidAndExamName(String openid, String examName); + + @Query(value = "SELECT DISTINCT exam_name FROM manually_enter_grades WHERE wechat_openid =?1 AND exam_name LIKE ?2", nativeQuery = true) + List getExamNameByYearMonthAndWechatOpenid(String openid, String yearMonth); + + List findAllByWechatOpenidAndExamName(String openid,String examName); + // 使用in来代替 openid or openid 。。。 + List findByWechatOpenidIn(List openids); + + //动态太拼接openid 和 其他的条件 + @Query(value = "SELECT * FROM manually_enter_grades WHERE student_number=?2 AND wechat_openid IN (?1)", nativeQuery = true) + List findByWechatOpenidInAndStudentNumber(List openids,String studengNumber); + + // 手动录入成绩,删除 某条 数据功能,根据openid和examName + int deleteByStudentNumberAndExamNameAndSubjectName(String studentNumber, String examname,String subject); + +// @Modifying :只能用于返回值为 void int +// @Query(name = "", nativeQuery = true) +// ManuallyEnterGrades updateByWechatOpenidAndExamName(String openid, String examname); + + // 获取录入的某条数据,根据openid、studentnumber 、examName + @Query(value = "SELECT * FROM manually_enter_grades WHERE wechat_openid=?1 AND student_number=?2 AND exam_name=?3 ", nativeQuery = true) + ManuallyEnterGrades findByWechatOpenidAndStudentNumberAndExamName(String openid,String studentNumber,String examName); + + // 批量录入手动录入成绩实体时,判断如果其中有某条数据 已经录入过,就不允许此次录入操作 + ManuallyEnterGrades findAllByStudentNumberAndExamNameAndSubjectName(String studentNumber, String examname, String subjectName); + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dao/SubjectDTODao.java b/src/main/java/com/zgczx/repository/mysql1/score/dao/SubjectDTODao.java new file mode 100644 index 0000000..6395221 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dao/SubjectDTODao.java @@ -0,0 +1,19 @@ +package com.zgczx.repository.mysql1.score.dao; + +import com.zgczx.repository.mysql1.score.dto.SubjectDTO; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author aml + * @date 2019/10/23 14:18 + */ +@Repository +public interface SubjectDTODao extends JpaRepository { + + @Query(value = "SELECT id,AVG(yuwen_score) as yuwen,AVG(shuxue_score) as shuxue,AVG(yingyu_score)as yingyu, AVG(wuli_coversion)as wuli,AVG(huaxue_coversion)as huaxue,AVG(shengwu_coversion)as shengwu,AVG(zhengzhi_coversion)as zhengzhi,AVG(lishi_coversion)as lishi,AVG(dili_coversion)as dili FROM exam_coversion_total WHERE exam_type=?1" , nativeQuery = true) + List avgSubject(String examType); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dao/SubjectFullScoreDao.java b/src/main/java/com/zgczx/repository/mysql1/score/dao/SubjectFullScoreDao.java new file mode 100644 index 0000000..dfb83b3 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dao/SubjectFullScoreDao.java @@ -0,0 +1,17 @@ +package com.zgczx.repository.mysql1.score.dao; + +import com.zgczx.repository.mysql1.score.model.SubjectFullScore; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/9/19 16:19 + */ +@Repository +public interface SubjectFullScoreDao extends JpaRepository { + + @Query(value = "SELECT * FROM subject_full_score sfs,exam_full_score_set sfss WHERE sfs.id=sfss.subject_schame_id AND sfss.examinfo_id=?1 ", nativeQuery = true) + SubjectFullScore findById(int id); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/AsahiChartAllRateDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/AsahiChartAllRateDTO.java new file mode 100644 index 0000000..f589a62 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/AsahiChartAllRateDTO.java @@ -0,0 +1,45 @@ +package com.zgczx.repository.mysql1.score.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * @author aml + * @date 2019/9/26 10:50 + */ +@Data +public class AsahiChartAllRateDTO { + + // 总分率值,即所得总分 / 总分满分标准 + private String totalScoreRate; + + // 三科分数之和率值,三科得分数和/ 三科总分 + private String threeSubjectsRate; + + // 6选3综合率值, 6选3综合得分 / 6选3综合满分标准分 + private String comprehensiveRate; + + // 所有真实科目的率值,k: 科目名称;v:所对应的率值 + private Map allSubjectRateMap; + +// +// // 语文率值, 语文得分 / 语文总分 +// private int languageScoreRate; +// // 数学率值, 数学得分 / 数学总分 +// private int mathScoreRate; +// // 英语率值, 英语得分 / 英语总分 +// private int englishScoreRate; +// // 物理率值, 物理得分 / 物理总分 +// private int physicalScoreRate; +// // 化学率值, 化学得分 / 化学总分 +// private int chemistryScoreRate; +// // 生物率值, 生物得分 / 生物总分 +// private int biologicalScoreRate; +// // 政治率值, 政治得分 / 政治总分 +// private int politicalScoreRate; +// // 历史率值, 历史得分 / 历史总分 +// private int historyScoreRate; +// // 地理率值, 地理得分 / 地理总分 +// private int geographyScoreRate; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/HistoricalAnalysisSingleDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/HistoricalAnalysisSingleDTO.java new file mode 100644 index 0000000..921c9e6 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/HistoricalAnalysisSingleDTO.java @@ -0,0 +1,39 @@ +package com.zgczx.repository.mysql1.score.dto; + +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import lombok.Data; + +import java.util.Map; + +/** + * @author aml + * @date 2019/9/24 20:30 + */ +@Data +public class HistoricalAnalysisSingleDTO { + + // private ExamCoversionTotal examCoversionTotal; +// //单科班级排名 +// private int classRank; +// //单科年级排名 +// private int gradeRank; +// // 班级平均分 +// private String classAverage; +// // 年级平均分 +// private String gradeAverage; +// // 年级排名的百分率 +// private String gradePercentage; +// // 班级排名的百分率 +// private String classPercentage; +// // 班级平均分百分率 +// private String classAveragePercentage; +// // 年级平均分百分率 +// private String gradeAveragePercentage; +// // 单科分数的百分率 +// private String singleScorePercentage; + + // 里面存放多个子map,例如班排map、年排map、平均分map等 +// private Map> map; + + private Map> mapTotal; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/HistoricalAnalysisTotalDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/HistoricalAnalysisTotalDTO.java new file mode 100644 index 0000000..c6a72b8 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/HistoricalAnalysisTotalDTO.java @@ -0,0 +1,40 @@ +package com.zgczx.repository.mysql1.score.dto; + +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import lombok.Data; + +import java.util.Map; + +/** + * @author aml + * @date 2019/9/24 16:08 + */ +@Data +public class HistoricalAnalysisTotalDTO { + +// private ExamCoversionTotal examCoversionTotal; +//// //班级排名 +//// private int classRank; +//// //年级排名 +//// private int gradeRank; +// // 班级平均分 +// private String classAverage; +// // 年级平均分 +// private String gradeAverage; +// // 年级排名的百分率 +// private String gradePercentage; +// // 班级排名的百分率 +// private String classPercentage; +// // 班级平均分百分率 +// private String classAveragePercentage; +// // 年级平均分百分率 +// private String gradeAveragePercentage; +// // 总分的百分率 +// private String totalScorePercentage; + + // 里面存放多个子map,例如班排map、年排map、平均分map等 + // private Map> map; + + private Map> mapTotal; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/ManuallyEnterGradesDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/ManuallyEnterGradesDTO.java new file mode 100644 index 0000000..ea4d045 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/ManuallyEnterGradesDTO.java @@ -0,0 +1,21 @@ +package com.zgczx.repository.mysql1.score.dto; + +import com.zgczx.repository.mysql1.score.model.ManuallyEnterGrades; +import lombok.Data; + +import java.util.List; + +/** + * 五、录入统计4) 根据考试名称和openid获取对应的数据 + * 封装下 图片,将string改为 string[]类型 + * @author aml + * @date 2019/12/9 15:52 + */ +@Data +public class ManuallyEnterGradesDTO { + + private ManuallyEnterGrades manuallyEnterGrades; + //图片list + // private String[] imgurllist; + private List imgurllist; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/MonthByYearListDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/MonthByYearListDTO.java new file mode 100644 index 0000000..3a300f4 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/MonthByYearListDTO.java @@ -0,0 +1,18 @@ +package com.zgczx.repository.mysql1.score.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @author aml + * @date 2019/11/11 14:37 + */ +@Data +public class MonthByYearListDTO { + + private List list; + + // 这一年共有几次考试 + private int countTimes; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/ScoreReportDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/ScoreReportDTO.java new file mode 100644 index 0000000..aab512a --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/ScoreReportDTO.java @@ -0,0 +1,53 @@ +package com.zgczx.repository.mysql1.score.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * @author aml + * @date 2019/9/27 12:12 + */ +@Data +public class ScoreReportDTO { + // 总分分数 + private String totalScore; + // 总分的年级排名 + private int totalScoreGradeRank; + // 总分的班级排名 + private int totalScoreClassRank; + + //总分的年级平均分 + private String totalAverage; + + private Map> map; + + //总分满分数值 + private String totalScoreStandard; + //班级总人数 + private int totalClassNumber; + // 年级总人数 + private int totalGradeNumber; + +// // 具体科目的分数map,k: 科目名称,V:对应的分数 +// private Map subjectScoreMap; +// // 具体科目的年级排名,K:科目名称,V:对应的年级排名 +// private Map subjectGradeRankMap; +// // 具体科目的班级排名,K:科目名称,V:对应的班级排名 +// private Map subjectClassRankMap; +// // 总分满分标准、各科满分标准 +// private Map subjectStandardMap; +// + + +// //语文map,一个map中存放,分数、年排、班排、满分标准 +// private Map yuwenMap; +// private Map shuxueMap; +// private Map yingyuMap; +// private Map wuliMap; +// private Map huaxueMap; +// private Map shengwuMap; +// private Map diliMap; +// private Map lishiMap; +// private Map zhengzhiMap; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/SixRateDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/SixRateDTO.java new file mode 100644 index 0000000..eef0766 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/SixRateDTO.java @@ -0,0 +1,40 @@ +package com.zgczx.repository.mysql1.score.dto; + +import lombok.Data; + +/** + * @author aml + * @date 2019/9/19 15:30 + */ +@Data +public class SixRateDTO { +// // 高分率 +// private double highNumRate; +// // 优秀率 +// private double excellentRate; +// //良好率 +// private double goodRate; +// // 及格率 +// private double passRate; +// // 低分率 +// private double failRate; +// // 超均率 +// private double beyondRate; +// // 所处率值 +// private String locationRate; + + // 高分人数 + private int highNumRate; + // 优秀人数 + private int excellentRate; + //良好人数 + private int goodRate; + // 及格人数 + private int passRate; + // 低分人数 + private int failRate; + // 超均人数 + private int beyondRate; + // 所处率值 + private String locationRate; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/SubjectAnalysisDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/SubjectAnalysisDTO.java new file mode 100644 index 0000000..ff6b357 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/SubjectAnalysisDTO.java @@ -0,0 +1,35 @@ +package com.zgczx.repository.mysql1.score.dto; + +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import lombok.Data; + +import java.util.Map; + +/** + * @author aml + * @date 2019/9/23 11:17 + */ +@Data +public class SubjectAnalysisDTO { + + private ExamCoversionTotal examCoversionTotal; + + // 学科贡献率,各单科贡献率,各科分数和总分的比值 + private Map contributionRate; + + // 学科均衡差值,即各科年排排名和总分年级排名的差值 + private Map equilibriumDifference; + + // 年级的标准率值,即年级排名 / 年级总人数 + private String gradeRate; + +// // 上次考试的 学科贡献率,各单科贡献率,各科分数和总分的比值 +// private Map oldcontributionRate; +// +// // 前三次 学科贡献率的平均值 +// private Map avgcontributionRate; + + // 此map中九门科目的map,每一个map中最多能放 + // 本次、上次、平均、差值(本次 - 平均) 率值 + private Map> map; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/dto/SubjectDTO.java b/src/main/java/com/zgczx/repository/mysql1/score/dto/SubjectDTO.java new file mode 100644 index 0000000..6906281 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/dto/SubjectDTO.java @@ -0,0 +1,28 @@ +package com.zgczx.repository.mysql1.score.dto; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; + +/** + * @author aml + * @date 2019/10/23 14:14 + */ +@Data +@Entity +public class SubjectDTO { + + @Id + int id; + private String yuwen; + private String shuxue; + private String yingyu; + private String wuli; + private String huaxue; + private String shengwu; + private String zhengzhi; + private String lishi; + private String dili; + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/model/ExamFullScoreSet.java b/src/main/java/com/zgczx/repository/mysql1/score/model/ExamFullScoreSet.java new file mode 100644 index 0000000..98d3cda --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/model/ExamFullScoreSet.java @@ -0,0 +1,61 @@ +package com.zgczx.repository.mysql1.score.model; + +import javax.persistence.*; +import java.util.Objects; + +/** + * @author aml + * @date 2019/9/19 15:21 + */ +@Entity +@Table(name = "exam_full_score_set", schema = "score_ananlysis_dev", catalog = "") +public class ExamFullScoreSet { + private long id; + private Long examinfoId; + private Long subjectSchameId; + + @Id + @Column(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Basic + @Column(name = "examinfo_id") + public Long getExaminfoId() { + return examinfoId; + } + + public void setExaminfoId(Long examinfoId) { + this.examinfoId = examinfoId; + } + + @Basic + @Column(name = "subject_schame_id") + public Long getSubjectSchameId() { + return subjectSchameId; + } + + public void setSubjectSchameId(Long subjectSchameId) { + this.subjectSchameId = subjectSchameId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ExamFullScoreSet that = (ExamFullScoreSet) o; + return id == that.id && + Objects.equals(examinfoId, that.examinfoId) && + Objects.equals(subjectSchameId, that.subjectSchameId); + } + + @Override + public int hashCode() { + return Objects.hash(id, examinfoId, subjectSchameId); + } +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/model/ExamInfo.java b/src/main/java/com/zgczx/repository/mysql1/score/model/ExamInfo.java new file mode 100644 index 0000000..0d7b0d6 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/model/ExamInfo.java @@ -0,0 +1,103 @@ +package com.zgczx.repository.mysql1.score.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import javax.persistence.*; +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author aml + * @date 2019/9/10 15:39 + */ +@Entity +@Data +@Table(name = "exam_info", schema = "score_ananlysis_dev", catalog = "") +public class ExamInfo implements Serializable { + private long id; + private String examName; + private String examGrade; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp examDate; + private String paperId; + private String schoolName; + + @Column(name = "school_name") + public String getSchoolName() { + return schoolName; + } + + public void setSchoolName(String schoolName) { + this.schoolName = schoolName; + } + + @Id + @Column(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Basic + @Column(name = "exam_name") + public String getExamName() { + return examName; + } + + public void setExamName(String examName) { + this.examName = examName; + } + + @Basic + @Column(name = "exam_grade") + public String getExamGrade() { + return examGrade; + } + + public void setExamGrade(String examGrade) { + this.examGrade = examGrade; + } + + @Basic + @Column(name = "exam_date") + public Timestamp getExamDate() { + return examDate; + } + + public void setExamDate(Timestamp examDate) { + this.examDate = examDate; + } + + @Basic + @Column(name = "paper_id") + public String getPaperId() { + return paperId; + } + + public void setPaperId(String paperId) { + this.paperId = paperId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ExamInfo examInfo = (ExamInfo) o; + return id == examInfo.id && + Objects.equals(examName, examInfo.examName) && + Objects.equals(examGrade, examInfo.examGrade) && + Objects.equals(examDate, examInfo.examDate) && + Objects.equals(paperId, examInfo.paperId); + } + + @Override + public int hashCode() { + return Objects.hash(id, examName, examGrade, examDate, paperId); + } +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/model/GoalSet.java b/src/main/java/com/zgczx/repository/mysql1/score/model/GoalSet.java new file mode 100644 index 0000000..42248cf --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/model/GoalSet.java @@ -0,0 +1,46 @@ +package com.zgczx.repository.mysql1.score.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; + +/** + * 对比分析中目标设定表 + * @author aml + * @date 2019/11/29 15:35 + */ +@Data +@Entity +@Table(name="goal_set") +public class GoalSet { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + @Column(name = "student_number") + private String studentNumber; + @Column(name = "exam_name") + private String examName; + private String openid; + @Column(name = "total_score") + private String totalScore; + private String yuwen; + private String shuxue; + private String yingyu; + private String wuli; + private String huaxue; + private String shengwu; + private String zhengzhi; + private String lishi; + private String dili; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/model/ImportConversionScore.java b/src/main/java/com/zgczx/repository/mysql1/score/model/ImportConversionScore.java new file mode 100644 index 0000000..02b895e --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/model/ImportConversionScore.java @@ -0,0 +1,220 @@ +package com.zgczx.repository.mysql1.score.model; + +import lombok.Data; + +import javax.persistence.*; +import java.util.Objects; + +/** + * @author aml + * @date 2019/9/22 16:28 + */ +@Entity +@Data +@Table(name = "import_conversion_score", schema = "score_ananlysis_dev", catalog = "") +public class ImportConversionScore { + private int id; + private String studentMachineCard; + private String username; + private String yuwenScore; + private String shuxueScore; + private String yingyuScore; + private String wuliConverscore; + private String huaxueConverscore; + private String shengwuConverscore; + private String lishiConverscore; + private String diliConverscore; + private String zhengzhiConverscore; + private String totalScore; + private String classIndex; + private String schoolIndex; + private String examType; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Basic + @Column(name = "student_machine_card") + public String getStudentMachineCard() { + return studentMachineCard; + } + + public void setStudentMachineCard(String studentMachineCard) { + this.studentMachineCard = studentMachineCard; + } + + @Basic + @Column(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @Basic + @Column(name = "yuwen_score") + public String getYuwenScore() { + return yuwenScore; + } + + public void setYuwenScore(String yuwenScore) { + this.yuwenScore = yuwenScore; + } + + @Basic + @Column(name = "shuxue_score") + public String getShuxueScore() { + return shuxueScore; + } + + public void setShuxueScore(String shuxueScore) { + this.shuxueScore = shuxueScore; + } + + @Basic + @Column(name = "yingyu_score") + public String getYingyuScore() { + return yingyuScore; + } + + public void setYingyuScore(String yingyuScore) { + this.yingyuScore = yingyuScore; + } + + @Basic + @Column(name = "wuli_converscore") + public String getWuliConverscore() { + return wuliConverscore; + } + + public void setWuliConverscore(String wuliConverscore) { + this.wuliConverscore = wuliConverscore; + } + + @Basic + @Column(name = "huaxue_converscore") + public String getHuaxueConverscore() { + return huaxueConverscore; + } + + public void setHuaxueConverscore(String huaxueConverscore) { + this.huaxueConverscore = huaxueConverscore; + } + + @Basic + @Column(name = "shengwu_converscore") + public String getShengwuConverscore() { + return shengwuConverscore; + } + + public void setShengwuConverscore(String shengwuConverscore) { + this.shengwuConverscore = shengwuConverscore; + } + + @Basic + @Column(name = "lishi_converscore") + public String getLishiConverscore() { + return lishiConverscore; + } + + public void setLishiConverscore(String lishiConverscore) { + this.lishiConverscore = lishiConverscore; + } + + @Basic + @Column(name = "dili_converscore") + public String getDiliConverscore() { + return diliConverscore; + } + + public void setDiliConverscore(String diliConverscore) { + this.diliConverscore = diliConverscore; + } + + @Basic + @Column(name = "zhengzhi_converscore") + public String getZhengzhiConverscore() { + return zhengzhiConverscore; + } + + public void setZhengzhiConverscore(String zhengzhiConverscore) { + this.zhengzhiConverscore = zhengzhiConverscore; + } + + @Basic + @Column(name = "total_score") + public String getTotalScore() { + return totalScore; + } + + public void setTotalScore(String totalScore) { + this.totalScore = totalScore; + } + + @Basic + @Column(name = "class_index") + public String getClassIndex() { + return classIndex; + } + + public void setClassIndex(String classIndex) { + this.classIndex = classIndex; + } + + @Basic + @Column(name = "school_index") + public String getSchoolIndex() { + return schoolIndex; + } + + public void setSchoolIndex(String schoolIndex) { + this.schoolIndex = schoolIndex; + } + + @Basic + @Column(name = "exam_type") + public String getExamType() { + return examType; + } + + public void setExamType(String examType) { + this.examType = examType; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ImportConversionScore that = (ImportConversionScore) o; + return id == that.id && + Objects.equals(studentMachineCard, that.studentMachineCard) && + Objects.equals(username, that.username) && + Objects.equals(yuwenScore, that.yuwenScore) && + Objects.equals(shuxueScore, that.shuxueScore) && + Objects.equals(yingyuScore, that.yingyuScore) && + Objects.equals(wuliConverscore, that.wuliConverscore) && + Objects.equals(huaxueConverscore, that.huaxueConverscore) && + Objects.equals(shengwuConverscore, that.shengwuConverscore) && + Objects.equals(lishiConverscore, that.lishiConverscore) && + Objects.equals(diliConverscore, that.diliConverscore) && + Objects.equals(zhengzhiConverscore, that.zhengzhiConverscore) && + Objects.equals(totalScore, that.totalScore) && + Objects.equals(classIndex, that.classIndex) && + Objects.equals(schoolIndex, that.schoolIndex) && + Objects.equals(examType, that.examType); + } + + @Override + public int hashCode() { + return Objects.hash(id, studentMachineCard, username, yuwenScore, shuxueScore, yingyuScore, wuliConverscore, huaxueConverscore, shengwuConverscore, lishiConverscore, diliConverscore, zhengzhiConverscore, totalScore, classIndex, schoolIndex, examType); + } +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/model/ManualGradeEntryConversion.java b/src/main/java/com/zgczx/repository/mysql1/score/model/ManualGradeEntryConversion.java new file mode 100644 index 0000000..7e58d1a --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/model/ManualGradeEntryConversion.java @@ -0,0 +1,303 @@ +package com.zgczx.repository.mysql1.score.model; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * 这个表是手动录入成绩转换为等级分后的总表,所有手动录入成绩的数据都从此表中获取 + * @author aml + * @date 2019/10/14 13:59 + */ +@Entity +@Table(name = "manual_grade_entry_conversion", schema = "score_ananlysis_dev", catalog = "") +public class ManualGradeEntryConversion { + private int id; + private String wechatOpenid; + private String studentNumber; + private Double yuwenScore; + private Double shuxueScore; + private Double yingyuScore; + private Double wuliCoversion; + private Double huaxueCoversion; + private Double shengwuCoversion; + private Double lishiCoversion; + private Double diliCoversion; + private Double zhengzhiCoversion; + private Double coversionTotal; + private Double coversionAvg; + private Integer classRank; + private Integer gradeRank; + private String examName; + private String schoolName; + private String gradeName; + private String className; + private String examFullName; + private Timestamp insettime; + private Timestamp updatetime; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Basic + @Column(name = "wechat_openid") + public String getWechatOpenid() { + return wechatOpenid; + } + + public void setWechatOpenid(String wechatOpenid) { + this.wechatOpenid = wechatOpenid; + } + + @Basic + @Column(name = "student_number") + public String getStudentNumber() { + return studentNumber; + } + + public void setStudentNumber(String studentNumber) { + this.studentNumber = studentNumber; + } + + @Basic + @Column(name = "yuwen_score") + public Double getYuwenScore() { + return yuwenScore; + } + + public void setYuwenScore(Double yuwenScore) { + this.yuwenScore = yuwenScore; + } + + @Basic + @Column(name = "shuxue_score") + public Double getShuxueScore() { + return shuxueScore; + } + + public void setShuxueScore(Double shuxueScore) { + this.shuxueScore = shuxueScore; + } + + @Basic + @Column(name = "yingyu_score") + public Double getYingyuScore() { + return yingyuScore; + } + + public void setYingyuScore(Double yingyuScore) { + this.yingyuScore = yingyuScore; + } + + @Basic + @Column(name = "wuli_coversion") + public Double getWuliCoversion() { + return wuliCoversion; + } + + public void setWuliCoversion(Double wuliCoversion) { + this.wuliCoversion = wuliCoversion; + } + + @Basic + @Column(name = "huaxue_coversion") + public Double getHuaxueCoversion() { + return huaxueCoversion; + } + + public void setHuaxueCoversion(Double huaxueCoversion) { + this.huaxueCoversion = huaxueCoversion; + } + + @Basic + @Column(name = "shengwu_coversion") + public Double getShengwuCoversion() { + return shengwuCoversion; + } + + public void setShengwuCoversion(Double shengwuCoversion) { + this.shengwuCoversion = shengwuCoversion; + } + + @Basic + @Column(name = "lishi_coversion") + public Double getLishiCoversion() { + return lishiCoversion; + } + + public void setLishiCoversion(Double lishiCoversion) { + this.lishiCoversion = lishiCoversion; + } + + @Basic + @Column(name = "dili_coversion") + public Double getDiliCoversion() { + return diliCoversion; + } + + public void setDiliCoversion(Double diliCoversion) { + this.diliCoversion = diliCoversion; + } + + @Basic + @Column(name = "zhengzhi_coversion") + public Double getZhengzhiCoversion() { + return zhengzhiCoversion; + } + + public void setZhengzhiCoversion(Double zhengzhiCoversion) { + this.zhengzhiCoversion = zhengzhiCoversion; + } + + @Basic + @Column(name = "coversion_total") + public Double getCoversionTotal() { + return coversionTotal; + } + + public void setCoversionTotal(Double coversionTotal) { + this.coversionTotal = coversionTotal; + } + + @Basic + @Column(name = "coversion_avg") + public Double getCoversionAvg() { + return coversionAvg; + } + + public void setCoversionAvg(Double coversionAvg) { + this.coversionAvg = coversionAvg; + } + + @Basic + @Column(name = "class_rank") + public Integer getClassRank() { + return classRank; + } + + public void setClassRank(Integer classRank) { + this.classRank = classRank; + } + + @Basic + @Column(name = "grade_rank") + public Integer getGradeRank() { + return gradeRank; + } + + public void setGradeRank(Integer gradeRank) { + this.gradeRank = gradeRank; + } + + @Basic + @Column(name = "exam_name") + public String getExamName() { + return examName; + } + + public void setExamName(String examName) { + this.examName = examName; + } + + @Basic + @Column(name = "school_name") + public String getSchoolName() { + return schoolName; + } + + public void setSchoolName(String schoolName) { + this.schoolName = schoolName; + } + + @Basic + @Column(name = "grade_name") + public String getGradeName() { + return gradeName; + } + + public void setGradeName(String gradeName) { + this.gradeName = gradeName; + } + + @Basic + @Column(name = "class_name") + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + @Basic + @Column(name = "exam_full_name") + public String getExamFullName() { + return examFullName; + } + + public void setExamFullName(String examFullName) { + this.examFullName = examFullName; + } + + @Basic + @Column(name = "insettime") + public Timestamp getInsettime() { + return insettime; + } + + public void setInsettime(Timestamp insettime) { + this.insettime = insettime; + } + + @Basic + @Column(name = "updatetime") + public Timestamp getUpdatetime() { + return updatetime; + } + + public void setUpdatetime(Timestamp updatetime) { + this.updatetime = updatetime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ManualGradeEntryConversion that = (ManualGradeEntryConversion) o; + return id == that.id && + Objects.equals(wechatOpenid, that.wechatOpenid) && + Objects.equals(studentNumber, that.studentNumber) && + Objects.equals(yuwenScore, that.yuwenScore) && + Objects.equals(shuxueScore, that.shuxueScore) && + Objects.equals(yingyuScore, that.yingyuScore) && + Objects.equals(wuliCoversion, that.wuliCoversion) && + Objects.equals(huaxueCoversion, that.huaxueCoversion) && + Objects.equals(shengwuCoversion, that.shengwuCoversion) && + Objects.equals(lishiCoversion, that.lishiCoversion) && + Objects.equals(diliCoversion, that.diliCoversion) && + Objects.equals(zhengzhiCoversion, that.zhengzhiCoversion) && + Objects.equals(coversionTotal, that.coversionTotal) && + Objects.equals(coversionAvg, that.coversionAvg) && + Objects.equals(classRank, that.classRank) && + Objects.equals(gradeRank, that.gradeRank) && + Objects.equals(examName, that.examName) && + Objects.equals(schoolName, that.schoolName) && + Objects.equals(gradeName, that.gradeName) && + Objects.equals(className, that.className) && + Objects.equals(examFullName, that.examFullName) && + Objects.equals(insettime, that.insettime) && + Objects.equals(updatetime, that.updatetime); + } + + @Override + public int hashCode() { + return Objects.hash(id, wechatOpenid, studentNumber, yuwenScore, shuxueScore, yingyuScore, wuliCoversion, huaxueCoversion, shengwuCoversion, lishiCoversion, diliCoversion, zhengzhiCoversion, coversionTotal, coversionAvg, classRank, gradeRank, examName, schoolName, gradeName, className, examFullName, insettime, updatetime); + } +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/model/ManuallyEnterGrades.java b/src/main/java/com/zgczx/repository/mysql1/score/model/ManuallyEnterGrades.java new file mode 100644 index 0000000..4eae9f7 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/model/ManuallyEnterGrades.java @@ -0,0 +1,62 @@ +package com.zgczx.repository.mysql1.score.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author aml + * @date 2019/10/29 19:10 + */ +@Entity +@Data +//@Table(name = "manually_enter_grades", schema = "score_ananlysis_dev", catalog = "") +@ApiModel(value = "ManuallyEnterGrades实体对象", description = "批量录入实体") +@Table(name = "manually_enter_grades") +public class ManuallyEnterGrades { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + @Basic + @Column(name = "wechat_openid") + private String wechatOpenid; + + @Basic + @Column(name = "student_number") + private String studentNumber; + + @Basic + @Column(name = "subject_name") + private String subjectName; + + @Basic + @Column(name = "score") + private String score; + + @Basic + @Column(name = "class_rank") + private String classRank; + + @Basic + @Column(name = "grade_rank") + private String gradeRank; + @Basic + @Column(name = "exam_name") + private String examName; + + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + + @Column(name = "imgs") + @Basic + private String imgs; + + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/score/model/SubjectFullScore.java b/src/main/java/com/zgczx/repository/mysql1/score/model/SubjectFullScore.java new file mode 100644 index 0000000..df20d51 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/score/model/SubjectFullScore.java @@ -0,0 +1,157 @@ +package com.zgczx.repository.mysql1.score.model; + +import javax.persistence.*; +import java.util.Objects; + +/** + * @author aml + * @date 2019/9/19 15:22 + */ +@Entity +@Table(name = "subject_full_score", schema = "score_ananlysis_dev", catalog = "") +public class SubjectFullScore { + private long id; + private String schemaname; + private Long yuwen; + private Long shuxue; + private Long yingyu; + private Long wuli; + private Long huaxue; + private Long shengwu; + private Long zhengzhi; + private Long dili; + private Long lishi; + + @Id + @Column(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Basic + @Column(name = "schemaname") + public String getSchemaname() { + return schemaname; + } + + public void setSchemaname(String schemaname) { + this.schemaname = schemaname; + } + + @Basic + @Column(name = "yuwen") + public Long getYuwen() { + return yuwen; + } + + public void setYuwen(Long yuwen) { + this.yuwen = yuwen; + } + + @Basic + @Column(name = "shuxue") + public Long getShuxue() { + return shuxue; + } + + public void setShuxue(Long shuxue) { + this.shuxue = shuxue; + } + + @Basic + @Column(name = "yingyu") + public Long getYingyu() { + return yingyu; + } + + public void setYingyu(Long yingyu) { + this.yingyu = yingyu; + } + + @Basic + @Column(name = "wuli") + public Long getWuli() { + return wuli; + } + + public void setWuli(Long wuli) { + this.wuli = wuli; + } + + @Basic + @Column(name = "huaxue") + public Long getHuaxue() { + return huaxue; + } + + public void setHuaxue(Long huaxue) { + this.huaxue = huaxue; + } + + @Basic + @Column(name = "shengwu") + public Long getShengwu() { + return shengwu; + } + + public void setShengwu(Long shengwu) { + this.shengwu = shengwu; + } + + @Basic + @Column(name = "zhengzhi") + public Long getZhengzhi() { + return zhengzhi; + } + + public void setZhengzhi(Long zhengzhi) { + this.zhengzhi = zhengzhi; + } + + @Basic + @Column(name = "dili") + public Long getDili() { + return dili; + } + + public void setDili(Long dili) { + this.dili = dili; + } + + @Basic + @Column(name = "lishi") + public Long getLishi() { + return lishi; + } + + public void setLishi(Long lishi) { + this.lishi = lishi; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SubjectFullScore that = (SubjectFullScore) o; + return id == that.id && + Objects.equals(schemaname, that.schemaname) && + Objects.equals(yuwen, that.yuwen) && + Objects.equals(shuxue, that.shuxue) && + Objects.equals(yingyu, that.yingyu) && + Objects.equals(wuli, that.wuli) && + Objects.equals(huaxue, that.huaxue) && + Objects.equals(shengwu, that.shengwu) && + Objects.equals(zhengzhi, that.zhengzhi) && + Objects.equals(dili, that.dili) && + Objects.equals(lishi, that.lishi); + } + + @Override + public int hashCode() { + return Objects.hash(id, schemaname, yuwen, shuxue, yingyu, wuli, huaxue, shengwu, zhengzhi, dili, lishi); + } +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/dao/StudentInfoDao.java b/src/main/java/com/zgczx/repository/mysql1/user/dao/StudentInfoDao.java new file mode 100644 index 0000000..8363d45 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/dao/StudentInfoDao.java @@ -0,0 +1,15 @@ +package com.zgczx.repository.mysql1.user.dao; + +import com.zgczx.repository.mysql1.user.model.StudentInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/9/10 15:53 + */ +@Repository +public interface StudentInfoDao extends JpaRepository { + + StudentInfo getStudentInfoByStudentNumber(String studentNumber); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/dao/SysLoginDao.java b/src/main/java/com/zgczx/repository/mysql1/user/dao/SysLoginDao.java new file mode 100644 index 0000000..6e53a83 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/dao/SysLoginDao.java @@ -0,0 +1,14 @@ +package com.zgczx.repository.mysql1.user.dao; + +import com.zgczx.repository.mysql1.user.model.SysLogin; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/9/10 20:03 + */ +@Repository +public interface SysLoginDao extends JpaRepository { + +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/dao/UserFeedBackDao.java b/src/main/java/com/zgczx/repository/mysql1/user/dao/UserFeedBackDao.java new file mode 100644 index 0000000..a028b20 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/dao/UserFeedBackDao.java @@ -0,0 +1,11 @@ +package com.zgczx.repository.mysql1.user.dao; + +import com.zgczx.repository.mysql1.user.model.UserFeedBack; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @author aml + * @date 2019/9/6 21:15 + */ +public interface UserFeedBackDao extends JpaRepository { +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/dao/WechatStudentDao.java b/src/main/java/com/zgczx/repository/mysql1/user/dao/WechatStudentDao.java new file mode 100644 index 0000000..8459606 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/dao/WechatStudentDao.java @@ -0,0 +1,15 @@ +package com.zgczx.repository.mysql1.user.dao; + +import com.zgczx.repository.mysql1.user.model.WechatStudent; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/11/8 19:39 + */ +@Repository +public interface WechatStudentDao extends JpaRepository { + + WechatStudent findByOpenid(String openid); +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/model/StudentInfo.java b/src/main/java/com/zgczx/repository/mysql1/user/model/StudentInfo.java new file mode 100644 index 0000000..8dc6def --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/model/StudentInfo.java @@ -0,0 +1,269 @@ +package com.zgczx.repository.mysql1.user.model; + +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author aml + * @date 2019/9/10 15:40 + */ +@Entity +@Data +@Table(name = "student_info", schema = "score_ananlysis_dev", catalog = "") +public class StudentInfo { + private int id; + private String userId; + private String studentMachineCard; + private String studentNumber; + private String studentName; + private String schoolName; + private String schoolId; + private String gradeId; + private String gradeName; + private String classId; + private String className; + private String cardNum; + private String province; + private String address; + private String birthdate; + private String sex; + private String phone; + private String image; + private Long createUser; + private Timestamp createTime; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Basic + @Column(name = "user_id") + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + @Basic + @Column(name = "student_machine_card") + public String getStudentMachineCard() { + return studentMachineCard; + } + + public void setStudentMachineCard(String studentMachineCard) { + this.studentMachineCard = studentMachineCard; + } + + @Basic + @Column(name = "student_number") + public String getStudentNumber() { + return studentNumber; + } + + public void setStudentNumber(String studentNumber) { + this.studentNumber = studentNumber; + } + + @Basic + @Column(name = "student_name") + public String getStudentName() { + return studentName; + } + + public void setStudentName(String studentName) { + this.studentName = studentName; + } + + @Basic + @Column(name = "school_name") + public String getSchoolName() { + return schoolName; + } + + public void setSchoolName(String schoolName) { + this.schoolName = schoolName; + } + + @Basic + @Column(name = "school_id") + public String getSchoolId() { + return schoolId; + } + + public void setSchoolId(String schoolId) { + this.schoolId = schoolId; + } + + @Basic + @Column(name = "grade_id") + public String getGradeId() { + return gradeId; + } + + public void setGradeId(String gradeId) { + this.gradeId = gradeId; + } + + @Basic + @Column(name = "grade_name") + public String getGradeName() { + return gradeName; + } + + public void setGradeName(String gradeName) { + this.gradeName = gradeName; + } + + @Basic + @Column(name = "class_id") + public String getClassId() { + return classId; + } + + public void setClassId(String classId) { + this.classId = classId; + } + + @Basic + @Column(name = "class_name") + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + @Basic + @Column(name = "card_num") + public String getCardNum() { + return cardNum; + } + + public void setCardNum(String cardNum) { + this.cardNum = cardNum; + } + + @Basic + @Column(name = "province") + public String getProvince() { + return province; + } + + public void setProvince(String province) { + this.province = province; + } + + @Basic + @Column(name = "address") + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Basic + @Column(name = "birthdate") + public String getBirthdate() { + return birthdate; + } + + public void setBirthdate(String birthdate) { + this.birthdate = birthdate; + } + + @Basic + @Column(name = "sex") + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + @Basic + @Column(name = "phone") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @Basic + @Column(name = "image") + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + @Basic + @Column(name = "create_user") + public Long getCreateUser() { + return createUser; + } + + public void setCreateUser(Long createUser) { + this.createUser = createUser; + } + + @Basic + @Column(name = "create_time") + public Timestamp getCreateTime() { + return createTime; + } + + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StudentInfo that = (StudentInfo) o; + return id == that.id && + Objects.equals(userId, that.userId) && + Objects.equals(studentMachineCard, that.studentMachineCard) && + Objects.equals(studentNumber, that.studentNumber) && + Objects.equals(studentName, that.studentName) && + Objects.equals(schoolName, that.schoolName) && + Objects.equals(schoolId, that.schoolId) && + Objects.equals(gradeId, that.gradeId) && + Objects.equals(gradeName, that.gradeName) && + Objects.equals(classId, that.classId) && + Objects.equals(className, that.className) && + Objects.equals(cardNum, that.cardNum) && + Objects.equals(province, that.province) && + Objects.equals(address, that.address) && + Objects.equals(birthdate, that.birthdate) && + Objects.equals(sex, that.sex) && + Objects.equals(phone, that.phone) && + Objects.equals(image, that.image) && + Objects.equals(createUser, that.createUser) && + Objects.equals(createTime, that.createTime); + } + + @Override + public int hashCode() { + return Objects.hash(id, userId, studentMachineCard, studentNumber, studentName, schoolName, schoolId, gradeId, gradeName, classId, className, cardNum, province, address, birthdate, sex, phone, image, createUser, createTime); + } +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/model/SysLogin.java b/src/main/java/com/zgczx/repository/mysql1/user/model/SysLogin.java new file mode 100644 index 0000000..8c9702b --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/model/SysLogin.java @@ -0,0 +1,101 @@ +package com.zgczx.repository.mysql1.user.model; + +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author aml + * @date 2019/9/10 20:02 + */ +@Entity +@Data +@Table(name = "sys_login", schema = "score_ananlysis_dev", catalog = "") +public class SysLogin { + private int id; + private String username; + private String password; + private Timestamp createTime; + private String email; + private String imageUrl; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Basic + @Column(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @Basic + @Column(name = "password") + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Basic + @Column(name = "create_time") + public Timestamp getCreateTime() { + return createTime; + } + + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + @Basic + @Column(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Basic + @Column(name = "image_url") + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SysLogin sysLogin = (SysLogin) o; + return id == sysLogin.id && + Objects.equals(username, sysLogin.username) && + Objects.equals(password, sysLogin.password) && + Objects.equals(createTime, sysLogin.createTime) && + Objects.equals(email, sysLogin.email) && + Objects.equals(imageUrl, sysLogin.imageUrl); + } + + @Override + public int hashCode() { + return Objects.hash(id, username, password, createTime, email, imageUrl); + } +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/model/UserFeedBack.java b/src/main/java/com/zgczx/repository/mysql1/user/model/UserFeedBack.java new file mode 100644 index 0000000..9e3a97c --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/model/UserFeedBack.java @@ -0,0 +1,39 @@ +package com.zgczx.repository.mysql1.user.model; + +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * @author aml + * @date 2019/11/20 21:12 + */ +@Data +@DynamicInsert +@Entity +@Table(name = "user_feed_back", schema = "score_ananlysis_dev", catalog = "") +public class UserFeedBack implements Serializable { + + //系统反馈Id + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + //用户提交反馈id + @Basic + @Column(name = "user_openid") + private String userOpenid; + + //系统反馈内容 + @Basic + @Column(name = "content") + private String content; + + //反馈时间 + @Basic + @Column(name = "insert_time") + private Date insertTime; +} diff --git a/src/main/java/com/zgczx/repository/mysql1/user/model/WechatStudent.java b/src/main/java/com/zgczx/repository/mysql1/user/model/WechatStudent.java new file mode 100644 index 0000000..a506c35 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql1/user/model/WechatStudent.java @@ -0,0 +1,90 @@ +package com.zgczx.repository.mysql1.user.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.NotBlank; +import org.hibernate.validator.constraints.NotEmpty; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author aml + * @date 2019/11/8 19:35 + */ +@Data +@Entity +@Table(name = "wechat_student", schema = "score_ananlysis_dev", catalog = "") +public class WechatStudent { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private int id; + +// @NotEmpty(message = "统一登录平台的主键id,用作此表的外键,必填") + @NotNull(message = "统一登录平台的主键id,用作此表的外键,必填") + @Basic + @Column(name = "foreign_ke_id") + private Integer foreignKeId; + + @NotEmpty(message = "用户openid必填") + @Basic + @Column(name = "openid") + private String openid; + +// @NotEmpty(message = "注册的用户名,必填且唯一") +// @Basic +// @Column(name = "username") +// private String username; +// +// @NotEmpty(message = "注册的密码,必填") +// @Size(min = 4,max = 20,message = "密码的长度应该在4和20之间") +// @Basic +// @Column(name = "password") +// private String password; +// +// @Basic +// @Column(name = "student_id") +// private String studentId;//学号,可以暂时不用注册 +// +// @NotEmpty(message = "学校全称,必填") +// @Basic +// @Column(name = "school_name") +// private String schoolName; +// +// @NotEmpty(message = "年级全称,例如:高一,必填") +// @Basic +// @Column(name = "grade") +// private String grade; +// +// @NotEmpty(message = "班级名称,必填") +// @Basic +// @Column(name = "class_name") +// private String className; +// +// +// @Pattern(regexp = "^1(3|4|5|7|8)\\d{9}$",message = "手机号码格式错误") +// @NotBlank(message = "手机号码不能为空") +// @Basic +// @Column(name = "phone") +// private String phone; +// @Basic +// @Column(name = "verify_code") +// private String verifyCode; + //解决返回给前端的是一个时间戳,改成为年月日时分秒格式 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp inserttime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Timestamp updatetime; + + + + + + +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dao/ExamCoversionTotalDao.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dao/ExamCoversionTotalDao.java new file mode 100644 index 0000000..49b2e4d --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dao/ExamCoversionTotalDao.java @@ -0,0 +1,276 @@ +package com.zgczx.repository.mysql2.scoretwo.dao; + +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import org.apache.ibatis.annotations.Param; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigInteger; +import java.util.List; + +/** + * @author aml + * @date 2019/9/10 15:52 + */ +@Repository +public interface ExamCoversionTotalDao extends JpaRepository { + + /** + * 11.22,修改查询条件,加上@query,主要加上valid=1 + * 根据学号获取此学生所有成绩 + * + * @param stuNumber 学号 + * @return ExamCoversionTotal实体对象 + */ + @Query(value = "select * from exam_coversion_total where student_number=?1 and exam_type=?2 and valid='1'", nativeQuery = true) + ExamCoversionTotal findByStudentNumberAndExamType(String stuNumber,String examType); + + @Query(value = "SELECT * FROM exam_coversion_total WHERE (student_number=?1 OR openid=?2) AND exam_type=?3 AND valid='1'", nativeQuery = true) + ExamCoversionTotal findByStudentNumberOrOpenidAndExamType(String stuNumber,String openid,String examType); + /** + * 获取单科的班级排名 + * @param 单科具体科目 + * @return 学号、单科分数、单科班级排名 + */ +// @Query(value = "SELECT t.student_number, t.yuwen_score,t.rank" + +// "FROM " + +// " (select u.student_number, u.yuwen_score, @rank:= @rank + 1," + +// " @last_rank:= CASE " + +// " WHEN @last_score = u.yuwen_score\n" + +// " THEN @last_rank" + +// " WHEN @last_score:= u.yuwen_score \n" + +// " THEN @rank " + +// " END AS rank " + +// " FROM " + +// " (SELECT * FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 ORDER BY yuwen_score DESC) u, " + +// " (SELECT @rank:= 0, @last_score:= NULL, @last_rank:= 0) r" + +// ")t ", nativeQuery = true) + @Query(value = "SELECT t.student_number, t.shuxue_score,t.rank FROM(SELECT u.student_number,u.shuxue_score,@rank \\:= @rank + 1,@last_rank \\:= CASE WHEN @last_score = u.shuxue_score THEN @last_rank WHEN @last_score \\:= u.shuxue_score THEN @rank END AS rank FROM (SELECT * FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 ORDER BY shuxue_score DESC)u,(SELECT @rank \\:= 0,@last_score \\:= NULL,@last_rank \\:= 0)r)t", nativeQuery = true) + List getSingleClassRank(String classid, String examType); + + //11.22 获取单科班级排名 + //ORDER BY ?4: 他是直接填充为 'yuwen_score', 查询就变成 order by 'yuwen_score' 我要的是 order by yuwen_score 这种的 + //目前这样查询的结果不对 + @Query(value = "SELECT * FROM exam_coversion_total WHERE school_name=?1 AND class_id=?2 AND exam_type=?3 AND valid=1 ORDER BY ?4 DESC", nativeQuery = true) + List getAllSingleClassRank(String schoolName,String classid,String examName,@Param(value = "subject") String subject); + + /** + * 获取某科目的成绩排序,降序 + * @param classid 班级id + * @param examType 哪次考试 + * @param subject 哪个科目 + * @return 实体对象 + */ + //@Query("select examCoversionTotal from ExamCoversionTotal examCoversionTotal where examCoversionTotal.classId = ?1 and examCoversionTotal.examType = ?2 order by ?3 desc ") + //@Query(value = "SELECT * FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 ORDER BY yingyu_score=?3 DESC", nativeQuery = true) 必须得指定第三个参数是数据库中哪个列的 + List findAllByClassIdAndExamType(String classid, String examType,String subject); + + // 获取三科的班排 + @Query(value = "SELECT student_number,yuwen_score+shuxue_score+yingyu_score AS s FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid=1 ORDER BY s DESC", nativeQuery = true) + List findByClassIdAndExamType(String classid, String examType,String schoolName,String gradeName); + + //获取三科的年排 + @Query(value = "SELECT student_number,yuwen_score+shuxue_score+yingyu_score AS s FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 ORDER BY s DESC", nativeQuery = true) + List findByClassIdAndExamTypeGrade(String examType,String schoolName,String gradeName); + + // 获取综合的班排 + @Query(value = "SELECT student_number,wuli_coversion+huaxue_coversion+shengwu_coversion+lishi_coversion+dili_coversion+zhengzhi_coversion AS s FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid=1 ORDER BY s DESC", nativeQuery = true) + List findByClassIdAndExamTypeComplex(String classid, String examType,String schoolName,String gradeName); + + // 获取综合的年排 + @Query(value = "SELECT student_number,wuli_coversion+huaxue_coversion+shengwu_coversion+lishi_coversion+dili_coversion+zhengzhi_coversion AS s FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 ORDER BY s DESC", nativeQuery = true) + List findByClassIdAndExamTypeComplexGrade(String examType,String schoolName,String gradeName); + + @Query(value = "select e.coversionTotal from ExamCoversionTotal as e where e.classId = ?1 and e.examType = ?2 and e.schoolName=?3 and e.gradeName=?4") + List getCoversionTotalByClassIdAndExamType(String classid, String examType,String schoolName,String gradeName); + + @Query(value = "select sum(sfs.yuwen+sfs.shuxue+sfs.yingyu+sfs.wuli+sfs.huaxue+sfs.shengwu+sfs.zhengzhi+sfs.lishi+sfs.dili)as total from subject_full_score sfs,exam_full_score_set sfss where sfs.id=sfss.subject_schame_id and sfss.examinfo_id=?1 ",nativeQuery = true) + @Transactional + BigInteger findSchametotal(int examid); + + + + /** + * 语数英、物化生、政史地,九门科目的降序排列,年级排名 + * 年级排名:by schoolName、gradename + * @param examType 具体考试名称 + * @return 返回单个数据库字段的所有值 + */ + @Query(value = "select yuwen_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by yuwen_score desc", nativeQuery = true) + List findByYuwenScore(String examType,String schoolName,String gradeName); + @Query(value = "select yuwen_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by yuwen_score desc", nativeQuery = true) + List findByYuwenScoreAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求语文的班级排名list + @Query(value = "select yuwen_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by yuwen_score desc", nativeQuery = true) + List findByYuwenScoreAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + @Query(value = "select shuxue_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by shuxue_score desc", nativeQuery = true) + List findByShuxueScore(String examType,String schoolName,String gradeName); + @Query(value = "select shuxue_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by shuxue_score desc", nativeQuery = true) + List findByShuxueScoreAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求数学的班级排名list + @Query(value = "select shuxue_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by shuxue_score desc", nativeQuery = true) + List findByShuxueScoreAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + @Query(value = "select yingyu_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by yingyu_score desc", nativeQuery = true) + List findByYingyuScore(String examType,String schoolName,String gradeName); + @Query(value = "select yingyu_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by yingyu_score desc", nativeQuery = true) + List findByYingyuScoreAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求英语的班级排名list + @Query(value = "select yingyu_score from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by yingyu_score desc", nativeQuery = true) + List findByYingyuScoreAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + + @Query(value = "select wuli_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by wuli_coversion desc", nativeQuery = true) + List findByWuliCoversion(String examType,String schoolName,String gradeName); + @Query(value = "select wuli_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by wuli_coversion desc", nativeQuery = true) + List findByWuliCoversionAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求物理的班级排名list + @Query(value = "select wuli_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by wuli_coversion desc", nativeQuery = true) + List findByWuliCoversionAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + + + @Query(value = "select huaxue_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by huaxue_coversion desc", nativeQuery = true) + List findByHuaxueCoversion(String examType,String schoolName,String gradeName); + @Query(value = "select huaxue_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by huaxue_coversion desc", nativeQuery = true) + List findByHuaxueCoversionAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求化学的班级排名list + @Query(value = "select huaxue_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by huaxue_coversion desc", nativeQuery = true) + List findByHuaxueCoversionAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + + @Query(value = "select shengwu_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by shengwu_coversion desc", nativeQuery = true) + List findByShengwuCoversion(String examType,String schoolName,String gradeName); + @Query(value = "select shengwu_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by shengwu_coversion desc", nativeQuery = true) + List findByShengwuCoversionAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求生物的班级排名list + @Query(value = "select shengwu_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by shengwu_coversion desc", nativeQuery = true) + List findByShengwuCoversionAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + + @Query(value = "select lishi_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by lishi_coversion desc", nativeQuery = true) + List findByLishiCoversion(String examType,String schoolName,String gradeName); + @Query(value = "select lishi_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by lishi_coversion desc", nativeQuery = true) + List findByLishiCoversionAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求历史的班级排名list + @Query(value = "select lishi_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by lishi_coversion desc", nativeQuery = true) + List findByLishiCoversionAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + + @Query(value = "select dili_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by dili_coversion desc", nativeQuery = true) + List findByDiliCoversion(String examType,String schoolName,String gradeName); + @Query(value = "select dili_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by dili_coversion desc", nativeQuery = true) + List findByDiliCoversionAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求历史的班级排名list + @Query(value = "select dili_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by dili_coversion desc", nativeQuery = true) + List findByDiliCoversionAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + + @Query(value = "select zhengzhi_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 order by zhengzhi_coversion desc", nativeQuery = true) + List findByZhengzhiCoversion(String examType,String schoolName,String gradeName); + @Query(value = "select zhengzhi_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND grade_name=?4 order by zhengzhi_coversion desc", nativeQuery = true) + List findByZhengzhiCoversionAndSchoolNameAndValid(String examType,String schoolName, int valid,String gradeName); + // 求历史的班级排名list + @Query(value = "select zhengzhi_coversion from exam_coversion_total where exam_type=?1 AND school_name=?2 AND valid=?3 AND class_id=?4 AND grade_name=?5 order by zhengzhi_coversion desc", nativeQuery = true) + List findByZhengzhiCoversionAndSchoolNameAndValidAndClassId(String examType,String schoolName, int valid,String classid,String gradeName); + + // 年级总分排名; 获取总分的数组降序; 年级排名 + @Query(value = "SELECT coversion_total FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid='1' ORDER BY coversion_total DESC", nativeQuery = true) + List findByTotalScore(String examType,String schoolName,String gradeName); + //11.19年级总分排名; 此用户在某学校-某年级-某考试下的年级总分降序,用来获取年级排名 + @Query(value = "SELECT coversion_total FROM exam_coversion_total WHERE school_name=?1 AND grade_name=?2 AND exam_type=?3 AND valid='1' ORDER BY coversion_total DESC", nativeQuery = true) + List findAllBySchoolNameAndGradeNameAndExamType(String schoolName,String gradeName,String examName); + + //11.25 班级总分排名; 获取总分的数组降序; 班级排名 + @Query(value = "SELECT coversion_total AS s FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid=1 ORDER BY s DESC", nativeQuery = true) + List findClassTotalByClassIdAndExamType(String classid, String examType,String schoolName,String gradeName); + + /** + * 语数英、物化生、政史地,九门科目的降序排列,班级排名 + * @param examType 具体考试名称 + * @return 返回单个数据库字段的所有值 + */ + @Query(value = "select yuwen_score from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by yuwen_score desc", nativeQuery = true) + List findByClassIdAndYuwenScore(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select shuxue_score from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by shuxue_score desc", nativeQuery = true) + List findByClassIdAndShuxueScore(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select yingyu_score from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by yingyu_score desc", nativeQuery = true) + List findByClassIdAndYingyuScore(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select wuli_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by wuli_coversion desc", nativeQuery = true) + List findByClassIdAndWuliCoversion(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select huaxue_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by huaxue_coversion desc", nativeQuery = true) + List findByClassIdAndHuaxueCoversion(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select shengwu_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by shengwu_coversion desc", nativeQuery = true) + List findByClassIdAndShengwuCoversion(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select lishi_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by lishi_coversion desc", nativeQuery = true) + List findByClassIdAndLishiCoversion(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select dili_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by dili_coversion desc", nativeQuery = true) + List findByClassIdAndDiliCoversion(String classid, String examType,String schoolName,String gradeName); + @Query(value = "select zhengzhi_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 AND school_name=?3 AND grade_name=?4 AND valid='1' order by zhengzhi_coversion desc", nativeQuery = true) + List findByClassIdAndZhengzhiCoversion(String classid, String examType,String schoolName,String gradeName); + + // 获取此次考试的年级人数 + int countByExamTypeAndSchoolNameAndGradeNameAndValid(String examType,String schoolName,String gradeName,int valid); + // 获取此次考试的年级人数,以valid = 1 的所有数据来统计 + int countByExamTypeAndValidAndSchoolNameAndGradeName(String examType,int valid,String schoolName,String gradeName); + + // 获取此次考试的班级人数 + int countByClassIdAndExamType(String classid, String examType); + int countByClassIdAndExamTypeAndValidAndSchoolNameAndGradeName(String classid, String examType,int valid,String schoolName,String gradeName); + + // 获取选取物理的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 AND wuli_coversion > '0'", nativeQuery = true) + int countByExamTypeAndWuli(String examType,String schoolName,String gradeName); + // 获取选取化学的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 AND huaxue_coversion > '0'", nativeQuery = true) + int countByExamTypeAndHuaxue(String examType,String schoolName,String gradeName); + // 获取选取生物的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 AND shengwu_coversion > '0'", nativeQuery = true) + int countByExamTypeAndShengwu(String examType,String schoolName,String gradeName); + // 获取选取政治的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 AND zhengzhi_coversion > '0'", nativeQuery = true) + int countByExamTypeAndZhegnzhi(String examType,String schoolName,String gradeName); + // 获取选取历史的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 AND lishi_coversion > '0'", nativeQuery = true) + int countByExamTypeAndLishi(String examType,String schoolName,String gradeName); + // 获取选取地理的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid=1 AND dili_coversion > '0'", nativeQuery = true) + int countByExamTypeAndDili(String examType,String schoolName,String gradeName); + + + + + + // 班级总分累加和 +// @Query(value = "SELECT SUM(coversion_total) FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 ", nativeQuery = true) +// float sumCoversionTotalByClassIdAndExamType(String classid, String examType); + @Query(value = "SELECT SUM(coversion_total) FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 AND valid=?3 AND school_name=?4 AND grade_name=?5", nativeQuery = true) + float sumCoversionTotalByClassIdAndExamTypeAndValidAndSchoolName(String classid, String examType,int valid,String schoolName,String gradeName); + + + //年级总分累积和 + @Query(value = "SELECT SUM(coversion_total) FROM exam_coversion_total WHERE exam_type=?1 ", nativeQuery = true) + float sumCoversionTotalByExamType(String examType); + @Query(value = "SELECT SUM(coversion_total) FROM exam_coversion_total WHERE exam_type=?1 AND valid=?2 AND school_name=?3 AND grade_name=?4", nativeQuery = true) + float sumCoversionTotalByExamTypeAndValidAndSchoolName(String examType,int valid,String schoolName,String gradeName); + + //总分的年级平均分 + @Query(value = "SELECT AVG(coversion_total) FROM exam_coversion_total WHERE exam_type=?1 AND school_name=?2 AND grade_name=?3 AND valid='1' ", nativeQuery = true) + String totalAverageByExamType(String examType,String schoolName,String gradeName); + + @Query(value = "SELECT exam_type FROM exam_coversion_total WHERE school_name = ?1 GROUP BY exam_type", nativeQuery = true) + List getAllExamTypeBySchoolName(String schoolName); + + + // 获取此用户的班级 + @Query(value = "SELECT class_id FROM exam_coversion_total WHERE (username=?1 OR student_number=?2) AND school_name=?3 AND exam_type=?4 AND valid=?5 AND grade_name=?6", nativeQuery = true) + String getClassIdByStudentNameAndSchoolNameAndExamTypeAndValid(String username,String studentNumber,String schoolName, String examType,String valid,String gradeName); + + //学科贡献率时,获取此学生的所有考试名称 + @Query(value = "SELECT exam_type FROM exam_coversion_total WHERE student_number=?1 AND school_name=?2 AND grade_name=?3 AND class_id=?4 AND valid=?5", nativeQuery = true) + List getAllExamNameByStudentNumberAndSchoolNameAndGradeNameAndClassIdAndValid(String studentNumber,String schoolName,String gradeName,String classid,int valid); +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/CommentValueDTO.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/CommentValueDTO.java new file mode 100644 index 0000000..1c2b0fb --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/CommentValueDTO.java @@ -0,0 +1,23 @@ +package com.zgczx.repository.mysql2.scoretwo.dto; + +import lombok.Data; + +/** + * 定位对比图一上的 评语中的四个值 + * 班级最高分、年级最高分、班级平均分、年级平均分 + * @author aml + * @date 2019/11/25 10:49 + */ +@Data +public class CommentValueDTO { + //班级最高分 + private String classHighScore; + //年级最高分 + private String gradeHighScore; + //班级平均分 + private String classAvgScore; + //年级平均分 + private String gradeAvgScore; + // 自己的总分分数 + private String totalScore; +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalDTO.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalDTO.java new file mode 100644 index 0000000..af4e010 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalDTO.java @@ -0,0 +1,21 @@ +package com.zgczx.repository.mysql2.scoretwo.dto; + +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import lombok.Data; + +/** + * @author aml + * @date 2019/9/11 21:00 + * DTO(Data Transfer Object) :数据传输对象, Service 或 Manager 向外传输的对象 + * controller中真正返回给前端的数据对象 + */ +@Data +public class ExamCoversionTotalDTO { + + private ExamCoversionTotal examCoversionTotal; + // 年级排名进退名次 + private int waveGrade; + // 班级排名进退名次 + private int waveClass; + +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalSectionDTO.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalSectionDTO.java new file mode 100644 index 0000000..31a1de0 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalSectionDTO.java @@ -0,0 +1,45 @@ +package com.zgczx.repository.mysql2.scoretwo.dto; + +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import lombok.Data; + +import java.util.List; + +/** + * @author aml + * @date 2019/9/17 21:11 + */ +@Data +public class ExamCoversionTotalSectionDTO { + + private ExamCoversionTotal examCoversionTotal; + // 三科:语数英的总分分值 + private Float threeSubject; + //剩下的6选3的总分分值 + private Float comprehensive; + //三科班级排名 + private int classRank; + //三科年级排名 + private int gradeRank; + //综合班级排名 + private int complexClassRank; + //综合年级排名 + private int complexGradeRank; + +// // 年级排名进退名次 +// private int waveGrade; +// // 班级排名进退名次 +// private int waveClass; + //存放某学生的6选3的具体科目 + private List list; + + //三科班级进退名次 + private int threeWaveClass; + //三科年级进退名次 + private int threeWaveGrade; + //综合班级进退名次 + private int complexWaveClass; + //综合年级进退名次 + private int complexWaveGrade; + +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalSingleDTO.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalSingleDTO.java new file mode 100644 index 0000000..326893d --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/ExamCoversionTotalSingleDTO.java @@ -0,0 +1,47 @@ +package com.zgczx.repository.mysql2.scoretwo.dto; + +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import lombok.Data; + +/** + * @author aml + * @date 2019/9/16 14:08 + */ +@Data +public class ExamCoversionTotalSingleDTO { + private ExamCoversionTotal examCoversionTotal; + //班级排名 + private int classRank; + //年级排名 + private int gradeRank; + // 年级排名进退名次 + private int waveGrade; + // 班级排名进退名次 + private int waveClass; + // 班级人数 + private int classNumber; + //年级人数 + private int gradeNumber; + //本此考试的总分标准 + private int sumScore; + // 语文总分标准 + private int languageScore; + // 数学满分标准 + private int mathScore; + // 英语满分标准 + private int englishScore; + // 物理满分标准 + private int physicalScore; + // 化学满分标准 + private int chemistryScore; + // 生物满分标准 + private int biologicalScore; + // 政治满分标准 + private int politicalScore; + // 历史满分标准 + private int historyScore; + // 地理满分标准 + private int geographyScore; + // subject此科目的对应分数 + private String score; +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/LocationComparisonDTO.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/LocationComparisonDTO.java new file mode 100644 index 0000000..8e9c0b4 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/LocationComparisonDTO.java @@ -0,0 +1,16 @@ +package com.zgczx.repository.mysql2.scoretwo.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * 定位对比二 和前排人的差距值 + * @author aml + * @date 2019/11/19 19:18 + */ +@Data +public class LocationComparisonDTO { + + private Map> stringMap; +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/SingleContrastInfoDTO.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/SingleContrastInfoDTO.java new file mode 100644 index 0000000..fefb8a6 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/SingleContrastInfoDTO.java @@ -0,0 +1,17 @@ +package com.zgczx.repository.mysql2.scoretwo.dto; + +import lombok.Data; + +import java.util.Map; + +/** + * 定位对比:1. 单科的 自己排名、目标排名、自己分数、目标分数、差值 + * @author aml + * @date 2019/11/27 14:29 + */ +@Data +public class SingleContrastInfoDTO { + + private Map> map; + +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/TotalScoreInfoDTO.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/TotalScoreInfoDTO.java new file mode 100644 index 0000000..6ae4590 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/dto/TotalScoreInfoDTO.java @@ -0,0 +1,22 @@ +package com.zgczx.repository.mysql2.scoretwo.dto; + +import lombok.Data; + +/** + * 定位对比 1. 总分的 对比信息 + * @author aml + * @date 2019/11/27 10:29 + */ +@Data +public class TotalScoreInfoDTO { + //我的排名 + private int myRank; + //目标排名 + private int targetRank; + //我的分数 + private String myScore; + //目标分数 + private String targetScore; + //分数差值 + private String scoreDifferentValue; +} diff --git a/src/main/java/com/zgczx/repository/mysql2/scoretwo/model/ExamCoversionTotal.java b/src/main/java/com/zgczx/repository/mysql2/scoretwo/model/ExamCoversionTotal.java new file mode 100644 index 0000000..735cd3d --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql2/scoretwo/model/ExamCoversionTotal.java @@ -0,0 +1,351 @@ +package com.zgczx.repository.mysql2.scoretwo.model; + +import lombok.Data; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; +import javax.persistence.Entity; + +/** + * @author aml + * @date 2019/9/10 15:38 + */ +@Component +@Entity +@Data +//@Table(name = "exam_coversion_total", schema = "score_ananlysis_wechat", catalog = "") +@Table(name = "exam_coversion_total", schema = "score_ananlysis_wechat", catalog = "") +public class ExamCoversionTotal { + private long id; + private long examId; + private String studentMachineCard; + private String studentNumber; + private String studentName; + private String classId; + private String gradeName; + private Timestamp examDate; + private String examType; + private Double yuwenScore; + private Double shuxueScore; + private Double yingyuScore; + private Double wuliCoversion; + private Double huaxueCoversion; + private Double shengwuCoversion; + private Double lishiCoversion; + private Double diliCoversion; + private Double zhengzhiCoversion; + private Double coversionTotal; + private Double coversionAvg; + private Integer schoolIndex; + private Integer classIndex; + // @Basic +// @Column(name = "openid") +// private String openid; +// @Basic +// @Column(name = "data_source") +// private Integer dataSource; +// @Basic +// @Column(name = "valid") +// private Integer valid; + private String openid; + private Integer dataSource; + private Integer valid; + private String schoolName; + private String username; + + @Id + @Column(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Basic + @Column(name = "exam_id") + public long getExamId() { + return examId; + } + + public void setExamId(long examId) { + this.examId = examId; + } + + @Basic + @Column(name = "student_machine_card") + public String getStudentMachineCard() { + return studentMachineCard; + } + + public void setStudentMachineCard(String studentMachineCard) { + this.studentMachineCard = studentMachineCard; + } + + @Basic + @Column(name = "student_number") + public String getStudentNumber() { + return studentNumber; + } + + public void setStudentNumber(String studentNumber) { + this.studentNumber = studentNumber; + } + + @Basic + @Column(name = "student_name") + public String getStudentName() { + return studentName; + } + + public void setStudentName(String studentName) { + this.studentName = studentName; + } + + @Basic + @Column(name = "class_id") + public String getClassId() { + return classId; + } + + public void setClassId(String classId) { + this.classId = classId; + } + + @Basic + @Column(name = "grade_name") + public String getGradeName() { + return gradeName; + } + + public void setGradeName(String gradeName) { + this.gradeName = gradeName; + } + + @Basic + @Column(name = "exam_date") + public Timestamp getExamDate() { + return examDate; + } + + public void setExamDate(Timestamp examDate) { + this.examDate = examDate; + } + + @Basic + @Column(name = "exam_type") + public String getExamType() { + return examType; + } + + public void setExamType(String examType) { + this.examType = examType; + } + + @Basic + @Column(name = "yuwen_score") + public Double getYuwenScore() { + return yuwenScore; + } + + public void setYuwenScore(Double yuwenScore) { + this.yuwenScore = yuwenScore; + } + + @Basic + @Column(name = "shuxue_score") + public Double getShuxueScore() { + return shuxueScore; + } + + public void setShuxueScore(Double shuxueScore) { + this.shuxueScore = shuxueScore; + } + + @Basic + @Column(name = "yingyu_score") + public Double getYingyuScore() { + return yingyuScore; + } + + public void setYingyuScore(Double yingyuScore) { + this.yingyuScore = yingyuScore; + } + + @Basic + @Column(name = "wuli_coversion") + public Double getWuliCoversion() { + return wuliCoversion; + } + + public void setWuliCoversion(Double wuliCoversion) { + this.wuliCoversion = wuliCoversion; + } + + @Basic + @Column(name = "huaxue_coversion") + public Double getHuaxueCoversion() { + return huaxueCoversion; + } + + public void setHuaxueCoversion(Double huaxueCoversion) { + this.huaxueCoversion = huaxueCoversion; + } + + @Basic + @Column(name = "shengwu_coversion") + public Double getShengwuCoversion() { + return shengwuCoversion; + } + + public void setShengwuCoversion(Double shengwuCoversion) { + this.shengwuCoversion = shengwuCoversion; + } + + @Basic + @Column(name = "lishi_coversion") + public Double getLishiCoversion() { + return lishiCoversion; + } + + public void setLishiCoversion(Double lishiCoversion) { + this.lishiCoversion = lishiCoversion; + } + + @Basic + @Column(name = "dili_coversion") + public Double getDiliCoversion() { + return diliCoversion; + } + + public void setDiliCoversion(Double diliCoversion) { + this.diliCoversion = diliCoversion; + } + + @Basic + @Column(name = "zhengzhi_coversion") + public Double getZhengzhiCoversion() { + return zhengzhiCoversion; + } + + public void setZhengzhiCoversion(Double zhengzhiCoversion) { + this.zhengzhiCoversion = zhengzhiCoversion; + } + + @Basic + @Column(name = "coversion_total") + public Double getCoversionTotal() { + return coversionTotal; + } + + public void setCoversionTotal(Double coversionTotal) { + this.coversionTotal = coversionTotal; + } + + @Basic + @Column(name = "coversion_avg") + public Double getCoversionAvg() { + return coversionAvg; + } + +// @Basic +// @Column(name = "data_source") +// public Integer getDataSource() { +// return dataSource; +// } +// +// public void setDataSource(Integer dataSource) { +// this.dataSource = dataSource; +// } + + public void setCoversionAvg(Double coversionAvg) { + this.coversionAvg = coversionAvg; + } + + @Basic + @Column(name = "school_index") + public Integer getSchoolIndex() { + return schoolIndex; + } + + public void setSchoolIndex(Integer schoolIndex) { + this.schoolIndex = schoolIndex; + } + + @Basic + @Column(name = "class_index") + public Integer getClassIndex() { + return classIndex; + } + + public void setClassIndex(Integer classIndex) { + this.classIndex = classIndex; + } + + @Basic + @Column(name = "openid") + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + @Basic + @Column(name = "data_source") + public Integer getDataSource() { + return dataSource; + } + + public void setDataSource(Integer dataSource) { + this.dataSource = dataSource; + } + + @Basic + @Column(name = "valid") + public Integer getValid() { + return valid; + } + + public void setValid(Integer valid) { + this.valid = valid; + } + + @Basic + @Column(name = "school_name") + public String getSchoolName() { + return schoolName; + } + + public void setSchoolName(String schoolName) { + this.schoolName = schoolName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ExamCoversionTotal that = (ExamCoversionTotal) o; + return Objects.equals(schoolName, that.schoolName); + } + + @Override + public int hashCode() { + return Objects.hash(schoolName); + } + + @Basic + @Column(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/GoodsDao.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/GoodsDao.java new file mode 100644 index 0000000..ee21183 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/GoodsDao.java @@ -0,0 +1,15 @@ +package com.zgczx.repository.mysql3.unifiedlogin.dao; + +import com.zgczx.repository.mysql3.unifiedlogin.model.Goods; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @ClassName: Jason + * @Author: 陈志恒 + * @Date: 2019/7/8 16:04 + * @Description: + */ +public interface GoodsDao extends JpaRepository { + Goods findByGoodsId(Integer goodsId); + Goods findByGoodsName(String name); +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/MonitorDao.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/MonitorDao.java new file mode 100644 index 0000000..6bddb74 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/MonitorDao.java @@ -0,0 +1,35 @@ +package com.zgczx.repository.mysql3.unifiedlogin.dao; + + +import com.zgczx.repository.mysql3.unifiedlogin.model.Monitor; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + + +/** + * + * @author changzhijun + * @date 2017-12-27 + * + */ +@Repository +public interface MonitorDao extends JpaRepository { + + public List getMonitorByIpAndDateAndName(String ip, String date, String name); + + @Query(value = "update monitor set pv=pv+1 where ip=?1 and date=?2 and name=?3", nativeQuery = true) + @Modifying + public int add(String ip, String date, String name); + + @Query(value = "update monitor set pv=pv-1 where ip=?1 and date=?2 and name=?3 ", nativeQuery = true) + @Modifying + public int minus(String ip); + + + + +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/OrderDao.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/OrderDao.java new file mode 100644 index 0000000..ca51772 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/OrderDao.java @@ -0,0 +1,24 @@ +package com.zgczx.repository.mysql3.unifiedlogin.dao; + +import com.zgczx.repository.mysql3.unifiedlogin.model.OrderInfo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OrderDao extends JpaRepository { + /** + *根据用户微信openid与货物id查看订单详情信息 + * + * @Author chen + * @Date 16:08 2019/7/8 + * @param openid 微信openid + * @param goods 货物openid + * @return + **/ + OrderInfo findByOpenidAndGoodsId(String openid, Integer goods); + + OrderInfo findByOrderId(String orderId); + // List findByFlagsAndGroupId(Boolean istrue, Integer groupId); + //ListfindByFlagsAndGroupIdAndUpdateTimeBetween(Boolean istrue, Integer groupId, Date startTime, Date endTime); + // ListfindByOpenidAndFlags(String openid, Boolean istrue); + /* @Query("SELECT openid,COUNT(oi.openid) as cs FROM OrderInfo oi WHERE oi.groupId=?1 AND oi.flags=TRUE GROUP BY oi.openid ORDER BY cs DESC") + public Page findGroupUserPayCount(Integer groupId, Pageable pageable);*/ +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/UserDao.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/UserDao.java new file mode 100644 index 0000000..0b4eded --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/UserDao.java @@ -0,0 +1,25 @@ +package com.zgczx.repository.mysql3.unifiedlogin.dao; + +import com.zgczx.repository.mysql3.unifiedlogin.model.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @ProjectName: springboot-demo + * @Package: com.zkrt.springboot.repository.mysql.user.dao + * @ClassName: UserDao + * @Author: zyh + * @Description: ${description} + * @Date: 2019/6/18 14:46 + * @Version: 1.0 + **/ +@Repository +public interface UserDao extends JpaRepository { + /** + * 根据openid验证此用户是否存在 + * @param openId + * @return + */ + User findByWechatid(String openId); + +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/UserLoginDao.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/UserLoginDao.java new file mode 100644 index 0000000..2c0247c --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/UserLoginDao.java @@ -0,0 +1,52 @@ +package com.zgczx.repository.mysql3.unifiedlogin.dao; + + +import com.zgczx.repository.mysql3.unifiedlogin.model.UserLogin; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import javax.transaction.Transactional; +import java.util.List; + +@Repository +public interface UserLoginDao extends JpaRepository { + + List getUserByAccountOrDiyid(String account, int diyid); + + List getUserByAccount(String account); + + List getUserByDiyidAndMessagecode(int diyid, String messagecode); + + @Query(value = "update user_login set headimage=?2 where account=?1 or diyid=?1 ", nativeQuery = true) + @Modifying + int setHeadimage(String account, String headimage); + + /** + * 根据wechat_openid注册账号 + * @param wechatId + * @param userName + * @param headimg + * @return + */ + @Modifying + @Transactional + @Query(value = "insert into user_login(wechat_id, user_name,headimg) values (?1,?2,?3)", nativeQuery = true) + int insertUserInfo(String wechatId, String userName, String headimg); + + // 根据WeChatId获取此用户数据 + @Transactional + @Query(value = "SELECT * FROM user_login WHERE wechat_id=?1", nativeQuery = true) + UserLogin getUserLoginByWechatId(String wechatId); + + UserLogin findAllByWechatId(String wechatId); + + // 根据学号查询是否 学校提供有此 用户的基本信息 + UserLogin findByDiyid(String diyid); + + //根据姓名查询 + @Query(value = "SELECT * FROM user_login WHERE real_name=?1 " ,nativeQuery = true) + List findByRealName(String name); + +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/WechatLoginDao.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/WechatLoginDao.java new file mode 100644 index 0000000..81c05ab --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/dao/WechatLoginDao.java @@ -0,0 +1,20 @@ +package com.zgczx.repository.mysql3.unifiedlogin.dao; + +import com.zgczx.repository.mysql3.unifiedlogin.model.WechatLogin; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; + +/** + * @author aml + * @date 2019/11/17 19:24 + */ +public interface WechatLoginDao extends JpaRepository { + + WechatLogin findAllByOpenid(String openid); + + @Modifying +// @Transactional + @Query(value = "UPDATE wechat_login SET diyid=?1 WHERE openid=?2 ", nativeQuery = true) + int updateDiyidByOpenid(String diyid, String openid); +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/Goods.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/Goods.java new file mode 100644 index 0000000..e753058 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/Goods.java @@ -0,0 +1,52 @@ +package com.zgczx.repository.mysql3.unifiedlogin.model; + +import lombok.Data; +import lombok.ToString; + +import javax.persistence.*; + +/** + * @ClassName: Jason + * @Author: 陈志恒 + * @Date: 2019/7/8 16:02 + * @Description: + */ +@Entity +@Data +@ToString +@Table(name = "orderinfo") +public class Goods { + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + + /*以这种注解形式,补全每个参数含义*/ + private Integer goodsId; + + /*补全*/ + private String goodsName; + private Double price; + + public Integer getGoodsId() { + return goodsId; + } + + public void setGoodsId(Integer goodsId) { + this.goodsId = goodsId; + } + + public String getGoodsName() { + return goodsName; + } + + public void setGoodsName(String goodsName) { + this.goodsName = goodsName; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/Monitor.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/Monitor.java new file mode 100644 index 0000000..5588d62 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/Monitor.java @@ -0,0 +1,118 @@ +package com.zgczx.repository.mysql3.unifiedlogin.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.sql.Timestamp; + +/** + * @ProjectName login_platform + * @ClassName Monitor + * @Author lixu + * @Date 2019/9/16 13:28 + * @Version 1.0 + * @Description TODO + */ +@Entity +public class Monitor { + + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private int id; + private String date; + private String ip; + private String name; + private String country; + private String address; + private int pv; + private int threshold; + private Timestamp updatetime; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getPv() { + return pv; + } + + public void setPv(int pv) { + this.pv = pv; + } + + public int getThreshold() { + return threshold; + } + + public void setThreshold(int threshold) { + this.threshold = threshold; + } + + public Timestamp getUpdatetime() { + return updatetime; + } + + public void setUpdatetime(Timestamp updatetime) { + this.updatetime = updatetime; + } + + @Override + public String toString() { + return "Monitor{" + + "id=" + id + + ", date='" + date + '\'' + + ", ip='" + ip + '\'' + + ", name='" + name + '\'' + + ", country='" + country + '\'' + + ", address='" + address + '\'' + + ", pv=" + pv + + ", threshold=" + threshold + + ", updatetime=" + updatetime + + '}'; + } +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/OrderInfo.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/OrderInfo.java new file mode 100644 index 0000000..16f076c --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/OrderInfo.java @@ -0,0 +1,94 @@ +package com.zgczx.repository.mysql3.unifiedlogin.model; + +import lombok.Data; +import lombok.ToString; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.util.Date; + +/** + * @ClassName: Jason + * @Author: 陈志恒 + * @Date: 2019/5/23 13:06 + * @Description: + */ +@Entity +@Data +@ToString +@Table(name = "orderinfo") +@DynamicUpdate +@DynamicInsert +public class OrderInfo { + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private int id; + /*用户微信openid*/ + private String openid; + /*用户是否支付过*/ + private Boolean flags; + /*订单号*/ + private String orderId; + /*商品号*/ + private Integer goodsId; + private Date createTime; + + private Date updateTime; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public Boolean getFlags() { + return flags; + } + + public void setFlags(Boolean flags) { + this.flags = flags; + } + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public Integer getGoodsId() { + return goodsId; + } + + public void setGoodsId(Integer goodsId) { + this.goodsId = goodsId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/User.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/User.java new file mode 100644 index 0000000..360acdb --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/User.java @@ -0,0 +1,225 @@ +package com.zgczx.repository.mysql3.unifiedlogin.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class User { + + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private long id; + private String account; + private String diyid; + private String wechatid; + private String qqid; + private String email; + private String role; + private String passwdmd5Md5; + private String messagecode; + private String messagecodeinserttime; + private String showname; + private String headimage; + private String updatetime; + private String reserve1; + private String reserve2; + private String resever3; + private String reserve4; + private String reserve5; + private String openid; + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + + public String getDiyid() { + return diyid; + } + + public void setDiyid(String diyid) { + this.diyid = diyid; + } + + + public String getWechatid() { + return wechatid; + } + + public void setWechatid(String wechatid) { + this.wechatid = wechatid; + } + + + public String getQqid() { + return qqid; + } + + public void setQqid(String qqid) { + this.qqid = qqid; + } + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + + public String getPasswdmd5Md5() { + return passwdmd5Md5; + } + + public void setPasswdmd5Md5(String passwdmd5Md5) { + this.passwdmd5Md5 = passwdmd5Md5; + } + + + public String getMessagecode() { + return messagecode; + } + + public void setMessagecode(String messagecode) { + this.messagecode = messagecode; + } + + + public String getMessagecodeinserttime() { + return messagecodeinserttime; + } + + public void setMessagecodeinserttime(String messagecodeinserttime) { + this.messagecodeinserttime = messagecodeinserttime; + } + + + public String getShowname() { + return showname; + } + + public void setShowname(String showname) { + this.showname = showname; + } + + + public String getHeadimage() { + return headimage; + } + + public void setHeadimage(String headimage) { + this.headimage = headimage; + } + + + public String getUpdatetime() { + return updatetime; + } + + public void setUpdatetime(String updatetime) { + this.updatetime = updatetime; + } + + + public String getReserve1() { + return reserve1; + } + + public void setReserve1(String reserve1) { + this.reserve1 = reserve1; + } + + + public String getReserve2() { + return reserve2; + } + + public void setReserve2(String reserve2) { + this.reserve2 = reserve2; + } + + + public String getResever3() { + return resever3; + } + + public void setResever3(String resever3) { + this.resever3 = resever3; + } + + + public String getReserve4() { + return reserve4; + } + + public void setReserve4(String reserve4) { + this.reserve4 = reserve4; + } + + public String getReserve5() { + return reserve5; + } + + public void setReserve5(String reserve5) { + this.reserve5 = reserve5; + } + + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", account='" + account + '\'' + + ", diyid='" + diyid + '\'' + + ", wechatid='" + wechatid + '\'' + + ", qqid='" + qqid + '\'' + + ", email='" + email + '\'' + + ", role='" + role + '\'' + + ", passwdmd5Md5='" + passwdmd5Md5 + '\'' + + ", messagecode='" + messagecode + '\'' + + ", messagecodeinserttime='" + messagecodeinserttime + '\'' + + ", showname='" + showname + '\'' + + ", headimage='" + headimage + '\'' + + ", updatetime='" + updatetime + '\'' + + ", reserve1='" + reserve1 + '\'' + + ", reserve2='" + reserve2 + '\'' + + ", resever3='" + resever3 + '\'' + + ", reserve4='" + reserve4 + '\'' + + ", reserve5='" + reserve5 + '\'' + + '}'; + } +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/UserLogin.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/UserLogin.java new file mode 100644 index 0000000..689c684 --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/UserLogin.java @@ -0,0 +1,104 @@ +package com.zgczx.repository.mysql3.unifiedlogin.model; + +import lombok.Data; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @ProjectName login_platform + * @ClassName UserLogin + * @Author lixu + * @Date 2019/9/16 16:15 + * @Version 1.0 + * @Description TODO + */ +@Data +@Entity +@Table(name = "user_login") +public class UserLogin { + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private int id; + @Column(name = "diyid") + private String diyid; + @Column(name = "account") + private String account; + @Column(name = "passwdmd5") + private String passwdmd5; + @Column(name = "user_name") + private String userName; + @Column(name = "messagecode") + private String messagecode; + @Column(name = "role") + private String role; + @Column(name = "shool_code") + private String shoolCode; + @Column(name = "school_name") + private String schoolName; + @Column(name = "tel_number") + private String telNumber; + @Column(name = "qq_id") + private String qqId; + @Column(name = "wechat_id") + private String wechatId; + @Column(name = "headimg") + private String headimg; + @Column(name = "token") + private String token; + @Column(name = "state") + private int state; + @Column(name = "grade") + private String grade; + @Column(name = "level") + private String level; + + @Column(name = "grade_level") + private String gradeLevel; + @Column(name = "class_name") + private String className; + + private Timestamp updatetime; + + private Timestamp inserttime; + @Column(name = "confirm_passwordmd5") + private String confirmPasswordmd5; + + @Column(name = "real_name") + private String realName; + + @Column(name = "nick_name") + private String nickName; + + private String sex; + + private String birthday; + + private String location; + + private String signature; + + + @Column(name = "serial_number") + private Long serialNumber; + + @Column(name = "number_id") + private String numberId; + + private String nation; + + @Column(name = "contact_man") + private String contactMan; + + @Column(name = "contact_number") + private String contactNumber; + + @Column(name = "contact_relation") + private String contactRelation; + + @Column(name = "contact_address") + private String contactAddress; + + private String department; +} diff --git a/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/WechatLogin.java b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/WechatLogin.java new file mode 100644 index 0000000..412892e --- /dev/null +++ b/src/main/java/com/zgczx/repository/mysql3/unifiedlogin/model/WechatLogin.java @@ -0,0 +1,127 @@ +package com.zgczx.repository.mysql3.unifiedlogin.model; + +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author aml + * @date 2019/11/17 19:24 + */ +@DynamicUpdate//生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中 +@DynamicInsert// 如果这个字段的值是null就不会加入到insert语句当中. +@Entity +@Table(name = "wechat_login", schema = "unified-login", catalog = "") +public class WechatLogin { + private int id; + private String openid; + private String diyid; + private String nickName; + private String headimgurl; + private String wechatSource; + private Timestamp inserttime; + private Timestamp updatetime; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Basic + @Column(name = "openid") + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + @Basic + @Column(name = "diyid") + public String getDiyid() { + return diyid; + } + + public void setDiyid(String diyid) { + this.diyid = diyid; + } + + @Basic + @Column(name = "nick_name") + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + @Basic + @Column(name = "headimgurl") + public String getHeadimgurl() { + return headimgurl; + } + + public void setHeadimgurl(String headimgurl) { + this.headimgurl = headimgurl; + } + + @Basic + @Column(name = "wechat_source") + public String getWechatSource() { + return wechatSource; + } + + public void setWechatSource(String wechatSource) { + this.wechatSource = wechatSource; + } + + @Basic + @Column(name = "inserttime") + public Timestamp getInserttime() { + return inserttime; + } + + public void setInserttime(Timestamp inserttime) { + this.inserttime = inserttime; + } + + @Basic + @Column(name = "updatetime") + public Timestamp getUpdatetime() { + return updatetime; + } + + public void setUpdatetime(Timestamp updatetime) { + this.updatetime = updatetime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + WechatLogin that = (WechatLogin) o; + return id == that.id && + Objects.equals(openid, that.openid) && + Objects.equals(diyid, that.diyid) && + Objects.equals(nickName, that.nickName) && + Objects.equals(headimgurl, that.headimgurl) && + Objects.equals(wechatSource, that.wechatSource) && + Objects.equals(inserttime, that.inserttime) && + Objects.equals(updatetime, that.updatetime); + } + + @Override + public int hashCode() { + return Objects.hash(id, openid, diyid, nickName, headimgurl, wechatSource, inserttime, updatetime); + } +} diff --git a/src/main/java/com/zgczx/repository/score/ExamCoversionTotalDao.java b/src/main/java/com/zgczx/repository/score/ExamCoversionTotalDao.java index 49c47bf..2284b45 100644 --- a/src/main/java/com/zgczx/repository/score/ExamCoversionTotalDao.java +++ b/src/main/java/com/zgczx/repository/score/ExamCoversionTotalDao.java @@ -79,4 +79,95 @@ public interface ExamCoversionTotalDao extends JpaRepository findByYuwenScore(String examType); + @Query(value = "select shuxue_score from exam_coversion_total where exam_type=?1 order by shuxue_score desc", nativeQuery = true) + List findByShuxueScore(String examType); + @Query(value = "select yingyu_score from exam_coversion_total where exam_type=?1 order by yingyu_score desc", nativeQuery = true) + List findByYingyuScore(String examType); + @Query(value = "select wuli_coversion from exam_coversion_total where exam_type=?1 order by wuli_coversion desc", nativeQuery = true) + List findByWuliCoversion(String examType); + @Query(value = "select huaxue_coversion from exam_coversion_total where exam_type=?1 order by huaxue_coversion desc", nativeQuery = true) + List findByHuaxueCoversion(String examType); + @Query(value = "select shengwu_coversion from exam_coversion_total where exam_type=?1 order by shengwu_coversion desc", nativeQuery = true) + List findByShengwuCoversion(String examType); + @Query(value = "select lishi_coversion from exam_coversion_total where exam_type=?1 order by lishi_coversion desc", nativeQuery = true) + List findByLishiCoversion(String examType); + @Query(value = "select dili_coversion from exam_coversion_total where exam_type=?1 order by dili_coversion desc", nativeQuery = true) + List findByDiliCoversion(String examType); + @Query(value = "select zhengzhi_coversion from exam_coversion_total where exam_type=?1 order by zhengzhi_coversion desc", nativeQuery = true) + List findByZhengzhiCoversion(String examType); + + // 获取总分的数组降序 + @Query(value = "SELECT coversion_total FROM exam_coversion_total WHERE exam_type=?1 ORDER BY coversion_total DESC", nativeQuery = true) + List findByTotalScore(String examType); + + /** + * 语数英、物化生、政史地,九门科目的降序排列,班级排名 + * @param examType 具体考试名称 + * @return 返回单个数据库字段的所有值 + */ + @Query(value = "select yuwen_score from exam_coversion_total where class_id = ?1 and exam_type=?2 order by yuwen_score desc", nativeQuery = true) + List findByClassIdAndYuwenScore(String classid, String examType); + @Query(value = "select shuxue_score from exam_coversion_total where class_id = ?1 and exam_type=?2 order by shuxue_score desc", nativeQuery = true) + List findByClassIdAndShuxueScore(String classid, String examType); + @Query(value = "select yingyu_score from exam_coversion_total where class_id = ?1 and exam_type=?2 order by yingyu_score desc", nativeQuery = true) + List findByClassIdAndYingyuScore(String classid, String examType); + @Query(value = "select wuli_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 order by wuli_coversion desc", nativeQuery = true) + List findByClassIdAndWuliCoversion(String classid, String examType); + @Query(value = "select huaxue_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 order by huaxue_coversion desc", nativeQuery = true) + List findByClassIdAndHuaxueCoversion(String classid, String examType); + @Query(value = "select shengwu_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 order by shengwu_coversion desc", nativeQuery = true) + List findByClassIdAndShengwuCoversion(String classid, String examType); + @Query(value = "select lishi_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 order by lishi_coversion desc", nativeQuery = true) + List findByClassIdAndLishiCoversion(String classid, String examType); + @Query(value = "select dili_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 order by dili_coversion desc", nativeQuery = true) + List findByClassIdAndDiliCoversion(String classid, String examType); + @Query(value = "select zhengzhi_coversion from exam_coversion_total where class_id = ?1 and exam_type=?2 order by zhengzhi_coversion desc", nativeQuery = true) + List findByClassIdAndZhengzhiCoversion(String classid, String examType); + + // 获取此次考试的年级人数 + int countByExamType(String examType); + // 获取此次考试的班级人数 + int countByClassIdAndExamType(String classid, String examType); + // 获取选取物理的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND wuli_coversion > '0'", nativeQuery = true) + int countByExamTypeAndWuli(String examType); + // 获取选取化学的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND huaxue_coversion > '0'", nativeQuery = true) + int countByExamTypeAndHuaxue(String examType); + // 获取选取生物的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND shengwu_coversion > '0'", nativeQuery = true) + int countByExamTypeAndShengwu(String examType); + // 获取选取政治的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND zhengzhi_coversion > '0'", nativeQuery = true) + int countByExamTypeAndZhegnzhi(String examType); + // 获取选取历史的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND lishi_coversion > '0'", nativeQuery = true) + int countByExamTypeAndLishi(String examType); + // 获取选取地理的年级总人数,按照考试分数 > 0来计算,可能会有些误差 + @Query(value = "SELECT COUNT(*) FROM exam_coversion_total WHERE exam_type=?1 AND dili_coversion > '0'", nativeQuery = true) + int countByExamTypeAndDili(String examType); + + + + + + // 班级总分累加和 + @Query(value = "SELECT SUM(coversion_total) FROM exam_coversion_total WHERE class_id=?1 AND exam_type=?2 ", nativeQuery = true) + float sumCoversionTotalByClassIdAndExamType(String classid, String examType); + + //年级总分累积和 + @Query(value = "SELECT SUM(coversion_total) FROM exam_coversion_total WHERE exam_type=?1 ", nativeQuery = true) + float sumCoversionTotalByExamType(String examType); + + //总分的年级平均分 + @Query(value = "SELECT AVG(coversion_total) FROM exam_coversion_total WHERE exam_type=?1", nativeQuery = true) + String totalAverageByExamType(String examType); } diff --git a/src/main/java/com/zgczx/repository/score/ExamInfoDao.java b/src/main/java/com/zgczx/repository/score/ExamInfoDao.java index eefb4aa..b3b3fb5 100644 --- a/src/main/java/com/zgczx/repository/score/ExamInfoDao.java +++ b/src/main/java/com/zgczx/repository/score/ExamInfoDao.java @@ -5,6 +5,8 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + /** * @author aml * @date 2019/9/10 15:53 @@ -19,4 +21,9 @@ public interface ExamInfoDao extends JpaRepository { */ @Query(value = "select e.id from ExamInfo e where e.examName = ?1") int findByExamName(String examType); + // @Query(value = "select * from exam_info where exam_name=?1",nativeQuery = true) + ExamInfo getByExamName(String examType); + + @Query(value = "SELECT exam_name FROM exam_info ", nativeQuery = true) + ListgetAllExamName(); } diff --git a/src/main/java/com/zgczx/repository/score/ImportConversionScoreDao.java b/src/main/java/com/zgczx/repository/score/ImportConversionScoreDao.java new file mode 100644 index 0000000..7bf8a6b --- /dev/null +++ b/src/main/java/com/zgczx/repository/score/ImportConversionScoreDao.java @@ -0,0 +1,20 @@ +package com.zgczx.repository.score; + +import com.zgczx.dataobject.score.ImportConversionScore; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/9/22 16:28 + */ +@Repository +public interface ImportConversionScoreDao extends JpaRepository { + /** + * + * @param machine 某此考试的机读号 + * @param examType 具体的考试名称 + * @return ImportConversionScore对象 + */ + ImportConversionScore findByStudentMachineCardAndExamType(String machine, String examType); +} diff --git a/src/main/java/com/zgczx/repository/score/ManuallyEnterGradesDao.java b/src/main/java/com/zgczx/repository/score/ManuallyEnterGradesDao.java new file mode 100644 index 0000000..6fb4493 --- /dev/null +++ b/src/main/java/com/zgczx/repository/score/ManuallyEnterGradesDao.java @@ -0,0 +1,15 @@ +package com.zgczx.repository.score; + +import com.zgczx.dataobject.score.ManuallyEnterGrades; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * @author aml + * @date 2019/10/29 19:15 + */ +@Repository +public interface ManuallyEnterGradesDao extends JpaRepository { + + +} diff --git a/src/main/java/com/zgczx/repository/score/SubjectDTODao.java b/src/main/java/com/zgczx/repository/score/SubjectDTODao.java new file mode 100644 index 0000000..397fab9 --- /dev/null +++ b/src/main/java/com/zgczx/repository/score/SubjectDTODao.java @@ -0,0 +1,22 @@ +package com.zgczx.repository.score; + +import com.zgczx.dataobject.score.ExamCoversionTotal; +import com.zgczx.dto.SubjectDTO; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import javax.validation.Valid; +import java.util.List; +import java.util.UUID; + +/** + * @author aml + * @date 2019/10/23 14:18 + */ +@Repository +public interface SubjectDTODao extends JpaRepository { + + @Query(value = "SELECT id,AVG(yuwen_score) as yuwen,AVG(shuxue_score) as shuxue,AVG(yingyu_score)as yingyu, AVG(wuli_coversion)as wuli,AVG(huaxue_coversion)as huaxue,AVG(shengwu_coversion)as shengwu,AVG(zhengzhi_coversion)as zhengzhi,AVG(lishi_coversion)as lishi,AVG(dili_coversion)as dili FROM exam_coversion_total WHERE exam_type=?1" , nativeQuery = true) + List avgSubject(String examType); +} diff --git a/src/main/java/com/zgczx/repository/score/SubjectFullScoreDao.java b/src/main/java/com/zgczx/repository/score/SubjectFullScoreDao.java index 8eeefd3..c124571 100644 --- a/src/main/java/com/zgczx/repository/score/SubjectFullScoreDao.java +++ b/src/main/java/com/zgczx/repository/score/SubjectFullScoreDao.java @@ -2,6 +2,7 @@ import com.zgczx.dataobject.score.SubjectFullScore; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.math.BigInteger; @@ -12,4 +13,7 @@ */ @Repository public interface SubjectFullScoreDao extends JpaRepository { + + @Query(value = "SELECT * FROM subject_full_score sfs,exam_full_score_set sfss WHERE sfs.id=sfss.subject_schame_id AND sfss.examinfo_id=?1 ", nativeQuery = true) + SubjectFullScore findById(int id); } diff --git a/src/main/java/com/zgczx/service/exam/ExamService.java b/src/main/java/com/zgczx/service/exam/ExamService.java new file mode 100644 index 0000000..b1b9a0d --- /dev/null +++ b/src/main/java/com/zgczx/service/exam/ExamService.java @@ -0,0 +1,127 @@ +package com.zgczx.service.exam; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.zgczx.repository.mysql1.exam.dto.*; +import com.zgczx.repository.mysql1.exam.model.Question; +import com.zgczx.repository.mysql1.exam.model.UserCollect; +import com.zgczx.repository.mysql1.exam.model.UserPaperRecord; +import com.zgczx.repository.mysql1.exam.model.UserQuestionRecord; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.List; +import java.util.Map; + +/** + * @author aml + * @date 2019/12/11 15:44 + */ +public interface ExamService { + + String parseWord(MultipartFile file, HttpSession session, HttpServletRequest request); + + List getAllChapter(String levelName,String subject); + + List getAllSection(String levelName,String chapter,String subject); + + List splitExam(String examName, String subject); + + List findExamQuestionInfo(String examName, String subject,String studentNumber,String openid,String gradeLevel); + + DoQuestionInfoDTO judgeQuestionRight(int id, String studentNumber, String openid, String commitString, String paperName, String subject, int sourcePaperId,String gradeLevel,String doTime); + +// UserCollect insertCollect(int id, String studentNumber, String openid, String classification,String commitString); + UserCollect insertCollect(int id, String studentNumber, String openid, String classification); + + DoQuestionInfoDTO getDoQuestionInfo(String studentNumber, String examName, String subject, int sourcePaperId); + + List echoDoQuestionInfo(String studentNumber, String examName, String subject); + + UserCollect cancelCollect(int id,String studentNumber, String openid,String examName, String subject, int cancel); + + /** + * 十一、 用户整套试卷(也可以是一章中的一节题)的记录 + * @param studentNumber + * @param openid + * @param examName + * @param subject + * @param examPaperContent + * @param examPaperAnwer + * @return + */ + UserPaperRecord fullPaperRecord(String studentNumber,String openid,String examName,String subject,String examPaperContent,String examPaperAnwer); + + /** + * 十二、点击练习错题时,展现的章节名称和对应的错题数量 + * @param stuNumber + * @param openid + * @param subject + * @return + */ + JSONObject getChapterErrNumber(String stuNumber, String openid, String subject, String examCategory); + + /** + * 十三、用户回显此时卷所有信息 + * @param stuNumber + * @param openid + * @param subject + * @param examName + * @return + */ + List echoPaperInfo(String stuNumber, String openid, String subject, String examName); + + /** + * 十四、查询此题是否收藏过 + * @param id + * @return + */ + FindCollectDTO findCollectInfo(String stuNumber,String subject,int questionId); + + /** + * 十五、获取此章下面的所有节的名称和对应的错题数量,根据章的名称 + * @param stuNumber + * @param openid + * @param subject + * @param chapterName + * @return + */ + SectionErrNumberDTO getSectionErrNumber(String stuNumber,String openid,String subject,String chapterName,String ifMastered); + + // 十六、错题本:获取某类别所有未掌握题的所有情况 + JSONObject getNotMasteredInfo(String studentNumber,String openid,String subject,String examCategory,String gradeLevel, int master); + + // 十七、错题本中的 下面的分类详情 + JSONObject getClassification(String studentNumber,String openid,String subject,String examCategory,String gradeLevel, int master); + + // 十八、错题本:统计分类中 未掌握或已掌握的 各分类的数量 + JSONObject getClassificationQuantity(String studentNumber, String openid, String subject, String gradeLevel, int master); + //十九、错题表:获取 此题的所有信息 + JSONObject getQuestionInfo(int id,String stuNumber,String openid); + //二十、专项练习: 获取此年级、科目所有的知识点 + JSONObject getAllKnowledge(String studentNumber,String openid,String subject,String gradeLevel); + //二十一、专项练习: 专项练习:根据知识点获取所有相关的题 + JSONArray getAllQuestionByPoint(String studentNumber,String openid,String subject,String gradeLevel,String knowledgePoint); + + //二十二、 专项练习: 记录用户做某道题 到用户记录中 + JSONObject specialRecordId(int id, String studentNumber, String openid, String commitString, String examCategory,String subject,String gradeLevel,String doTime); + + //二十三、历年真题、模拟考试:获取此年级、科目的分類的各个考试名称和题数 + JSONObject getAllExamName(String studentNumber,String openid,String subject,String gradeLevel,String examCategory); + + //二十四、首页面中继续学习-仅章节练习 + JSONObject continueLearn(String studentNumber, String openid,String subject); + + JSONObject findCoiliInfo(String examName, String subject,String studentNumber,String openid,String gradeLevel); + + // 二十六、“我的收藏”:统计分类中 各分类的数量 + JSONObject getcollectClassifyQuantity(String studentNumber, String openid, String subject, String gradeLevel); + // 十六、错题本:获取某类别所有未掌握题的所有情况 + JSONObject getcollectMasteredInfo(String studentNumber,String openid,String subject,String examCategory,String gradeLevel); + + //二十八、“生物学号校验”:校验能做中关村生物的学生 + JSONObject checkStudentNumber(String studentNumber,String openid,String subject,String gradeLevel); +} diff --git a/src/main/java/com/zgczx/service/exam/ExamServiceImpl.java b/src/main/java/com/zgczx/service/exam/ExamServiceImpl.java new file mode 100644 index 0000000..6cc90cc --- /dev/null +++ b/src/main/java/com/zgczx/service/exam/ExamServiceImpl.java @@ -0,0 +1,2180 @@ +package com.zgczx.service.exam; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.google.gson.Gson; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.mapper.EUserQuestionRecordMapper; +import com.zgczx.repository.mysql1.exam.dao.*; +import com.zgczx.repository.mysql1.exam.dto.*; +import com.zgczx.repository.mysql1.exam.model.*; +import com.zgczx.repository.mysql3.unifiedlogin.dao.UserLoginDao; +import com.zgczx.repository.mysql3.unifiedlogin.model.UserLogin; +import com.zgczx.utils.SpecialCharactersUtil; +import com.zgczx.utils.StringToMapUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import java.io.IOException; +import java.sql.Timestamp; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static com.zgczx.utils.FilterStringUtil.*; +import static com.zgczx.utils.FilterStringUtil.filterspecial; + +import static com.zgczx.utils.RecursionTreeUtil.randomSort; +import static com.zgczx.utils.SpecialCharactersUtil.replaceThe8194; +import static com.zgczx.utils.WordRedUtil.readWord; + +/** + * @author aml + * @date 2019/12/11 15:48 + */ +@Service +@Slf4j +public class ExamServiceImpl implements ExamService { + + @Autowired + private ChapterDao chapterDao; + + @Autowired + private QuestionDao questionDao; + + @Autowired + private ExamPaperDao examPaperDao; + + @Autowired + private UserQuestionRecordDao userQuestionRecordDao; + + @Autowired + private UserCollectDao userCollectDao; + + @Autowired + private ExamContentDao examContentDao; + + @Autowired + private UserPaperRecordDao userPaperRecordDao; + + @Autowired + private UserLoginDao userLoginDao; + + @Autowired + private UserWrongQustionDao userWrongQustionDao; + + @Autowired + private UserCheckDao userCheckDao; + + @Autowired + private EUserQuestionRecordMapper eUserQuestionRecordMapper; + + private String info; + + @Override + public String parseWord(MultipartFile file, HttpSession session, HttpServletRequest request) { + String text = null; + try { + JSONObject docJson = readWord(file); + text = String.valueOf(docJson.get("doctext")); + String title = filterChineseAndMath(String.valueOf(docJson.get("title"))); + String imgList = String.valueOf(docJson.get("imgList")); + + +// 1. 将试卷读进去 + ExamContent examContent = new ExamContent(); + examContent.setContent(text); + examContent.setExamName(title); + examContent.setSubject("生物"); + ExamContent save = examContentDao.save(examContent); + String[] split = save.getContent().split("#");// + for (String string : split) { + + } +// // 2. 将答案读进去 +// ExamContent examContent = examContentDao.findOne(2); +// examContent.setAnswer(text); +// examContentDao.save(examContent); + System.out.println("打印text: " + text); + + } catch (IOException e) { + e.printStackTrace(); + } + return text; + } + + @Override + public List getAllChapter(String levelName, String subject) { + List name = chapterDao.findByLevelNameAndSubject(levelName, subject); + if (name == null || name.size() == 0) { + info = "暂时没有此年级的章目"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + return name; + } + + @Override + public List getAllSection(String levelName, String chapter, String subject) { + List name = chapterDao.findByLevelNameAndChapterAndSubject(levelName, chapter, subject); + if (name == null || name.size() == 0) { + info = "暂时没有此年级此章目的小节"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + log.info(String.valueOf(name)); + return name; + } + + @Transactional(propagation = Propagation.REQUIRED) + @Override + public List splitExam(String examName, String subject) { + ExamContent content = examContentDao.findByExamNameAndSubject(examName, subject); + String[] split = content.getContent().split("#"); + log.info("[split: ]{}", split); + + + ExamPaper examPaper = examPaperDao.findByExamNameAndSubjectAndValid(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String examContent = examPaper.getExamContent(); + + List stringList = new ArrayList<>(); + int i1 = examContent.indexOf("1."); + int i2 = examContent.indexOf("2."); + int i3 = examContent.indexOf("3."); + int i4 = examContent.indexOf("4."); + int i5 = examContent.indexOf("5."); + int i6 = examContent.indexOf("6."); + int i7 = examContent.indexOf("7."); + int i8 = examContent.indexOf("8."); + int i9 = examContent.indexOf("9."); + int i10 = examContent.indexOf("10."); + String str1 = examContent.substring(i1, i2); + String str2 = examContent.substring(i2, i3); + String str3 = examContent.substring(i3, i4); + String str4 = examContent.substring(i4, i5); + String str5 = examContent.substring(i5, i6); + String str6 = examContent.substring(i6, i7); + String str7 = examContent.substring(i7, i8); + String str8 = examContent.substring(i8, i9); + String str9 = examContent.substring(i9, i10); + String str10 = examContent.substring(i10, examContent.length()); + stringList.add(str1); + stringList.add(str2); + stringList.add(str3); + stringList.add(str4); + stringList.add(str5); + stringList.add(str6); + stringList.add(str7); + stringList.add(str8); + stringList.add(str9); + stringList.add(str10); + + for (int i = 0; i < stringList.size(); i++) { + Question question = new Question(); + String s = stringList.get(i); + question.setExamId(examPaper.getId()); + question.setQuestionSource("模拟考试"); + question.setExamName("3.1 细胞膜的结构和功能"); + question.setExamLocation("北京"); + question.setQuestionId(i + 1); + question.setQuestionType("单选"); + question.setQuestionDifficult("一般"); + question.setQuestionContext(s); + question.setQuestionAttribute("细胞膜的结构和功能"); + int a = s.indexOf("A"); + int b = s.indexOf("【答案】"); + int c = s.indexOf("【解析】"); + String option = s.substring(a, b); + String correctOption1 = s.substring(b, c);//此题的正确答案选项; + String correctOption = filterAlphabetCapital(correctOption1); + //切分所有选项 A-D,判断答案是哪个选项,然后存哪个选项的文本; + int b1 = s.indexOf("B"); + int c1 = s.indexOf("C"); + int d1 = s.indexOf("D"); + String contentA = s.substring(a, b1); + String contentB = s.substring(b1, c1); + String contentC = s.substring(c1, d1); + String contentD = s.substring(d1, b); + question.setQuestionOption(option);//题的选项 + question.setCorrectOption(correctOption);//题的正确答案选项 + question.setCorrectAnalysis(s.substring(c, s.length()));//答案的正确内容 + if (correctOption.trim().equals("A")) { + question.setCorrectText(contentA);//正确答案的文本 + } else if (correctOption.trim().equals("B")) { + question.setCorrectText(contentB); + } else if (correctOption.trim().equals("C")) { + question.setCorrectText(contentC); + } else { + question.setCorrectText(contentD); + } + question.setValid(1);//1:此数据有效 + Question save = questionDao.save(question); + } + List list = questionDao.findByExamName("3.1 细胞膜的结构和功能"); + List list1 = new ArrayList<>(); + for (Question question : list) { + list1.add(question.getId()); + } + examPaper.setQuestionList(String.valueOf(list1)); + ExamPaper save = examPaperDao.save(examPaper); + log.info("【试卷表的详细信息:】 {}", save); + return list; + } + + @Override + public List findExamQuestionInfo(String examName, String subject, String studentNumber, String openid,String gradeLevel) { + ExamPaper examPaper = examPaperDao.findByExamNameAndSubjectAndValidAndGradeLevel(examName, subject, 1,gradeLevel); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 去除[] 和 空格,或者从插库时处理,直接就存1,2,3... ;而不是存成[1, 2, 3...] + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + //System.out.println(idList); + } + List list = new ArrayList<>(); + + for (Integer integer : idList) { + QuestionDTO questionDTO = new QuestionDTO(); + Question one = questionDao.findOne(integer); + if (one == null){ + continue; + } + questionDTO.setQuestion(one); + //2.4 修改 图片为list + List imgList = new LinkedList<>();//2.4 新修改 + String questionImgs = one.getQuestionImgs(); + if (questionImgs == null){ +// imgList.add(); +// jsonObject.put("imgList",imgList); + questionDTO.setImgList(imgList); + } + else if (questionImgs.contains(",")){ + String[] split = questionImgs.split(","); + for (int i=0; i optionList = new LinkedList<>(); + List optionList1 = new LinkedList<>(); + List optionList2 = new LinkedList<>(); + + List> optionMapList = new LinkedList<>(); + Map map = new HashMap<>(); + + String oneQuestionOption = one.getQuestionOption();//获取所有选项的文本 +// String questionOption = filterspecial(oneQuestionOption);//过滤下\t,\n等字符 + String questionOption = null;//过滤下\t,\n等字符 + questionOption = filterspecial2(oneQuestionOption);//过滤下\t,\n等字符, 不过滤n + /* if (subject.equals("英语")){ + questionOption = filterspecial2(oneQuestionOption);//过滤下\t,\n等字符, 不过滤n + }else { + questionOption = filterspecial(oneQuestionOption);//过滤下\t,\n等字符 + }*/ + + log.info("【去除t,n等字符】: {}", questionOption); + int i1 = -1; + if (questionOption.indexOf("A.") != -1) { + i1 = questionOption.indexOf("A."); + } else { + i1 = questionOption.indexOf("A."); + } + int i2 = -1; + if (questionOption.indexOf("B.") != -1) { + i2 = questionOption.indexOf("B."); + } else { + i2 = questionOption.indexOf("B."); + } + int i3 = -1; + if (questionOption.indexOf("C.") != -1) { + i3 = questionOption.indexOf("C."); + } else if (questionOption.indexOf("C.") != -1){ + i3 = questionOption.indexOf("C."); + }else if (questionOption.indexOf("C.") != -1){ + i3 = questionOption.indexOf("C."); + } else { + i3 = questionOption.indexOf("C."); + } + int i4 = -1; + if (questionOption.indexOf("D.") != -1) { + i4 = questionOption.indexOf("D."); + } else if (questionOption.indexOf("D.") != -1){ + i3 = questionOption.indexOf("D."); + }else if (questionOption.indexOf("D.") != -1){ + i3 = questionOption.indexOf("D."); + }else { + i4 = questionOption.indexOf("D."); + } + List letterList = new ArrayList<>(); + letterList.add(i1); + letterList.add(i2); + letterList.add(i3); + letterList.add(i4); + +// String str1 = questionOption.substring(i1, i2);//A选项 +// String str2 = questionOption.substring(i2, i3);//B选项 +// String str3 = questionOption.substring(i3, i4);//C选项 +// String str4 = questionOption.substring(i4, questionOption.length());//D选项 + String str1 = questionOption.substring(i1 + 2, i2);//A选项 + String str2 = questionOption.substring(i2 + 2, i3);//B选项 + String str3 = questionOption.substring(i3 + 2, i4);//C选项 + String str4 = questionOption.substring(i4 + 2, questionOption.length());//D选项 + + optionList.add(str1); + optionList.add(str2); + optionList.add(str3); + optionList.add(str4); + + // 将选项内容做映射,请求全排列, + Map sortMap = new HashMap<>(); + + sortMap.put(1, str1); + sortMap.put(2, str2); + sortMap.put(3, str3); + sortMap.put(4, str4); + //这个是截取原选项中的ABCD.;可能有的是中文点 + /*optionList2.add(questionOption.substring(i1, i1 + 2)); + optionList2.add(questionOption.substring(i2, i2 + 2)); + optionList2.add(questionOption.substring(i3, i3 + 2)); + optionList2.add(questionOption.substring(i4, i4 + 2));*/ + //全部定死为 英文点 + optionList2.add("A."); + optionList2.add("B."); + optionList2.add("C."); + optionList2.add("D."); + int[] array = new int[]{1, 2, 3, 4}; + + boolean contains = questionOption.contains("E.");//判断选项中是否包含 D选项 + if (contains) { + int i5 = questionOption.indexOf("E."); + letterList.add(i5); + String str5 = questionOption.substring(i5 + 2, questionOption.length());//E选项 + optionList.add(str5); + sortMap.put(5, str5); +// optionList2.add(questionOption.substring(i5, i5 + 2)); + optionList2.add("E."); + array = new int[]{1, 2, 3, 4, 5}; + } +/* + 这里 是 实现 随机选项的 方案 2: 使用的是 全排列,随机性高,但是 递归过程慢,耗时长 + */ +// permute2(array,0);// 调用 全排列的递归函数 +// int random = (int) (Math.random() * (l.size() - 1) + 1); // 从递归得到的全排列中获取 任意的 一个结果 +// String s2 = filterMiddleBrackets(l.get(random)); +// String replace = s2.replace("\"", ""); +// String[] split = replace.split(","); +// for (int i = 0; i < split.length; i++){ +// String s3 = split[i]; +// int s4 = Integer.parseInt(s3.replaceAll("\"", "")); +// String s = sortMap.get(s4); +// String s1 = optionList2.get(i); +// optionList1.add(s1+s); +// } + +/* + 这里 是 实现 随机选项的 方案 1: 使用的是random,随机性不高 + */ + int[] ints = randomSort(array, 0);// 这个是随机函数,不是全排列函数 + for (int i = 0; i < ints.length; i++) { + String s = sortMap.get(ints[i]); + String s1 = optionList2.get(i); + optionList1.add(s1 + s); + //optionList1.add(sortMap.get(ints[i])); + } +// System.out.println(optionList1); + for (int i = 0; i < optionList1.size(); i++) { + /* int ponit = 0; + String trim = optionList1.get(i).trim(); + if (trim.indexOf(".") != -1){ + ponit = trim.indexOf("."); + }else { + ponit = trim.indexOf("."); + } + String answer =trim.substring(ponit+1,trim.length()).trim(); +// String answer = filterspecial2(optionLetter(optionList1.get(i))); +// String answer = optionLetter(optionList1.get(i)).trim(); + if (!answer.equals("") && (answer.substring(0,1).equals(" ")||answer.substring(0,1).equals(" "))){ + answer = answer.substring(1,answer.length()); + } + int len = answer.length(); + if (answer.substring(len-1,len).equals(" ")||answer.substring(len-1,len).equals(" ")){ + answer = answer.substring(0,len-1); + }*/ +// String userAnswer = optionLetter2(optionList1.get(i)); + String userAnswer = optionList1.get(i); + userAnswer = userAnswer.replace(' ',' '); + userAnswer = userAnswer.substring(2,userAnswer.length()).trim(); + + //optionLetter(optionList1.get(i)) + if (one.getCorrectText().replace(' ',' ').trim().equals(userAnswer)) { + String answerOption = optionList1.get(i).substring(0, 1).trim(); +// questionDTO.setRightOption(answerOption); + questionDTO.setRightOption(String.valueOf(i));//将返回的正确答案选项改为,索引方式 + } + } +//Collections.shuffle(list);//集合打乱顺序 +// questionDTO.setOption(optionList); + questionDTO.setRandomOption(optionList1); + + questionDTO.setSourcePaperId(examPaper.getId()); + + UserCollect userCollect = userCollectDao.getByStudentNumberAndSubjectAndExamPaperIdAndQuestionId(studentNumber, subject, examPaper.getId(), integer, 1); + if (userCollect != null) { + questionDTO.setCollect(1); + } else { + questionDTO.setCollect(2); + } + + list.add(questionDTO); + } + return list; + } + + @Transactional(propagation = Propagation.REQUIRED) + @Override + public synchronized DoQuestionInfoDTO judgeQuestionRight(int id, String studentNumber, String openid, String commitString, String examName, String subject, int sourcePaperId,String gradeLevel,String doTime) { + Question question = questionDao.getByIdAndValid(id,1); + if (question == null) { + info = "您所查询的此题不存在,请核对后再查"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 获取此试卷的所有信息 + ExamPaper paper = examPaperDao.findByExamNameAndSubjectAndValidAndGradeLevel(examName, subject, 1,gradeLevel); + String examSource = paper.getExamSource();// 获取试卷的类别,章节练习,模拟考试,历年真题等 + String paperExamName = paper.getExamName(); + String subjectName = questionDao.getSubjectName(id); +// String userAnswer = optionLetter2(commitString);//用户的答案,不过滤AT + commitString = filterspecial2(commitString);//过滤下\t,\n等字符, 不过滤n + String userAnswer =commitString; + userAnswer = userAnswer.replace(' ',' '); + userAnswer = userAnswer.substring(2,userAnswer.length()).trim(); + List repatQuestion = userQuestionRecordDao.getByStudentNumberAndExamPaperIdAndQuestionId2(studentNumber, sourcePaperId, id); + if (repatQuestion == null || repatQuestion.size() == 0) { + UserQuestionRecord userQuestionRecord = new UserQuestionRecord(); + + if (question.getCorrectText().replace(' ',' ').trim().equals(userAnswer)) { + userQuestionRecord.setDoRight(1); + } else { + userQuestionRecord.setDoRight(2); + } + userQuestionRecord.setUserAnswer(userAnswer); + userQuestionRecord.setSubject(subjectName); + userQuestionRecord.setStudentNumber(studentNumber); + userQuestionRecord.setOpenid(openid); + userQuestionRecord.setQuestionId(id); + userQuestionRecord.setExamPaperId(sourcePaperId);// 试卷id:(不是这道题是从哪个试卷中录入进去的)保存这道题被组卷在哪套试题中 + userQuestionRecord.setTimes(1); + userQuestionRecord.setExamPaperName(paperExamName); + userQuestionRecord.setExamCategory(examSource); + userQuestionRecord.setDoTime(doTime);//2.2 新增做题时间 + UserQuestionRecord save = userQuestionRecordDao.save(userQuestionRecord); + } else { + int times = repatQuestion.get(0).getTimes(); + int count = eUserQuestionRecordMapper.queryRecordInfo(studentNumber, paper.getId(), paper.getExamSource(), subject, times).size(); + int repatTime = 0; + if (count >= paper.getQuestionCount()) { + repatTime = times + 1; + } else { + repatTime = times; + } + + if (eUserQuestionRecordMapper.queryRecordAlready(studentNumber, paper.getId(), paper.getExamSource(), subject, repatTime, id) == null) { + UserQuestionRecord userQuestionRecord = new UserQuestionRecord(); + +// String userAnswer = optionLetter(commitString); + if (question.getCorrectText().replace(' ', ' ').trim().equals(userAnswer)) { + userQuestionRecord.setDoRight(1); + } else { + userQuestionRecord.setDoRight(2); + } + userQuestionRecord.setUserAnswer(userAnswer); + userQuestionRecord.setSubject(subjectName); + userQuestionRecord.setStudentNumber(studentNumber); + userQuestionRecord.setOpenid(openid); + userQuestionRecord.setQuestionId(id); + userQuestionRecord.setExamPaperId(sourcePaperId);// 试卷id:(不是这道题是从哪个试卷中录入进去的)保存这道题被组卷在哪套试题中 + userQuestionRecord.setTimes(repatTime); + userQuestionRecord.setExamPaperName(paperExamName); + userQuestionRecord.setExamCategory(examSource); + userQuestionRecord.setDoTime(doTime);//2.2 新增做题时间 + UserQuestionRecord save = userQuestionRecordDao.save(userQuestionRecord); + } + } + +// DoQuestionInfoDTO dto = getDto(studentNumber, examName, subject,sourcePaperId); + ExamPaper examPaper = examPaperDao.findOne(sourcePaperId); + //ExamPaper examPaper = examPaperDao.getBy(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 去除[] 和 空格,或者从插库时处理,直接就存1,2,3... ;而不是存成[1, 2, 3...] + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + // List repatQuestion = userQuestionRecordDao.getByStudentNumberAndExamPaperIdAndQuestionId(studentNumber, sourcePaperId, idList.get(0)); + int times = 1; + if (repatQuestion.size() > 0) { + times = repatQuestion.get(0).getTimes() + 1; + } + // 这一份试卷的 题的数量 + int questionCount = idList.size(); + // 获取某学生->某科目 -> 某试卷 --》 “某次” (最近一次)-->的所有做题记录; + List stulist = userQuestionRecordDao.getByStudentNumberAndSubjectAndExamPaperIdAndTimes(studentNumber, subject, examPaper.getId(), times); + int doRight = 0; + int doError = 0; + List doRightList = new ArrayList<>(); // 做对的题号 + List doErrorList = new ArrayList<>(); // 做错的题号 + List notDoList = new ArrayList<>(); + for (UserQuestionRecord questionRecord : stulist) { + if (questionRecord.getDoRight() == 1) { + if (!doRightList.contains(questionRecord.getQuestionId())) { + doRightList.add(questionRecord.getQuestionId()); + doRight++; + } + + } else { + if (!doErrorList.contains(questionRecord.getQuestionId())) { + doErrorList.add(questionRecord.getQuestionId()); + doError++; + } + } + } + int notDo = questionCount - doRight - doError; + for (int i = 1; i <= questionCount; i++) { + if (!doRightList.contains(i) && !doErrorList.contains(i)) { + notDoList.add(i); + } + } + log.info("【总共做题数量:】{}", questionCount); + log.info("【作对题的数量:】{}", doRight); + log.info("【作错题的数量:】{}", doError); + log.info("【未做题的数量:】{}", notDo); + + // 新增往错题表中插数据 + List repatQuestion2 = userQuestionRecordDao.getByStudentNumberAndExamPaperIdAndQuestionId2(studentNumber, sourcePaperId, id); + UserQuestionRecord questionRecord = repatQuestion2.get(0);// 获取刚插入的此题所有数据 + if (questionRecord.getDoRight() == 2) { + // 此题错误,判断此题的 相同来源是否 插入过库中 + UserWrongQustion userWrong = userWrongQustionDao.getByStudentNumberAndExamCategoryAndQuestionId(studentNumber, questionRecord.getExamCategory(), id, subject); + if (userWrong != null){ + System.out.println("错题表已经有此数据,不在存储!"); + } + +// if (userWrong == null) { + else { + //如果不存在,则插入 + UserWrongQustion wrongQustion = new UserWrongQustion(); + wrongQustion.setStudentNumber(studentNumber); + wrongQustion.setOpenid(openid); + wrongQustion.setSubject(subject); + wrongQustion.setDoRight(2); + wrongQustion.setQuestionId(id); + wrongQustion.setUserAnswer(userAnswer); + wrongQustion.setExamPaperId(sourcePaperId);// 试卷id:(不是这道题是从哪个试卷中录入进去的)保存这道题被组卷在哪套试题中 + wrongQustion.setExamPaperName(paperExamName); + wrongQustion.setExamCategory(examSource); + wrongQustion.setDoTime(doTime);//2.2 新增做题时间 + userWrongQustionDao.save(wrongQustion); + } + + + } + + //List dtoList = new ArrayList<>(); + DoQuestionInfoDTO dto = new DoQuestionInfoDTO(); + dto.setQuestionCount(questionCount); + dto.setDoRight(doRight); + dto.setDoError(doError); + dto.setNotDo(notDo); + dto.setDoRightList(doRightList); + dto.setDoErrorList(doErrorList); + dto.setNotDoList(notDoList); + + return dto; + } + + @Override + public UserCollect insertCollect(int id, String studentNumber, String openid, String classification) { + Question question = questionDao.findOne(id); + if (question == null) { + info = "您所查询的此题不存在,请核对后再查"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 科目名称 + String subjectName = questionDao.getSubject(id); + UserCollect collect = userCollectDao.findByStudentNumberAndQuestionId(studentNumber, id); + if (collect != null && collect.getValid() == 2) { + collect.setValid(1);// 将此题重新设置为收藏状态 + Timestamp date = new Timestamp(System.currentTimeMillis()); + collect.setUpdatetime(date); + UserCollect save = userCollectDao.save(collect); + return save; + } + if (collect == null) { +// String userAnswer = optionLetter(commitString); + UserCollect userCollect = new UserCollect(); + userCollect.setStudentNumber(studentNumber); + userCollect.setOpenid(openid); + userCollect.setSubject(subjectName); + userCollect.setExamPaperId(question.getExamId());// 收藏时,是针对题,如果这道题已经收藏过了,就不允许再次收藏 + userCollect.setQuestionId(id); + userCollect.setValid(1); +// userCollect.setUserAnswer(userAnswer); + userCollect.setClassification(classification); + + UserCollect save = userCollectDao.save(userCollect); + return save; + }else { + return collect; + } + } + // 3.29 此接口暂时无用 + @Override + public DoQuestionInfoDTO getDoQuestionInfo(String studentNumber, String examName, String subject, int sourcePaperId) { + DoQuestionInfoDTO dto = getDto(studentNumber, examName, subject, sourcePaperId); + return dto; + } + + + @Override + public List echoDoQuestionInfo(String studentNumber, String examName, String subject) { + ExamPaper examPaper = examPaperDao.getBy(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + List echolist = userQuestionRecordDao.getByStudentNumberAndSubjectAndExamPaperId(studentNumber, subject, examPaper.getId()); + if (echolist == null || echolist.size() == 0) { + info = "您还未做过此试卷,暂无记录"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 调用公共函数 2,获取questionList + List questionList = questionList(examPaper.getQuestionList()); + + List echoDoQuestionDTOList = new ArrayList<>(); + + int times = echolist.get(0).getTimes(); + for (UserQuestionRecord questionRecord : echolist) { + if (questionRecord.getTimes() == times) { + EchoDoQuestionDTO echoDoQuestionDTO = new EchoDoQuestionDTO(); + // 题号 + int questionNo = questionList.indexOf(questionRecord.getQuestionId()) + 1; + echoDoQuestionDTO.setQuestionNo(questionNo); + // 题填写的文本 + echoDoQuestionDTO.setQuestionNoText(questionRecord.getUserAnswer()); + echoDoQuestionDTOList.add(echoDoQuestionDTO); + } + + } + return echoDoQuestionDTOList; + } + + + @Override + public UserCollect cancelCollect(int id, String studentNumber, String openid, String examName, String subject, int cancel) { + if (examName.equals("")){ + //错题本中的情况,无法传此题的试卷名称,可能此题是多个分类的情况下 + UserCollect userCollect = userCollectDao.getByStudentNumberAndSubjectAndQuestionId(studentNumber, subject, id); + if (userCollect == null) { + info = "您此题还未收藏过,暂无法取消收藏"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + userCollect.setValid(cancel); + UserCollect save = userCollectDao.save(userCollect); + return save; + } + ExamPaper examPaper = examPaperDao.getBy(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 模拟考试和历年真题 其他模块下已经存入此题了,因此不需要传入 试卷名称 + if (examPaper.getExamSource().equals("模拟考试") || examPaper.getExamSource().equals("历年真题")){ + UserCollect userCollect = userCollectDao.getByStudentNumberAndSubjectAndQuestionId(studentNumber, subject, id); + if (userCollect == null) { + info = "您此题还未收藏过,暂无法取消收藏"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + userCollect.setValid(cancel); + UserCollect save = userCollectDao.save(userCollect); + return save; + } + UserCollect userCollect = userCollectDao.getByStudentNumberAndSubjectAndExamPaperIdAndQuestionId(studentNumber, subject, examPaper.getId(), id, 1); + if (userCollect == null) { + info = "您此题还未收藏过,暂无法取消收藏"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + userCollect.setValid(cancel); + UserCollect save = userCollectDao.save(userCollect); + return save; + } + + @Override + public UserPaperRecord fullPaperRecord(String studentNumber, String openid, String examName, String subject, String examPaperContent, String examPaperAnwer) { + ExamPaper examPaper = examPaperDao.getBy(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + if (examPaperContent.equals("[]")||examPaperAnwer.equals("{}")){ + info = "本次试卷记录为空,不存本次"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + List paperRecordlist = userPaperRecordDao.getByStudentNumberAndSubjectAndExamPaperId(studentNumber, subject, examPaper.getId()); + int times = 1; + if (paperRecordlist.size() == 0) { + UserPaperRecord userPaperRecord = new UserPaperRecord(); + userPaperRecord.setStudentNumber(studentNumber); + userPaperRecord.setOpenid(openid); + userPaperRecord.setExamPaperId(examPaper.getId()); + userPaperRecord.setSubject(subject); + userPaperRecord.setExamPaperContent(examPaperContent); + userPaperRecord.setExamPaperAnwer(examPaperAnwer); + userPaperRecord.setTimes(times); + + UserPaperRecord save = userPaperRecordDao.save(userPaperRecord); + return save; + } else { + int times1 = paperRecordlist.get(0).getTimes() + 1; + UserPaperRecord userPaperRecord = new UserPaperRecord(); + userPaperRecord.setStudentNumber(studentNumber); + userPaperRecord.setOpenid(openid); + userPaperRecord.setExamPaperId(examPaper.getId()); + userPaperRecord.setSubject(subject); + userPaperRecord.setExamPaperContent(examPaperContent); + userPaperRecord.setExamPaperAnwer(examPaperAnwer); + userPaperRecord.setTimes(times1); + + UserPaperRecord save = userPaperRecordDao.save(userPaperRecord); + return save; + } + + } + + @Override + public JSONObject getChapterErrNumber(String stuNumber, String openid, String subject, String examCategory) { + + + JSONObject json = new JSONObject(); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } +// String gradeLevel = userInfo.getGradeLevel();//此用户的年级水平,例如高1 + + Map getNotMasteredErrorNum = new LinkedHashMap<>(); + Map getMasteredErrorNum = new LinkedHashMap<>(); + if (examCategory.equals("1")) { + + String levelName = "高1"; + + // 得到该学科所有的章节 + List getChaptersBySubject = chapterDao.findChapterBySubject(subject, levelName); + if (getChaptersBySubject == null || getChaptersBySubject.size() == 0) { + info = "暂时没有该学科对应的章节信息"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < getChaptersBySubject.size(); i++) { + String chapter = getChaptersBySubject.get(i); + // 章练习未掌握错题数 + int getNotMasteredErrorNumByChapter = userWrongQustionDao.getErrorNumByChapter(stuNumber, subject, chapter, 2); + if (getNotMasteredErrorNumByChapter != 0) { + getNotMasteredErrorNum.put(chapter, getNotMasteredErrorNumByChapter); + } + // 章练习已掌握错题数 + int getMasteredErrorNumByChapter = userWrongQustionDao.getErrorNumByChapter(stuNumber, subject, chapter, 1); + if (getMasteredErrorNumByChapter != 0) { + getMasteredErrorNum.put(chapter, getMasteredErrorNumByChapter); + } + } + } + } else if (examCategory.equals("2")) { + // 得到该学科所有的章节 + List getExamName = examPaperDao.getExamName(); + if (getExamName == null || getExamName.size() == 0) { + info = "暂时没有考试题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < getExamName.size(); i++) { + String examName = getExamName.get(i); + // 考试未掌握错题数 + int getNotMasteredErrorNumByExam = userWrongQustionDao.getErrorNumByExam(stuNumber, subject, examName, 2); + if (getNotMasteredErrorNumByExam != 0) { + getNotMasteredErrorNum.put(examName, getNotMasteredErrorNumByExam); + } + + // 考试已掌握错题数 + int getMasteredErrorNumByExam = userWrongQustionDao.getErrorNumByExam(stuNumber, subject, examName, 1); + if (getMasteredErrorNumByExam != 0) { + getMasteredErrorNum.put(examName, getMasteredErrorNumByExam); + } + } + } + } + json.put("notMastered", getNotMasteredErrorNum); + json.put("mastered", getMasteredErrorNum); + return json; + +// Map chapterErrNumMap = new HashMap<>(); +// List chapterSectionList = new ArrayList<>();//章-节 list +// Map chapterSectionMap = new HashMap<>();//章-节 map +// Map sectionErrNumMap = new HashMap<>();// 节-错题数量 map +// String examCategory1 = null; +// String examCategory2 = null; +// if (examCategory.equals("1")){ +// examCategory1 = "章节练习"; +// examCategory2 = "专项练习"; +// }else { +// examCategory1 = "模拟考试"; +// examCategory2 = "历年真题"; +// } +// +// //1. 先 获取此用户-》此科目-》章节练习中 所有错题 试卷名称(每节的名称) +//// List paperName = userQuestionRecordDao.getAllErrInfo(stuNumber, subject, 2, "章节练习"); +// List paperName = userWrongQustionDao.getAllErrInfo(stuNumber, subject, 2, examCategory1,examCategory2); +// if (paperName.size() == 0) { +// info = "您所做的章节练习中还没错题"; +// ChapterErrNumberDTO chapterErrNumberDTO = new ChapterErrNumberDTO(); +// chapterErrNumberDTO.setGradeLevel(gradeLevel); +// chapterErrNumberDTO.setChapterNumber(null); +// return chapterErrNumberDTO; +// } else { +// //2. 根据所有 节的名称 获取所有章的名称 +// List chapterNameList = chapterDao.findBySectionIn(paperName); +// for (String chapterName : chapterNameList){ +// //3. 获取所有节的名称,根据章名称和科目 +// List sectionList = chapterDao.findByChapterAndSubject(chapterName, subject); +// for (String section: sectionList){ +// System.out.println(section); +// //4. 获取此节的 错题数量 +// int errNumber = userWrongQustionDao.getByErrNumber(stuNumber, subject, section); +// chapterSectionList.add(chapterName+","+section); +// chapterSectionMap.put(chapterName,section); +// sectionErrNumMap.put(section,errNumber); +// } +// } +// +// log.info("【chapterSectionMap】{}",chapterSectionMap); +// log.info("【sectionErrNumMap】{}",sectionErrNumMap); +// log.info("【chapterSectionList】{}",chapterSectionList); +// } +// ChapterErrNumberDTO chapterErrNumberDTO = new ChapterErrNumberDTO(); +// for (String string : chapterSectionList){ +// int i = string.indexOf(","); +// String chapterName = string.substring(0, i); +// String sectionName = string.substring(i + 1, string.length()); +// Integer integer = sectionErrNumMap.get(sectionName); +// if (chapterErrNumMap.containsKey(chapterName)){ +// Integer integer1 = chapterErrNumMap.get(chapterName); +// integer += integer1; +// chapterErrNumMap.put(chapterName,integer); +// } +// chapterErrNumMap.put(chapterName,integer); +// } +// chapterErrNumberDTO.setGradeLevel(gradeLevel); +// chapterErrNumberDTO.setChapterNumber(chapterErrNumMap); +// log.info("【chapterErrNumMap】{}",chapterErrNumMap); +// +// return chapterErrNumberDTO; + + + + /* //获取 此用户有错题的 所有试卷id + List examPaperIdList = userQuestionRecordDao.getAllExamPaperId(stuNumber, subject); + if (examPaperIdList.size() == 0){ + info = "您所做的练习中还没错题"; + ChapterErrNumberDTO chapterErrNumberDTO = new ChapterErrNumberDTO(); + chapterErrNumberDTO.setGradeLevel(gradeLevel); + chapterErrNumberDTO.setChapterNumber(null); + return chapterErrNumberDTO; + }else { + // 获取试卷的 exam_source试卷来源名称: 例如:模拟考试;历年真题;章节练习;专项练习等 + List examPaperList = examPaperDao.findByIdIn(examPaperIdList); + for (ExamPaper examPaper : examPaperList){ + if (examPaper.getExamSource().equals("章节练习")){ + + } + int id = examPaper.getId(); + String examName = examPaper.getExamName(); // + + } + + }*/ + + + } + + @Override + public List echoPaperInfo(String stuNumber, String openid, String subject, String examName) { + ExamPaper examPaper = examPaperDao.getBy(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + List paperRecordList = userPaperRecordDao.getByStudentNumberAndSubjectAndExamPaperId(stuNumber, subject, examPaper.getId()); + if (paperRecordList.size() == 0) { + info = "您还没做过此时卷,因此暂无保存进度"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.NEVER_DID_THIS_PAPER, info); + + } else { + String examPaperContent1 = paperRecordList.get(0).getExamPaperContent(); + + String examPaperContent = examPaperContent1.replaceAll("\\{\"question\":", ""); + String s1 = filter1(examPaperContent); + String s2 = filter2(s1); + String b = s2.replaceAll("(\",\"B)", "B"); + String c = b.replaceAll("(\",\"C)", "C"); + String d = c.replaceAll("(\",\"D)", "D"); +// Map map = new HashMap(); +// map = gson.fromJson(text, map.getClass()); + List echoPaperDTOList = JSON.parseObject(d, new TypeReference>() { + }); + + //处理 用户的所有选项 + String paperAnwer = paperRecordList.get(0).getExamPaperAnwer(); + StringToMapUtil stringToMapUtil = new StringToMapUtil(); + Map map = stringToMapUtil.stringToMap(paperAnwer); + log.info("【map: 】{}", map); + EchoPaperCompleteDTO completeDTO = new EchoPaperCompleteDTO(); +// for (String value : map.values()){ +// if (value.equals("")){ +// completeDTO.setEffective(2);//此时卷没做完 +// break; +// } +// completeDTO.setEffective(1);//此试卷已经做完 +// } + + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().equals("")) { + completeDTO.setEffective(2);//此时卷没做完 + completeDTO.setFirstNoDoneNum(entry.getKey()); + break; + } + completeDTO.setFirstNoDoneNum(String.valueOf(map.entrySet().size())); + completeDTO.setEffective(1);//此试卷已经做完 + } + + int complete = 1;// 默认此题为 已经做完此时卷 + List completeDTOList = new ArrayList<>(); + List list = new ArrayList<>(); + + for (int i = 0; i < echoPaperDTOList.size(); i++) { + EchoPaperTotalDTO paperTotalDTO = new EchoPaperTotalDTO(); + String o = String.valueOf(map.get(String.valueOf(i))); + if (o.equals("")) { + complete = 2; + paperTotalDTO.setComplete(2); + paperTotalDTO.setUserOption(""); + } else { + paperTotalDTO.setUserOption(String.valueOf(o)); + paperTotalDTO.setComplete(1); + } + EchoPaperDTO paperDTO = echoPaperDTOList.get(i); + paperTotalDTO.setQuestion(paperDTO); + //将 选项的字符文本,封装为linkedlist按顺序添加 + //List list1 = stringTurnList(paperDTO.getRandomOption()); + List list1 = stringTurnList2(paperDTO.getRandomOption()); + paperTotalDTO.setRandomOption(list1); + +// paperTotalDTO.setComplete(complete); + // 此题是否已经收藏过,如果userCollect存在,则此题收藏了 + UserCollect userCollect = userCollectDao.getByStudentNumberAndSubjectAndExamPaperIdAndQuestionId(stuNumber, subject, examPaper.getId(), paperDTO.getId(), 1); + if (userCollect == null) { + paperTotalDTO.setCollect(2); + } else { + paperTotalDTO.setCollect(1); + } + + // 设置 rightOption + paperTotalDTO.setRightOption(paperDTO.getRightOption()); + //设置 sourcePaperId + paperTotalDTO.setSourcePaperId(paperDTO.getSourcePaperId()); + list.add(paperTotalDTO); + completeDTO.setList(list); + + //2.4 修改 图片为list + List imgList = new LinkedList<>();//2.4 新修改 + String questionImgs = paperDTO.getQuestionImgs(); + if (questionImgs == null){ + paperTotalDTO.setImgList(imgList); + } + else if (questionImgs.contains(",")){ + String[] split = questionImgs.split(","); + for (int j=0; j sectionList = chapterDao.findByChapterAndSubject(chapterName, subject); + if (sectionList.size() == 0) { + info = "暂无您要查询的小节名称"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + Map sectionErrNumMap = new LinkedHashMap<>(); + SectionErrNumberDTO sectionErrNumberDTO = new SectionErrNumberDTO(); + for (String section : sectionList) { + System.out.println(section); + if (ifMastered.equals("未掌握")) { + //4. 获取此节的 错题数量(未掌握) + int errNumber = userWrongQustionDao.getByErrNumber(stuNumber, subject, section, 2); + if (errNumber == 0) { + continue; + } + sectionErrNumMap.put(section, errNumber); + } else if (ifMastered.equals("已掌握")) { + //4. 获取此节的 错题数量(已掌握) + int errNumber = userWrongQustionDao.getByErrNumber(stuNumber, subject, section, 1); + if (errNumber == 0) { + continue; + } + sectionErrNumMap.put(section, errNumber); + } + } + sectionErrNumberDTO.setSectionNumber(sectionErrNumMap); + return sectionErrNumberDTO; + } + + @Override + public JSONObject getNotMasteredInfo(String studentNumber, String openid, String subject, String examCategory, String gradeLevel, int master) { + JSONObject json = new JSONObject(); + JSONArray jsonArray = new JSONArray();// 提的所有详情 + if (!examCategory.equals("全部")) { + List wrongQustions = null; + if (examCategory.equals("专项练习")){ + wrongQustions = userWrongQustionDao.getAllInfo2(studentNumber, gradeLevel, subject, master, examCategory);//去重qustion_id + }else { + wrongQustions = userWrongQustionDao.getAllInfo(studentNumber, gradeLevel, subject, master, examCategory);//去重qustion_id + } + if (wrongQustions.size() == 0) { + info = "暂无您要查询的未掌握题情况"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (UserWrongQustion wrongQustion : wrongQustions) { + JSONObject jsonObject1 = new JSONObject();// 分装Json + int questionId = wrongQustion.getQuestionId();// question表的id + //此题的分类标签,可能有多个 + List questionSource = userWrongQustionDao.getallQuestionSource(studentNumber, gradeLevel, subject, master, questionId); + Question question = questionDao.getByIdAndValid(questionId, 1);// 获取此题的所有数据 + String questionContext = question.getQuestionContext(); + String titleContent = filterTitleNumber(questionContext);// 题目内容 + jsonObject1.put("titleContent", titleContent); + List labelList = new LinkedList<>();// 此题的标签属 + String questionAttribute = question.getQuestionAttribute();// 此题的知识点属性 + //labelList.add(wrongQustion.getExamCategory());// 分类标签: 章节还是 专项等 + for (String s : questionSource) { + labelList.add(s); + } + if (questionAttribute.contains(",")) { + String[] split = questionAttribute.split(","); + for (int i = 0; i < split.length; i++) { + String s = split[i]; + if (s.equals("")){ + continue; + } + labelList.add(s); + } + } else { +// labelList.add(questionAttribute); + if (!questionAttribute.equals("")){ + labelList.add(questionAttribute); + } + } + jsonObject1.put("labelList", labelList);// 题的标签 + jsonObject1.put("question", question);// 此题的所有情况 + jsonArray.add(jsonObject1); + json.put("questionInfo", jsonArray); + } + } + } else { + // 获取全部的题,不重复的形式 + List wrongQustions = userWrongQustionDao.getAllByQuestion(studentNumber, gradeLevel, subject, master);//去重qustion_id + if (wrongQustions.size() == 0) { + info = "暂无您要查询的未掌握题情况"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (UserWrongQustion wrongQustion : wrongQustions) { + JSONObject jsonObject1 = new JSONObject();// 分装Json + int questionId = wrongQustion.getQuestionId(); + //此题的分类标签,可能有多个 + List questionSource = userWrongQustionDao.getallQuestionSource(studentNumber, gradeLevel, subject, master, questionId); + Question question = questionDao.getByIdAndValid(questionId, 1);// 获取此题的所有数据 + String questionContext = question.getQuestionContext(); + String titleContent = filterTitleNumber(questionContext);// 题目内容 + jsonObject1.put("titleContent", titleContent); + List labelList = new LinkedList<>();// 此题的标签属 + String questionAttribute = question.getQuestionAttribute();// 此题的知识点属性 + //labelList.add(wrongQustion.getExamCategory());// 分类标签: 章节还是 专项等 + for (String s : questionSource) { + labelList.add(s); + } + if (questionAttribute.contains(",")) { + String[] split = questionAttribute.split(","); + for (int i = 0; i < split.length; i++) { +// labelList.add(split[i]); + String s = split[i]; + if (s.equals("")){ + continue; + } + labelList.add(s); + } + } else { + if (!questionAttribute.equals("")){ + labelList.add(questionAttribute); + } + + } + jsonObject1.put("labelList", labelList);// 题的标签 + jsonObject1.put("question", question);// 此题的所有情况 + jsonArray.add(jsonObject1); + json.put("questionInfo", jsonArray); + } + } + } + return json; + } + + @Override + public JSONObject getClassification(String studentNumber, String openid, String subject, String examCategory, String gradeLevel, int master) { + JSONArray jsonArray1 = new JSONArray();// 分类详情 + JSONObject jsonObject = new JSONObject(); + //分类详情 + if (examCategory.equals("章节练习")) { + //获取掌握或未掌握的 节的名称 + List sectionName = userWrongQustionDao.getSectionName(studentNumber, gradeLevel, subject, master, examCategory); + if (sectionName.size() == 0) { + info = "您章节练习模块中未有错题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + Map> map = new HashMap<>(); + Map sectionInfoMap = new HashMap<>();//k:节的名称、v:错题的数量 + Map chapterMap = new HashMap<>();//k:章的名称、v:错题的数量 + for (String section : sectionName) { + // 根据节的获取章的名称 + List chapterName = chapterDao.findBySection(section); + String chapter = chapterName.get(0); + int chapterNum = userWrongQustionDao.getErrorNumByChapter(studentNumber, subject, chapter, master); + chapterMap.put(chapter, chapterNum); + int number = userWrongQustionDao.getByErrNumber(studentNumber, subject, section, master); + sectionInfoMap.put(section, number); + + map.put(chapter, sectionInfoMap); + log.info("【map: 】{}", map); + } +// jsonArray1.add(map); + jsonObject.put("info", map);//分类详情 + List wrongQustions = userWrongQustionDao.getAllInfo(studentNumber, gradeLevel, subject, master, examCategory); + jsonObject.put("totalNum", wrongQustions.size()); + return jsonObject; + } else if (examCategory.equals("专项练习")) { + //1. 列出所有错题的知识点属性 + List questionLabelList = userWrongQustionDao.getQuestionAttribute(studentNumber, gradeLevel, subject, master, examCategory); + if (questionLabelList.size() == 0) { + info = "您专项练习模块中未有错题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + List labelList = new ArrayList<>();// 错题的所有属性 + for (String questionAttribute : questionLabelList) { + if (questionAttribute.contains(",")) { + String[] split = questionAttribute.split(","); + for (int i = 0; i < split.length; i++) { + if (labelList.contains(split[i])) { + continue; + } + labelList.add(split[i]); + } + } else { + if (labelList.contains(questionAttribute)){ + continue; + } + labelList.add(questionAttribute); + } + } + log.info("【labelList:】{}",labelList); + Map map = new HashMap<>(); + for (String string : labelList){ + int questionAttributeNum = userWrongQustionDao.getQuestionAttributeNum(studentNumber, gradeLevel, subject, master, examCategory, string); + map.put(string,questionAttributeNum); + } + jsonObject.put("info", map);//分类详情 + List wrongQustions = userWrongQustionDao.getAllChapterInfo(studentNumber, gradeLevel, subject, master, examCategory); + jsonObject.put("totalNum", wrongQustions.size()); + return jsonObject; + }else if (examCategory.equals("全部")){ + List userWrongQustions = userWrongQustionDao.totalNum(studentNumber, subject, gradeLevel, master); + if (userWrongQustions.size() == 0) { + info = "您曾未有错题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + jsonObject.put("totalNum", userWrongQustions.size()); + return jsonObject; + }else { + // 历年真题和 模拟考试 + //1. 先获取所有错题或正确题的 去重后的名称,放到list中 + List examPaperNameList = userWrongQustionDao.getExamPaperName(studentNumber, gradeLevel, subject, master, examCategory); + if (examPaperNameList.size() == 0) { + info = "您专项考试模块中未有错题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + //2. 遍历list然后查询有多少道错题,放到map中 + Map map = new HashMap<>(); + for (String examName : examPaperNameList){ + int examNameNum = userWrongQustionDao.getgetExamPaperNameNum(studentNumber, gradeLevel, subject, master, examName); + map.put(examName,examNameNum); + } + jsonObject.put("info", map);//分类详情 + int totalExamPaperNum = userWrongQustionDao.getTotalExamPaperNum(studentNumber, gradeLevel, subject, master, examCategory); + jsonObject.put("totalNum", totalExamPaperNum); + + } + return jsonObject; + } + + @Override + public JSONObject getClassificationQuantity(String studentNumber, String openid, String subject, String gradeLevel, int master) { + JSONObject jsonObject = new JSONObject(); + // 获取 全部的 已掌握或未掌握的 数量 + List userWrongQustions = userWrongQustionDao.totalNum(studentNumber, subject, gradeLevel, master); + jsonObject.put("totalNum", userWrongQustions.size()); + // 章节练习 数量 + List wrongQustions = userWrongQustionDao.getAllInfo(studentNumber, gradeLevel, subject, master, "章节练习"); + jsonObject.put("chapterNum", wrongQustions.size()); + //专项练习 数量 + List wrongQustions2 = userWrongQustionDao.getAllChapterInfo(studentNumber, gradeLevel, subject, master, "专项练习"); + jsonObject.put("specialNum", wrongQustions2.size()); + //模拟考试 数量 + int totalExamPaperNum = userWrongQustionDao.getTotalExamPaperNum(studentNumber, gradeLevel, subject, master, "模拟考试"); + jsonObject.put("mockNum", totalExamPaperNum); + // 历年真题 数量 + int totalExamPaperNum2 = userWrongQustionDao.getTotalExamPaperNum(studentNumber, gradeLevel, subject, master, "历年真题"); + jsonObject.put("truthNum", totalExamPaperNum2); + + return jsonObject; + } + + + @Override + public JSONObject getQuestionInfo(int id, String stuNumber, String openid) { + JSONObject jsonObject = new JSONObject(); + Question question = questionDao.getByIdAndValid(id, 1); + if (question == null){ + info = "您专项考试模块中未有错题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + jsonObject.put("question",question); + List optionList = new LinkedList<>();// 此题选项的list + String oneQuestionOption = question.getQuestionOption();//获取所有选项的文本 + String questionOption = null;//过滤下\t,\n等字符 + if (question.getSubject().equals("英语")){ + questionOption = filterspecial2(oneQuestionOption);//过滤下\t,\n等字符, 不过滤n + }else { + questionOption = filterspecial(oneQuestionOption);//过滤下\t,\n等字符 + } + + log.info("【去除t,n等字符】: {}", questionOption); + int i1 = -1; + if (questionOption.indexOf("A.") != -1) { + i1 = questionOption.indexOf("A."); + } else { + i1 = questionOption.indexOf("A."); + } + int i2 = -1; + if (questionOption.indexOf("B.") != -1) { + i2 = questionOption.indexOf("B."); + } else { + i2 = questionOption.indexOf("B."); + } + int i3 = -1; + if (questionOption.indexOf("C.") != -1) { + i3 = questionOption.indexOf("C."); + } else { + i3 = questionOption.indexOf("C."); + } + int i4 = -1; + if (questionOption.indexOf("D.") != -1) { + i4 = questionOption.indexOf("D."); + } else { + i4 = questionOption.indexOf("D."); + } + List letterList = new ArrayList<>(); + letterList.add(i1); + letterList.add(i2); + letterList.add(i3); + letterList.add(i4); + String str1 = questionOption.substring(i1+2, i2);//A选项 + String str2 = questionOption.substring(i2+2 , i3);//B选项 + String str3 = questionOption.substring(i3+2 , i4);//C选项 + String str4 = questionOption.substring(i4+2 , questionOption.length());//D选项 + optionList.add("A."+str1); + optionList.add("B."+str2); + optionList.add("C."+str3); + optionList.add("D."+str4); + jsonObject.put("optionList",optionList); + List imgList = new LinkedList<>(); + String questionImgs = question.getQuestionImgs(); + if (questionImgs == null){ +// imgList.add(); + jsonObject.put("imgList",imgList); + } + else if (questionImgs.contains(",")){ + String[] split = questionImgs.split(","); + for (int i=0; i idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + List repatQuestion = userQuestionRecordDao.getByStudentNumberAndExamPaperIdAndQuestionId(studentNumber, sourcePaperId, idList.get(0)); + int times = 1; + if (repatQuestion != null || repatQuestion.size() > 0) { + times = repatQuestion.get(0).getTimes(); + } + // 这一份试卷的 题的数量 + int questionCount = idList.size(); + // 获取某学生->某科目 -> 某试卷 --》 “某次” (最近一次)-->的所有做题记录; + List stulist = userQuestionRecordDao.getByStudentNumberAndSubjectAndExamPaperIdAndTimes(studentNumber, subject, examPaper.getId(), times); + int doRight = 0; + int doError = 0; + List doRightList = new ArrayList<>(); // 做对的题号 + List doErrorList = new ArrayList<>(); // 做错的题号 + List notDoList = new ArrayList<>(); + for (UserQuestionRecord questionRecord : stulist) { + if (questionRecord.getDoRight() == 1) { + if (!doRightList.contains(questionRecord.getQuestionId())) { + doRightList.add(questionRecord.getQuestionId()); + doRight++; + } + + } else { + if (!doErrorList.contains(questionRecord.getQuestionId())) { + doErrorList.add(questionRecord.getQuestionId()); + doError++; + } + + } + } + int notDo = questionCount - doRight - doError; + for (int i = 1; i <= questionCount; i++) { + if (!doRightList.contains(i) && !doErrorList.contains(i)) { + notDoList.add(i); + } + } + log.info("【总共做题数量:】{}", questionCount); + log.info("【作对题的数量:】{}", doRight); + log.info("【作错题的数量:】{}", doError); + log.info("【未做题的数量:】{}", notDo); + + //List dtoList = new ArrayList<>(); + DoQuestionInfoDTO dto = new DoQuestionInfoDTO(); + dto.setQuestionCount(questionCount); + dto.setDoRight(doRight); + dto.setDoError(doError); + dto.setNotDo(notDo); + dto.setDoRightList(doRightList); + dto.setDoErrorList(doErrorList); + dto.setNotDoList(notDoList); + return dto; + } + + /** + * 公共函数 2 + * 将一份试卷中的 question_list 转换为 list 数组: 用来获取此试卷的题号 + * 这个 抽取为公共函数 + */ + public static List questionList(String questionListString) { + String[] questionList = filterMiddleBrackets(questionListString).split(","); + + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + //System.out.println(idList); + } + return idList; + } + + /** + * 公共函数 3 + * A.较大的稳定性B.选择透性C.一定的流动性D.运输物质的功能 + * 将 上述字符串 切分然后放到list中 + */ + public static List stringTurnList(String string) { + List list = new LinkedList<>(); + int i1 = string.indexOf("A."); + int i2 = string.indexOf("B."); + int i3 = string.indexOf("C."); + int i4 = string.indexOf("D."); + + String str1 = string.substring(i1, i2);//A选项 + String str2 = string.substring(i2, i3);//B选项 + String str3 = string.substring(i3, i4);//C选项 + String str4 = string.substring(i4, string.length());//D选项 + list.add(str1); + list.add(str2); + list.add(str3); + list.add(str4); + + return list; + } + + /** + * 公共函数 4 将中文的. 改为 英文的. + * A.较大的稳定性B.选择透性C.一定的流动性D.运输物质的功能 + * 将 上述字符串 切分然后放到list中 + */ + public static List stringTurnList2(String string) { + List list = new LinkedList<>(); + int i1 = -1; + if (string.indexOf("A.") != -1) { + i1 = string.indexOf("A."); + } else { + i1 = string.indexOf("A."); + } + int i2 = -1; + if (string.indexOf("B.") != -1) { + i2 = string.indexOf("B."); + } else { + i2 = string.indexOf("B."); + } + int i3 = -1; + if (string.indexOf("C.") != -1) { + i3 = string.indexOf("C."); + } else { + i3 = string.indexOf("C."); + } + int i4 = -1; + if (string.indexOf("D.") != -1) { + i4 = string.indexOf("D."); + } else { + i4 = string.indexOf("D."); + } + + String str1 = "A." + string.substring(i1 + 2, i2);//A选项 + String str2 = "B." + string.substring(i2 + 2, i3);//B选项 + String str3 = "C." + string.substring(i3 + 2, i4);//C选项 + String str4 = "D." + string.substring(i4 + 2, string.length());//D选项 + list.add(str1); + list.add(str2); + list.add(str3); + list.add(str4); + + return list; + } + + + @Override + public JSONObject getAllKnowledge(String studentNumber, String openid, String subject, String gradeLevel) { + JSONObject jsonObject = new JSONObject(); + // 查询所有知识点 + List questionAttributes = questionDao.getQUestionAttribute(subject, gradeLevel); + if (questionAttributes.size() == 0) { + info = "该年级、该科目中暂时没有知识点"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + List attributesList = new ArrayList<>(); + attributesList.add("全部"); + for (int j = 0; j < questionAttributes.size(); j++) { + // 得到知识点 + String questionAttribute = questionAttributes.get(j); + if (questionAttribute.contains(",")) { + String[] attributeArr = questionAttribute.split(","); + for (int k = 0; k < attributeArr.length; k++) { + String attribute = attributeArr[k]; + if (!(attributesList.contains(attribute))) { + attributesList.add(attribute); + } + } + } else { + if (!(attributesList.contains(questionAttribute))) { + attributesList.add(questionAttribute); + } + } + } + jsonObject.put("attributesList", attributesList); + return jsonObject; + } + } + + @Override + public JSONArray getAllQuestionByPoint(String studentNumber, String openid, String subject, String gradeLevel, String knowledgePoint) { +// JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + if (!knowledgePoint.equals("全部")) { + List questions = questionDao.getAllSubjectAndLevelNameByQuestionAndAttribute(subject, gradeLevel, knowledgePoint); + if (questions.size() == 0) { + info = "该年级、该科目中暂时没有该知识点的题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + List questionTitleList = new ArrayList<>();// 用户去除 题目相同的题 + for (Question question : questions) { + JSONObject jsonObject1 = new JSONObject(); + String questionContext = question.getQuestionContext(); + String titleContent = filterTitleNumber(questionContext);// 题目内容 + if (questionTitleList.contains(titleContent)){ + continue; + } + questionTitleList.add(titleContent);// 加入list中 + jsonObject1.put("question", question); + jsonObject1.put("titleContent", titleContent); + List labelList = new LinkedList<>();// 此题的标签属 + String questionAttribute = question.getQuestionAttribute();// 此题的知识点属性 + if (questionAttribute.contains(",")) { + String[] split = questionAttribute.split(","); + for (int i = 0; i < split.length; i++) { + String s = split[i]; + if (s.equals("")) { + continue; + } + labelList.add(s); + } + } else { +// labelList.add(questionAttribute); + if (!questionAttribute.equals("")){ + labelList.add(questionAttribute); + } + } + jsonObject1.put("labelList", labelList);// 题的标签 + jsonArray.add(jsonObject1); + } + return jsonArray; + } + }else { + // 默认 显示 全部的情况 + List questions = questionDao.getAllSubjectAndLevelName(subject, gradeLevel); + if (questions.size() == 0){ + info = "该年级、该科目中暂时没有题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + List questionTitleList = new ArrayList<>();// 用户去除 题目相同的题 + for (Question question : questions){ + JSONObject jsonObject1 = new JSONObject(); + String questionContext = question.getQuestionContext(); + String titleContent = filterTitleNumber(questionContext);// 题目内容 + if (questionTitleList.contains(titleContent)){ + continue; + } + questionTitleList.add(titleContent);// 加入list中 + jsonObject1.put("question", question); + jsonObject1.put("titleContent", titleContent); + List labelList = new LinkedList<>();// 此题的标签属 + String questionAttribute = question.getQuestionAttribute();// 此题的知识点属性 + if (questionAttribute.contains(",")) { + String[] split = questionAttribute.split(","); + for (int i = 0; i < split.length; i++) { + String s = split[i]; + if (s.equals("")){ + continue; + } + labelList.add(s); + } + } else { +// labelList.add(questionAttribute); + if (!questionAttribute.equals("")){ + labelList.add(questionAttribute); + } + } + jsonObject1.put("labelList", labelList);// 题的标签 + jsonArray.add(jsonObject1); + } + return jsonArray; + } + } + + @Transactional(propagation = Propagation.REQUIRED) + @Override + public synchronized JSONObject specialRecordId(int id, String studentNumber, String openid, String commitString, String examCategory,String subject, String gradeLevel, String doTime) { + JSONObject jsonObject = new JSONObject(); + Question question = questionDao.getByIdAndValid(id, 1); + if (question == null) { + info = "您所查询的此题不存在,请核对后再查"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + commitString = replaceThe8194(commitString).trim(); + String userAnswer = commitString.substring(2,commitString.length());//用户的答案 + List repatQuestion = userQuestionRecordDao.getSpecialRecord(studentNumber, examCategory, id, subject); + ExamPaper paper = examPaperDao.findByIdAndValid(question.getExamId(), 1); + UserQuestionRecord save = null; + if (repatQuestion == null || repatQuestion.size() == 0) { + UserQuestionRecord userQuestionRecord = new UserQuestionRecord(); + if (replaceThe8194(question.getCorrectText()).trim().equals(userAnswer)) { + userQuestionRecord.setDoRight(1); + } else { + userQuestionRecord.setDoRight(2); + } + userQuestionRecord.setUserAnswer(userAnswer); + userQuestionRecord.setSubject(subject); + userQuestionRecord.setStudentNumber(studentNumber); + userQuestionRecord.setOpenid(openid); + userQuestionRecord.setQuestionId(id); + //2.27 新增情况:录题时只录入专项练习,也就是按照知识点录题, + userQuestionRecord.setExamPaperId(question.getExamId()); + if (paper.getExamSource().equals("专项练习")){ + userQuestionRecord.setExamPaperName(paper.getExamName()); + } +// userQuestionRecord.setExamPaperId(sourcePaperId);// 试卷id:(不是这道题是从哪个试卷中录入进去的)保存这道题被组卷在哪套试题中 + userQuestionRecord.setTimes(1); + userQuestionRecord.setExamCategory(examCategory); + userQuestionRecord.setDoTime(doTime);//2.2 新增做题时间 + save = userQuestionRecordDao.save(userQuestionRecord); + } else { + int times = repatQuestion.get(0).getTimes(); + int repatTime = times + 1; + + UserQuestionRecord userQuestionRecord = new UserQuestionRecord(); + + if (replaceThe8194(question.getCorrectText()).trim().equals(userAnswer)) { + userQuestionRecord.setDoRight(1); + } else { + userQuestionRecord.setDoRight(2); + } + userQuestionRecord.setUserAnswer(userAnswer); + userQuestionRecord.setSubject(subject); + userQuestionRecord.setStudentNumber(studentNumber); + userQuestionRecord.setOpenid(openid); + userQuestionRecord.setQuestionId(id); + //2.27 新增情况:录题时只录入专项练习,也就是按照知识点录题, + userQuestionRecord.setExamPaperId(question.getExamId()); +// userQuestionRecord.setExamPaperId(sourcePaperId);// 试卷id:(不是这道题是从哪个试卷中录入进去的)保存这道题被组卷在哪套试题中 + userQuestionRecord.setTimes(repatTime); + if (paper.getExamSource().equals("专项练习")) { + userQuestionRecord.setExamPaperName(paper.getExamName()); + } + userQuestionRecord.setExamCategory(examCategory); + userQuestionRecord.setDoTime(doTime);//2.2 新增做题时间 + save = userQuestionRecordDao.save(userQuestionRecord); + } + // 新增往错题表中插数据 + List repatQuestion2 = userQuestionRecordDao.getSpecialRecord(studentNumber, examCategory, id, subject); + UserQuestionRecord questionRecord = repatQuestion2.get(0);// 获取刚插入的此题所有数据 + if (questionRecord.getDoRight() == 2) { + // 此题错误,判断此题的 相同来源是否 插入过库中 + UserWrongQustion userWrong = userWrongQustionDao.getByStudentNumberAndExamCategoryAndQuestionId(studentNumber, questionRecord.getExamCategory(), id, subject); + if (userWrong != null){ + System.out.println("错题表已经有此数据,不在存储!"); + } +// if (userWrong == null) { + else { + //如果不存在,则插入 + UserWrongQustion wrongQustion = new UserWrongQustion(); + wrongQustion.setStudentNumber(studentNumber); + wrongQustion.setOpenid(openid); + wrongQustion.setSubject(subject); + wrongQustion.setDoRight(2); + wrongQustion.setQuestionId(id); + wrongQustion.setUserAnswer(userAnswer); + //2.27 新增情况:录题时只录入专项练习,也就是按照知识点录题, + wrongQustion.setExamPaperId(question.getExamId()); +// wrongQustion.setExamPaperId(sourcePaperId);// 试卷id:(不是这道题是从哪个试卷中录入进去的)保存这道题被组卷在哪套试题中 + if (paper.getExamSource().equals("专项练习")) { + wrongQustion.setExamPaperName(paper.getExamName()); + } + wrongQustion.setExamCategory(examCategory); + wrongQustion.setDoTime(doTime);//2.2 新增做题时间 + userWrongQustionDao.save(wrongQustion); + } + } + jsonObject.put("save", save); + return jsonObject; + } + + @Override + public JSONObject getAllExamName(String studentNumber, String openid, String subject, String gradeLevel,String examCategory) { + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray1 = new JSONArray(); + JSONArray jsonArray2 = new JSONArray(); + JSONArray jsonArray3 = new JSONArray(); + //1. 获取模拟题的 所有数据 + List mockExam = examPaperDao.getAllBySubjectAndGradeLevelAndExamSource(subject, gradeLevel, examCategory, "%期中%", "%期末%"); + if (mockExam.size() > 0){ + for (ExamPaper examPaper : mockExam){ + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("name",examPaper.getExamName()); + // 去除[] 和 空格,或者从插库时处理,直接就存1,2,3... ;而不是存成[1, 2, 3...] + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + jsonObject1.put("count",idList.size()); + jsonObject1.put("difficult",examPaper.getDifficult()); + jsonObject1.put("totalScore",examPaper.getExamScore()); + jsonArray1.add(jsonObject1); + } + } + //2. 获取所有 期中考试的 数据 + List midtermList = examPaperDao.getAllBySubjectAndGradeLevelAndExamSource2(subject, gradeLevel, examCategory, "%期中%"); + if (midtermList.size() > 0){ + for (ExamPaper examPaper : midtermList){ + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("name",examPaper.getExamName()); + // 去除[] 和 空格,或者从插库时处理,直接就存1,2,3... ;而不是存成[1, 2, 3...] + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + jsonObject1.put("count",idList.size()); + jsonObject1.put("difficult",examPaper.getDifficult()); + jsonObject1.put("totalScore",examPaper.getExamScore()); + jsonArray2.add(jsonObject1); + } + } +//2. 获取所有 期中考试的 数据 + List finalExam = examPaperDao.getAllBySubjectAndGradeLevelAndExamSource2(subject, gradeLevel, examCategory, "%期末%"); + if (finalExam.size() > 0){ + for (ExamPaper examPaper : finalExam){ + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("name",examPaper.getExamName()); + // 去除[] 和 空格,或者从插库时处理,直接就存1,2,3... ;而不是存成[1, 2, 3...] + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + jsonObject1.put("count",idList.size()); + jsonObject1.put("difficult",examPaper.getDifficult()); + jsonObject1.put("totalScore",examPaper.getExamScore()); + jsonArray3.add(jsonObject1); + } + } + jsonObject.put("mockExam",jsonArray1);//模拟题 + jsonObject.put("midterm",jsonArray2);//期中模拟题 + jsonObject.put("finalExam",jsonArray3);//期末模拟题 + return jsonObject; + } + + @Override + public JSONObject continueLearn(String studentNumber, String openid, String subject) { + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + List echolist = userQuestionRecordDao.getByStudentNumberAndSubjectAndExamPaperId2(studentNumber, subject); + if (echolist == null || echolist.size() == 0) { + info = "您还未做过此试卷,暂无记录"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 调用公共函数 2,获取questionList + ExamPaper one = examPaperDao.findOne(echolist.get(0).getExamPaperId()); + List questionList = questionList(one.getQuestionList()); + List chapter = chapterDao.findBySection(echolist.get(0).getExamPaperName());//章的名称 + int times = echolist.get(0).getTimes(); + for (UserQuestionRecord questionRecord : echolist) { + if (questionRecord.getTimes() == times) { + JSONObject jsonObject1 = new JSONObject(); + // 题号 + int questionNo = questionList.indexOf(questionRecord.getQuestionId()) + 1; + jsonObject1.put("questionNo", questionNo); + // 题填写的文本 + + jsonObject1.put("questionNoText",questionRecord.getUserAnswer()); + jsonArray.add(jsonObject1); + + } + + } + jsonObject.put("examPaperName",chapter.get(0)); + jsonObject.put("sectionName",echolist.get(0).getExamPaperName()); + jsonObject.put("info",jsonArray); + return jsonObject; + } + + @Override + public JSONObject findCoiliInfo(String examName, String subject, String studentNumber, String openid, String gradeLevel) { + JSONObject jsonObject1 = new JSONObject(); + ExamPaper examPaper = examPaperDao.findByExamNameAndSubjectAndValidAndGradeLevel(examName, subject, 1,gradeLevel); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + // 去除[] 和 空格,或者从插库时处理,直接就存1,2,3... ;而不是存成[1, 2, 3...] + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + + JSONArray jsonArray = new JSONArray(); + for (Integer integer : idList) { + + JSONObject jsonObject = new JSONObject(); + Question one = questionDao.findOne(integer); + if (one == null){ + continue; + } + + jsonObject.put("question", one); + + //2.4 修改 图片为list + List imgList = new LinkedList<>();//2.4 新修改 + String questionImgs = one.getQuestionImgs(); + if (questionImgs == null){ +// imgList.add(); + jsonObject.put("imgList",imgList); + + } + else if (questionImgs.contains(",")){ + String[] split = questionImgs.split(","); + for (int i=0; i userWrongQustions = userCollectDao.totalNum(studentNumber, subject, gradeLevel); + jsonObject.put("totalNum", userWrongQustions.size()); + // 章节练习 数量 + List wrongQustions = userCollectDao.getAllInfo(studentNumber, gradeLevel, subject, "章节练习"); + jsonObject.put("chapterNum", wrongQustions.size()); + //专项练习 数量 + List wrongQustions2 = userCollectDao.getAllInfo(studentNumber, gradeLevel, subject, "专项练习"); + jsonObject.put("specialNum", wrongQustions2.size()); + //模拟考试 数量 + List totalExamPaperNum = userCollectDao.getAllInfo(studentNumber, gradeLevel, subject, "模拟考试"); + jsonObject.put("mockNum", totalExamPaperNum.size()); + // 历年真题 数量 + List totalExamPaperNum2 =userCollectDao.getAllInfo(studentNumber, gradeLevel, subject, "历年真题"); + jsonObject.put("truthNum", totalExamPaperNum2.size()); + + return jsonObject; + } + + @Override + public JSONObject getcollectMasteredInfo(String studentNumber, String openid, String subject, String examCategory, String gradeLevel) { + JSONObject json = new JSONObject(); + JSONArray jsonArray = new JSONArray();// 提的所有详情 + if (!examCategory.equals("全部")) { + List wrongQustions = null; + + wrongQustions = userCollectDao.getAllInfo(studentNumber, gradeLevel, subject, examCategory);//去重qustion_id + + if (wrongQustions.size() == 0) { + info = "暂无您要查询的未掌握题情况"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (UserCollect wrongQustion : wrongQustions) { + JSONObject jsonObject1 = new JSONObject();// 分装Json + int questionId = wrongQustion.getQuestionId();// question表的id + //此题的分类标签,可能有多个 + // List questionSource = userWrongQustionDao.getallQuestionSource(studentNumber, gradeLevel, subject, master, questionId); + List examAllInfo = examPaperDao.getBySubjectAndGradeLevelAndValid(subject, gradeLevel, 1); + List labelList = new LinkedList<>();// 此题的标签属 + for (ExamPaper examPaper : examAllInfo){ + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + boolean existence = existence(questionId, idList); + String examSource = examPaper.getExamSource(); + if (existence && !labelList.contains(examSource) && !examSource.equals("专项练习")){ + labelList.add(examSource); + } + } + Question question = questionDao.getByIdAndValid(questionId, 1);// 获取此题的所有数据 + String questionContext = question.getQuestionContext(); + String titleContent = filterTitleNumber(questionContext);// 题目内容 + jsonObject1.put("titleContent", titleContent); + + String questionAttribute = question.getQuestionAttribute();// 此题的知识点属性 + if (questionAttribute.contains(",")) { + String[] split = questionAttribute.split(","); + for (int i = 0; i < split.length; i++) { + String s = split[i]; + if (s.equals("")){ + continue; + } + labelList.add(s); + } + } else { +// labelList.add(questionAttribute); + if (!questionAttribute.equals("")){ + labelList.add(questionAttribute); + } + } + jsonObject1.put("labelList", labelList);// 题的标签 + jsonObject1.put("question", question);// 此题的所有情况 + jsonArray.add(jsonObject1); + json.put("questionInfo", jsonArray); + } + } + } else { + // 获取全部的题,不重复的形式 + List wrongQustions = userCollectDao.getAllByFull(studentNumber, gradeLevel, subject);//去重qustion_id + if (wrongQustions.size() == 0) { + info = "暂无您要查询的未掌握题情况"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (UserCollect wrongQustion : wrongQustions) { + JSONObject jsonObject1 = new JSONObject();// 分装Json + int questionId = wrongQustion.getQuestionId(); + //此题的分类标签,可能有多个 +// List questionSource = userWrongQustionDao.getallQuestionSource(studentNumber, gradeLevel, subject, master, questionId); + List examAllInfo = examPaperDao.getBySubjectAndGradeLevelAndValid(subject, gradeLevel, 1); + List labelList = new LinkedList<>();// 此题的标签属 + for (ExamPaper examPaper : examAllInfo){ + String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); + List idList = new ArrayList<>(); + for (int i = 0; i < questionList.length; i++) { + int integer = Integer.parseInt(questionList[i]); + idList.add(integer); + } + boolean existence = existence(questionId, idList); + String examSource = examPaper.getExamSource(); + if (existence && !labelList.contains(examSource) && !examSource.equals("专项练习")){ + labelList.add(examSource); + } + } + Question question = questionDao.getByIdAndValid(questionId, 1);// 获取此题的所有数据 + String questionContext = question.getQuestionContext(); + String titleContent = filterTitleNumber(questionContext);// 题目内容 + jsonObject1.put("titleContent", titleContent); + + String questionAttribute = question.getQuestionAttribute();// 此题的知识点属性 + //labelList.add(wrongQustion.getExamCategory());// 分类标签: 章节还是 专项等 + + if (questionAttribute.contains(",")) { + String[] split = questionAttribute.split(","); + for (int i = 0; i < split.length; i++) { +// labelList.add(split[i]); + String s = split[i]; + if (s.equals("")){ + continue; + } + labelList.add(s); + } + } else { + if (!questionAttribute.equals("")){ + labelList.add(questionAttribute); + } + + } + jsonObject1.put("labelList", labelList);// 题的标签 + jsonObject1.put("question", question);// 此题的所有情况 + jsonArray.add(jsonObject1); + json.put("questionInfo", jsonArray); + } + } + } + return json; + } + + + /** + * 公共函数五、 判断此题是否在某套试卷中 + * @param questionid 题 + * @param qiestionList 某个试卷的 所有题列表 + * @return + */ + public static boolean existence(int questionid,List qiestionList) { + if (qiestionList.indexOf(questionid) != -1){ + return true; + }else { + return false; + } + } + + @Override + public JSONObject checkStudentNumber(String studentNumber, String openid, String subject, String gradeLevel) { + JSONObject jsonObject = new JSONObject(); + UserCheck userCheck = userCheckDao.findByStudent_number(studentNumber); + if (userCheck == null){ + info = "您暂无做此生物题的权限,请联系管理员进行审核添加"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + jsonObject.put("userCheck", userCheck); + return jsonObject; + } +} + diff --git a/src/main/java/com/zgczx/service/exam/ExamTwoService.java b/src/main/java/com/zgczx/service/exam/ExamTwoService.java new file mode 100644 index 0000000..5a591fe --- /dev/null +++ b/src/main/java/com/zgczx/service/exam/ExamTwoService.java @@ -0,0 +1,70 @@ +package com.zgczx.service.exam; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import java.util.Map; + +/** +* @author lxj +* @data 2019/12/30 +* */ +public interface ExamTwoService { + + // 1. 我的错题中:总错题数、章节错题数、考试错题数 + public Map getErrorProblemsNum(String stuNumber, String openid, String subject); + + // 2. 我的收藏:总收藏数、章节收藏数、考试收藏数 + public Map getCollectProblemsNum(String stuNumber, String openid, String subject); + + // 3. 我的收藏:默认选择练习题收藏(每一章及收藏的题数),选择考试题收藏时,显示对应的考试名称和收藏题数 + public Map getCollectProblemsNum(String stuNumber, String openid, String subject, String category); + + // 4. 点开章,根据章的名称获取 节的名称和对应收藏的题数 + public Map getCollectProblemsNumByChapter(String studentNumber,String openid,String subject, String chapter); + + // 5. 根据章节名称查询收藏的题的详细信息 lxj + public JSONArray getSectionCollectProblems(String stuNumber, String openid, String subject, String chapter, String section); + + // 6. 根据考试名称查询收藏的题的详细信息 lxj + public JSONArray getExamCollectProblems(String stuNumber,String openid,String subject,String examName); + + // 7. 七、 练习错题:点击章、节显示 此小节错题的详细信息 lxj + public JSONArray getErrorProblemsByChapterAndSection(String stuNumber, String openid, String subject, String chapter, String section,String ifMastered); + + // 8. 八、 考试错题:点击某次考试,显示本次考试错题的详细信息 lxj + public JSONArray getErrorProblemsByExamName(String stuNumber, String openid, String subject, String examName,String ifMastered); + + // 9. 九、 删除已掌握错题中的某道题 lxj + public Map deleteMasteredQuestions(String stuNumber,String openid,String subject,int questionId,String questionSource); + + // 10. 十、 做错题中未掌握的题,正确进入已掌握 lxj + public Map doNotMasteredQuestions(String stuNumber,String openid,String subject,int questionId,String questionSource,String userAnswer,int examPaperId,String examPaperName); + + // 11. 十一、 专项练习:知识点中统计每章的题数 lxj + public Map getQuestionsByChapterAndSubject(String subject,String levelName); + + // 12. 十二、 专项练习:知识点中每章下所有知识点及对应的题数 lxj + public Map getQuestionsNumsByAttribute(String subject, String levelName, String chapter); + + // 13. 十三、 专项练习:根据章名称 和知识点查看题的详细信息 lxj + public JSONArray getQuestionsByQuestionsAttribute(String stuNumber, String openid, String subject,String levelName, String chapter,String attribute); + + // 14. 十四、 根据学科和年级统计用户做题记录 + public JSONArray getDoQUestionRecord(String stuNumber,String openid,String subject,String levelName,String starTime,String endTime); + + // 15. 十五、 做题记录中关于某一份试卷/章节/知识点做题详情(做题时间、题难易度等) + public JSONArray getDoQuestionRecordDetail(String stuNumber,String openid,String subject,String levelName,String examName,String source); + + // 16. 十六、 学习记录中:统计做题数 + public JSONArray getDoQuestionsCount(String stuNumber,String openid,String subject,String levelName); + + // 17. 十七、 学习记录:统计错题和收藏总数 + public Map getWrongCollectQuestionsCount(String stuNumber,String openid,String subject,String levelName); + + // 18. 十八、 学习记录:按天统计做题正确率和做题时长 + public JSONArray getRightRateAndClassHours(String stuNumber,String openid,String subject,String levelName); + + // 19. 十九、 学习记录:上面三个数的统计 + public JSONObject getPracticeRecord(String stuNumber, String openid, String subject, String levelName); +} diff --git a/src/main/java/com/zgczx/service/exam/ExamTwoServiceImpl.java b/src/main/java/com/zgczx/service/exam/ExamTwoServiceImpl.java new file mode 100644 index 0000000..cdfe9a8 --- /dev/null +++ b/src/main/java/com/zgczx/service/exam/ExamTwoServiceImpl.java @@ -0,0 +1,1691 @@ +package com.zgczx.service.exam; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONException; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonArray; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.repository.mysql1.exam.dao.*; +import com.zgczx.repository.mysql1.exam.model.ExamPaper; +import com.zgczx.repository.mysql1.exam.model.Question; +import com.zgczx.repository.mysql1.exam.model.UserQuestionRecord; +import com.zgczx.repository.mysql1.exam.model.UserWrongQustion; +import com.zgczx.repository.mysql3.unifiedlogin.dao.UserLoginDao; +import com.zgczx.repository.mysql3.unifiedlogin.model.UserLogin; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +import static com.zgczx.utils.FilterStringUtil.filterspecial; +import static com.zgczx.utils.FilterStringUtil.optionLetter; +import static com.zgczx.utils.RecursionTreeUtil.randomSort; + +/** + * @author lxj + * @date 2019/12/30 + */ +@Service +@Slf4j +public class ExamTwoServiceImpl implements ExamTwoService { + + @Autowired + UserLoginDao userLoginDao; + + @Autowired + UserCollectDao userCollectDao; + + @Autowired + ChapterDao chapterDao; + + @Autowired + ExamPaperDao examPaperDao; + + @Autowired + QuestionDao questionDao; + + @Autowired + UserWrongQustionDao userWrongQustionDao; + + @Autowired + UserQuestionRecordDao userQuestionRecordDao; + + private String info; + + // 1. 我的错题中:总错题数、章节错题数、考试错题数 lxj + @Override + public Map getErrorProblemsNum(String stuNumber, String openid, String subject) { + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + Map errorProblemsNumMap = new LinkedHashMap<>(); + +// // 统计章节练习错题数(未掌握的) +// int chapterNotMasteredErrorProblemsNum=userWrongQustionDao.getChapterErrProblemsNum(stuNumber,subject); +// errorProblemsNumMap.put("chapterNotMasteredErrorProblemsNum",chapterNotMasteredErrorProblemsNum); +// +// // 统计考试错题数(未掌握的) +// int examNotMasteredErrorProblemsNum=userWrongQustionDao.getExamErrorProblemsNum(stuNumber,subject); +// errorProblemsNumMap.put("examNotMasteredErrorProblemsNum",examNotMasteredErrorProblemsNum); + + // 统计未掌握错题总数 + int notMasteredErrorProblemsNum = userWrongQustionDao.getNotMasteredErrorProblemsNum(stuNumber, subject); + errorProblemsNumMap.put("notMasteredErrorProblemsNum", notMasteredErrorProblemsNum); + +// // 练习错题数(已掌握的) +// int chapterMasteredErrorProblemsNum=userWrongQustionDao.getChapterErrProblemsNum2(stuNumber,subject); +// errorProblemsNumMap.put("chapterMasteredErrorProblemsNum",chapterMasteredErrorProblemsNum); +// +// // 考试错题数(已掌握的) +// int examMasteredErrorProblemsNum=userWrongQustionDao.getExamErrorProblemsNum2(stuNumber,subject); +// errorProblemsNumMap.put("examMasteredErrorProblemsNum",examMasteredErrorProblemsNum); + + // 统计已掌握错题总数 + int masteredErrorProblemsNum = userWrongQustionDao.getMasteredErrorProblemsNum(stuNumber, subject); + errorProblemsNumMap.put("masteredErrorProblemsNum", masteredErrorProblemsNum); + + // 统计练习错题总数 + int practiceErrorNum = userWrongQustionDao.getPracticeErrorNum(stuNumber, subject); + errorProblemsNumMap.put("practiceErrorNum", practiceErrorNum); + + // 统计考试错题总数 + int examErrorNum = userWrongQustionDao.getExamErrorNum(stuNumber, subject); + errorProblemsNumMap.put("examErrorNum", examErrorNum); + + // 统计我的错题数(总数) + int errorProblemsNum = userWrongQustionDao.getErrorProblemsNumber(stuNumber, subject); + errorProblemsNumMap.put("myErrorProblemsNum", errorProblemsNum); + + return errorProblemsNumMap; + + } + + // 2. 我的收藏:收藏总题数、收藏练习题数、收藏考试题数 lxj + @Override + public Map getCollectProblemsNum(String stuNumber, String openid, String subject) { + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + Map collectProblemsNumMap = new LinkedHashMap<>(); + // 统计我的错题数 + int errorProblemsNum = userCollectDao.getCollectProblemsNum(stuNumber, subject); + collectProblemsNumMap.put("myCollectProblemsNum", errorProblemsNum); + + // 统计章节练习错题数 + int chapterAndSectionsErrorProblemsNum = userCollectDao.getCollectChapterProblemsNum(stuNumber, subject); + collectProblemsNumMap.put("chapterCollectProblemsNum", chapterAndSectionsErrorProblemsNum); + + // 统计考试错题数 + int examErrorProblemsNum = userCollectDao.getCollectExamProblemsNum(stuNumber, subject); + collectProblemsNumMap.put("examCollectProblemsNum", examErrorProblemsNum); + + return collectProblemsNumMap; + } + + // 3. 我的收藏:默认选择练习题收藏(每一章及收藏的题数),选择考试题收藏时,显示对应的考试名称和收藏题数 lxj + @Override + public Map getCollectProblemsNum(String stuNumber, String openid, String subject, String category) { + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + Map getCollectNum = new LinkedHashMap<>(); + if (category.equals("练习题收藏")) { + + String levelName = "高1"; + + // 得到该学科所有的章节 + List getChaptersBySubject = chapterDao.findChapterBySubject(subject, levelName); + if (getChaptersBySubject == null || getChaptersBySubject.size() == 0) { + info = "暂时没有该学科对应的章节信息"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < getChaptersBySubject.size(); i++) { + String chapter = getChaptersBySubject.get(i); + // 练习题收藏 + int getChapterAndProblemCollectNums = userCollectDao.getCollectProblemsByChapter(stuNumber, subject, chapter); + if (getChapterAndProblemCollectNums != 0) { + getCollectNum.put(chapter, getChapterAndProblemCollectNums); + } + } + } + } else if (category.equals("考试题收藏")) { + // 得到该学科所有的章节 + List getExamName = examPaperDao.getExamName(); + if (getExamName == null || getExamName.size() == 0) { + info = "暂时没有考试题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < getExamName.size(); i++) { + String examName = getExamName.get(i); + // 练习题收藏 + int getExamAndProblemCollectNums = userCollectDao.getCollectProblemsByExam(stuNumber, subject, examName); + if (getExamAndProblemCollectNums != 0) { + getCollectNum.put(examName, getExamAndProblemCollectNums); + } + } + } + } + return getCollectNum; + } + + // 4. 点开章,根据章的名称获取 节的名称和对应收藏的题数 lxj + @Override + public Map getCollectProblemsNumByChapter(String studentNumber, String openid, String subject, String chapter) { + UserLogin userInfo = userLoginDao.findByDiyid(studentNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + Map getCollectProblemsNumBySectionMap = new LinkedHashMap<>(); + // 根据章的名称获取节的名称 + List sections = chapterDao.findByChapterAndSubject(chapter, subject); + if (sections == null || sections.size() == 0) { + info = "该章暂无小节信息"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < sections.size(); i++) { + String section = sections.get(i); + int getCollectProblemsNumBySection = userCollectDao.getCollectProblemsBySection(studentNumber, subject, section); + if (getCollectProblemsNumBySection != 0) { + getCollectProblemsNumBySectionMap.put(section, getCollectProblemsNumBySection); + } + } + } + + return getCollectProblemsNumBySectionMap; + } + + // 5. 根据章节名称查询收藏的题的详细信息 lxj + @Override + public JSONArray getSectionCollectProblems(String stuNumber, String openid, String subject, String chapter, String section) { + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + +// List sectionCollectQuestions=new ArrayList<>(); + // JSONObject sectionCollectQuestionsJson=new JSONObject(); + JSONArray sectionCollectQuestionsArr = new JSONArray(); + List sectionCollectProblems = questionDao.getSectionCollectProblems(stuNumber, subject, chapter, section); + if (sectionCollectProblems == null || sectionCollectProblems.size() == 0) { + info = "暂时没有收藏该章节的题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < sectionCollectProblems.size(); i++) { + JSONObject jo = new JSONObject(); +// Question questions=new Question(); + int id = sectionCollectProblems.get(i).getId(); + jo.put("id", id); + int exam_id = sectionCollectProblems.get(i).getExamId(); + jo.put("exam_id", exam_id); + String subjects = sectionCollectProblems.get(i).getSubject(); + jo.put("subject", subjects); + String question_source = sectionCollectProblems.get(i).getQuestionSource(); + jo.put("question_source", question_source); + String exam_name = sectionCollectProblems.get(i).getExamName(); + jo.put("exam_name", exam_name); + String exam_type = sectionCollectProblems.get(i).getExamType(); + jo.put("exam_type", exam_type); + String exam_location = sectionCollectProblems.get(i).getExamLocation(); + jo.put("exam_location", exam_location); + int question_id = sectionCollectProblems.get(i).getQuestionId(); + jo.put("question_id", question_id); + String question_type = sectionCollectProblems.get(i).getQuestionType(); + jo.put("question_type", question_type); + String question_difficult = sectionCollectProblems.get(i).getQuestionDifficult(); + jo.put("question_difficult", question_difficult); + String question_context = sectionCollectProblems.get(i).getQuestionContext(); + question_context = filterspecial(question_context); + jo.put("question_context", question_context); + String question_image = sectionCollectProblems.get(i).getQuestionImgs(); + jo.put("question_imgs", question_image); + String question_option = sectionCollectProblems.get(i).getQuestionOption(); + question_option = filterspecial(question_option); + question_option = question_option.replaceAll(" ", ""); + log.info("【去除t,n等字符】: {}", question_option); + int i1 = -1; + if (question_option.indexOf("A.") != -1) { + i1 = question_option.indexOf("A."); + } else { + i1 = question_option.indexOf("A."); + } + int i2 = -1; + if (question_option.indexOf("B.") != -1) { + i2 = question_option.indexOf("B."); + } else { + i2 = question_option.indexOf("B."); + } + int i3 = -1; + if (question_option.indexOf("C.") != -1) { + i3 = question_option.indexOf("C."); + } else { + i3 = question_option.indexOf("C."); + } + int i4 = -1; + if (question_option.indexOf("D.") != -1) { + i4 = question_option.indexOf("D."); + } else { + i4 = question_option.indexOf("D."); + } + + String str1 = question_option.substring(i1 + 2, i2);//A选项 + String str2 = question_option.substring(i2 + 2, i3);//B选项 + String str3 = question_option.substring(i3 + 2, i4);//C选项 + String str4 = question_option.substring(i4 + 2, question_option.length());//D选项 + List options = new ArrayList<>(); + options.add("A." + str1); + options.add("B." + str2); + options.add("C." + str3); + options.add("D." + str4); + jo.put("question_option", options); + String question_score = String.valueOf(sectionCollectProblems.get(i).getQuestionScore()); + jo.put("question_score", question_score); + String question_attribute = sectionCollectProblems.get(i).getQuestionAttribute(); + jo.put("question_attribute", question_attribute); + String correct_option = sectionCollectProblems.get(i).getCorrectOption(); + jo.put("correct_option", correct_option); + String correct_text = sectionCollectProblems.get(i).getCorrectText(); + jo.put("correct_text", correct_text); + String correct_analysis = sectionCollectProblems.get(i).getCorrectAnalysis(); + jo.put("correct_analysis", correct_analysis); + int chapter_id = sectionCollectProblems.get(i).getChapterId(); + jo.put("chapter_id", chapter_id); + String level = sectionCollectProblems.get(i).getLevel(); + jo.put("level", level); + String level_name = sectionCollectProblems.get(i).getLevelName(); + jo.put("level_name", level_name); + String creater_user = sectionCollectProblems.get(i).getCreateUser(); + jo.put("create_user", creater_user); + String knowledge_module = sectionCollectProblems.get(i).getKnowledgeModule(); + jo.put("knowledge_module", knowledge_module); + String cognitive_level = sectionCollectProblems.get(i).getCognitiveLevel(); + jo.put("cognitive_level", cognitive_level); + String core_literacy = sectionCollectProblems.get(i).getCoreLiteracy(); + jo.put("core_literacy", core_literacy); + int valid = sectionCollectProblems.get(i).getValid(); + jo.put("valid", valid); + Timestamp inserttime = sectionCollectProblems.get(i).getInserttime(); + jo.put("inserttime", inserttime); + Timestamp updatetime = sectionCollectProblems.get(i).getUpdatetime(); + jo.put("updatetime", updatetime); + + jo.put("ifCollect", 1); + + sectionCollectQuestionsArr.add(jo); + } + } + + return sectionCollectQuestionsArr; + } + + // 6. 根据考试名称查询收藏的题的详细信息 lxj + @Override + public JSONArray getExamCollectProblems(String stuNumber, String openid, String subject, String examName) { + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + // List examCollectQuestions=new ArrayList<>(); + JSONArray examCollectQuestionsArr = new JSONArray(); + List examCollectProblems = questionDao.getExamCollectProblems(stuNumber, subject, examName); + if (examCollectProblems == null || examCollectProblems.size() == 0) { + info = "暂时没有收藏这次考试的题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < examCollectProblems.size(); i++) { + JSONObject jo = new JSONObject(); + int id = examCollectProblems.get(i).getId(); + jo.put("id", id); + int exam_id = examCollectProblems.get(i).getExamId(); + jo.put("exam_id", exam_id); + String subjects = examCollectProblems.get(i).getSubject(); + jo.put("subject", subjects); + String question_source = examCollectProblems.get(i).getQuestionSource(); + jo.put("question_source", question_source); + String exam_name = examCollectProblems.get(i).getExamName(); + jo.put("exam_name", exam_name); + String exam_type = examCollectProblems.get(i).getExamType(); + jo.put("exam_type", exam_type); + String exam_location = examCollectProblems.get(i).getExamLocation(); + jo.put("exam_location", exam_location); + int question_id = examCollectProblems.get(i).getQuestionId(); + jo.put("question_id", question_id); + String question_type = examCollectProblems.get(i).getQuestionType(); + jo.put("question_type", question_type); + String question_difficult = examCollectProblems.get(i).getQuestionDifficult(); + jo.put("question_difficult", question_difficult); + String question_context = examCollectProblems.get(i).getQuestionContext(); + question_context = filterspecial(question_context); + jo.put("question_context", question_context); + String question_image = examCollectProblems.get(i).getQuestionImgs(); + jo.put("question_imgs", question_image); + String question_option = examCollectProblems.get(i).getQuestionOption(); + question_option = filterspecial(question_option); + question_option = question_option.replaceAll(" ", ""); + log.info("【去除t,n等字符】: {}", question_option); + int i1 = -1; + if (question_option.indexOf("A.") != -1) { + i1 = question_option.indexOf("A."); + } else { + i1 = question_option.indexOf("A."); + } + int i2 = -1; + if (question_option.indexOf("B.") != -1) { + i2 = question_option.indexOf("B."); + } else { + i2 = question_option.indexOf("B."); + } + int i3 = -1; + if (question_option.indexOf("C.") != -1) { + i3 = question_option.indexOf("C."); + } else { + i3 = question_option.indexOf("C."); + } + int i4 = -1; + if (question_option.indexOf("D.") != -1) { + i4 = question_option.indexOf("D."); + } else { + i4 = question_option.indexOf("D."); + } + + String str1 = question_option.substring(i1 + 2, i2);//A选项 + String str2 = question_option.substring(i2 + 2, i3);//B选项 + String str3 = question_option.substring(i3 + 2, i4);//C选项 + String str4 = question_option.substring(i4 + 2, question_option.length());//D选项 + List options = new ArrayList<>(); + options.add("A." + str1); + options.add("B." + str2); + options.add("C." + str3); + options.add("D." + str4); + jo.put("question_option", options); + String question_score = String.valueOf(examCollectProblems.get(i).getQuestionScore()); + jo.put("question_score", question_score); + String question_attribute = examCollectProblems.get(i).getQuestionAttribute(); + jo.put("question_attribute", question_attribute); + String correct_option = examCollectProblems.get(i).getCorrectOption(); + jo.put("correct_option", correct_option); + String correct_text = examCollectProblems.get(i).getCorrectText(); + jo.put("correct_text", correct_text); + String correct_analysis = examCollectProblems.get(i).getCorrectAnalysis(); + jo.put("correct_analysis", correct_analysis); + int chapter_id = examCollectProblems.get(i).getChapterId(); + jo.put("chapter_id", chapter_id); + String level = examCollectProblems.get(i).getLevel(); + jo.put("level", level); + String level_name = examCollectProblems.get(i).getLevelName(); + jo.put("level_name", level_name); + String creater_user = examCollectProblems.get(i).getCreateUser(); + jo.put("create_user", creater_user); + String knowledge_module = examCollectProblems.get(i).getKnowledgeModule(); + jo.put("knowledge_module", knowledge_module); + String cognitive_level = examCollectProblems.get(i).getCognitiveLevel(); + jo.put("cognitive_level", cognitive_level); + String core_literacy = examCollectProblems.get(i).getCoreLiteracy(); + jo.put("core_literacy", core_literacy); + int valid = examCollectProblems.get(i).getValid(); + jo.put("valid", valid); + Timestamp inserttime = examCollectProblems.get(i).getInserttime(); + jo.put("inserttime", inserttime); + Timestamp updatetime = examCollectProblems.get(i).getUpdatetime(); + jo.put("updatetime", updatetime); + + jo.put("ifCollect", 1); + + examCollectQuestionsArr.add(jo); + } + } + + return examCollectQuestionsArr; + } + + // 7. 七、 练习错题:点击章、节显示 此小节错题的详细信息 lxj + @Override + public JSONArray getErrorProblemsByChapterAndSection(String stuNumber, String openid, String subject, String chapter, String section, String ifMastered) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + JSONArray sectionErrorQuestionsArr = new JSONArray(); + List sectionErrorProblemsId = null; + if (ifMastered.equals("未掌握")) { + sectionErrorProblemsId = userWrongQustionDao.getErrorProblemsIdByChapterAndSection(stuNumber, subject, chapter, section, 2); + } else if (ifMastered.equals("已掌握")) { + sectionErrorProblemsId = userWrongQustionDao.getErrorProblemsIdByChapterAndSection(stuNumber, subject, chapter, section, 1); + } + if (sectionErrorProblemsId == null || sectionErrorProblemsId.size() == 0) { + info = "本章节中暂时没有错题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < sectionErrorProblemsId.size(); i++) { + JSONObject jo = new JSONObject(); + int question_id = sectionErrorProblemsId.get(i).getQuestionId(); + + String user_answer = sectionErrorProblemsId.get(i).getUserAnswer(); + jo.put("user_answer", user_answer); + int do_right = sectionErrorProblemsId.get(i).getDoRight(); + jo.put("do_right", do_right); + String do_time = sectionErrorProblemsId.get(i).getDoTime(); + jo.put("do_time", do_time); + + List examQuestions = questionDao.getQuestionInfoById(question_id, subject); + if (examQuestions == null || examQuestions.size() == 0) { + info = "查询的题不存在"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + int id = examQuestions.get(0).getId(); + jo.put("id", id); + int exam_id = examQuestions.get(0).getExamId(); + jo.put("exam_id", exam_id); + String subjects = examQuestions.get(0).getSubject(); + jo.put("subject", subjects); + String question_source = examQuestions.get(0).getQuestionSource(); + jo.put("question_source", question_source); + String exam_name = examQuestions.get(0).getExamName(); + jo.put("exam_name", exam_name); + String exam_type = examQuestions.get(0).getExamType(); + jo.put("exam_type", exam_type); + String exam_location = examQuestions.get(0).getExamLocation(); + jo.put("exam_location", exam_location); + int question_id1 = examQuestions.get(0).getQuestionId(); + jo.put("question_id", question_id1); + String question_type = examQuestions.get(0).getQuestionType(); + jo.put("question_type", question_type); + String question_difficult = examQuestions.get(0).getQuestionDifficult(); + jo.put("question_difficult", question_difficult); + String question_context = examQuestions.get(0).getQuestionContext(); + question_context = filterspecial(question_context); + jo.put("question_context", question_context); + String question_image = examQuestions.get(0).getQuestionImgs(); + jo.put("question_imgs", question_image); + String question_option = examQuestions.get(0).getQuestionOption(); + question_option = filterspecial(question_option); + question_option = question_option.replaceAll(" ", ""); + log.info("【去除t,n等字符】: {}", question_option); + int i1 = -1; + if (question_option.indexOf("A.") != -1) { + i1 = question_option.indexOf("A."); + } else { + i1 = question_option.indexOf("A."); + } + int i2 = -1; + if (question_option.indexOf("B.") != -1) { + i2 = question_option.indexOf("B."); + } else { + i2 = question_option.indexOf("B."); + } + int i3 = -1; + if (question_option.indexOf("C.") != -1) { + i3 = question_option.indexOf("C."); + } else { + i3 = question_option.indexOf("C."); + } + int i4 = -1; + if (question_option.indexOf("D.") != -1) { + i4 = question_option.indexOf("D."); + } else { + i4 = question_option.indexOf("D."); + } + + String str1 = question_option.substring(i1 + 2, i2);//A选项 + String str2 = question_option.substring(i2 + 2, i3);//B选项 + String str3 = question_option.substring(i3 + 2, i4);//C选项 + String str4 = question_option.substring(i4 + 2, question_option.length());//D选项 + List options = new ArrayList<>(); + options.add("A." + str1); + options.add("B." + str2); + options.add("C." + str3); + options.add("D." + str4); + jo.put("question_option", options); + String question_score = String.valueOf(examQuestions.get(0).getQuestionScore()); + jo.put("question_score", question_score); + String question_attribute = examQuestions.get(0).getQuestionAttribute(); + jo.put("question_attribute", question_attribute); + String correct_option = examQuestions.get(0).getCorrectOption(); + jo.put("correct_option", correct_option); + String correct_text = examQuestions.get(0).getCorrectText(); + jo.put("correct_text", correct_text); + String correct_analysis = examQuestions.get(0).getCorrectAnalysis(); + jo.put("correct_analysis", correct_analysis); + int chapter_id = examQuestions.get(0).getChapterId(); + jo.put("chapter_id", chapter_id); + String level = examQuestions.get(0).getLevel(); + jo.put("level", level); + String level_name = examQuestions.get(0).getLevelName(); + jo.put("level_name", level_name); + String creater_user = examQuestions.get(0).getCreateUser(); + jo.put("create_user", creater_user); + String knowledge_module = examQuestions.get(0).getKnowledgeModule(); + jo.put("knowledge_module", knowledge_module); + String cognitive_level = examQuestions.get(0).getCognitiveLevel(); + jo.put("cognitive_level", cognitive_level); + String core_literacy = examQuestions.get(0).getCoreLiteracy(); + jo.put("core_literacy", core_literacy); + int valid = examQuestions.get(0).getValid(); + jo.put("valid", valid); + String inserttime = format.format(examQuestions.get(0).getInserttime()); + jo.put("inserttime", inserttime); + String updatetime = format.format(examQuestions.get(0).getUpdatetime()); + jo.put("updatetime", updatetime); + } + + // 查看该用户是否收藏了这道题 + int ifCollect = userCollectDao.getIfCollectByStuNumAndQuestionId(stuNumber, subject, question_id); + if (ifCollect == 1) { +// jo.put("ifCollect","已收藏"); + jo.put("ifCollect", 1); + } else { +// jo.put("ifCollect","未收藏"); + jo.put("ifCollect", 2); + } + + + sectionErrorQuestionsArr.add(jo); + } + } + + return sectionErrorQuestionsArr; + } + + // 8. 八、 考试错题:点击某次考试,显示本次考试错题的详细信息 lxj + @Override + public JSONArray getErrorProblemsByExamName(String stuNumber, String openid, String subject, String examName, String ifMastered) { + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + JSONArray examErrorQuestionsArr = new JSONArray(); + // 得到用户错题id等信息 + List examErrorProblemsId = null; + if (ifMastered.equals("未掌握")) { + examErrorProblemsId = userWrongQustionDao.getErrorProblemsIdByExamName(stuNumber, subject, examName, 2); + } else if (ifMastered.equals("已掌握")) { + examErrorProblemsId = userWrongQustionDao.getErrorProblemsIdByExamName(stuNumber, subject, examName, 1); + } + if (examErrorProblemsId == null || examErrorProblemsId.size() == 0) { + info = "本章节中暂时没有错题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < examErrorProblemsId.size(); i++) { + JSONObject jo = new JSONObject(); + int question_id = examErrorProblemsId.get(i).getQuestionId(); + + String user_answer = examErrorProblemsId.get(i).getUserAnswer(); + jo.put("user_answer", user_answer); + int do_right = examErrorProblemsId.get(i).getDoRight(); + jo.put("do_right", do_right); + String do_time = examErrorProblemsId.get(i).getDoTime(); + jo.put("do_time", do_time); + + List examQuestions = questionDao.getQuestionInfoById(question_id, subject); + if (examQuestions == null || examQuestions.size() == 0) { + info = "查询的题不存在"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + int id = examQuestions.get(0).getId(); + jo.put("id", id); + int exam_id = examQuestions.get(0).getExamId(); + jo.put("exam_id", exam_id); + String subjects = examQuestions.get(0).getSubject(); + jo.put("subject", subjects); + String question_source = examQuestions.get(0).getQuestionSource(); + jo.put("question_source", question_source); + String exam_name = examQuestions.get(0).getExamName(); + jo.put("exam_name", exam_name); + String exam_type = examQuestions.get(0).getExamType(); + jo.put("exam_type", exam_type); + String exam_location = examQuestions.get(0).getExamLocation(); + jo.put("exam_location", exam_location); + int question_id1 = examQuestions.get(0).getQuestionId(); + jo.put("question_id", question_id1); + String question_type = examQuestions.get(0).getQuestionType(); + jo.put("question_type", question_type); + String question_difficult = examQuestions.get(0).getQuestionDifficult(); + jo.put("question_difficult", question_difficult); + String question_context = examQuestions.get(0).getQuestionContext(); + question_context = filterspecial(question_context); + jo.put("question_context", question_context); + String question_image = examQuestions.get(0).getQuestionImgs(); + jo.put("question_imgs", question_image); + String question_option = examQuestions.get(0).getQuestionOption(); + question_option = filterspecial(question_option); + question_option = question_option.replaceAll(" ", ""); + log.info("【去除t,n等字符】: {}", question_option); + int i1 = -1; + if (question_option.indexOf("A.") != -1) { + i1 = question_option.indexOf("A."); + } else { + i1 = question_option.indexOf("A."); + } + int i2 = -1; + if (question_option.indexOf("B.") != -1) { + i2 = question_option.indexOf("B."); + } else { + i2 = question_option.indexOf("B."); + } + int i3 = -1; + if (question_option.indexOf("C.") != -1) { + i3 = question_option.indexOf("C."); + } else { + i3 = question_option.indexOf("C."); + } + int i4 = -1; + if (question_option.indexOf("D.") != -1) { + i4 = question_option.indexOf("D."); + } else { + i4 = question_option.indexOf("D."); + } + + String str1 = question_option.substring(i1 + 2, i2);//A选项 + String str2 = question_option.substring(i2 + 2, i3);//B选项 + String str3 = question_option.substring(i3 + 2, i4);//C选项 + String str4 = question_option.substring(i4 + 2, question_option.length());//D选项 + List options = new ArrayList<>(); + options.add("A." + str1); + options.add("B." + str2); + options.add("C." + str3); + options.add("D." + str4); + jo.put("question_option", options); + String question_score = String.valueOf(examQuestions.get(0).getQuestionScore()); + jo.put("question_score", question_score); + String question_attribute = examQuestions.get(0).getQuestionAttribute(); + jo.put("question_attribute", question_attribute); + String correct_option = examQuestions.get(0).getCorrectOption(); + jo.put("correct_option", correct_option); + String correct_text = examQuestions.get(0).getCorrectText(); + jo.put("correct_text", correct_text); + String correct_analysis = examQuestions.get(0).getCorrectAnalysis(); + jo.put("correct_analysis", correct_analysis); + int chapter_id = examQuestions.get(0).getChapterId(); + jo.put("chapter_id", chapter_id); + String level = examQuestions.get(0).getLevel(); + jo.put("level", level); + String level_name = examQuestions.get(0).getLevelName(); + jo.put("level_name", level_name); + String creater_user = examQuestions.get(0).getCreateUser(); + jo.put("create_user", creater_user); + String knowledge_module = examQuestions.get(0).getKnowledgeModule(); + jo.put("knowledge_module", knowledge_module); + String cognitive_level = examQuestions.get(0).getCognitiveLevel(); + jo.put("cognitive_level", cognitive_level); + String core_literacy = examQuestions.get(0).getCoreLiteracy(); + jo.put("core_literacy", core_literacy); + int valid = examQuestions.get(0).getValid(); + jo.put("valid", valid); + String inserttime = format.format(examQuestions.get(0).getInserttime()); + jo.put("inserttime", inserttime); + String updatetime = format.format(examQuestions.get(0).getUpdatetime()); + jo.put("updatetime", updatetime); + } + + int ifCollect = userCollectDao.getIfCollectByStuNumAndQuestionId(stuNumber, subject, question_id); + if (ifCollect == 1) { +// jo.put("ifCollect","已收藏"); + jo.put("ifCollect", 1); + } else { +// jo.put("ifCollect","未收藏"); + jo.put("ifCollect", 2); + } + + examErrorQuestionsArr.add(jo); + } + } + return examErrorQuestionsArr; + } + + // 9. 九、 删除已掌握错题中的某道题 lxj + @Transactional(propagation = Propagation.REQUIRED) + @Override + public Map deleteMasteredQuestions(String stuNumber, String openid, String subject, int questionId, String questionSource) { + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + Map map = new LinkedHashMap<>(); + String userWrongQuestion = null; + String examCategory1 = null; + String examCategory2 = null; + String examCategory = null; + if (questionSource.equals("")){ + //错题本 删除已掌握的题 + List userWrongQuestion1 = userWrongQustionDao.getIdBySubjectAndQuestionId2(stuNumber, subject, questionId); + if (userWrongQuestion1 == null||userWrongQuestion1.size() == 0) { + info = "所删除的题在 已掌握错题 中暂时不存在"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + //userWrongQustionDao.deleteById(Integer.parseInt(userWrongQuestion)); + userWrongQustionDao.deleteInBatch(userWrongQuestion1); + map.put("delete", 1); + } + return map; + } + else if (questionSource.equals("1")) { + examCategory1 = "章节练习"; + examCategory2 = "专项练习"; + examCategory = "练习错题"; + } else if (questionSource.equals("2")) { + examCategory1 = "模拟考试"; + examCategory2 = "历年真题"; + examCategory = "考试错题"; + } + userWrongQuestion = userWrongQustionDao.getIdBySubjectAndQuestionIdAndExamCategory(stuNumber, subject, questionId, examCategory1, examCategory2); + if (userWrongQuestion == null) { + info = "所删除的题在" + examCategory + "的已掌握错题中暂时不存在"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + userWrongQustionDao.deleteById(Integer.parseInt(userWrongQuestion)); + map.put("delete", 1); + } + + return map; + } + + // 10. 十、 做错题中未掌握的题,正确进入已掌握 lxj + @Transactional(propagation = Propagation.REQUIRED) + @Override + public Map doNotMasteredQuestions(String stuNumber, String openid, String subject, int questionId, String questionSource, String userAnswer, int examId, String examName) { + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + ExamPaper examPaper = examPaperDao.findByExamNameAndSubjectAndValid(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + List questions = questionDao.getQuestionInfoById(questionId, subject); + if (questions == null || questions.size() == 0) { + info = "该科目暂时没有这道题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + Map map = new LinkedHashMap<>(); + String examCategory1 = null; + String examCategory2 = null; + if (questionSource.equals("1")) { + examCategory1 = "章节练习"; + examCategory2 = "专项练习"; + } else if (questionSource.equals("2")) { + examCategory1 = "模拟考试"; + examCategory2 = "历年真题"; + } + + UserWrongQustion getWrongQuestion = userWrongQustionDao.getUserWrongQustionByUserAndSubjectAndExamCategory(stuNumber, subject, questionId, examId, examName, examCategory1, examCategory2); + String correctText = questions.get(0).getCorrectText(); + int doRight; + if (userAnswer.equals(correctText)) { + doRight = 1; + } else { + doRight = 2; + } + Timestamp updateTime = new Timestamp(System.currentTimeMillis()); + getWrongQuestion.setDoRight(doRight); + getWrongQuestion.setUserAnswer(userAnswer); + getWrongQuestion.setUpdatetime(updateTime); + userWrongQustionDao.save(getWrongQuestion); + + map.put("doRight", doRight); + + return map; + } + + // 11. 十一、 专项练习:知识点中统计每章的题数 lxj + @Override + public Map getQuestionsByChapterAndSubject(String subject, String levelName) { + Map map = new LinkedHashMap<>(); + + // 根据学科获取章名称 + List chapters = chapterDao.findChapterBySubject(subject, levelName); + if (chapters == null || chapters.size() == 0) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < chapters.size(); i++) { + String chapter = chapters.get(i); + // 根据章获取对应的题数 + int questionsNumsByChapter = questionDao.getQuestionsNumByChapter(subject, levelName, chapter); + if (questionsNumsByChapter != 0) { + map.put(chapter, questionsNumsByChapter); + } + } + } + + return map; + } + + // 12. 十二、 专项练习:知识点中每章下所有知识点及对应的题数 + @Override + public Map getQuestionsNumsByAttribute(String subject, String levelName, String chapter) { + Map map = new LinkedHashMap<>(); + + // 先根据年级、学科、章 获取知识点 + List attributes = questionDao.getAttributesByChapter(subject, levelName, chapter); + if (attributes == null || attributes.size() == 0) { + info = "所查询的章下面没有相关知识点"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < attributes.size(); i++) { + String attribute = attributes.get(i); + // 根据知识点获取对应的题数 + int getQuestionNumsByAttribute = questionDao.getQuestionsNumsByAttribute(attribute); + if (getQuestionNumsByAttribute != 0) { + map.put(attribute, getQuestionNumsByAttribute); + } + } + } + + return map; + } + + // 13. 十三、 专项练习:根据章名称 和知识点查看题的详细信息 + @Override + public JSONArray getQuestionsByQuestionsAttribute(String stuNumber, String openid, String subject, String levelName, String chapter, String attribute) { + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + JSONArray arr = new JSONArray(); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + List questions = questionDao.getQuestionsBySubjectAndChapterAndAttribute(subject, levelName, chapter, attribute); + if (questions == null || questions.size() == 0) { + info = "该科目、该章节、该知识点中暂时没有题"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < questions.size(); i++) { + JSONObject jo = new JSONObject(); + int id = questions.get(i).getId(); + jo.put("id", id); + int exam_id = questions.get(i).getExamId(); + jo.put("exam_id", exam_id); + String subjects = questions.get(i).getSubject(); + jo.put("subject", subjects); + String question_source = questions.get(i).getQuestionSource(); + jo.put("question_source", question_source); + String exam_name = questions.get(i).getExamName(); + jo.put("exam_name", exam_name); + String exam_type = questions.get(i).getExamType(); + jo.put("exam_type", exam_type); + String exam_location = questions.get(i).getExamLocation(); + jo.put("exam_location", exam_location); + int question_id = questions.get(i).getQuestionId(); + jo.put("question_id", question_id); + String question_type = questions.get(i).getQuestionType(); + jo.put("question_type", question_type); + String question_difficult = questions.get(i).getQuestionDifficult(); + jo.put("question_difficult", question_difficult); + String question_context = questions.get(i).getQuestionContext(); + question_context = filterspecial(question_context); + jo.put("question_context", question_context); + String question_image = questions.get(i).getQuestionImgs(); + jo.put("question_imgs", question_image); + String question_option = questions.get(i).getQuestionOption(); + question_option = filterspecial(question_option); + question_option = question_option.replaceAll(" ", ""); + log.info("【去除t,n等字符】: {}", question_option); + int i1 = -1; + if (question_option.indexOf("A.") != -1) { + i1 = question_option.indexOf("A."); + } else { + i1 = question_option.indexOf("A."); + } + int i2 = -1; + if (question_option.indexOf("B.") != -1) { + i2 = question_option.indexOf("B."); + } else { + i2 = question_option.indexOf("B."); + } + int i3 = -1; + if (question_option.indexOf("C.") != -1) { + i3 = question_option.indexOf("C."); + } else { + i3 = question_option.indexOf("C."); + } + int i4 = -1; + if (question_option.indexOf("D.") != -1) { + i4 = question_option.indexOf("D."); + } else { + i4 = question_option.indexOf("D."); + } + List optionList = new LinkedList<>(); + List optionList1 = new LinkedList<>(); + List optionList2 = new LinkedList<>(); + + List letterList = new ArrayList<>(); + letterList.add(i1); + letterList.add(i2); + letterList.add(i3); + letterList.add(i4); + + String str1 = question_option.substring(i1 + 2, i2);//A选项 + String str2 = question_option.substring(i2 + 2, i3);//B选项 + String str3 = question_option.substring(i3 + 2, i4);//C选项 + String str4 = question_option.substring(i4 + 2, question_option.length());//D选项 + + optionList.add(str1); + optionList.add(str2); + optionList.add(str3); + optionList.add(str4); + + // 将选项内容做映射,请求全排列, + Map sortMap = new HashMap<>(); + + sortMap.put(1, str1); + sortMap.put(2, str2); + sortMap.put(3, str3); + sortMap.put(4, str4); + optionList2.add("A."); + optionList2.add("B."); + optionList2.add("C."); + optionList2.add("D."); + + int[] array = new int[]{1, 2, 3, 4}; + + boolean contains = question_option.contains("E.");//判断选项中是否包含 D选项 + if (contains) { + int i5 = question_option.indexOf("E."); + letterList.add(i5); + String str5 = question_option.substring(i5 + 2, question_option.length());//E选项 + optionList.add(str5); + sortMap.put(5, str5); + optionList2.add("E."); + array = new int[]{1, 2, 3, 4, 5}; + } + + // 这里 是 实现 随机选项的 方案 1: 使用的是random,随机性不高 + int[] ints = randomSort(array, 0);// 这个是随机函数,不是全排列函数 + for (int j = 0; j < ints.length; j++) { + String s = sortMap.get(ints[j]); + String s1 = optionList2.get(j); + optionList1.add(s1 + s); + } + + // Collections.shuffle(list);//集合打乱顺序 + + jo.put("question_option", optionList1); + String question_score = String.valueOf(questions.get(i).getQuestionScore()); + jo.put("question_score", question_score); + String question_attribute = questions.get(i).getQuestionAttribute(); + jo.put("question_attribute", question_attribute); + String correct_option = questions.get(i).getCorrectOption(); + jo.put("correct_option", correct_option); + String correct_text = questions.get(i).getCorrectText(); + jo.put("correct_text", correct_text); + String correct_analysis = questions.get(i).getCorrectAnalysis(); + jo.put("correct_analysis", correct_analysis); + int chapter_id = questions.get(i).getChapterId(); + jo.put("chapter_id", chapter_id); + String level = questions.get(i).getLevel(); + jo.put("level", level); + String level_name = questions.get(i).getLevelName(); + jo.put("level_name", level_name); + String creater_user = questions.get(i).getCreateUser(); + jo.put("create_user", creater_user); + String knowledge_module = questions.get(i).getKnowledgeModule(); + jo.put("knowledge_module", knowledge_module); + String cognitive_level = questions.get(i).getCognitiveLevel(); + jo.put("cognitive_level", cognitive_level); + String core_literacy = questions.get(i).getCoreLiteracy(); + jo.put("core_literacy", core_literacy); + int valid = questions.get(i).getValid(); + jo.put("valid", valid); + String inserttime = format.format(questions.get(i).getInserttime()); + jo.put("inserttime", inserttime); + String updatetime = format.format(questions.get(i).getUpdatetime()); + jo.put("updatetime", updatetime); + + int ifCollect = userCollectDao.getIfCollectByStuNumAndQuestionId(stuNumber, subject, id); + if (ifCollect == 1) { +// jo.put("ifCollect","已收藏"); + jo.put("ifCollect", 1); + } else { +// jo.put("ifCollect","未收藏"); + jo.put("ifCollect", 2); + } + + arr.add(jo); + } + } + return arr; + } + + // 14. 十四、 根据学科和年级统计用户做题记录 + @Override + public JSONArray getDoQUestionRecord(String stuNumber, String openid, String subject, String levelName,String starTime,String endTime) { + JSONArray arr = new JSONArray(); + + // 得到试题名称和对应的题的总数 + // 根据学科和年级查询对应考试名称 + List examPapers = examPaperDao.getExamPaper(subject, levelName); + // 查询所有知识点 + List questionAttributes = questionDao.getQUestionAttribute(subject, levelName); + if ((examPapers == null || examPapers.size() == 0) && (questionAttributes == null || questionAttributes.size() == 0)) { + info = "该年级、该科目中暂时没有做题记录信息"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + if ((examPapers != null) && (examPapers.size() != 0)) { + for (int i = 0; i < examPapers.size(); i++) { + JSONObject jo = new JSONObject(); + // 试卷名称 + String examPaperName = examPapers.get(i).getExamName(); + String examSource = examPapers.get(i).getExamSource(); + // 试卷类型:章节练习 +// String category="章节练习"; + + // 试卷总题数 + int questionCount = examPapers.get(i).getQuestionCount(); + + // 根据试卷名称查询用户做题情况 + + List userQuestionsRecord = null; + if (starTime.equals("") || endTime.equals("")){ + userQuestionsRecord = userQuestionRecordDao.getUserQuestionRecord(stuNumber, examPaperName,examSource); + }else { + userQuestionsRecord = userQuestionRecordDao.getUserQuestionRecord2(stuNumber, examPaperName,starTime,endTime); + } + + if (userQuestionsRecord != null && userQuestionsRecord.size() != 0) { + // 定义初始时间 + String startTime = "00:00:00"; + // 用户做了几道题 + int doQuestionsNums = userQuestionsRecord.size(); + // 完成率 + String completeRate = "共(" + doQuestionsNums + "/" + questionCount + ")题"; + // 统计用户正确题的个数 + int doQuestionsRightNums = 0; + for (int j = 0; j < userQuestionsRecord.size(); j++) { + // 判断题是否做对,计算做对题数 + int doRight = userQuestionsRecord.get(j).getDoRight(); + if (doRight == 1) { + doQuestionsRightNums += 1; + } + // 得到做题时间 + String doTime = userQuestionsRecord.get(j).getDoTime(); + if (doTime.equals("")){ + continue; + } + startTime = getTimeSum(startTime, doTime); + + } + // 用户做题的正确率 + double rightRate = ((double) doQuestionsRightNums / (double) doQuestionsNums) * 100; + DecimalFormat format = new DecimalFormat("0.0"); + String theRightRate = format.format(rightRate); + + // 查询用户此试卷最新做题时间 + String doTime = null; + if (starTime.equals("") || endTime.equals("")){ + doTime = userQuestionRecordDao.getDoTimeByChapter(stuNumber, examPaperName, examSource); + }else { + doTime = userQuestionRecordDao.getDoTimeByChapter2(stuNumber, examPaperName, examSource,starTime,endTime); + } + if (doTime == null) { + info = "暂时没有做题时间信息"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + jo.put("doRightRate", theRightRate); // 用户做题正确率 + jo.put("doTime", doTime);// 做题时间 + jo.put("examPaperName", examPaperName);// 试卷名称 + jo.put("questionCount", questionCount);// 试卷总题数 + jo.put("doQuestionsNums", doQuestionsNums);// 用户做题数 + jo.put("doRightNums", doQuestionsRightNums);// 正确题数 + jo.put("completeRate", completeRate);// 完成率 + jo.put("examSource", examSource);// 试题来源 + jo.put("doTimeLength", startTime);// 试题做题时长 + } + + if (!(jo.isEmpty() || jo.size() < 1)) { + arr.add(jo); + } + } + } + if (questionAttributes != null && questionAttributes.size() != 0) { + List attributesList = new ArrayList<>(); + for (int j = 0; j < questionAttributes.size(); j++) { + // 得到知识点 + String questionAttribute = questionAttributes.get(j); + + if (questionAttribute.contains(",")) { + String[] attributeArr = questionAttribute.split(","); + for (int k = 0; k < attributeArr.length; k++) { + String attribute = attributeArr[k]; + if (!(attributesList.contains(attribute))) { + attributesList.add(attribute); + } + } + } else { + if(!questionAttribute.equals("")){ + attributesList.add(questionAttribute); + } + } + } + for (int l = 0; l < attributesList.size(); l++) { + JSONObject jo1 = new JSONObject(); + String attributes = attributesList.get(l); + String category = "专项练习"; + + // 根据知识点查询题数 + int questionCount = questionDao.getQuestionsNumsByAttribute(attributes); + + // 根据知识点查询做题记录 + List getQuestionRecordByAttribute = null; + if (starTime.equals("") || endTime.equals("")){ + getQuestionRecordByAttribute = userQuestionRecordDao.getQuestionsRecordByAttribute(stuNumber, attributes, category); +// getQuestionRecordByAttribute = userQuestionRecordDao.getUserQuestionRecordByKnowledgePoints2(stuNumber,subject,category,levelName);//3.2 + }else { + getQuestionRecordByAttribute = userQuestionRecordDao.getQuestionsRecordByAttribute2(stuNumber, attributes, category,starTime,endTime); +// getQuestionRecordByAttribute = userQuestionRecordDao.getUserQuestionRecordByKnowledgePoints3(stuNumber,subject,category,levelName,starTime,endTime);//3.2 + } + + if ((getQuestionRecordByAttribute != null) && (getQuestionRecordByAttribute.size() != 0)) { + // 定义初始时间 + String startTime = "00:00:00"; + + // 用户做了几道题 + int doQuestionCount = getQuestionRecordByAttribute.size(); + + // 完成率 + String completeRate = "共(" + doQuestionCount + "/" + questionCount + ")题"; + + // 统计用户正确题的个数 + int doQuestionsRightNums = 0; + + for (int m = 0; m < getQuestionRecordByAttribute.size(); m++) { + int doRight = getQuestionRecordByAttribute.get(m).getDoRight(); + if (doRight == 1) { + doQuestionsRightNums += 1; + } + + // 得到做题时间 + String doTime = getQuestionRecordByAttribute.get(m).getDoTime(); + startTime = getTimeSum(startTime, doTime); + } + // 用户做题的正确率 + double rightRate = ((double) doQuestionsRightNums / (double) doQuestionCount) * 100; + DecimalFormat format = new DecimalFormat("0.0"); + String theRightRate = format.format(rightRate); + + // 查询用户此试卷最新做题时间 + String doTimeByAttribute = null; + if (starTime.equals("") || endTime.equals("")){ + doTimeByAttribute = userQuestionRecordDao.getDoTimeByAttribute(stuNumber, attributes, category); + }else { + doTimeByAttribute = userQuestionRecordDao.getDoTimeByAttribute2(stuNumber, attributes, category,starTime,endTime); + } + + if (doTimeByAttribute == null) { + info = "暂时没有做题时间信息"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + jo1.put("doRightRate", theRightRate); // 用户做题正确率 + jo1.put("doTime", doTimeByAttribute);// 做题时间 + jo1.put("examPaperName", attributes);// 试卷名称 + jo1.put("questionCount", questionCount);// 试卷总题数 + jo1.put("doQuestionsNums", doQuestionCount);// 用户做题数 + jo1.put("doRightNums", doQuestionsRightNums);// 正确题数 + jo1.put("completeRate", completeRate);// 完成率 + jo1.put("examSource", category);// 试题来源 + jo1.put("doTimeLength", startTime);// 试题做题时长 + } + if (!(jo1.isEmpty() || jo1.size() < 1)) { + arr.add(jo1); + } + } + } + } + + JSONArray arrSorted = jsonArraySort(arr.toString()); + JSONArray arrSorted1 = new JSONArray(); + for (int k = 0; k < arrSorted.size(); k++) { + JSONObject jsonObject = (JSONObject) arrSorted.get(k); + String doTime = jsonObject.getString("doTime"); + Timestamp time = Timestamp.valueOf(doTime); + doTime = new SimpleDateFormat("yyyy年MM月dd日 HH:mm").format(time); + jsonObject.put("doTime", doTime); + arrSorted1.add(jsonObject); + } + + return arrSorted; + } + + // 15. 十五、 做题记录中关于某一份试卷/章节/知识点做题详情(做题时间、题难易度等) + @Override + public JSONArray getDoQuestionRecordDetail(String stuNumber,String openid,String subject,String levelName,String examName,String source){ + JSONArray arr=new JSONArray(); + + // 判断该学号学生是否存在 + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + // 根据试卷名称查询做题记录详情 + List userQuestionsRecord=null; + + if((source.equals("章节练习")) || (source.equals("模拟考试")) || (source.equals("历年真题"))){ + userQuestionsRecord=userQuestionRecordDao.getUserQuestionRecord(stuNumber,examName,source); + }else if(source.equals("专项练习")){ + userQuestionsRecord=userQuestionRecordDao.getUserQuestionRecordByKnowledgePoints2(stuNumber,subject,source,levelName); + } + + if (userQuestionsRecord == null || userQuestionsRecord.size() == 0) { + info = "对于该试卷,该学生暂时没有做题记录"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < userQuestionsRecord.size(); i++) { + JSONObject jo = new JSONObject(); + // 整个题表中的id,用于去题表中查询相关信息 + int questionid = userQuestionsRecord.get(i).getQuestionId(); + // 做题是否正确 + int doRight = userQuestionsRecord.get(i).getDoRight(); + // 做题时间(时长) + String doTime = userQuestionsRecord.get(i).getDoTime(); + + // 根据题表中的id去查询该题对应的信息(包括题的难易程度和知识点) + List questions = questionDao.getQuestionInfoById(questionid, subject); + // 该试卷中的题号 + int questionIdByExamName = questions.get(0).getQuestionId(); + // 试题难易度 + String questionDifficult = questions.get(0).getQuestionDifficult(); + // 试题知识点 + String questionAttribute = questions.get(0).getQuestionAttribute(); + + jo.put("id", questionid);// 试题id + jo.put("questionId", questionIdByExamName);// 试题在该试卷中的id + jo.put("doRight", doRight);// 做题是否正确 + jo.put("doTime", doTime);// 做题所用时长 + jo.put("questionDifficult", questionDifficult);// 试题难易度 + jo.put("questionAttribute", questionAttribute);// 试题知识点 + + arr.add(jo); + } + } + return arr; + } + + // 16. 十六、 学习记录中:统计做题数 + @Override + public JSONArray getDoQuestionsCount(String stuNumber, String openid, String subject, String levelName) { + JSONArray arr = new JSONArray(); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + // 先根据用户、学科、年级得到用户做题时间(年月日) + List getDoQuestionsDate = userQuestionRecordDao.getDoQuestionsDate(stuNumber, subject, levelName); + if (getDoQuestionsDate == null || getDoQuestionsDate.size() == 0) { + info = "该学生暂时没有做题记录"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < getDoQuestionsDate.size(); i++) { + JSONObject jo = new JSONObject(); + // 得到做题时间 + String doDate = getDoQuestionsDate.get(i); + + // 根据做题时间和用户学号查询用户当天做题数 + int doCount = userQuestionRecordDao.getDoQUestionsNumsByDate(stuNumber, doDate,subject,levelName); + + jo.put("stuNumber", stuNumber);// 用户学号 + jo.put("doDate", doDate);// 做题时间 + jo.put("doCount", doCount);// 当天做题数 + + arr.add(jo); + } + } + + return arr; + } + + // 17. 十七、 学习记录:统计错题和收藏总数 + @Override + public Map getWrongCollectQuestionsCount(String stuNumber, String openid, String subject, String levelName) { + Map map = new LinkedHashMap<>(); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + // 统计用户已掌握错题数 + int doRight = 1; + int masteredErrorQuestionsCount = userWrongQustionDao.getMasteredErrorQuestionsCountByGradeLevel(stuNumber, levelName, subject, doRight); + + // 统计用户未掌握错题数 + doRight = 2; + int notMasteredErrorQuestionsCount = userWrongQustionDao.getMasteredErrorQuestionsCountByGradeLevel(stuNumber, levelName, subject, doRight); + + // 统计用户收藏题总数 + int collectQuestionsCount = userCollectDao.getCollectCountByGradeLevel(stuNumber, levelName, subject); + + map.put("masteredErrorQuestionsCount", masteredErrorQuestionsCount);// 已掌握题数 + map.put("notMasteredErrorQuestionsCount", notMasteredErrorQuestionsCount);// 未掌握题数 + map.put("collectQuestionsCount", collectQuestionsCount);// 收藏题数 + + return map; + } + + // 18. 十八、 学习记录:按天统计做题正确率和做题时长 + @Override + public JSONArray getRightRateAndClassHours(String stuNumber, String openid, String subject, String levelName) { + JSONArray arr = new JSONArray(); + + SimpleDateFormat myFormatter = new SimpleDateFormat("HH:mm:ss"); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + // 先根据用户、学科、年级得到用户做题时间(年月日) + List getDoQuestionsDate = userQuestionRecordDao.getDoQuestionsDate(stuNumber, subject, levelName); + if (getDoQuestionsDate == null || getDoQuestionsDate.size() == 0) { + info = "该学生暂时没有做题记录"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + for (int i = 0; i < getDoQuestionsDate.size(); i++) { + JSONObject jo = new JSONObject(); + // 得到做题时间 + String doDate = getDoQuestionsDate.get(i); + + // 根据做题时间和用户学号查询用户当天做题数 + int doCount = userQuestionRecordDao.getDoQUestionsNumsByDate(stuNumber, doDate,subject,levelName); + + // 根据做题时间和用户学号查询用户当天做对题数 + int doRight = 1; + int doRightCount = userQuestionRecordDao.getDoQuestionsRightNumsByDate(stuNumber, doDate, subject,levelName,doRight); + + // 计算正确率 + float rightRate = (float) doRightCount / doCount; + jo.put("rightRate1", rightRate);// 正确率 + // 保留三位小数 + DecimalFormat df = new DecimalFormat("0.000"); + String rightRateThree = df.format(rightRate); + + // 每一天,设置初始时长为00:00:00 + String startTime = "00:00:00"; + + String[] startLength = startTime.split(":"); + int hour = Integer.parseInt(startLength[0]); + int mins = Integer.parseInt(startLength[1]); + int sec = Integer.parseInt(startLength[2]); + //3.22修改,获取具体学科的做题时间 + List doTimeList = userQuestionRecordDao.getDoQuestionsTimeList(stuNumber, doDate,subject); + if (doTimeList == null || doTimeList.size() == 0) { + info = "该学生暂时没有做题记录"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } else { + + for (int j = 0; j < doTimeList.size(); j++) { + String doTime = doTimeList.get(j); + if (doTime.equals("")) { + continue; + } + String[] doLength = doTime.split(":"); + int doHour = Integer.parseInt(doLength[0]); + int doMins = Integer.parseInt(doLength[1]); + int doSec = Integer.parseInt(doLength[2]); + + sec = sec + doSec; + mins = mins + doMins; + hour = hour + doHour; + + if (sec >= 60) { + sec = 00; + if (mins >= 60) { + mins = 00; + hour = hour + 1; + } else { + mins = mins + 1; + } + } + } + } + + String hours = "", minss = "", secs = ""; + if (hour < 10) { + hours = "0" + hour; + } else { + hours = "" + hour; + } + if (mins < 10) { + minss = "0" + mins; + } else { + minss = "" + mins; + } + if (sec < 10) { + secs = "0" + sec; + } else { + secs = "" + sec; + } + String doTime = hours + ":" + minss + ":" + secs; + + jo.put("doDate", doDate);// 做题日期 + jo.put("doCount", doCount);// 做题总数 + jo.put("doRightCount", doRightCount);// 正确题数 + jo.put("rightRate", rightRateThree);// 正确率 + jo.put("doTimeLength", doTime);// 当天做题时长 + + arr.add(jo); + } + } + + return arr; + } + + // 19. 十九、 学习记录:上面三个数的统计 + @Override + public JSONObject getPracticeRecord(String stuNumber,String openid,String subject,String levelName){ + JSONObject json=new JSONObject(); + + UserLogin userInfo = userLoginDao.findByDiyid(stuNumber);// 获取此用户的所有基本信息 + if (userInfo == null) { + info = "暂时没有学号所对应的信息,请认真核对您的学号"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + // 得到用户做题总数 + int doQuestionCount=userQuestionRecordDao.getDoQuestionCount(stuNumber,subject,levelName); + + // 查询用户每道题做题时长,计算用户做题总时间 + // 每一天,设置初始时长为00:00:00 + String startTime = "00:00:00"; + List doQuestionTime=userQuestionRecordDao.getDoQUestionTime(stuNumber,subject,levelName); + if(doQuestionTime!=null && doQuestionTime.size()!=0){ + for(int i=0;i doQuestionUpdatetime=userQuestionRecordDao.getDoQuestionUpdatetime(stuNumber,subject,levelName); + if(doQuestionUpdatetime!=null && doQuestionUpdatetime.size()!=0){ + for(int i=0;i jsonValues = new ArrayList(); + for (int i = 0; i < jsonArr.size(); i++) { + jsonValues.add(jsonArr.getJSONObject(i)); + } + Collections.sort(jsonValues, new Comparator() { + // You can change "Name" with "ID" if you want to sort by ID + private static final String KEY_NAME = "doTime"; + + @Override + public int compare(JSONObject a, JSONObject b) { + String valA = new String(); + String valB = new String(); + try { + // 这里是a、b需要处理的业务,需要根据你的规则进行修改。 + String aStr = a.getString(KEY_NAME); + valA = aStr.replaceAll("-", ""); + valA = valA.replaceAll(":", ""); + valA = valA.replaceAll(" ", ""); + String bStr = b.getString(KEY_NAME); + valB = bStr.replaceAll("-", ""); + valB = valB.replaceAll(":", ""); + valB = valB.replaceAll(" ", ""); + } catch (JSONException e) { + // do something + } + return -valA.compareTo(valB); + // if you want to change the sort order, simply use the following: + // return -valA.compareTo(valB); + } + }); + for (int i = 0; i < jsonArr.size(); i++) { + sortedJsonArray.add(jsonValues.get(i)); + } + return sortedJsonArray; + } + + // 时间相加:格式00:00:00 + public static String getTimeSum(String time, String doTime) { + String[] length = time.split(":"); + int hour = Integer.parseInt(length[0]); + int mins = Integer.parseInt(length[1]); + int sec = Integer.parseInt(length[2]); + + String[] doLength = doTime.split(":"); + int doHour = Integer.parseInt(doLength[0]); + int doMins = Integer.parseInt(doLength[1]); + int doSec = Integer.parseInt(doLength[2]); + + sec = sec + doSec; + mins = mins + doMins; + hour = hour + doHour; + + if (sec >= 60) { + sec = 00; + if (mins >= 60) { + mins = 00; + hour = hour + 1; + } else { + mins = mins + 1; + } + } + + String hours = "", minss = "", secs = ""; + if (hour < 10) { + hours = "0" + hour; + } else { + hours = "" + hour; + } + if (mins < 10) { + minss = "0" + mins; + } else { + minss = "" + mins; + } + if (sec < 10) { + secs = "0" + sec; + } else { + secs = "" + sec; + } + String doTimeNum = hours + ":" + minss + ":" + secs; + + return doTimeNum; + } + +} diff --git a/src/main/java/com/zgczx/service/score/ScoreService.java b/src/main/java/com/zgczx/service/score/ScoreService.java index b9955c0..8a0ad23 100644 --- a/src/main/java/com/zgczx/service/score/ScoreService.java +++ b/src/main/java/com/zgczx/service/score/ScoreService.java @@ -1,11 +1,11 @@ package com.zgczx.service.score; -import com.zgczx.dataobject.score.ExamCoversionTotal; -import com.zgczx.dataobject.score.ExamInfo; -import com.zgczx.dto.ExamCoversionTotalDTO; -import com.zgczx.dto.ExamCoversionTotalSectionDTO; -import com.zgczx.dto.ExamCoversionTotalSingleDTO; -import com.zgczx.dto.SixRateDTO; +import com.zgczx.repository.mysql1.score.dto.*; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalSectionDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalSingleDTO; +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import com.zgczx.repository.mysql1.score.model.ExamInfo; import java.util.List; @@ -36,4 +36,15 @@ public interface ScoreService { List getExamCoversionTotalSectionInfo(String stuNumber, String examType); List getSixRateInfo(String stuNumber, String examType); + + List getSubjectAnalysisInfo(String stuNumber, String examType); + + List getHistoricalAnalysisTotalInfo(String stuNumber, String examType,String openid); + + List getHistoricalAnalysisSingleInfo(String stuNumber, String examType, String subject,String openid); + + List getAsahiChartAllRate(String stuNumber, String examType); + + List getScoreReport(String stuNumber, String examType); + } diff --git a/src/main/java/com/zgczx/service/score/impl/ScoreServiceImpl.java b/src/main/java/com/zgczx/service/score/impl/ScoreServiceImpl.java index 12d62f5..70dee78 100644 --- a/src/main/java/com/zgczx/service/score/impl/ScoreServiceImpl.java +++ b/src/main/java/com/zgczx/service/score/impl/ScoreServiceImpl.java @@ -1,42 +1,67 @@ package com.zgczx.service.score.impl; -import com.zgczx.dataobject.score.ExamCoversionTotal; -import com.zgczx.dataobject.score.ExamFullScoreSet; -import com.zgczx.dataobject.score.ExamInfo; -import com.zgczx.dataobject.score.SubjectFullScore; -import com.zgczx.dataobject.user.SysLogin; -import com.zgczx.dto.ExamCoversionTotalDTO; -import com.zgczx.dto.ExamCoversionTotalSectionDTO; -import com.zgczx.dto.ExamCoversionTotalSingleDTO; -import com.zgczx.dto.SixRateDTO; -import com.zgczx.enums.ResultEnum; -import com.zgczx.enums.UserEnum; -import com.zgczx.exception.ScoreException; -import com.zgczx.repository.score.ExamCoversionTotalDao; -import com.zgczx.repository.score.ExamFullScoreSetDao; -import com.zgczx.repository.score.ExamInfoDao; -import com.zgczx.repository.score.SubjectFullScoreDao; -import com.zgczx.repository.user.StudentInfoDao; -import com.zgczx.repository.user.SysLoginDao; -import com.zgczx.service.score.ScoreService; + +import static com.zgczx.utils.DateUtil.getNowTime; +import static com.zgczx.utils.JDBCDao.returnResultToList; + +import java.math.BigInteger; +import java.sql.*; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import javax.sql.DataSource; + +import com.zgczx.utils.SpringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.jdbc.support.JdbcUtils; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.stereotype.Service; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import java.math.BigInteger; -import java.text.DecimalFormat; -import java.util.*; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.repository.basefactory.BaseFactory; +import com.zgczx.repository.mysql1.score.dao.ExamFullScoreSetDao; +import com.zgczx.repository.mysql1.score.dao.ExamInfoDao; +import com.zgczx.repository.mysql1.score.dao.ImportConversionScoreDao; +import com.zgczx.repository.mysql1.score.dao.SubjectDTODao; +import com.zgczx.repository.mysql1.score.dao.SubjectFullScoreDao; +import com.zgczx.repository.mysql1.score.dto.AsahiChartAllRateDTO; +import com.zgczx.repository.mysql1.score.dto.HistoricalAnalysisSingleDTO; +import com.zgczx.repository.mysql1.score.dto.HistoricalAnalysisTotalDTO; +import com.zgczx.repository.mysql1.score.dto.ScoreReportDTO; +import com.zgczx.repository.mysql1.score.dto.SixRateDTO; +import com.zgczx.repository.mysql1.score.dto.SubjectAnalysisDTO; +import com.zgczx.repository.mysql1.score.dto.SubjectDTO; +import com.zgczx.repository.mysql1.score.model.ExamInfo; +import com.zgczx.repository.mysql1.score.model.SubjectFullScore; +import com.zgczx.repository.mysql1.user.dao.StudentInfoDao; +import com.zgczx.repository.mysql1.user.dao.SysLoginDao; +import com.zgczx.repository.mysql1.user.model.SysLogin; +import com.zgczx.repository.mysql2.scoretwo.dao.ExamCoversionTotalDao; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalSectionDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.ExamCoversionTotalSingleDTO; +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import com.zgczx.service.score.ScoreService; +import com.zgczx.utils.DateFormatUtil; /** * @author aml * @date 2019/9/10 17:15 */ @Service -public class ScoreServiceImpl implements ScoreService { +//@Transactional("transactionManagerDb2") +public class ScoreServiceImpl extends BaseFactory implements ScoreService { private static final Logger logger = LoggerFactory.getLogger(ScoreServiceImpl.class); @@ -59,7 +84,13 @@ public class ScoreServiceImpl implements ScoreService { private SubjectFullScoreDao subjectFullScoreDao; @Autowired - EntityManagerFactory ntityManagerFactory; + private ImportConversionScoreDao importConversionScoreDao; + + @Autowired + private SubjectDTODao subjectDTODao; + + //DateFormatUtil中的两个方法不是静态方法,只能new 对象,用对象去调用 + DateFormatUtil dateFormatUtil = new DateFormatUtil(); private String info; @@ -78,9 +109,14 @@ public ExamCoversionTotal getExamCoversionTotal(Integer userId, String examType) logger.error(info); throw new ScoreException(ResultEnum.PARAM_EXCEPTION, info); } -// ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber,examType); -// return examCoversionTotal; - return examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examType); + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber,examType); + if (examCoversionTotal == null){ + info = " 暂无本次考试的数据"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + return examCoversionTotal; +// return examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examType); } @Override @@ -88,9 +124,22 @@ public List getListExamInfols() { List examInfoList = examInfoDao.findAll(); if (examInfoList == null || examInfoList.size() == 0) { info = "查无结果"; - logger.error(info); + logger.error("查询所有考试结果: {}",info); throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); } +// for (ExamInfo examInfo: examInfoList){ +// try { +// String examName = examInfo.getExamName(); +// //String s1 = dateFormatUtil.dateFormat(examName); +// String s1 = dateFormatUtil.dateFormat(examName); +// System.out.println(s1); +// }catch (Exception e){ +// info = "调用DateFormatUtil类转换考试名称中的日期异常"; +// throw new ScoreException(ResultEnum.PARAM_STRING_EXCEPTION, info); +// } +// +// } + return examInfoList; } @@ -164,26 +213,57 @@ public List getExamCoversionTotalSingleInfo(String logger.error(info); throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); } - //使用原生SQL - EntityManager em = ntityManagerFactory.createEntityManager(); + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName();//哪个年级,高一还是高二等 //String querysql = "SELECT * FROM exam_coversion_total WHERE class_id="+examCoversionTotal.getClassId()+ "AND exam_type="+examType+" ORDER BY "+ subject + " DESC"; 这个是错的 //String querysql = "SELECT * FROM exam_coversion_total WHERE class_id=\""+examCoversionTotal.getClassId()+ "\" AND exam_type=\""+examType+"\" ORDER BY \""+ subject + "\" DESC"; 这个可以得用java转译字符 \" // 本次班级排名 - String querysql = "SELECT * FROM exam_coversion_total WHERE class_id='"+examCoversionTotal.getClassId()+ "' AND exam_type='"+examType+"' ORDER BY "+ subject + " DESC"; //这个是直接拼接 + String querysql = "SELECT * FROM exam_coversion_total WHERE valid='1' AND school_name='"+schoolName+"' AND grade_name='"+gradeName+"'AND class_id='"+examCoversionTotal.getClassId()+ "' AND exam_type='"+examType+"' ORDER BY "+ subject + " DESC"; //这个是直接拼接 logger.info("查询本次班级排名-->" + querysql); - Query query = em.createNativeQuery(querysql, ExamCoversionTotal.class); + //LocalContainerEntityManagerFactoryBean entityManagerFactoryDb2 =(LocalContainerEntityManagerFactoryBean) SpringUtil.getBean("entityManagerFactoryDb2"); +/** + * 手动连接数据库,并执行SQL查询获取结果集 + DataSource dataSource= (DataSource)SpringUtil.getBean("db2DataSource"); + try { + Connection connection = dataSource.getConnection(); + String sq = "SELECT * FROM exam_coversion_total WHERE id=7770"; + PreparedStatement preparedStatement = connection.prepareStatement(sq); + ResultSet resultSet = preparedStatement.executeQuery(); + + returnResultToList(resultSet); + + JdbcUtils.closeConnection(connection); + resultSet.last(); + } catch (SQLException e) { + e.printStackTrace(); + } +*/ + + Query query = entityManagerDb2.createNativeQuery(querysql, ExamCoversionTotal.class); @SuppressWarnings("unchecked") List examCoversionTotalSubject = query.getResultList(); + + logger.info("[输出subject:]{}",subject); + /* String str= subject.replace("\"", ""); + logger.info("[输出subject:]{}",str); + List examCoversionTotalSubject2 = examCoversionTotalDao.getAllSingleClassRank(schoolName,examCoversionTotal.getClassId(),examType,str);*/ + //本次年级排名 - String gradeQuerysql = "select * from exam_coversion_total where exam_type='"+examType+"' order by "+ subject + " desc"; + String gradeQuerysql = "select * from exam_coversion_total where valid='1' AND school_name='"+schoolName+"' AND grade_name='"+gradeName+"'AND exam_type='"+examType+"' order by "+ subject + " desc"; logger.info("查询本次年级排名-->" + gradeQuerysql); - Query gradeQuery = em.createNativeQuery(gradeQuerysql, ExamCoversionTotal.class); + Query gradeQuery = entityManagerDb2.createNativeQuery(gradeQuerysql, ExamCoversionTotal.class); @SuppressWarnings("unchecked") List gradeExamCoversionTotal = gradeQuery.getResultList(); + // 动态获取某科目的成绩 + String subjectSql = "select "+subject+" FROM exam_coversion_total WHERE student_number='"+stuNumber+"'and exam_type='"+examType+"'"; + System.out.println(subjectSql); + Query nativeQuery = entityManagerDb2.createNativeQuery(subjectSql); + @SuppressWarnings("unchecked") + List subjectScore = nativeQuery.getResultList(); - em.close(); + entityManagerDb2.close(); - // List examCoversionTotalSubject = examCoversionTotalDao.findAllByClassIdAndExamType(examCoversionTotal.getClassId(), examType,subject); + // List examCoversionTotalSubject = examCoversionTotalDao.findAllByClassIdAndExamType(examCoversionTotal.getClassId(), examType,subject); //当前试卷的班级排名map Map mapClass = new HashMap<>(); for(int i = 1; i < examCoversionTotalSubject.size(); i++){ @@ -322,8 +402,6 @@ public List getExamCoversionTotalSingleInfo(String } } - - // 获取所有考试列表 List examInfoList = examInfoDao.findAll(); if (examInfoList == null || examInfoList.size() == 0) { @@ -331,6 +409,12 @@ public List getExamCoversionTotalSingleInfo(String logger.error(info); throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); } + int examTnfoId = examInfoDao.findByExamName(examType); + SubjectFullScore subjectFullScore = subjectFullScoreDao.findById(examTnfoId); + // 本次考试的全科总分 + int sum = Math.toIntExact(subjectFullScore.getYuwen() + subjectFullScore.getShuxue() + subjectFullScore.getYingyu() + subjectFullScore.getWuli() + subjectFullScore.getHuaxue() + + subjectFullScore.getShengwu() + subjectFullScore.getZhengzhi() + subjectFullScore.getDili() + subjectFullScore.getLishi()) - 300; + String oldExamType = null; for (int i = 0; i < examInfoList.size(); i++) { if (examType.equals(examInfoList.get(0).getExamName())){ @@ -348,6 +432,20 @@ public List getExamCoversionTotalSingleInfo(String examCoversionTotalSingleDTO.setWaveGrade(waveGrade);//年级进退名次 examCoversionTotalSingleDTO.setWaveClass(waveClass);//班级进退名次 + examCoversionTotalSingleDTO.setClassNumber(examCoversionTotalSubject.size());//班级人数 + examCoversionTotalSingleDTO.setGradeNumber(gradeExamCoversionTotal.size());// 年级人数 + examCoversionTotalSingleDTO.setSumScore(sum);//总分标准 + examCoversionTotalSingleDTO.setLanguageScore(Math.toIntExact(subjectFullScore.getYuwen()));//语文满分 + examCoversionTotalSingleDTO.setMathScore(Math.toIntExact(subjectFullScore.getShuxue()));//数学满分 + examCoversionTotalSingleDTO.setEnglishScore(Math.toIntExact(subjectFullScore.getYingyu()));//英语满分 + examCoversionTotalSingleDTO.setPhysicalScore(Math.toIntExact(subjectFullScore.getWuli()));// 物理满分 + examCoversionTotalSingleDTO.setChemistryScore(Math.toIntExact(subjectFullScore.getHuaxue()));//化学满分 + examCoversionTotalSingleDTO.setBiologicalScore(Math.toIntExact(subjectFullScore.getShengwu()));//生物满分 + examCoversionTotalSingleDTO.setPoliticalScore(Math.toIntExact(subjectFullScore.getZhengzhi()));// 政治满分 + examCoversionTotalSingleDTO.setHistoryScore(Math.toIntExact(subjectFullScore.getLishi())); //历史满分 + examCoversionTotalSingleDTO.setGeographyScore(Math.toIntExact(subjectFullScore.getDili()));//地理满分 + examCoversionTotalSingleDTO.setScore(String.valueOf(subjectScore.get(0))); + examCoversionTotalSingleDTOList.add(examCoversionTotalSingleDTO); return examCoversionTotalSingleDTOList; } else if (examType.equals(examInfoList.get(i).getExamName())) { @@ -357,19 +455,19 @@ public List getExamCoversionTotalSingleInfo(String } //再次使用原生SQL语句查询,来获取班级年级的排名 - EntityManager entityManager = ntityManagerFactory.createEntityManager(); +// EntityManager entityManager = ntityManagerFactory.createEntityManager(); //上次班级排名 - String oldClassQuerysql = "SELECT * FROM exam_coversion_total WHERE class_id='"+examCoversionTotal.getClassId()+ "' AND exam_type='"+oldExamType+"' ORDER BY "+ subject + " DESC"; - Query oldClass = entityManager.createNativeQuery(oldClassQuerysql, ExamCoversionTotal.class); + String oldClassQuerysql = "SELECT * FROM exam_coversion_total WHERE valid='1' AND school_name='"+schoolName+"' AND class_id='"+examCoversionTotal.getClassId()+ "' AND exam_type='"+oldExamType+"' ORDER BY "+ subject + " DESC"; + Query oldClass = entityManagerDb2.createNativeQuery(oldClassQuerysql, ExamCoversionTotal.class); @SuppressWarnings("unchecked") List oldClassExamCoversionTotal = oldClass.getResultList(); //上次年级排名 - String oldGradeQuerysql = "select * from exam_coversion_total where exam_type='"+oldExamType+"' order by "+ subject + " desc"; - Query oldgGradeQuery = entityManager.createNativeQuery(oldGradeQuerysql, ExamCoversionTotal.class); + String oldGradeQuerysql = "select * from exam_coversion_total where valid='1' AND school_name='"+schoolName+"' AND grade_name='"+gradeName+"'AND exam_type='"+oldExamType+"' order by "+ subject + " desc"; + Query oldgGradeQuery = entityManagerDb2.createNativeQuery(oldGradeQuerysql, ExamCoversionTotal.class); @SuppressWarnings("unchecked") List oldGradeExamCoversionTotal = oldgGradeQuery.getResultList(); - entityManager.close(); + entityManagerDb2.close(); //上次试卷的班级排名map Map oldMapClass = new HashMap<>(); @@ -515,6 +613,8 @@ public List getExamCoversionTotalSingleInfo(String // 年级波动名称,进退名次 int waveGrade = mapGrade.get(stuNumber) - oldMapGrade.get(stuNumber); + + List examCoversionTotalSingleDTOList = new ArrayList<>(); ExamCoversionTotalSingleDTO examCoversionTotalSingleDTO = new ExamCoversionTotalSingleDTO(); examCoversionTotalSingleDTO.setExamCoversionTotal(examCoversionTotal); @@ -522,7 +622,25 @@ public List getExamCoversionTotalSingleInfo(String examCoversionTotalSingleDTO.setGradeRank(mapGrade.get(stuNumber));//年排名 examCoversionTotalSingleDTO.setWaveGrade(waveGrade);//年级进退名次 examCoversionTotalSingleDTO.setWaveClass(waveClass);//班级进退名次 + + examCoversionTotalSingleDTO.setClassNumber(examCoversionTotalSubject.size());//班级人数 + examCoversionTotalSingleDTO.setGradeNumber(gradeExamCoversionTotal.size());// 年级人数 + examCoversionTotalSingleDTO.setSumScore(sum);//总分标准 + examCoversionTotalSingleDTO.setLanguageScore(Math.toIntExact(subjectFullScore.getYuwen()));//语文满分 + examCoversionTotalSingleDTO.setMathScore(Math.toIntExact(subjectFullScore.getShuxue()));//数学满分 + examCoversionTotalSingleDTO.setEnglishScore(Math.toIntExact(subjectFullScore.getYingyu()));//英语满分 + examCoversionTotalSingleDTO.setPhysicalScore(Math.toIntExact(subjectFullScore.getWuli()));// 物理满分 + examCoversionTotalSingleDTO.setChemistryScore(Math.toIntExact(subjectFullScore.getHuaxue()));//化学满分 + examCoversionTotalSingleDTO.setBiologicalScore(Math.toIntExact(subjectFullScore.getShengwu()));//生物满分 + examCoversionTotalSingleDTO.setPoliticalScore(Math.toIntExact(subjectFullScore.getZhengzhi()));// 政治满分 + examCoversionTotalSingleDTO.setHistoryScore(Math.toIntExact(subjectFullScore.getLishi())); //历史满分 + examCoversionTotalSingleDTO.setGeographyScore(Math.toIntExact(subjectFullScore.getDili()));//地理满分 + examCoversionTotalSingleDTO.setScore(String.valueOf(subjectScore.get(0))); + examCoversionTotalSingleDTOList.add(examCoversionTotalSingleDTO); + + //打印出哪个接口,参数值是什么,当前时间,以便记录下当前访问哪个接口等信息,如有有openid则也记录下 + logger.info("getExamCoversionTotalSingleInfo--->"+"stuNumber :"+stuNumber+" "+"examType:"+examType+" subject: "+subject+" time:"+getNowTime()); return examCoversionTotalSingleDTOList; } @@ -542,38 +660,38 @@ public List getExamCoversionTotalSectionInfo(Strin float comprehensive = 0; threeSubject = (float) (examCoversionTotal.getYuwenScore() + examCoversionTotal.getShuxueScore() + examCoversionTotal.getYingyuScore()); comprehensive = (float) (examCoversionTotal.getWuliCoversion() + examCoversionTotal.getHuaxueCoversion() + examCoversionTotal.getShengwuCoversion() + examCoversionTotal.getLishiCoversion() + examCoversionTotal.getDiliCoversion() + examCoversionTotal.getZhengzhiCoversion()); - + String schoolName = examCoversionTotal.getSchoolName();//哪个学校 + String gradeName = examCoversionTotal.getGradeName();//哪个年级,高一还是高二等 //三科的班级排名 - List classRank = examCoversionTotalDao.findByClassIdAndExamType(examCoversionTotal.getClassId(), examType); + List classRank = examCoversionTotalDao.findByClassIdAndExamType(examCoversionTotal.getClassId(), examType,schoolName,gradeName); Map map = new HashMap<>(); for(int i = 0; i < classRank.size(); i++) { for (Object classRankObject[] : classRank) { map.put(classRankObject[0], classRankObject[1]); } } - //将map中的值放到list中,进行排序 - List mapValueList = new ArrayList<>(); - for (Object vaule : map.values()){ - mapValueList.add(String.valueOf(vaule)); - } - //对mapValueList进行降序排序 - Collections.sort(mapValueList, Collections.reverseOrder()); - + //将map中的值放到list中,进行排序 + List mapValueList = new ArrayList<>(); + for (Object vaule : map.values()){ + mapValueList.add(String.valueOf(vaule)); + } + //对mapValueList进行降序排序 + Collections.sort(mapValueList, Collections.reverseOrder()); //三科 班排的第一种方法,第一种方法无需在进行排名,只需要排好序即可 - // mapValueRank存放的是 分值和排名 - Map mapValueRank = new HashMap<>(); - for (int j = 1; j < mapValueList.size(); j++){ - mapValueRank.put(mapValueList.get(0), 1); - if (mapValueList.get(j - 1 ).equals(mapValueList.get(j))){ - mapValueRank.put(mapValueList.get(j), j - 1); - }else { - mapValueRank.put(mapValueList.get(j), j + 1); - } + // mapValueRank存放的是 分值和排名,这个是第二种方法,不用此方法,而且有点问题,mapValueRank有32,而mapValueList有33个排名 + Map mapValueRank = new HashMap<>(); + for (int j = 1; j < mapValueList.size(); j++){ + mapValueRank.put(mapValueList.get(0), 1); + if (mapValueList.get(j - 1 ).equals(mapValueList.get(j))){ + mapValueRank.put(mapValueList.get(j), j - 1); + }else { + mapValueRank.put(mapValueList.get(j), j + 1); } + } //三科年级排名 - List threeSubjectGradeRank = examCoversionTotalDao.findByClassIdAndExamTypeGrade(examType); + List threeSubjectGradeRank = examCoversionTotalDao.findByClassIdAndExamTypeGrade(examType,schoolName,gradeName); Map threeSubjectGradeMap = new HashMap<>(); for (int k = 0; k < threeSubjectGradeRank.size(); k++){ for (Object gradeRankObject[] : threeSubjectGradeRank){ @@ -587,7 +705,7 @@ public List getExamCoversionTotalSectionInfo(Strin Collections.sort(threeSubjectGradeList, Collections.reverseOrder()); //综合的班排名次 - List complexClassRank = examCoversionTotalDao.findByClassIdAndExamTypeComplex(examCoversionTotal.getClassId(), examType); + List complexClassRank = examCoversionTotalDao.findByClassIdAndExamTypeComplex(examCoversionTotal.getClassId(), examType,schoolName,gradeName); Map complexClassMap= new HashMap<>(); for(int i = 0; i < complexClassRank.size(); i++) { for (Object classRankObject[] : complexClassRank) { @@ -601,7 +719,7 @@ public List getExamCoversionTotalSectionInfo(Strin Collections.sort(mapValueListComplex, Collections.reverseOrder()); //综合的年排名次 - List complexGradeRank = examCoversionTotalDao.findByClassIdAndExamTypeComplexGrade(examType); + List complexGradeRank = examCoversionTotalDao.findByClassIdAndExamTypeComplexGrade(examType,schoolName,gradeName); Map complexGradeMap= new HashMap<>(); for(int i = 0; i < complexGradeRank.size(); i++) { for (Object classRankObject[] : complexGradeRank) { @@ -614,7 +732,18 @@ public List getExamCoversionTotalSectionInfo(Strin } Collections.sort(mapValueListComplexGrade, Collections.reverseOrder()); + //本次班级、年级排名情况 + //三科本次年级排名 + int gradeRank = threeSubjectGradeList.indexOf(String.valueOf(threeSubjectGradeMap.get(stuNumber))) + 1; + // 当前的班级排名 + int classrank = mapValueList.indexOf(String.valueOf(map.get(stuNumber))) + 1; + // 综合本次班级排名 + int complexClassrank = mapValueListComplex.indexOf(String.valueOf(complexClassMap.get(stuNumber))) + 1; + // 综合本次年级排名 + int complexGraderank = mapValueListComplexGrade.indexOf(String.valueOf(complexGradeMap.get(stuNumber))) + 1; + List list = new ArrayList<>(); + if (!examCoversionTotal.getWuliCoversion().toString().equals("0.0")){ list.add("物理"); } @@ -624,7 +753,7 @@ public List getExamCoversionTotalSectionInfo(Strin if (!examCoversionTotal.getShengwuCoversion().toString().equals("0.0")){ list.add("生物"); } - if (!examCoversionTotal.getLishiCoversion().toString().equals("0.0")){ + if (!examCoversionTotal.getLishiCoversion().toString().equals("0.0") ){ list.add("历史"); } if (!examCoversionTotal.getDiliCoversion().toString().equals("0.0")){ @@ -634,22 +763,140 @@ public List getExamCoversionTotalSectionInfo(Strin list.add("政治"); } + //显示上次考试的所有信息 + // 获取所有考试列表 + List examInfoList = examInfoDao.findAll(); + if (examInfoList == null || examInfoList.size() == 0) { + info = "查无结果"; + logger.error(info); + throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); + } + String oldExamType = null; + for (int i = 0; i < examInfoList.size(); i++) { + if (examType.equals(examInfoList.get(0).getExamName())){ + info = "本次为首次考试,暂无排名波动情况"; + logger.info(info); + //三科的班级进退步 + int threewaveClass =0; + //三科年级进退名次 + int threewaveGrade = 0; + //综合班级进退名次 + int complexwaveClass = 0; + //综合的年级进退名次 + int complexwaveGrade = 0; + List examCoversionTotalSectionDTOList = new ArrayList<>(); + ExamCoversionTotalSectionDTO examCoversionTotalSectionDTO = new ExamCoversionTotalSectionDTO(); + examCoversionTotalSectionDTO.setExamCoversionTotal(examCoversionTotal); + examCoversionTotalSectionDTO.setThreeSubject(threeSubject); + examCoversionTotalSectionDTO.setComprehensive(comprehensive); + // 求班排的第二中方法,即用排好序的list,取下标法,indexOf:如果元素相同取第一次出现的下标, + examCoversionTotalSectionDTO.setClassRank(classrank); + examCoversionTotalSectionDTO.setGradeRank(gradeRank); + examCoversionTotalSectionDTO.setComplexClassRank(complexClassrank); + examCoversionTotalSectionDTO.setComplexGradeRank(complexGraderank); + //三科和综合的班级、年级进退名次 + examCoversionTotalSectionDTO.setThreeWaveClass(threewaveClass); + examCoversionTotalSectionDTO.setThreeWaveGrade(threewaveGrade); + examCoversionTotalSectionDTO.setComplexWaveClass(complexwaveClass); + examCoversionTotalSectionDTO.setComplexWaveGrade(complexwaveGrade); + examCoversionTotalSectionDTO.setList(list); + examCoversionTotalSectionDTOList.add(examCoversionTotalSectionDTO); + return examCoversionTotalSectionDTOList; + + } else if (examType.equals(examInfoList.get(i).getExamName())) { + //获取上次试卷的名称 + oldExamType = examInfoList.get(i - 1).getExamName(); + } + } + //三科的上次班级排名 + List oldClassRank = examCoversionTotalDao.findByClassIdAndExamType(examCoversionTotal.getClassId(), oldExamType,schoolName,gradeName); + Map oldMap = new HashMap<>(); + for(int i = 0; i < oldClassRank.size(); i++) { + for (Object classRankObject[] : oldClassRank) { + oldMap.put(classRankObject[0], classRankObject[1]); + } + } + //将map中的值放到list中,进行排序 + List oldMapValueList = new ArrayList<>(); + for (Object vaule : oldMap.values()){ + oldMapValueList.add(String.valueOf(vaule)); + } + //对mapValueList进行降序排序 + Collections.sort(oldMapValueList, Collections.reverseOrder()); + + //三科的班级进退步 + int threewaveClass = classrank - (oldMapValueList.indexOf(String.valueOf(oldMap.get(stuNumber))) + 1); + //三科上次年级排名 + List oldThreeSubjectGradeRank = examCoversionTotalDao.findByClassIdAndExamTypeGrade(oldExamType,schoolName,gradeName); + Map oldThreeSubjectGradeMap = new HashMap<>(); + for (int k = 0; k < oldThreeSubjectGradeRank.size(); k++){ + for (Object gradeRankObject[] : oldThreeSubjectGradeRank){ + oldThreeSubjectGradeMap.put(gradeRankObject[0], gradeRankObject[1]); + } + } + List oldThreeSubjectGradeList = new ArrayList<>(); + for (Object threeSubjectValue : oldThreeSubjectGradeMap.values()){ + oldThreeSubjectGradeList.add(String.valueOf(threeSubjectValue)); + } + Collections.sort(oldThreeSubjectGradeList, Collections.reverseOrder()); + + //三科年级进退名次 + int threewaveGrade = gradeRank - (oldThreeSubjectGradeList.indexOf(String.valueOf(oldThreeSubjectGradeMap.get(stuNumber))) + 1); + + //综合的上次班排名次 + List oldComplexClassRank = examCoversionTotalDao.findByClassIdAndExamTypeComplex(examCoversionTotal.getClassId(), oldExamType,schoolName,gradeName); + Map oldComplexClassMap= new HashMap<>(); + for(int i = 0; i < oldComplexClassRank.size(); i++) { + for (Object classRankObject[] : oldComplexClassRank) { + oldComplexClassMap.put(classRankObject[0], classRankObject[1]); + } + } + List oldMapValueListComplex = new ArrayList<>(); + for (Object vaule : oldComplexClassMap.values()){ + oldMapValueListComplex.add(String.valueOf(vaule)); + } + Collections.sort(oldMapValueListComplex, Collections.reverseOrder()); + //综合班级进退名次 + int complexwaveClass = complexClassrank - (oldMapValueListComplex.indexOf(String.valueOf(oldComplexClassMap.get(stuNumber))) + 1); + //综合的上次年排名次 + List oldcomplexGradeRank = examCoversionTotalDao.findByClassIdAndExamTypeComplexGrade(oldExamType,schoolName,gradeName); + Map oldcomplexGradeMap= new HashMap<>(); + for(int i = 0; i < oldcomplexGradeRank.size(); i++) { + for (Object classRankObject[] : oldcomplexGradeRank) { + oldcomplexGradeMap.put(classRankObject[0], classRankObject[1]); + } + } + List oldmapValueListComplexGrade = new ArrayList<>(); + for (Object vaule : oldcomplexGradeMap.values()){ + oldmapValueListComplexGrade.add(String.valueOf(vaule)); + } + Collections.sort(oldmapValueListComplexGrade, Collections.reverseOrder()); + + //综合的年级进退名次 + int complexwaveGrade = complexGraderank - (oldmapValueListComplexGrade.indexOf(String.valueOf(oldcomplexGradeMap.get(stuNumber))) + 1); + List examCoversionTotalSectionDTOList = new ArrayList<>(); ExamCoversionTotalSectionDTO examCoversionTotalSectionDTO = new ExamCoversionTotalSectionDTO(); examCoversionTotalSectionDTO.setExamCoversionTotal(examCoversionTotal); examCoversionTotalSectionDTO.setThreeSubject(threeSubject); examCoversionTotalSectionDTO.setComprehensive(comprehensive); // 求班排的第二中方法,即用排好序的list,取下标法,indexOf:如果元素相同取第一次出现的下标, - examCoversionTotalSectionDTO.setClassRank(mapValueList.indexOf(String.valueOf(map.get(stuNumber))) + 1); + examCoversionTotalSectionDTO.setClassRank(classrank); //第一种方法,此方法 // String key = String.valueOf(map.get(stuNumber));//强转有问题,这样的也有问题,如果小数多(科学计数法)会出问题 // examCoversionTotalSectionDTO.setClassRank(mapValueRank.get(key)); - examCoversionTotalSectionDTO.setGradeRank(threeSubjectGradeList.indexOf(String.valueOf(threeSubjectGradeMap.get(stuNumber))) + 1); + examCoversionTotalSectionDTO.setGradeRank(gradeRank); + + examCoversionTotalSectionDTO.setComplexClassRank(complexClassrank); + examCoversionTotalSectionDTO.setComplexGradeRank(complexGraderank); - examCoversionTotalSectionDTO.setComplexClassRank(mapValueListComplex.indexOf(String.valueOf(complexClassMap.get(stuNumber))) + 1); - examCoversionTotalSectionDTO.setComplexGradeRank(mapValueListComplexGrade.indexOf(String.valueOf(complexGradeMap.get(stuNumber))) + 1); + //三科和综合的班级、年级进退名次 + examCoversionTotalSectionDTO.setThreeWaveClass(threewaveClass); + examCoversionTotalSectionDTO.setThreeWaveGrade(threewaveGrade); + examCoversionTotalSectionDTO.setComplexWaveClass(complexwaveClass); + examCoversionTotalSectionDTO.setComplexWaveGrade(complexwaveGrade); examCoversionTotalSectionDTO.setList(list); examCoversionTotalSectionDTOList.add(examCoversionTotalSectionDTO); @@ -665,13 +912,19 @@ public List getSixRateInfo(String stuNumber, String examType) { logger.error(info); throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); } + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName(); + long star = System.currentTimeMillis(); // 此班级的所有的总分数据 - List coversionTotalList= examCoversionTotalDao.getCoversionTotalByClassIdAndExamType(examCoversionTotal.getClassId(), examType); + List coversionTotalList= examCoversionTotalDao.getCoversionTotalByClassIdAndExamType(examCoversionTotal.getClassId(), examType,schoolName,gradeName); int examTnfoId = examInfoDao.findByExamName(examType); // ExamFullScoreSet examFullScoreSet= examFullScoreSetDao.findByExaminfoId((int) examTnfoId); // SubjectFullScore sbujectFullScore = subjectFullScoreDao.findOne((int) examFullScoreSet.getId()); // int totalScore = (int) (sbujectFullScore.getYingyu() + sbujectFullScore.getShuxue()+sbujectFullScore.getYingyu()+sbujectFullScore.getWuli()+sbujectFullScore.getHuaxue()+sbujectFullScore.getShengwu()+sbujectFullScore.getDili()+sbujectFullScore.getLishi()+sbujectFullScore.getZhengzhi() - 300); - BigInteger tatolscore = examCoversionTotalDao.findSchametotal(examTnfoId); + // BigInteger tatolscore = examCoversionTotalDao.findSchametotal(examTnfoId); //dao放置的位置不对 + BigInteger tatolscore = examFullScoreSetDao.getSchameTotal(examTnfoId); + long end = System.currentTimeMillis(); + System.out.println("sql耗费时间---> "+ String.valueOf(end - star) + "ms"); int score = Integer.parseInt(tatolscore.toString().trim()) - 300; double a = 0, avg = 0, personsum = 0, classtotalscore = 0; double highnumradio; @@ -711,7 +964,8 @@ public List getSixRateInfo(String stuNumber, String examType) { beyondnum++; } } - + long forTime = System.currentTimeMillis(); + System.out.println("for循环耗费时间--->" + String.valueOf(forTime - end) + "ms"); String location = ""; if (examCoversionTotal.getCoversionTotal() >= score * 0.9) { location = "高分区域"; @@ -736,15 +990,1755 @@ public List getSixRateInfo(String stuNumber, String examType) { List sixRateDTOList = new ArrayList<>(); SixRateDTO sixRateDTO = new SixRateDTO(); - sixRateDTO.setHighNumRate(Double.parseDouble(df.format(highnumradio))); - sixRateDTO.setExcellentRate(Double.parseDouble(df.format(excellentratio))); - sixRateDTO.setGoodRate(Double.parseDouble(df.format(goodratio))); - sixRateDTO.setPassRate(Double.parseDouble(df.format(passratio))); - sixRateDTO.setFailRate(Double.parseDouble(df.format(failratio))); - sixRateDTO.setBeyondRate(Double.parseDouble(df.format(beyondradio))); + sixRateDTO.setHighNumRate(highnum); + sixRateDTO.setExcellentRate(excellentnum); + sixRateDTO.setGoodRate(goodnum); + sixRateDTO.setPassRate(passnum); + sixRateDTO.setFailRate(failnum); + sixRateDTO.setBeyondRate(beyondnum); + +// sixRateDTO.setHighNumRate(Double.parseDouble(df.format(highnumradio))); +// sixRateDTO.setExcellentRate(Double.parseDouble(df.format(excellentratio))); +// sixRateDTO.setGoodRate(Double.parseDouble(df.format(goodratio))); +// sixRateDTO.setPassRate(Double.parseDouble(df.format(passratio))); +// sixRateDTO.setFailRate(Double.parseDouble(df.format(failratio))); +// sixRateDTO.setBeyondRate(Double.parseDouble(df.format(beyondradio))); sixRateDTO.setLocationRate(location); sixRateDTOList.add(sixRateDTO); + long entTime = System.currentTimeMillis(); + System.out.println("结束时间-->" + String.valueOf(entTime - star) + "ms"); + // logger.info("getSixRateInfo--->"+"openid:"+openid+" "+"artId:"+artId+" "+"time:"+getNowTime()); + //打印出哪个接口,参数值是什么,当前时间,以便记录下当前访问哪个接口等信息,如有有openid则也记录下 + logger.info("getSixRateInfo--->stuNumber :{}, examType: {}, time: {}",stuNumber,examType,getNowTime()); return sixRateDTOList; } + + @Override + public List getSubjectAnalysisInfo(String stuNumber, String examType) { + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examType); + if (null == examCoversionTotal) { + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName(); + List totalScoreList = examCoversionTotalDao.findByTotalScore(examType,schoolName,gradeName); + int totalScoreRank = totalScoreList.indexOf(Float.parseFloat(examCoversionTotal.getCoversionTotal().toString())) + 1 ; + logger.info("总分的年级排名:{}", totalScoreRank); + //LinkedHashMap将map中的顺序按照添加顺序排列 + Map> map = new LinkedHashMap<>(); + //定义九门课的map + Map yuwenMap = new HashMap<>(); + Map shuxueMap = new HashMap<>(); + Map yingyuMap = new HashMap<>(); + Map wuliMap = new HashMap<>(); + Map huaxueMap = new HashMap<>(); + Map shengwuMap = new HashMap<>(); + Map diliMap = new HashMap<>(); + Map lishiMap = new HashMap<>(); + Map zhengzhiMap = new HashMap<>(); + + // 本次 各单科与总分的比值,即本次考试的学科贡献率 + Map contributionRate = new HashMap<>(); + double language, // 语文 + math, // 数学 + english, // 英语 + physical, // 物理 + chemistry, //化学 + biological, // 生物 + political, //政治 + history, // 历史 + geography; //地理 + //保留两位小数 + DecimalFormat df = new DecimalFormat("#0.00"); + language = examCoversionTotal.getYuwenScore()/ examCoversionTotal.getCoversionTotal(); + math =examCoversionTotal.getShuxueScore() /examCoversionTotal.getCoversionTotal(); + english = examCoversionTotal.getYingyuScore() /examCoversionTotal.getCoversionTotal(); + + // 单科和总分的年级差值 + Map equilibriumDifferenceMap = new HashMap<>(); + + //获取年级总人数 + int gradeSum = examCoversionTotalDao.countByExamTypeAndSchoolNameAndGradeNameAndValid(examType,schoolName,gradeName,1); + //归一化操作,用各科的 排名/各科总人数 得到的率值,来判断降退 + //对比标准为 年级的率值 + float gradeRate = (float) examCoversionTotal.getSchoolIndex() / (float) gradeSum; + + contributionRate.put("语文", df.format(language) + "%"); + List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScore(examType,schoolName,gradeName); + int yuwenGradeRank = yuwenGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getYuwenScore().toString())) + 1; +// equilibriumDifferenceMap.put("语文差值", (int) (examCoversionTotal.getSchoolIndex() - yuwenGradeRank)); + // 语文归一化后的率值 + float yuwenRate = (float) yuwenGradeRank / (float)yuwenGradeExamCoversionTotal.size(); + equilibriumDifferenceMap.put("语文差值", df.format(gradeRate - yuwenRate)); + yuwenMap.put("currentRate", df.format(language) + "%"); // 本次率值 + yuwenMap.put("title", "语文"); + + + contributionRate.put("数学", df.format(math) + "%"); + List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScore(examType,schoolName,gradeName); + int shuxueGradeRank = shuxueGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getShuxueScore().toString())) + 1; +// equilibriumDifferenceMap.put("数学差值", (int) (examCoversionTotal.getSchoolIndex() - shuxueGradeRank )); + //数学归一化后台率值 + float shuxueRate = (float) shuxueGradeRank / (float) shuxueGradeExamCoversionTotal.size(); + equilibriumDifferenceMap.put("数学差值", df.format(gradeRate - shuxueRate)); + shuxueMap.put("currentRate", df.format(math) + "%"); // 本次率值 + shuxueMap.put("title", "数学"); + + + contributionRate.put("英语", df.format(english) + "%"); + List yingyuGradeExamCoversionTotal = examCoversionTotalDao.findByYingyuScore(examType,schoolName,gradeName); + int yingyuGradeRank = yingyuGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getYingyuScore().toString())) + 1; +// equilibriumDifferenceMap.put("英语差值", (int) (examCoversionTotal.getSchoolIndex() - yingyuGradeRank )); + //英语率值 + float yingyuRate = (float) yingyuGradeRank / (float) yingyuGradeExamCoversionTotal.size(); + equilibriumDifferenceMap.put("英语差值", df.format(gradeRate - yingyuRate)); + yingyuMap.put("currentRate", df.format(english) + "%"); // 本次率值 + yingyuMap.put("title", "英语"); + + + if (!examCoversionTotal.getWuliCoversion().toString().equals("0.0")){ + contributionRate.put("物理", df.format(examCoversionTotal.getWuliCoversion() / examCoversionTotal.getCoversionTotal()) + "%"); + wuliMap.put("currentRate", df.format(examCoversionTotal.getWuliCoversion() / examCoversionTotal.getCoversionTotal()) + "%"); + wuliMap.put("title", "物理"); + List wuliGradeExamCoversionTotal = examCoversionTotalDao.findByWuliCoversion(examType,schoolName,gradeName); + int wuliGradeRank = wuliGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getWuliCoversion().toString())) + 1; +// equilibriumDifferenceMap.put("物理差值", (int) (examCoversionTotal.getSchoolIndex() - wuliGradeRank )); + //选考物理的年级总人数 + int wuliSum = examCoversionTotalDao.countByExamTypeAndWuli(examType,schoolName,gradeName); + //物理率值 + float wuliRate = (float) wuliGradeRank / (float) wuliSum; + equilibriumDifferenceMap.put("物理差值", df.format(gradeRate - wuliRate)); + logger.info("物理年级排名:{}",wuliGradeRank); + } + if (!examCoversionTotal.getHuaxueCoversion().toString().equals("0.0")){ + contributionRate.put("化学", df.format(examCoversionTotal.getHuaxueCoversion() /examCoversionTotal.getCoversionTotal()) + "%"); + huaxueMap.put("currentRate", df.format(examCoversionTotal.getHuaxueCoversion() /examCoversionTotal.getCoversionTotal()) + "%");//本次率值 + huaxueMap.put("title", "化学"); + List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversion(examType,schoolName,gradeName); + int huaxueGradeRank = huaxueGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getHuaxueCoversion().toString())) + 1; +// equilibriumDifferenceMap.put("化学差值", (int) (examCoversionTotal.getSchoolIndex()) - huaxueGradeRank ); + //化学选考年级总人数 + int huaxueSum = examCoversionTotalDao.countByExamTypeAndHuaxue(examType,schoolName,gradeName); + //化学率值 + float huaxueRate = (float) huaxueGradeRank / (float) huaxueSum; + equilibriumDifferenceMap.put("化学差值", df.format(gradeRate - huaxueRate) ); + logger.info("化学年级排名:{}",huaxueGradeRank); + } + if (!examCoversionTotal.getShengwuCoversion().toString().equals("0.0")){ + contributionRate.put("生物", df.format(examCoversionTotal.getShengwuCoversion() / examCoversionTotal.getCoversionTotal()) + "%"); + shengwuMap.put("currentRate", df.format(examCoversionTotal.getShengwuCoversion() / examCoversionTotal.getCoversionTotal()) + "%");//本次率值 + shengwuMap.put("title", "生物"); + List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversion(examType,schoolName,gradeName); + int shengwuGradeRank = shengwuGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getShengwuCoversion().toString())) + 1; +// equilibriumDifferenceMap.put("生物差值", (int) (examCoversionTotal.getSchoolIndex() - shengwuGradeRank )); + //生物选考总人数 + int shengwuSum = examCoversionTotalDao.countByExamTypeAndShengwu(examType,schoolName,gradeName); + // 生物率值 + float shengwuRate = (float) shengwuGradeRank / (float) shengwuSum; + equilibriumDifferenceMap.put("生物差值", df.format(gradeRate - shengwuRate)); + logger.info("生物年级排名:{}",shengwuGradeRank); + } + if (!examCoversionTotal.getLishiCoversion().toString().equals("0.0") ){ + contributionRate.put("历史",df.format(examCoversionTotal.getLishiCoversion() / examCoversionTotal.getCoversionTotal()) + "%"); + lishiMap.put("currentRate", df.format(examCoversionTotal.getLishiCoversion() / examCoversionTotal.getCoversionTotal()) + "%");//本次率值 + lishiMap.put("title", "历史"); + List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversion(examType,schoolName,gradeName); + int lishiGradeRank = lishiGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getLishiCoversion().toString())) + 1; +// equilibriumDifferenceMap.put("历史差值", (int) (examCoversionTotal.getSchoolIndex()) - lishiGradeRank ); + //历史选考总人数 + int lishiSum = examCoversionTotalDao.countByExamTypeAndLishi(examType,schoolName,gradeName); + //历史率值 + float lishiRate = (float) lishiGradeRank / (float) lishiSum; + equilibriumDifferenceMap.put("历史差值", df.format(gradeRate - lishiRate) ); + logger.info("历史年级排名:{}",lishiGradeRank); + } + if (!examCoversionTotal.getDiliCoversion().toString().equals("0.0")){ + contributionRate.put("地理", df.format(examCoversionTotal.getDiliCoversion() / examCoversionTotal.getCoversionTotal()) + "%"); + diliMap.put("currentRate",df.format(examCoversionTotal.getDiliCoversion() / examCoversionTotal.getCoversionTotal()) + "%");//本次率值 + diliMap.put("title", "地理"); + List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversion(examType,schoolName,gradeName); + int diliGradeRank = diliGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getDiliCoversion().toString())) + 1; +// equilibriumDifferenceMap.put("地理差值", (int) (examCoversionTotal.getSchoolIndex()) - diliGradeRank ); + //地理选考总人数 + int diliSum = examCoversionTotalDao.countByExamTypeAndDili(examType,schoolName,gradeName); + //地理率值 + float diliRate = (float) diliGradeRank / (float) diliSum; + equilibriumDifferenceMap.put("地理差值", df.format(gradeRate - diliRate)); + logger.info("地理年级排名:{}",diliGradeRank); + } + if (!examCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")){ + contributionRate.put("政治", df.format(examCoversionTotal.getZhengzhiCoversion() / examCoversionTotal.getCoversionTotal()) + "%"); + zhengzhiMap.put("currentRate",df.format(examCoversionTotal.getZhengzhiCoversion() / examCoversionTotal.getCoversionTotal()) + "%");//本次率值 + zhengzhiMap.put("title", "政治"); + List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversion(examType,schoolName,gradeName); + int zhengzhiGradeRank = zhengzhiGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getZhengzhiCoversion().toString())) + 1; +// equilibriumDifferenceMap.put("政治差值", (int) (examCoversionTotal.getSchoolIndex() - zhengzhiGradeRank )); + //政治选考总人数 + int zhengzhiSum = examCoversionTotalDao.countByExamTypeAndZhegnzhi(examType,schoolName,gradeName); + //政治率值 + float zhengzhiRate = (float) zhengzhiGradeRank / (float) zhengzhiSum; + equilibriumDifferenceMap.put("政治差值", df.format(gradeRate - zhengzhiRate)); + logger.info("政治年级排名:{}",zhengzhiGradeRank); + } + logger.info("语文年级排名:{}",yuwenGradeRank); + logger.info("数学年级排名:{}",shuxueGradeRank); + logger.info("英语年级排名:{}",yingyuGradeRank); + + // 获取所有考试名称 + List examInfoList = examInfoDao.findAll(); + if (examInfoList == null || examInfoList.size() == 0) { + info = "查无结果"; + logger.error(info); + throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); + } + + //List allExamName = examInfoDao.getAllExamName(); + String classid = examCoversionTotal.getClassId(); + List allExamName = examCoversionTotalDao.getAllExamNameByStudentNumberAndSchoolNameAndGradeNameAndClassIdAndValid(stuNumber,schoolName,gradeName,classid,1); + String oldExamType = null; + for (int i = 0; i < examInfoList.size(); i++) { + if (examType.equals(examInfoList.get(0).getExamName())) { + info = "本次为首次考试,暂无上次学科贡献率"; + logger.info(info); + List list = new ArrayList<>(); + SubjectAnalysisDTO subjectAnalysisDTO = new SubjectAnalysisDTO(); + subjectAnalysisDTO.setExamCoversionTotal(examCoversionTotal); + subjectAnalysisDTO.setContributionRate(contributionRate); + subjectAnalysisDTO.setEquilibriumDifference(equilibriumDifferenceMap); + subjectAnalysisDTO.setGradeRate(df.format(gradeRate)); + // 本次为首次考试 + map.put("yuwenMap", yuwenMap); + map.put("shuxueMap",shuxueMap); + map.put("yingyuMap",yingyuMap); + if (wuliMap.size() != 0){ + map.put("wuliMap",wuliMap); + } + if (zhengzhiMap.size() != 0){ + map.put("zhengzhiMap",zhengzhiMap); + } + + if (huaxueMap.size() != 0){ + map.put("huaxueMap",huaxueMap); + } + if (lishiMap.size() != 0){ + map.put("lishiMap",lishiMap); + } + + if (shengwuMap.size() != 0){ + map.put("shengwuMap",shengwuMap); + } + if (diliMap.size() != 0){ + map.put("diliMap",diliMap); + } + subjectAnalysisDTO.setMap(map); + + list.add(subjectAnalysisDTO); + return list; + }else if (examType.equals(examInfoList.get(i).getExamName())) { + oldExamType = examInfoList.get(i - 1).getExamName(); + logger.info("求平均贡献率的第三次考试名称: {}", oldExamType); + } + } + //上次考试的成绩 + ExamCoversionTotal oldexamCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, oldExamType); + if (null == oldexamCoversionTotal) { + info = "查询上次考试此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 上次 各单科与总分的比值,即本次考试的学科贡献率 + Map oldcontributionRate = new HashMap<>(); + double oldlanguage, // 语文 + oldmath, // 数学 + oldenglish, // 英语 + oldphysical = 0, // 物理 + oldchemistry = 0, //化学 + oldbiological = 0, // 生物 + oldpolitical = 0, //政治 + oldhistory = 0, // 历史 + oldgeography = 0; //地理 + oldlanguage = oldexamCoversionTotal.getYuwenScore()/ oldexamCoversionTotal.getCoversionTotal(); + oldmath =oldexamCoversionTotal.getShuxueScore() /oldexamCoversionTotal.getCoversionTotal(); + oldenglish = oldexamCoversionTotal.getYingyuScore() /oldexamCoversionTotal.getCoversionTotal(); + oldcontributionRate.put("语文", df.format(oldlanguage) + "%"); + yuwenMap.put("lastRate", df.format(oldlanguage) + "%"); //上次率值 + + oldcontributionRate.put("数学", df.format(oldmath) + "%"); + shuxueMap.put("lastRate", df.format(oldmath) + "%"); // 上次率值 + + oldcontributionRate.put("英语", df.format(oldenglish) + "%"); + yingyuMap.put("lastRate", df.format(oldenglish) + "%");// 上次率值 + if (!oldexamCoversionTotal.getWuliCoversion().toString().equals("0.0")) { + oldphysical = oldexamCoversionTotal.getWuliCoversion() / oldexamCoversionTotal.getCoversionTotal(); + oldcontributionRate.put("物理", df.format(oldphysical) + "%"); + wuliMap.put("lastRate", df.format(oldphysical) + "%"); //上次率值 + } + if (!oldexamCoversionTotal.getHuaxueCoversion().toString().equals("0.0")) { + oldchemistry = oldexamCoversionTotal.getHuaxueCoversion() / oldexamCoversionTotal.getCoversionTotal(); + oldcontributionRate.put("化学", df.format(oldchemistry) + "%"); + huaxueMap.put("lastRate", df.format(oldchemistry) + "%"); //上次率值 + } + if (!oldexamCoversionTotal.getShengwuCoversion().toString().equals("0.0")) { + oldbiological = oldexamCoversionTotal.getShengwuCoversion() / oldexamCoversionTotal.getCoversionTotal(); + oldcontributionRate.put("生物", df.format(oldbiological) + "%"); + shengwuMap.put("lastRate", df.format(oldbiological) + "%"); //上次率值 + } + if (!oldexamCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")) { + oldpolitical = oldexamCoversionTotal.getZhengzhiCoversion() / oldexamCoversionTotal.getCoversionTotal(); + oldcontributionRate.put("政治", df.format(oldpolitical) + "%"); + zhengzhiMap.put("lastRate", df.format(oldpolitical) + "%"); //上次率值 + } + if (!oldexamCoversionTotal.getLishiCoversion().toString().equals("0.0")) { + oldhistory = oldexamCoversionTotal.getLishiCoversion() / oldexamCoversionTotal.getCoversionTotal(); + oldcontributionRate.put("历史", df.format(oldhistory) + "%"); + lishiMap.put("lastRate", df.format(oldhistory) + "%"); //上次率值 + } + if (!oldexamCoversionTotal.getDiliCoversion().toString().equals("0.0")) { + oldgeography = oldexamCoversionTotal.getDiliCoversion() / oldexamCoversionTotal.getCoversionTotal(); + oldcontributionRate.put("地理", df.format(oldgeography) + "%"); + diliMap.put("lastRate", df.format(oldgeography) + "%"); //上次率值 + } + // 判断当前的考试下标在数组中是否是 属于第四次考试,和所有考试次数是否大于 4次 + if ( allExamName.indexOf(examType) < 3 || examInfoList.size() <= 4){ + info = "本次不是首次考试,但考试次数不够四次,暂无前三次的学科贡献率的均值情况"; + logger.info(info); + List list = new ArrayList<>(); + SubjectAnalysisDTO subjectAnalysisDTO = new SubjectAnalysisDTO(); + subjectAnalysisDTO.setExamCoversionTotal(examCoversionTotal); + subjectAnalysisDTO.setContributionRate(contributionRate); + subjectAnalysisDTO.setEquilibriumDifference(equilibriumDifferenceMap); + subjectAnalysisDTO.setGradeRate(df.format(gradeRate)); +// // 上次的考试的学科贡献率 +// subjectAnalysisDTO.setOldcontributionRate(oldcontributionRate); + map.put("yuwenMap", yuwenMap); + map.put("shuxueMap",shuxueMap); + map.put("yingyuMap",yingyuMap); + if (wuliMap.size() != 0){ + map.put("wuliMap",wuliMap); + } + if (zhengzhiMap.size() != 0){ + map.put("zhengzhiMap",zhengzhiMap); + } + + if (huaxueMap.size() != 0){ + map.put("huaxueMap",huaxueMap); + } + if (lishiMap.size() != 0){ + map.put("lishiMap",lishiMap); + } + + if (shengwuMap.size() != 0){ + map.put("shengwuMap",shengwuMap); + } + if (diliMap.size() != 0){ + map.put("diliMap",diliMap); + } + subjectAnalysisDTO.setMap(map); + list.add(subjectAnalysisDTO); + return list; + } + + //求前三次各科贡献率平均值的,第二次考试 + String avgTwoExamType = null; + //求前三次各科贡献率平均值的,第一次考试 + String avgFirstExamType = null; + for (int i = 0; i < examInfoList.size(); i++) { + if (examType.equals(examInfoList.get(i).getExamName())) { + avgTwoExamType = examInfoList.get(i-2).getExamName(); + avgFirstExamType = examInfoList.get(i - 3).getExamName(); + logger.info("求平均贡献率的第一次考试名称: {}", avgFirstExamType); + logger.info("求平均贡献率的第二次考试名称: {}", avgTwoExamType); + } + } + //求前三次各科贡献率平均值的,第二次考试 + ExamCoversionTotal avgTwoexamCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, avgTwoExamType); + if (null == avgTwoexamCoversionTotal) { + info = "前三次各科贡献率平均值的,第二次考试,此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 前三次 学科贡献率的平均值 + Map avgcontributionRate = new HashMap<>(); + double avgTwolanguage, // 语文 + avgTwomath, // 数学 + avgTwoenglish, // 英语 + avgTwophysical = 0, // 物理 + avgTwochemistry = 0, //化学 + avgTwobiological = 0, // 生物 + avgTwopolitical = 0, //政治 + avgTwohistory = 0, // 历史 + avgTwogeography = 0; //地理 + avgTwolanguage = avgTwoexamCoversionTotal.getYuwenScore()/ avgTwoexamCoversionTotal.getCoversionTotal(); + avgTwomath =avgTwoexamCoversionTotal.getShuxueScore() /avgTwoexamCoversionTotal.getCoversionTotal(); + avgTwoenglish = avgTwoexamCoversionTotal.getYingyuScore() /avgTwoexamCoversionTotal.getCoversionTotal(); + + if (!avgTwoexamCoversionTotal.getWuliCoversion().toString().equals("0.0")) { + avgTwophysical = avgTwoexamCoversionTotal.getWuliCoversion() / avgTwoexamCoversionTotal.getCoversionTotal(); + + } + if (!avgTwoexamCoversionTotal.getHuaxueCoversion().toString().equals("0.0")) { + avgTwochemistry = avgTwoexamCoversionTotal.getHuaxueCoversion() / avgTwoexamCoversionTotal.getCoversionTotal(); + + } + if (!avgTwoexamCoversionTotal.getShengwuCoversion().toString().equals("0.0")) { + avgTwobiological = avgTwoexamCoversionTotal.getShengwuCoversion() / avgTwoexamCoversionTotal.getCoversionTotal(); + + } + if (!avgTwoexamCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")) { + avgTwopolitical = avgTwoexamCoversionTotal.getZhengzhiCoversion() / avgTwoexamCoversionTotal.getCoversionTotal(); + + } + if (!avgTwoexamCoversionTotal.getLishiCoversion().toString().equals("0.0")) { + avgTwohistory = avgTwoexamCoversionTotal.getLishiCoversion() / avgTwoexamCoversionTotal.getCoversionTotal(); + + } + if (!avgTwoexamCoversionTotal.getDiliCoversion().toString().equals("0.0")) { + avgTwogeography = avgTwoexamCoversionTotal.getDiliCoversion() / avgTwoexamCoversionTotal.getCoversionTotal(); + + } + ExamCoversionTotal avgFirstexamCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, avgFirstExamType); + if (null == avgFirstexamCoversionTotal) { + info = "前三次各科贡献率平均值的,第一次考试,此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + double avgFirstlanguage, // 语文 + avgFirstmath, // 数学 + avgFirstenglish, // 英语 + avgFirstphysical = 0, // 物理 + avgFirstchemistry = 0, //化学 + avgFirstbiological = 0, // 生物 + avgFirstpolitical = 0, //政治 + avgFirsthistory = 0, // 历史 + avgFirstgeography = 0; //地理 + avgFirstlanguage = avgFirstexamCoversionTotal.getYuwenScore()/ avgFirstexamCoversionTotal.getCoversionTotal(); + avgFirstmath =avgFirstexamCoversionTotal.getShuxueScore() /avgFirstexamCoversionTotal.getCoversionTotal(); + avgFirstenglish = avgFirstexamCoversionTotal.getYingyuScore() /avgFirstexamCoversionTotal.getCoversionTotal(); + if (!avgFirstexamCoversionTotal.getWuliCoversion().toString().equals("0.0")) { + avgFirstphysical = avgFirstexamCoversionTotal.getWuliCoversion() / avgFirstexamCoversionTotal.getCoversionTotal(); + } + if (!avgFirstexamCoversionTotal.getHuaxueCoversion().toString().equals("0.0")) { + avgFirstchemistry = avgFirstexamCoversionTotal.getHuaxueCoversion() / avgFirstexamCoversionTotal.getCoversionTotal(); + } + if (!avgFirstexamCoversionTotal.getShengwuCoversion().toString().equals("0.0")) { + avgFirstbiological = avgFirstexamCoversionTotal.getShengwuCoversion() / avgFirstexamCoversionTotal.getCoversionTotal(); + } + if (!avgFirstexamCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")) { + avgFirstpolitical = avgFirstexamCoversionTotal.getZhengzhiCoversion() / avgFirstexamCoversionTotal.getCoversionTotal(); + } + if (!avgFirstexamCoversionTotal.getLishiCoversion().toString().equals("0.0")) { + avgFirsthistory = avgFirstexamCoversionTotal.getLishiCoversion() / avgFirstexamCoversionTotal.getCoversionTotal(); + } + if (!avgFirstexamCoversionTotal.getDiliCoversion().toString().equals("0.0")) { + avgFirstgeography = avgFirstexamCoversionTotal.getDiliCoversion() / avgFirstexamCoversionTotal.getCoversionTotal(); + } + double avgyuwen = (oldlanguage+avgFirstlanguage+avgTwolanguage) / 3 ; // 语文平均贡献率 + double avgshuxue = (oldmath+avgFirstmath+avgTwomath) / 3; //数学平均贡献率 + double avgyingyu = (oldenglish+avgFirstenglish+avgTwoenglish) / 3;//英语平均贡献率 + // 前三次考试的 各单科的学科贡献率的平均值 + avgcontributionRate.put("语文平均贡献率", df.format(avgyuwen) + "%"); + avgcontributionRate.put("数学平均贡献率", df.format(avgshuxue) + "%"); + avgcontributionRate.put("英语平均贡献率", df.format(avgyingyu ) + "%"); + yuwenMap.put("averageRate",df.format(avgyuwen) + "%"); //语文平均率值 + yuwenMap.put("rateDifference",df.format(language - avgyuwen ));// 率值差: 本次 - 平均率值 + yuwenMap.put("title", "语文"); + shuxueMap.put("averageRate",df.format(avgshuxue) + "%"); //数学平均率值 + shuxueMap.put("rateDifference",df.format(math - avgshuxue ));// 率值差: 本次 - 平均率值 + shuxueMap.put("title", "数学"); + yingyuMap.put("averageRate", df.format(avgyingyu ) + "%");//英语平均贡献率 + yingyuMap.put("rateDifference",df.format(english - avgyingyu));// 率值差: 本次 - 平均率值 + yingyuMap.put("title", "英语"); + + double avgwuli = (oldphysical + avgFirstphysical + avgTwophysical) /3 ; + double avghuaxue = (oldchemistry + avgFirstchemistry + avgTwochemistry) / 3; + double avgshengwu = (oldbiological + avgFirstbiological + avgTwobiological) /3; + double avgzhengzhi = (oldpolitical + avgFirstpolitical +avgTwopolitical) / 3; + double avglishi = ( oldhistory + avgFirsthistory + avgTwohistory) / 3; + double avgdili = (oldgeography + avgFirstgeography + avgTwogeography) / 3; + if (avgwuli != 0){ + avgcontributionRate.put("物理平均贡献率", df.format( avgwuli ) + "%"); + wuliMap.put("title", "物理"); + wuliMap.put("averageRate", df.format(avgwuli ) + "%"); //物理平均率值 + wuliMap.put("rateDifference",df.format(examCoversionTotal.getWuliCoversion() / examCoversionTotal.getCoversionTotal() - avgwuli));// 率值差: 本次 - 平均率值 + } + if (avghuaxue != 0){ + avgcontributionRate.put("化学平均贡献率", df.format( avghuaxue ) + "%"); + huaxueMap.put("title", "化学"); + huaxueMap.put("averageRate", df.format(avghuaxue ) + "%"); + huaxueMap.put("rateDifference",df.format(examCoversionTotal.getHuaxueCoversion() /examCoversionTotal.getCoversionTotal() - avghuaxue));// 率值差: 本次 - 平均率值 + } + if (avgshengwu != 0){ + avgcontributionRate.put("生物平均贡献率", df.format( avgshengwu ) + "%"); + shengwuMap.put("title", "生物"); + shengwuMap.put("averageRate", df.format(avgshengwu ) + "%"); + shengwuMap.put("rateDifference",df.format(examCoversionTotal.getShengwuCoversion() / examCoversionTotal.getCoversionTotal() - avgshengwu));// 率值差: 本次 - 平均率值 + } + if (avgzhengzhi != 0){ + avgcontributionRate.put("政治平均贡献率", df.format( avgzhengzhi ) + "%"); + zhengzhiMap.put("title", "政治"); + zhengzhiMap.put("averageRate", df.format(avgzhengzhi ) + "%"); + zhengzhiMap.put("rateDifference",df.format(examCoversionTotal.getZhengzhiCoversion() / examCoversionTotal.getCoversionTotal() - avgzhengzhi));// 率值差: 本次 - 平均率值 + } + if (avglishi != 0 ){ + avgcontributionRate.put("历史平均贡献率", df.format( avglishi ) + "%"); + lishiMap.put("title", "历史"); + lishiMap.put("averageRate", df.format(avglishi ) + "%"); + lishiMap.put("rateDifference",df.format(examCoversionTotal.getLishiCoversion() / examCoversionTotal.getCoversionTotal() - avglishi));// 率值差: 本次 - 平均率值 + } + if (avgdili != 0 ){ + avgcontributionRate.put("地理平均贡献率", df.format( avgdili ) + "%"); + diliMap.put("title", "地理"); + diliMap.put("averageRate", df.format(avgdili ) + "%"); + diliMap.put("rateDifference",df.format(examCoversionTotal.getDiliCoversion() / examCoversionTotal.getCoversionTotal() - avgdili));// 率值差: 本次 - 平均率值 + } + List list = new ArrayList<>(); + SubjectAnalysisDTO subjectAnalysisDTO = new SubjectAnalysisDTO(); + subjectAnalysisDTO.setExamCoversionTotal(examCoversionTotal); + subjectAnalysisDTO.setContributionRate(contributionRate); + subjectAnalysisDTO.setEquilibriumDifference(equilibriumDifferenceMap); + subjectAnalysisDTO.setGradeRate(df.format(gradeRate)); +// // 上次的考试的学科贡献率 +//// subjectAnalysisDTO.setOldcontributionRate(oldcontributionRate); +//// //前三次考试的 各科学科贡献率的平均值 +//// subjectAnalysisDTO.setAvgcontributionRate(avgcontributionRate); + map.put("yuwenMap", yuwenMap); + map.put("shuxueMap",shuxueMap); + map.put("yingyuMap",yingyuMap); + if (wuliMap.size() != 0){ + map.put("wuliMap",wuliMap); + } + if (zhengzhiMap.size() != 0){ + map.put("zhengzhiMap",zhengzhiMap); + } + + if (huaxueMap.size() != 0){ + map.put("huaxueMap",huaxueMap); + } + if (lishiMap.size() != 0){ + map.put("lishiMap",lishiMap); + } + + if (shengwuMap.size() != 0){ + map.put("shengwuMap",shengwuMap); + } + if (diliMap.size() != 0){ + map.put("diliMap",diliMap); + } + subjectAnalysisDTO.setMap(map); + list.add(subjectAnalysisDTO); + return list; + } + + + @Override + public List getHistoricalAnalysisTotalInfo(String stuNumber, String examType,String openid) { + + //实现动态查询当前考试和之前所有考试的数据信息 + //获取当前用户的考试信息 + ExamCoversionTotal currentExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, examType); + if (null == currentExamCoversionTotal) { + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String schoolName= currentExamCoversionTotal.getSchoolName(); + String gradeName = currentExamCoversionTotal.getGradeName(); + String classid = currentExamCoversionTotal.getClassId(); + // 获取此学校的所有考试名称 + List examInfoList = examCoversionTotalDao.getAllExamNameByStudentNumberAndSchoolNameAndGradeNameAndClassIdAndValid(stuNumber,schoolName,gradeName,classid,1); + if (examInfoList == null || examInfoList.size() == 0) { + info = "查无结果"; + logger.error(info); + throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); + } + Map> mapTotal = new HashMap<>(); // 总的map + //保留两位小数 + DecimalFormat df = new DecimalFormat("#0.00"); + // 当前考试名称在考试列表中的size大小 + int currentExamSize= examInfoList.indexOf(examType) + 1; + for (int i = 0; i < currentExamSize; i++){ + String currentExamName = examInfoList.get(i); + ExamCoversionTotal dynamicExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, currentExamName); + //年级总人数 + int gradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolNameAndGradeName(examInfoList.get(i),1,schoolName,gradeName); + //动态获取用户的所在班级 + String classId = examCoversionTotalDao.getClassIdByStudentNameAndSchoolNameAndExamTypeAndValid("",stuNumber,schoolName,examInfoList.get(i),"1",gradeName); + // 班级总人数 + int classNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolNameAndGradeName(classId, examInfoList.get(i),1,schoolName,gradeName); + float gradeAveragePercentage = Float.parseFloat(dynamicExamCoversionTotal.getSchoolIndex().toString()) / gradeNumber; + float classAveragePercentage = Float.parseFloat(dynamicExamCoversionTotal.getClassIndex().toString()) / classNumber; + //班级总分 + float classSum = examCoversionTotalDao.sumCoversionTotalByClassIdAndExamTypeAndValidAndSchoolName(dynamicExamCoversionTotal.getClassId(), currentExamName,1,schoolName,gradeName); + float classAverage = classSum / classNumber; // 班級平均分 + int examTnfoId = examInfoDao.findByExamName(currentExamName);//当前的考试名称 + SubjectFullScore subjectFullScore = subjectFullScoreDao.findById(examTnfoId);// 当前考试的满分标准 + // 本次考试的全科总分 + int sum = Math.toIntExact(subjectFullScore.getYuwen() + subjectFullScore.getShuxue() + subjectFullScore.getYingyu() + subjectFullScore.getWuli() + subjectFullScore.getHuaxue() + + subjectFullScore.getShengwu() + subjectFullScore.getZhengzhi() + subjectFullScore.getDili() + subjectFullScore.getLishi()) - 300; + float gradeSum = examCoversionTotalDao.sumCoversionTotalByExamTypeAndValidAndSchoolName(currentExamName,1,schoolName,gradeName);//年级总分 + float gradeAverage = gradeSum / gradeNumber; + Map currentMap = new HashMap<>();// 当前考试的信息 + currentMap.put("gradePercentage", df.format(gradeAveragePercentage));// 年级排名的百分率 + currentMap.put("classPercentage", df.format(classAveragePercentage));//班级排名百分率 + currentMap.put("classAverage", df.format(classAverage));//班级平均分 + currentMap.put("gradeAverage",df.format(gradeAverage));// 年级平均分 + currentMap.put("classAveragePercentage", df.format(classAverage / sum));// 班级平均分百分率 + currentMap.put("gradeAveragePercentage", df.format(gradeAverage / sum));// 年级平均分百分率 + currentMap.put("totalScorePercentage", df.format(dynamicExamCoversionTotal.getCoversionTotal() / sum));// 总分百分率 + currentMap.put("title", currentExamName);// 考试名称 + //currentMap.put("examCoversionTotal", String.valueOf(examCoversionTotal));// 考试名称 + currentMap.put("classRank", String.valueOf(dynamicExamCoversionTotal.getClassIndex()));// 总分班排 + currentMap.put("gradeRank", String.valueOf(dynamicExamCoversionTotal.getSchoolIndex()));// 总分年排 + currentMap.put("total", String.valueOf(dynamicExamCoversionTotal.getCoversionTotal()));// 总分年排 + + //将所有currentMap(子map)放到 total(总map)中去 + mapTotal.put(i,currentMap); + } + // 封装dto,传输给controller并显示给前台渲染 + List list = new ArrayList<>(); + HistoricalAnalysisTotalDTO historicalAnalysisTotalDTO = new HistoricalAnalysisTotalDTO(); + historicalAnalysisTotalDTO.setMapTotal(mapTotal); + list.add(historicalAnalysisTotalDTO); + return list; + + + +// //ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examType); +// ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, examType); +// if (null == examCoversionTotal) { +// info = "查询此学生的所有信息失败"; +// logger.error(info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } +// Map> map = new HashMap<>(); // 总的map +// Map currentMap = new HashMap<>();// 当前考试的信息 +// Map lastMap = new HashMap<>();// 上次的考试信息 +// Map perMap = new HashMap<>();// 三次考试中的头一次的考试信息 +// //保留两位小数 +// DecimalFormat df = new DecimalFormat("#0.00"); +// +// String schoolName= examCoversionTotal.getSchoolName(); +// // 年级总人数,这样获取还不太好,如果两个学校的考试名称一样的话,就不对了,可以从用户表中根据 “校名”and“年级”获取 +// //int gradeNumber = examCoversionTotalDao.countByExamType(examType); +// int gradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolName(examType,1,schoolName); +// +// // 班级总人数, +// //int classNumber = examCoversionTotalDao.countByClassIdAndExamType(examCoversionTotal.getClassId(), examType); +// int classNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolName(examCoversionTotal.getClassId(), examType,1,schoolName); +// +// +// float gradeAveragePercentage = Float.parseFloat(examCoversionTotal.getSchoolIndex().toString()) / gradeNumber; +// float classAveragePercentage = Float.parseFloat(examCoversionTotal.getClassIndex().toString()) / classNumber; +// //班级总分:班级分数累加和 +// //float classSum = examCoversionTotalDao.sumCoversionTotalByClassIdAndExamType(examCoversionTotal.getClassId(), examType); +// float classSum = examCoversionTotalDao.sumCoversionTotalByClassIdAndExamTypeAndValidAndSchoolName(examCoversionTotal.getClassId(), examType,1,schoolName); +// +// +// float classAverage = classSum / classNumber; // 班級平均分 +// //float gradeSum = examCoversionTotalDao.sumCoversionTotalByExamType(examType); +// float gradeSum = examCoversionTotalDao.sumCoversionTotalByExamTypeAndValidAndSchoolName(examType,1,schoolName); +// +// float gradeAverage = gradeSum / gradeNumber; +// +// int examTnfoId = examInfoDao.findByExamName(examType);// +// SubjectFullScore subjectFullScore = subjectFullScoreDao.findById(examTnfoId); +// // 本次考试的全科总分 +// int sum = Math.toIntExact(subjectFullScore.getYuwen() + subjectFullScore.getShuxue() + subjectFullScore.getYingyu() + subjectFullScore.getWuli() + subjectFullScore.getHuaxue() +// + subjectFullScore.getShengwu() + subjectFullScore.getZhengzhi() + subjectFullScore.getDili() + subjectFullScore.getLishi()) - 300; +// +// currentMap.put("gradePercentage", df.format(gradeAveragePercentage));// 年级排名的百分率 +// currentMap.put("classPercentage", df.format(classAveragePercentage));//班级排名百分率 +// currentMap.put("classAverage", df.format(classAverage));//班级平均分 +// currentMap.put("gradeAverage",df.format(gradeAverage));// 年级平均分 +// currentMap.put("classAveragePercentage", df.format(classAverage / sum));// 班级平均分百分率 +// currentMap.put("gradeAveragePercentage", df.format(gradeAverage / sum));// 年级平均分百分率 +// currentMap.put("totalScorePercentage", df.format(examCoversionTotal.getCoversionTotal() / sum));// 总分百分率 +// currentMap.put("title", examType);// 考试名称 +// //currentMap.put("examCoversionTotal", String.valueOf(examCoversionTotal));// 考试名称 +// currentMap.put("classRank", String.valueOf(examCoversionTotal.getClassIndex()));// 总分班排 +// currentMap.put("gradeRank", String.valueOf(examCoversionTotal.getSchoolIndex()));// 总分年排 +// currentMap.put("total", String.valueOf(examCoversionTotal.getCoversionTotal()));// 总分年排 +// // 获取此学校的所有考试名称 +// //List examInfoList = examInfoDao.findAll(); +// List examInfoList = examCoversionTotalDao.getAllExamTypeBySchoolName(schoolName); +// +// if (examInfoList == null || examInfoList.size() == 0) { +// info = "查无结果"; +// logger.error(info); +// throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); +// } +// String oldExamType = null; +// for (int i = 0; i < examInfoList.size(); i++) { +// if (examType.equals(examInfoList.get(0))) { +// info = "本次为首次考试,暂无上次考试的信息"; +// logger.info(info); +// List list = new ArrayList<>(); +// HistoricalAnalysisTotalDTO historicalAnalysisTotalDTO = new HistoricalAnalysisTotalDTO(); +// map.put("currentMap",currentMap); +// historicalAnalysisTotalDTO.setMap(map); +// list.add(historicalAnalysisTotalDTO); +// return list; +// }else if (examType.equals(examInfoList.get(i))) { +// oldExamType = examInfoList.get(i - 1); +// logger.info("求历史分析总分的上次考试名称: {}", oldExamType); +// } +// } +// ExamCoversionTotal oldExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, oldExamType); +// if (null == oldExamCoversionTotal) { +// info = "查询此学生的所有信息失败"; +// logger.error(info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } +// // 上次考试年级总人数, +// int oldgradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolName(oldExamType,1,schoolName); +// // 上次考试班级总人数, +// int oldclassNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolName(examCoversionTotal.getClassId(), oldExamType,1,schoolName); +// float oldgradeAveragePercentage = Float.parseFloat(oldExamCoversionTotal.getSchoolIndex().toString()) / oldgradeNumber; +// float oldclassAveragePercentage = Float.parseFloat(oldExamCoversionTotal.getClassIndex().toString()) / oldclassNumber; +// float oldclassSum = examCoversionTotalDao.sumCoversionTotalByClassIdAndExamTypeAndValidAndSchoolName(examCoversionTotal.getClassId(), oldExamType,1,schoolName); +// float oldclassAverage = oldclassSum / oldclassNumber; // 班級平均分 +// float oldgradeSum = examCoversionTotalDao.sumCoversionTotalByExamTypeAndValidAndSchoolName(oldExamType,1,schoolName); +// float oldgradeAverage = oldgradeSum / oldgradeNumber; +// int oldexamTnfoId = examInfoDao.findByExamNameAndSchoolName(oldExamType,schoolName); +// SubjectFullScore oldsubjectFullScore = subjectFullScoreDao.findById(oldexamTnfoId); +// // 本次考试的全科总分 +// int oldsum = Math.toIntExact(oldsubjectFullScore.getYuwen() + oldsubjectFullScore.getShuxue() + oldsubjectFullScore.getYingyu() + oldsubjectFullScore.getWuli() + oldsubjectFullScore.getHuaxue() +// + oldsubjectFullScore.getShengwu() + oldsubjectFullScore.getZhengzhi() + oldsubjectFullScore.getDili() + oldsubjectFullScore.getLishi()) - 300; +// lastMap.put("gradePercentage", df.format(oldgradeAveragePercentage));// 年级排名的百分率 +// lastMap.put("classPercentage", df.format(oldclassAveragePercentage));//班级排名百分率 +// lastMap.put("classAverage", df.format(oldclassAverage));//班级平均分 +// lastMap.put("gradeAverage",df.format(oldgradeAverage));// 年级平均分 +// lastMap.put("classAveragePercentage", df.format(oldclassAverage / oldsum));// 班级平均分百分率 +// lastMap.put("gradeAveragePercentage", df.format(oldgradeAverage / oldsum));// 年级平均分百分率 +// lastMap.put("totalScorePercentage", df.format(oldExamCoversionTotal.getCoversionTotal() / oldsum));// 总分百分率 +// lastMap.put("title", oldExamType);// 考试名称 +// //lastMap.put("examCoversionTotal", String.valueOf(oldExamCoversionTotal));// 考试名称 +// lastMap.put("classRank", String.valueOf(oldExamCoversionTotal.getClassIndex()));// 总分班排 +// lastMap.put("gradeRank", String.valueOf(oldExamCoversionTotal.getSchoolIndex()));// 总分年排 +// lastMap.put("total", String.valueOf(oldExamCoversionTotal.getCoversionTotal()));// 总分年排 +// if (examInfoList.indexOf(oldExamType) != (examInfoList.indexOf(examType) - 1)|| examInfoList.size() <= 3){ +// info = "本次不是首次考试,但选中的本次考试不是 。。。 ,但考试次数不够三次,只有两次考试的信息"; +// logger.info(info); +// List list = new ArrayList<>(); +// HistoricalAnalysisTotalDTO historicalAnalysisTotalDTO = new HistoricalAnalysisTotalDTO(); +// map.put("currentMap",currentMap); +// map.put("lastMap", lastMap); +// historicalAnalysisTotalDTO.setMap(map); +// list.add(historicalAnalysisTotalDTO); +// return list; +// } +// String perExamType = null; +// for (int i = 0; i < examInfoList.size(); i++) { +// if (examType.equals(examInfoList.get(i))) { +// perExamType = examInfoList.get(i-2); +// logger.info("求平均贡献率的第一次考试名称: {}", perExamType); +// +// } +// } +// ExamCoversionTotal perExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, perExamType); +// if (null == perExamCoversionTotal) { +// info = "查询此学生的所有信息失败"; +// logger.error(info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } +// // 上次考试年级总人数, +// int pergradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolName(perExamType,1,schoolName); +// // 上次考试班级总人数, +// int perclassNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolName(perExamCoversionTotal.getClassId(), perExamType,1,schoolName); +// float pergradeAveragePercentage = Float.parseFloat(perExamCoversionTotal.getSchoolIndex().toString()) / pergradeNumber; +// float perclassAveragePercentage = Float.parseFloat(perExamCoversionTotal.getClassIndex().toString()) / perclassNumber; +// float perclassSum = examCoversionTotalDao.sumCoversionTotalByClassIdAndExamTypeAndValidAndSchoolName(perExamCoversionTotal.getClassId(), perExamType,1,schoolName); +// float perclassAverage = perclassSum / perclassNumber; // 班級平均分 +// float pergradeSum = examCoversionTotalDao.sumCoversionTotalByExamTypeAndValidAndSchoolName(perExamType,1,schoolName); +// float pergradeAverage = pergradeSum / pergradeNumber; +// int perexamTnfoId = examInfoDao.findByExamNameAndSchoolName(perExamType,schoolName); +// SubjectFullScore persubjectFullScore = subjectFullScoreDao.findById(perexamTnfoId); +// // 本次考试的全科总分 +// int persum = Math.toIntExact(persubjectFullScore.getYuwen() + persubjectFullScore.getShuxue() + persubjectFullScore.getYingyu() + persubjectFullScore.getWuli() + persubjectFullScore.getHuaxue() +// + persubjectFullScore.getShengwu() + persubjectFullScore.getZhengzhi() + persubjectFullScore.getDili() + persubjectFullScore.getLishi()) - 300; +// perMap.put("gradePercentage", df.format(pergradeAveragePercentage));// 年级排名的百分率 +// perMap.put("classPercentage", df.format(perclassAveragePercentage));//班级排名百分率 +// perMap.put("classAverage", df.format(perclassAverage));//班级平均分 +// perMap.put("gradeAverage",df.format(pergradeAverage));// 年级平均分 +// perMap.put("classAveragePercentage", df.format(perclassAverage / persum));// 班级平均分百分率 +// perMap.put("gradeAveragePercentage", df.format(pergradeAverage / persum));// 年级平均分百分率 +// perMap.put("totalScorePercentage", df.format(perExamCoversionTotal.getCoversionTotal() / persum));// 总分百分率 +// perMap.put("title", perExamType);// 考试名称 +// // perMap.put("examCoversionTotal", String.valueOf(perExamCoversionTotal));// +// perMap.put("classRank", String.valueOf(perExamCoversionTotal.getClassIndex()));// 总分班排 +// perMap.put("gradeRank", String.valueOf(perExamCoversionTotal.getSchoolIndex()));// 总分年排 +// perMap.put("total", String.valueOf(perExamCoversionTotal.getCoversionTotal()));// 总分年排 +// // 封装dto,传输给controller并显示给前台渲染 +// List list = new ArrayList<>(); +// HistoricalAnalysisTotalDTO historicalAnalysisTotalDTO = new HistoricalAnalysisTotalDTO(); +// map.put("currentMap",currentMap); +// map.put("lastMap", lastMap); +// map.put("perMap",perMap); +// historicalAnalysisTotalDTO.setMap(map); +// +// list.add(historicalAnalysisTotalDTO); +// return list; + } + + @Override + public List getHistoricalAnalysisSingleInfo(String stuNumber, String examType, String subject,String openid) { + //实现动态查询当前考试和之前所有考试的数据信息 + //获取当前用户的考试信息 + ExamCoversionTotal currentExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, examType); + if (null == currentExamCoversionTotal) { + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + // 学校名字 + String schoolName= currentExamCoversionTotal.getSchoolName(); + String gradeName = currentExamCoversionTotal.getGradeName(); + String classid = currentExamCoversionTotal.getClassId(); + // 获取此学校的所有考试名称 + List examInfoList = examCoversionTotalDao.getAllExamNameByStudentNumberAndSchoolNameAndGradeNameAndClassIdAndValid(stuNumber,schoolName,gradeName,classid,1); + if (examInfoList == null || examInfoList.size() == 0) { + info = "查无结果"; + logger.error(info); + throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); + } + Map> mapTotal = new HashMap<>(); // 总的map + //保留两位小数 + DecimalFormat df = new DecimalFormat("#0.00"); + // 当前考试名称在考试列表中的size大小 + int currentExamSize= examInfoList.indexOf(examType) + 1; + for (int i = 0; i < currentExamSize; i++){ + String currentExamName = examInfoList.get(i); + ExamCoversionTotal dynamicExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, currentExamName); + //单科班级总分 + String singleClassQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE grade_name='"+gradeName+"'AND class_id='"+dynamicExamCoversionTotal.getClassId()+"' AND exam_type='"+currentExamName+"'AND school_name= '"+schoolName+"' AND valid=1"; + logger.info("查询本次单科班级总分-->" + singleClassQuerysql); + Query singleClassQuery = entityManagerDb2.createNativeQuery(singleClassQuerysql); + List singleClassList = singleClassQuery.getResultList();// 单科班级总分 + //单科年级总分 + String singleGradeQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE grade_name='"+gradeName+"'AND exam_type='"+currentExamName+"'AND school_name= '"+schoolName+"' AND valid=1"; + logger.info("查询本次单科班级总分-->" + singleGradeQuerysql); + Query singleGradeQuery = entityManagerDb2.createNativeQuery(singleGradeQuerysql); + List singleGradeList = singleGradeQuery.getResultList();// 单科班级总分 + entityManagerDb2.close(); + // 年级总人数 + int gradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolNameAndGradeName(currentExamName,1,schoolName,gradeName); + // 班级总人数 + int classNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolNameAndGradeName(dynamicExamCoversionTotal.getClassId(), currentExamName,1,schoolName,gradeName); + double classAverage =Double.parseDouble(singleClassList.get(0).toString()) / classNumber; // 班級平均分 + double gradeAverage =Double.parseDouble(singleGradeList.get(0).toString()) / gradeNumber; // 年级平均分 + int examTnfoId = examInfoDao.findByExamNameAndSchoolName(currentExamName,schoolName); + SubjectFullScore subjectFullScore = subjectFullScoreDao.findById(examTnfoId); + int gradeRank = 0; + int classRank = 0; + double singleScorePercentage = 0; // 单科平均分百分率 + double classAveragePercentage = 0; //班级平均分百分率 + double gradeAveragePercentage = 0; // 年级平均分百分率 + String classId = dynamicExamCoversionTotal.getClassId();//班级id + String total = null; // 单科分数 + if (subject.equals("yuwen_score")){ + List yuwenClassList = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = yuwenClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getYuwenScore().toString())) + 1;// 班级排名 + List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + // 年级排名 + gradeRank = yuwenGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getYuwenScore().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getYuwenScore() / subjectFullScore.getYuwen(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getYuwen(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getYuwen(); + total = dynamicExamCoversionTotal.getYuwenScore().toString(); + }else if (subject.equals("shuxue_score")){ + List shuxueClassList = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = shuxueClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getShuxueScore().toString())) + 1;// 班级排名 + List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + // 年级排名 + gradeRank = shuxueGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getShuxueScore().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getShuxueScore() / subjectFullScore.getShuxue(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getShuxue(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getShuxue(); + total = dynamicExamCoversionTotal.getShuxueScore().toString(); + }else if (subject.equals("yingyu_score")){ + List yingyuClassList = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = yingyuClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getYingyuScore().toString())) + 1;// 班级排名 + + //List yingyuGradeExamCoversionTotal = examCoversionTotalDao.findByYingyuScore(examType); + List yingyuGradeExamCoversionTotal = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + // 年级排名 + gradeRank = yingyuGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getYingyuScore().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getYingyuScore() / subjectFullScore.getYingyu(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getYingyu(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getYingyu(); + total = dynamicExamCoversionTotal.getYingyuScore().toString(); + }else if (subject.equals("wuli_coversion")){ + List wuliClassList = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = wuliClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getWuliCoversion().toString())) + 1;// 班级排名 + + //List wuliGradeExamCoversionTotal = examCoversionTotalDao.findByWuliCoversion(examType); + List wuliGradeExamCoversionTotal = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + gradeRank = wuliGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getWuliCoversion().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getWuliCoversion() / subjectFullScore.getWuli(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getWuli(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getWuli(); + total = dynamicExamCoversionTotal.getWuliCoversion().toString(); + }else if (subject.equals("huaxue_coversion")){ + List huaxueClassList = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = huaxueClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getHuaxueCoversion().toString())) + 1;// 班级排名 + + //List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversion(examType); + List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + gradeRank = huaxueGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getHuaxueCoversion().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getHuaxueCoversion() / subjectFullScore.getHuaxue(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getHuaxue(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getHuaxue(); + total = dynamicExamCoversionTotal.getHuaxueCoversion().toString(); + }else if (subject.equals("shengwu_coversion")){ + List shengwuClassList = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = shengwuClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getShengwuCoversion().toString())) + 1;// 班级排名 + + //List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversion(examType); + List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + gradeRank = shengwuGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getShengwuCoversion().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getShengwuCoversion() / subjectFullScore.getShengwu(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getShengwu(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getShengwu(); + total = dynamicExamCoversionTotal.getShengwuCoversion().toString(); + }else if (subject.equals("lishi_coversion")){ + List lishiClassList = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = lishiClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getLishiCoversion().toString())) + 1;// 班级排名 + + //List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversion(examType); + List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + gradeRank = lishiGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getLishiCoversion().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getLishiCoversion() / subjectFullScore.getLishi(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getLishi(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getLishi(); + total = dynamicExamCoversionTotal.getLishiCoversion().toString(); + }else if (subject.equals("dili_coversion")){ + List diliClassList = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = diliClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getDiliCoversion().toString())) + 1;// 班级排名 + + //List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversion(examType); + List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + gradeRank = diliGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getDiliCoversion().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getDiliCoversion() / subjectFullScore.getDili(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getDili(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getDili(); + total = dynamicExamCoversionTotal.getDiliCoversion().toString(); + }else if (subject.equals("zhengzhi_coversion")){ + List zhengzhiClassList = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValidAndClassId(currentExamName,schoolName, 1,classId,gradeName); + classRank = zhengzhiClassList.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getZhengzhiCoversion().toString())) + 1;// 班级排名 + + //List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversion(examType); + List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValid(currentExamName,schoolName,1,gradeName); + gradeRank = zhengzhiGradeExamCoversionTotal.indexOf(Float.parseFloat(dynamicExamCoversionTotal.getZhengzhiCoversion().toString())) + 1; + singleScorePercentage = dynamicExamCoversionTotal.getZhengzhiCoversion() / subjectFullScore.getZhengzhi(); + classAveragePercentage = (float) classAverage/ subjectFullScore.getZhengzhi(); + gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getZhengzhi(); + total = dynamicExamCoversionTotal.getZhengzhiCoversion().toString(); + } + Map currentMap = new HashMap<>();// 当前考试的信息 + currentMap.put("classRank", df.format(classRank));//班排名 + currentMap.put("gradeRank", df.format(gradeRank));// 年级排名 + currentMap.put("classPercentage", df.format( (float)classRank / classNumber));// 班级排名百分率 + currentMap.put("gradePercentage",df.format((float)gradeRank / gradeNumber));// 年级排名百分率 + currentMap.put("classAverage", df.format(classAverage));// 班级平均分 + currentMap.put("gradeAverage", df.format(gradeAverage));// 年级平均分 + currentMap.put("classAveragePercentage", df.format( classAveragePercentage));// 班级平均分百分率 + currentMap.put("gradeAveragePercentage", df.format( gradeAveragePercentage));// 年级平均分百分率 + currentMap.put("singleScorePercentage", df.format(singleScorePercentage)); // 单科分数的百分率 + currentMap.put("title", currentExamName);// 考试名称 + currentMap.put("total", total);// 单科分数 + + //将所有currentMap(子map)放到 total(总map)中去 + mapTotal.put(i,currentMap); + } + // 封装dto,传输给controller并显示给前台渲染 + List list = new ArrayList<>(); + HistoricalAnalysisSingleDTO historicalAnalysisTotalDTO = new HistoricalAnalysisSingleDTO(); + historicalAnalysisTotalDTO.setMapTotal(mapTotal); + list.add(historicalAnalysisTotalDTO); + return list; + + + + +// ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, examType); +// if (null == examCoversionTotal) { +// info = "查询此学生的所有信息失败"; +// logger.error(info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } +// Map> map = new HashMap<>(); // 总的map +// Map currentMap = new HashMap<>();// 当前考试的信息 +// Map lastMap = new HashMap<>();// 上次的考试信息 +// Map perMap = new HashMap<>();// 前两次的信息 +// // 学校名字 +// String schoolName= examCoversionTotal.getSchoolName(); +// //单科班级总分 +// String singleClassQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE class_id='"+examCoversionTotal.getClassId()+"' AND exam_type='"+examType+"'AND school_name= '"+schoolName+"' AND valid=1"; +// logger.info("查询本次单科班级总分-->" + singleClassQuerysql); +// Query singleClassQuery = entityManagerDb2.createNativeQuery(singleClassQuerysql); +// List singleClassList = singleClassQuery.getResultList();// 单科班级总分 +// +// //单科年级总分 +// String singleGradeQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE exam_type='"+examType+"'AND school_name= '"+schoolName+"' AND valid=1"; +// logger.info("查询本次单科班级总分-->" + singleGradeQuerysql); +// Query singleGradeQuery = entityManagerDb2.createNativeQuery(singleGradeQuerysql); +// List singleGradeList = singleGradeQuery.getResultList();// 单科班级总分 +// +// entityManagerDb2.close(); +// //保留两位小数 +// DecimalFormat df = new DecimalFormat("#0.00"); +// // 年级总人数 +// //int gradeNumber = examCoversionTotalDao.countByExamType(examType); +// int gradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolName(examType,1,schoolName); +// // 班级总人数 +// //int classNumber = examCoversionTotalDao.countByClassIdAndExamType(examCoversionTotal.getClassId(), examType); +// int classNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolName(examCoversionTotal.getClassId(), examType,1,schoolName); +// +// double classAverage =Double.parseDouble(singleClassList.get(0).toString()) / classNumber; // 班級平均分 +// double gradeAverage =Double.parseDouble(singleGradeList.get(0).toString()) / gradeNumber; // 年级平均分 +// +// //int examTnfoId = examInfoDao.findByExamName(examType); +// int examTnfoId = examInfoDao.findByExamNameAndSchoolName(examType,schoolName); +// SubjectFullScore subjectFullScore = subjectFullScoreDao.findById(examTnfoId); +//// // 本次考试的全科总分 +//// int sum = Math.toIntExact(subjectFullScore.getYuwen() + subjectFullScore.getShuxue() + subjectFullScore.getYingyu() + subjectFullScore.getWuli() + subjectFullScore.getHuaxue() +//// + subjectFullScore.getShengwu() + subjectFullScore.getZhengzhi() + subjectFullScore.getDili() + subjectFullScore.getLishi()) - 300; +// int gradeRank = 0; +// int classRank = 0; +// double singleScorePercentage = 0; // 单科平均分百分率 +// double classAveragePercentage = 0; //班级平均分百分率 +// double gradeAveragePercentage = 0; // 年级平均分百分率 +// String classId = examCoversionTotal.getClassId();//班级id +// String total = null; // 单科分数 +// if (subject.equals("yuwen_score")){ +// List yuwenClassList = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = yuwenClassList.indexOf(Float.parseFloat(examCoversionTotal.getYuwenScore().toString())) + 1;// 班级排名 +// +// //List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScore(examType); +// List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValid(examType,schoolName,1); +// // 年级排名 +// gradeRank = yuwenGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getYuwenScore().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getYuwenScore() / subjectFullScore.getYuwen(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getYuwen(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getYuwen(); +// total = examCoversionTotal.getYuwenScore().toString(); +// }else if (subject.equals("shuxue_score")){ +// List shuxueClassList = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = shuxueClassList.indexOf(Float.parseFloat(examCoversionTotal.getShuxueScore().toString())) + 1;// 班级排名 +// +// //List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScore(examType); +// List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValid(examType,schoolName,1); +// // 年级排名 +// gradeRank = shuxueGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getShuxueScore().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getShuxueScore() / subjectFullScore.getShuxue(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getShuxue(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getShuxue(); +// total = examCoversionTotal.getShuxueScore().toString(); +// }else if (subject.equals("yingyu_score")){ +// List yingyuClassList = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = yingyuClassList.indexOf(Float.parseFloat(examCoversionTotal.getYingyuScore().toString())) + 1;// 班级排名 +// +// //List yingyuGradeExamCoversionTotal = examCoversionTotalDao.findByYingyuScore(examType); +// List yingyuGradeExamCoversionTotal = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValid(examType,schoolName,1); +// // 年级排名 +// gradeRank = yingyuGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getYingyuScore().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getYingyuScore() / subjectFullScore.getYingyu(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getYingyu(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getYingyu(); +// total = examCoversionTotal.getYingyuScore().toString(); +// }else if (subject.equals("wuli_coversion")){ +// List wuliClassList = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = wuliClassList.indexOf(Float.parseFloat(examCoversionTotal.getWuliCoversion().toString())) + 1;// 班级排名 +// +// //List wuliGradeExamCoversionTotal = examCoversionTotalDao.findByWuliCoversion(examType); +// List wuliGradeExamCoversionTotal = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValid(examType,schoolName,1); +// gradeRank = wuliGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getWuliCoversion().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getWuliCoversion() / subjectFullScore.getWuli(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getWuli(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getWuli(); +// total = examCoversionTotal.getWuliCoversion().toString(); +// }else if (subject.equals("huaxue_coversion")){ +// List huaxueClassList = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = huaxueClassList.indexOf(Float.parseFloat(examCoversionTotal.getHuaxueCoversion().toString())) + 1;// 班级排名 +// +// //List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversion(examType); +// List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValid(examType,schoolName,1); +// gradeRank = huaxueGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getHuaxueCoversion().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getHuaxueCoversion() / subjectFullScore.getHuaxue(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getHuaxue(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getHuaxue(); +// total = examCoversionTotal.getHuaxueCoversion().toString(); +// }else if (subject.equals("shengwu_coversion")){ +// List shengwuClassList = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = shengwuClassList.indexOf(Float.parseFloat(examCoversionTotal.getShengwuCoversion().toString())) + 1;// 班级排名 +// +// //List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversion(examType); +// List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValid(examType,schoolName,1); +// gradeRank = shengwuGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getShengwuCoversion().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getShengwuCoversion() / subjectFullScore.getShengwu(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getShengwu(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getShengwu(); +// total = examCoversionTotal.getShengwuCoversion().toString(); +// }else if (subject.equals("lishi_coversion")){ +// List lishiClassList = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = lishiClassList.indexOf(Float.parseFloat(examCoversionTotal.getLishiCoversion().toString())) + 1;// 班级排名 +// +// //List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversion(examType); +// List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValid(examType,schoolName,1); +// gradeRank = lishiGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getLishiCoversion().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getLishiCoversion() / subjectFullScore.getLishi(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getLishi(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getLishi(); +// total = examCoversionTotal.getLishiCoversion().toString(); +// }else if (subject.equals("dili_coversion")){ +// List diliClassList = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = diliClassList.indexOf(Float.parseFloat(examCoversionTotal.getDiliCoversion().toString())) + 1;// 班级排名 +// +// //List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversion(examType); +// List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValid(examType,schoolName,1); +// gradeRank = diliGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getDiliCoversion().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getDiliCoversion() / subjectFullScore.getDili(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getDili(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getDili(); +// total = examCoversionTotal.getDiliCoversion().toString(); +// }else if (subject.equals("zhengzhi_coversion")){ +// List zhengzhiClassList = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValidAndClassId(examType,schoolName, 1,classId); +// classRank = zhengzhiClassList.indexOf(Float.parseFloat(examCoversionTotal.getZhengzhiCoversion().toString())) + 1;// 班级排名 +// +// //List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversion(examType); +// List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValid(examType,schoolName,1); +// gradeRank = zhengzhiGradeExamCoversionTotal.indexOf(Float.parseFloat(examCoversionTotal.getZhengzhiCoversion().toString())) + 1; +// singleScorePercentage = examCoversionTotal.getZhengzhiCoversion() / subjectFullScore.getZhengzhi(); +// classAveragePercentage = (float) classAverage/ subjectFullScore.getZhengzhi(); +// gradeAveragePercentage = (float) gradeAverage / subjectFullScore.getZhengzhi(); +// total = examCoversionTotal.getZhengzhiCoversion().toString(); +// } +// currentMap.put("classRank", df.format(classRank));//班排名 +// currentMap.put("gradeRank", df.format(gradeRank));// 年级排名 +// currentMap.put("classPercentage", df.format( (float)classRank / classNumber));// 班级排名百分率 +// currentMap.put("gradePercentage",df.format((float)gradeRank / gradeNumber));// 年级排名百分率 +// currentMap.put("classAverage", df.format(classAverage));// 班级平均分 +// currentMap.put("gradeAverage", df.format(gradeAverage));// 年级平均分 +// currentMap.put("classAveragePercentage", df.format( classAveragePercentage));// 班级平均分百分率 +// currentMap.put("gradeAveragePercentage", df.format( gradeAveragePercentage));// 年级平均分百分率 +// currentMap.put("singleScorePercentage", df.format(singleScorePercentage)); // 单科分数的百分率 +// currentMap.put("title", examType);// 考试名称 +// currentMap.put("total", total);// 单科分数 +// // 获取此学校的所有考试名称 +// List examInfoList = examCoversionTotalDao.getAllExamTypeBySchoolName(schoolName); +// if (examInfoList == null || examInfoList.size() == 0) { +// info = "查无结果"; +// logger.error(info); +// throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION, info); +// } +// String oldExamType = null; +// for (int i = 0; i < examInfoList.size(); i++) { +// if (examType.equals(examInfoList.get(0))) { +// info = "本次为首次考试,暂无上次考试的信息"; +// logger.info(info); +// List list = new ArrayList<>(); +// HistoricalAnalysisSingleDTO historicalAnalysisSingleDTO = new HistoricalAnalysisSingleDTO(); +// map.put("currentMap",currentMap); +// historicalAnalysisSingleDTO.setMap(map); +// list.add(historicalAnalysisSingleDTO); +// return list; +// }else if (examType.equals(examInfoList.get(i))) { +// oldExamType = examInfoList.get(i - 1); +// logger.info("求历史分析单科的上次考试名称: {}", oldExamType); +// } +// } +// ExamCoversionTotal oldExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, oldExamType); +// if (null == oldExamCoversionTotal) { +// info = "查询此学生的所有信息失败"; +// logger.error(info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } +// //old单科班级总分 +// String oldsingleClassQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE class_id='"+oldExamCoversionTotal.getClassId()+"' AND exam_type='"+oldExamType+"'AND school_name= '"+schoolName+"' AND valid=1"; +// logger.info("查询本次单科班级总分-->" + singleClassQuerysql); +// Query oldsingleClassQuery = entityManagerDb2.createNativeQuery(oldsingleClassQuerysql); +// List oldsingleClassList = oldsingleClassQuery.getResultList();// old单科班级总分 +// +// //old单科年级总分 +// String oldsingleGradeQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE exam_type='"+oldExamType+"'AND school_name= '"+schoolName+"' AND valid=1"; +// logger.info("查询本次单科班级总分-->" + oldsingleGradeQuerysql); +// Query oldsingleGradeQuery = entityManagerDb2.createNativeQuery(oldsingleGradeQuerysql); +// List oldsingleGradeList = oldsingleGradeQuery.getResultList();// old单科班级总分 +// +// entityManagerDb2.close(); +// // old年级总人数 +// int oldgradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolName(oldExamType,1,schoolName); +// // old班级总人数 +// int oldclassNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolName(oldExamCoversionTotal.getClassId(), oldExamType,1,schoolName); +// double oldclassAverage =Double.parseDouble(oldsingleClassList.get(0).toString()) / oldclassNumber; // old班級平均分 +// double oldgradeAverage =Double.parseDouble(oldsingleGradeList.get(0).toString()) / oldgradeNumber; // old年级平均分 +// +// int oldexamTnfoId = examInfoDao.findByExamNameAndSchoolName(oldExamType,schoolName); +// SubjectFullScore oldsubjectFullScore = subjectFullScoreDao.findById(oldexamTnfoId); +// int oldgradeRank = 0; +// int oldclassRank = 0; +// double oldsingleScorePercentage = 0; // 单科平均分百分率 +// double oldclassAveragePercentage = 0; //班级平均分百分率 +// double oldgradeAveragePercentage = 0; // 年级平均分百分率 +// String oldclassId = oldExamCoversionTotal.getClassId();//班级id +// String oldTotal = null;//单科分数 +// if (subject.equals("yuwen_score")){ +// List yuwenClassList = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = yuwenClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getYuwenScore().toString())) + 1;// 班级排名 +// +// //List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScore(examType); +// List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValid(oldExamType,schoolName,1); +// // 年级排名 +// oldgradeRank = yuwenGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getYuwenScore().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getYuwenScore() / oldsubjectFullScore.getYuwen(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getYuwen(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getYuwen(); +// oldTotal = oldExamCoversionTotal.getYuwenScore().toString(); +// }else if (subject.equals("shuxue_score")){ +// List shuxueClassList = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = shuxueClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getShuxueScore().toString())) + 1;// 班级排名 +// +// //List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScore(examType); +// List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValid(oldExamType,schoolName,1); +// // 年级排名 +// oldgradeRank = shuxueGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getShuxueScore().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getShuxueScore() / oldsubjectFullScore.getShuxue(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getShuxue(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getShuxue(); +// oldTotal = oldExamCoversionTotal.getShuxueScore().toString(); +// }else if (subject.equals("yingyu_score")){ +// List yingyuClassList = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = yingyuClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getYingyuScore().toString())) + 1;// 班级排名 +// +// List yingyuGradeExamCoversionTotal = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValid(oldExamType,schoolName,1); +// // 年级排名 +// oldgradeRank = yingyuGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getYingyuScore().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getYingyuScore() / oldsubjectFullScore.getYingyu(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getYingyu(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getYingyu(); +// oldTotal = oldExamCoversionTotal.getYingyuScore().toString(); +// }else if (subject.equals("wuli_coversion")){ +// List wuliClassList = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = wuliClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getWuliCoversion().toString())) + 1;// 班级排名 +// +// List wuliGradeExamCoversionTotal = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValid(oldExamType,schoolName,1); +// oldgradeRank = wuliGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getWuliCoversion().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getWuliCoversion() / oldsubjectFullScore.getWuli(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getWuli(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getWuli(); +// oldTotal = oldExamCoversionTotal.getWuliCoversion().toString(); +// }else if (subject.equals("huaxue_coversion")){ +// List huaxueClassList = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = huaxueClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getHuaxueCoversion().toString())) + 1;// 班级排名 +// +// //List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversion(examType); +// List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValid(oldExamType,schoolName,1); +// oldgradeRank = huaxueGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getHuaxueCoversion().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getHuaxueCoversion() / oldsubjectFullScore.getHuaxue(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getHuaxue(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getHuaxue(); +// oldTotal = oldExamCoversionTotal.getHuaxueCoversion().toString(); +// }else if (subject.equals("shengwu_coversion")){ +// List shengwuClassList = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = shengwuClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getShengwuCoversion().toString())) + 1;// 班级排名 +// +// //List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversion(examType); +// List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValid(oldExamType,schoolName,1); +// oldgradeRank = shengwuGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getShengwuCoversion().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getShengwuCoversion() / oldsubjectFullScore.getShengwu(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getShengwu(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getShengwu(); +// oldTotal = oldExamCoversionTotal.getShengwuCoversion().toString(); +// }else if (subject.equals("lishi_coversion")){ +// List lishiClassList = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = lishiClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getLishiCoversion().toString())) + 1;// 班级排名 +// +// //List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversion(examType); +// List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValid(oldExamType,schoolName,1); +// oldgradeRank = lishiGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getLishiCoversion().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getLishiCoversion() / oldsubjectFullScore.getLishi(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getLishi(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getLishi(); +// oldTotal = oldExamCoversionTotal.getLishiCoversion().toString(); +// }else if (subject.equals("dili_coversion")){ +// List diliClassList = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = diliClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getDiliCoversion().toString())) + 1;// 班级排名 +// +// //List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversion(examType); +// List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValid(oldExamType,schoolName,1); +// oldgradeRank = diliGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getDiliCoversion().toString())) + 1; +// singleScorePercentage = oldExamCoversionTotal.getDiliCoversion() / oldsubjectFullScore.getDili(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getDili(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getDili(); +// oldTotal = oldExamCoversionTotal.getDiliCoversion().toString(); +// }else if (subject.equals("zhengzhi_coversion")){ +// List zhengzhiClassList = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValidAndClassId(oldExamType,schoolName, 1,classId); +// oldclassRank = zhengzhiClassList.indexOf(Float.parseFloat(oldExamCoversionTotal.getZhengzhiCoversion().toString())) + 1;// 班级排名 +// +// //List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversion(examType); +// List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValid(oldExamType,schoolName,1); +// oldgradeRank = zhengzhiGradeExamCoversionTotal.indexOf(Float.parseFloat(oldExamCoversionTotal.getZhengzhiCoversion().toString())) + 1; +// oldsingleScorePercentage = oldExamCoversionTotal.getZhengzhiCoversion() / oldsubjectFullScore.getZhengzhi(); +// oldclassAveragePercentage = (float) oldclassAverage/ oldsubjectFullScore.getZhengzhi(); +// oldgradeAveragePercentage = (float) oldgradeAverage / oldsubjectFullScore.getZhengzhi(); +// oldTotal = oldExamCoversionTotal.getZhengzhiCoversion().toString(); +// } +// lastMap.put("classRank", df.format(oldclassRank));//班排名 +// lastMap.put("gradeRank", df.format(oldgradeRank));// 年级排名 +// lastMap.put("classPercentage", df.format( (float)oldclassRank / oldclassNumber));// 班级排名百分率 +// lastMap.put("gradePercentage",df.format((float)oldgradeRank / oldgradeNumber));// 年级排名百分率 +// lastMap.put("classAverage", df.format(oldclassAverage));// 班级平均分 +// lastMap.put("gradeAverage", df.format(oldgradeAverage));// 年级平均分 +// lastMap.put("classAveragePercentage", df.format( oldclassAveragePercentage));// 班级平均分百分率 +// lastMap.put("gradeAveragePercentage", df.format( oldgradeAveragePercentage));// 年级平均分百分率 +// lastMap.put("singleScorePercentage", df.format(oldsingleScorePercentage)); // 单科分数的百分率 +// lastMap.put("title", oldExamType);// 考试名称 +// lastMap.put("total", oldTotal);// 单科分数 +// if (examInfoList.indexOf(oldExamType) != (examInfoList.indexOf(examType) - 1)|| examInfoList.size() <= 3){ +// info = "本次不是首次考试,但选中的本次考试不是 。。。 ,但考试次数不够三次,只有两次考试的信息"; +// logger.info(info); +// List list = new ArrayList<>(); +// HistoricalAnalysisSingleDTO historicalAnalysisSingleDTO = new HistoricalAnalysisSingleDTO(); +// map.put("currentMap",currentMap); +// map.put("lastMap",lastMap); +// historicalAnalysisSingleDTO.setMap(map); +// list.add(historicalAnalysisSingleDTO); +// return list; +// } +// String perExamType = null; +// for (int i = 0; i < examInfoList.size(); i++) { +// if (examType.equals(examInfoList.get(i))) { +// perExamType = examInfoList.get(i-2); +// logger.info("求平均贡献率的第一次考试名称: {}", perExamType); +// } +// } +// ExamCoversionTotal perExamCoversionTotal = examCoversionTotalDao.findByStudentNumberOrOpenidAndExamType(stuNumber, openid, perExamType); +// if (null == perExamCoversionTotal) { +// info = "查询此学生的所有信息失败"; +// logger.error(info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } +// //old单科班级总分 +// String persingleClassQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE class_id='"+perExamCoversionTotal.getClassId()+"' AND exam_type='"+perExamType+"'AND school_name= '"+schoolName+"' AND valid=1"; +// logger.info("查询本次单科班级总分-->" + persingleClassQuerysql); +// Query persingleClassQuery = entityManagerDb2.createNativeQuery(persingleClassQuerysql); +// List persingleClassList = persingleClassQuery.getResultList();// old单科班级总分 +// +// //old单科年级总分 +// String persingleGradeQuerysql = "SELECT SUM("+subject+") FROM exam_coversion_total WHERE exam_type='"+perExamType+"'AND school_name= '"+schoolName+"' AND valid=1"; +// logger.info("查询本次单科班级总分-->" + persingleGradeQuerysql); +// Query persingleGradeQuery = entityManagerDb2.createNativeQuery(persingleGradeQuerysql); +// List persingleGradeList = persingleGradeQuery.getResultList();// old单科班级总分 +// +// entityManagerDb2.close(); +// // old年级总人数 +// int pergradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolName(perExamType,1,schoolName); +// // old班级总人数 +// int perclassNumber = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolName(perExamCoversionTotal.getClassId(), perExamType,1,schoolName); +// double perclassAverage =Double.parseDouble(persingleClassList.get(0).toString()) / perclassNumber; // old班級平均分 +// double pergradeAverage =Double.parseDouble(persingleGradeList.get(0).toString()) / pergradeNumber; // old年级平均分 +// +// int perexamTnfoId = examInfoDao.findByExamNameAndSchoolName(perExamType,schoolName); +// SubjectFullScore persubjectFullScore = subjectFullScoreDao.findById(perexamTnfoId); +// int pergradeRank = 0; +// int perclassRank = 0; +// double persingleScorePercentage = 0; // 单科平均分百分率 +// double perclassAveragePercentage = 0; //班级平均分百分率 +// double pergradeAveragePercentage = 0; // 年级平均分百分率 +// String perclassId = oldExamCoversionTotal.getClassId();//班级id +// String perTotal = null; // 单科分数 +// if (subject.equals("yuwen_score")){ +// List yuwenClassList = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = yuwenClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getYuwenScore().toString())) + 1;// 班级排名 +// +// //List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScore(perExamType); +// List yuwenGradeExamCoversionTotal = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValid(perExamType,schoolName,1); +// // 年级排名 +// pergradeRank = yuwenGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getYuwenScore().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getYuwenScore() / persubjectFullScore.getYuwen(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getYuwen(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getYuwen(); +// perTotal = perExamCoversionTotal.getYuwenScore().toString(); +// }else if (subject.equals("shuxue_score")){ +// List shuxueClassList = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = shuxueClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getShuxueScore().toString())) + 1;// 班级排名 +// +// //List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScore(perExamType); +// List shuxueGradeExamCoversionTotal = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValid(perExamType,schoolName,1); +// // 年级排名 +// pergradeRank = shuxueGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getShuxueScore().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getShuxueScore() / persubjectFullScore.getShuxue(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getShuxue(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getShuxue(); +// perTotal = perExamCoversionTotal.getShuxueScore().toString(); +// }else if (subject.equals("yingyu_score")){ +// List yingyuClassList = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = yingyuClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getYingyuScore().toString())) + 1;// 班级排名 +// +// List yingyuGradeExamCoversionTotal = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValid(perExamType,schoolName,1); +// // 年级排名 +// pergradeRank = yingyuGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getYingyuScore().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getYingyuScore() / persubjectFullScore.getYingyu(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getYingyu(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getYingyu(); +// perTotal = perExamCoversionTotal.getYingyuScore().toString(); +// }else if (subject.equals("wuli_coversion")){ +// List wuliClassList = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = wuliClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getWuliCoversion().toString())) + 1;// 班级排名 +// +// List wuliGradeExamCoversionTotal = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValid(perExamType,schoolName,1); +// pergradeRank = wuliGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getWuliCoversion().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getWuliCoversion() / persubjectFullScore.getWuli(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getWuli(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getWuli(); +// perTotal = perExamCoversionTotal.getWuliCoversion().toString(); +// }else if (subject.equals("huaxue_coversion")){ +// List huaxueClassList = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = huaxueClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getHuaxueCoversion().toString())) + 1;// 班级排名 +// +// //List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversion(perExamType); +// List huaxueGradeExamCoversionTotal = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValid(perExamType,schoolName,1); +// pergradeRank = huaxueGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getHuaxueCoversion().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getHuaxueCoversion() / persubjectFullScore.getHuaxue(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getHuaxue(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getHuaxue(); +// perTotal = perExamCoversionTotal.getHuaxueCoversion().toString(); +// }else if (subject.equals("shengwu_coversion")){ +// List shengwuClassList = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = shengwuClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getShengwuCoversion().toString())) + 1;// 班级排名 +// +// //List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversion(perExamType); +// List shengwuGradeExamCoversionTotal = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValid(perExamType,schoolName,1); +// pergradeRank = shengwuGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getShengwuCoversion().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getShengwuCoversion() / persubjectFullScore.getShengwu(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getShengwu(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getShengwu(); +// perTotal = perExamCoversionTotal.getShengwuCoversion().toString(); +// }else if (subject.equals("lishi_coversion")){ +// List lishiClassList = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = lishiClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getLishiCoversion().toString())) + 1;// 班级排名 +// +// //List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversion(perExamType); +// List lishiGradeExamCoversionTotal = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValid(perExamType,schoolName,1); +// pergradeRank = lishiGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getLishiCoversion().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getLishiCoversion() / persubjectFullScore.getLishi(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getLishi(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getLishi(); +// perTotal = perExamCoversionTotal.getLishiCoversion().toString(); +// }else if (subject.equals("dili_coversion")){ +// List diliClassList = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = diliClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getDiliCoversion().toString())) + 1;// 班级排名 +// +// //List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversion(perExamType); +// List diliGradeExamCoversionTotal = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValid(perExamType,schoolName,1); +// pergradeRank = diliGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getDiliCoversion().toString())) + 1; +// singleScorePercentage = perExamCoversionTotal.getDiliCoversion() / persubjectFullScore.getDili(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getDili(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getDili(); +// perTotal = perExamCoversionTotal.getDiliCoversion().toString(); +// }else if (subject.equals("zhengzhi_coversion")){ +// List zhengzhiClassList = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValidAndClassId(perExamType,schoolName, 1,classId); +// perclassRank = zhengzhiClassList.indexOf(Float.parseFloat(perExamCoversionTotal.getZhengzhiCoversion().toString())) + 1;// 班级排名 +// +// //List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversion(perExamType); +// List zhengzhiGradeExamCoversionTotal = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValid(perExamType,schoolName,1); +// pergradeRank = zhengzhiGradeExamCoversionTotal.indexOf(Float.parseFloat(perExamCoversionTotal.getZhengzhiCoversion().toString())) + 1; +// persingleScorePercentage = perExamCoversionTotal.getZhengzhiCoversion() / persubjectFullScore.getZhengzhi(); +// perclassAveragePercentage = (float) perclassAverage/ persubjectFullScore.getZhengzhi(); +// pergradeAveragePercentage = (float) pergradeAverage / persubjectFullScore.getZhengzhi(); +// perTotal = perExamCoversionTotal.getZhengzhiCoversion().toString(); +// } +// perMap.put("classRank", df.format(perclassRank));//班排名 +// perMap.put("gradeRank", df.format(pergradeRank));// 年级排名 +// perMap.put("classPercentage", df.format( (float)perclassRank / perclassNumber));// 班级排名百分率 +// perMap.put("gradePercentage",df.format((float)pergradeRank / pergradeNumber));// 年级排名百分率 +// perMap.put("classAverage", df.format(perclassAverage));// 班级平均分 +// perMap.put("gradeAverage", df.format(pergradeAverage));// 年级平均分 +// perMap.put("classAveragePercentage", df.format( perclassAveragePercentage));// 班级平均分百分率 +// perMap.put("gradeAveragePercentage", df.format( pergradeAveragePercentage));// 年级平均分百分率 +// perMap.put("singleScorePercentage", df.format(persingleScorePercentage)); // 单科分数的百分率 +// perMap.put("title", perExamType);// 考试名称 +// perMap.put("total", perTotal);// 单科分数 +// +// // 封装dto,传输给controller并显示给前台渲染 +// List list = new ArrayList<>(); +// HistoricalAnalysisSingleDTO historicalAnalysisSingleDTO = new HistoricalAnalysisSingleDTO(); +// +// map.put("currentMap",currentMap); +// map.put("lastMap",lastMap); +// map.put("perMap",perMap); +// historicalAnalysisSingleDTO.setMap(map); +// list.add(historicalAnalysisSingleDTO); +// list.add(historicalAnalysisSingleDTO); +// return list; + } + + + @Override + public List getAsahiChartAllRate(String stuNumber, String examType) { + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examType); + if (null == examCoversionTotal) { + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + int examTnfoId = examInfoDao.findByExamName(examType); + SubjectFullScore subjectFullScore = subjectFullScoreDao.findById(examTnfoId); + // 本次考试的全科总分 + int sum = Math.toIntExact(subjectFullScore.getYuwen() + subjectFullScore.getShuxue() + subjectFullScore.getYingyu() + subjectFullScore.getWuli() + subjectFullScore.getHuaxue() + + subjectFullScore.getShengwu() + subjectFullScore.getZhengzhi() + subjectFullScore.getDili() + subjectFullScore.getLishi()) - 300; + // 三科比率值 + double threeSubject = (examCoversionTotal.getYuwenScore()+examCoversionTotal.getShuxueScore()+examCoversionTotal.getYingyuScore()) /(subjectFullScore.getYingyu()+subjectFullScore.getShuxue()+subjectFullScore.getYingyu()); + +// ImportConversionScore importConversionScore = importConversionScoreDao.findByStudentMachineCardAndExamType(examCoversionTotal.getStudentMachineCard(), examCoversionTotal.getExamType()); +// if (importConversionScore == null){ +// info = "查无此数据"; +// logger.error(info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } + + // 综合分数、真实所选的科目分数之和 + double comprehensiveScore = 0.00; + // 综合的标准满分, 真实所选的科目分数之和 + int comprehensiveStandardScore = 0; + + //保留两位小数 + DecimalFormat df = new DecimalFormat("#0.00"); + + // 所有真实科目的率值,k: 科目名称;v:所对应的率值 + Map allSubjectRateMap = new HashMap<>(); + double languageScoreRate = examCoversionTotal.getYuwenScore() / subjectFullScore.getYuwen(); + allSubjectRateMap.put("language", df.format(languageScoreRate));//语文 + double mathScoreRate = examCoversionTotal.getShuxueScore() / subjectFullScore.getShuxue(); + allSubjectRateMap.put("math",df.format(mathScoreRate)); + double englishScoreRate = examCoversionTotal.getYingyuScore() / subjectFullScore.getYingyu(); + allSubjectRateMap.put("english",df.format(englishScoreRate)); + + if (!examCoversionTotal.getWuliCoversion().toString().equals("0.0")){ + comprehensiveScore += examCoversionTotal.getWuliCoversion(); + comprehensiveStandardScore += subjectFullScore.getWuli(); + double physicalScoreRate = examCoversionTotal.getWuliCoversion() / subjectFullScore.getWuli(); + allSubjectRateMap.put("physical",df.format(physicalScoreRate)); + + } + if (!examCoversionTotal.getHuaxueCoversion().toString().equals("0.0")){ + comprehensiveScore =+ examCoversionTotal.getHuaxueCoversion(); + comprehensiveStandardScore += subjectFullScore.getHuaxue(); + double chemistryScoreRate = examCoversionTotal.getHuaxueCoversion() / subjectFullScore.getHuaxue(); + allSubjectRateMap.put("chemistry",df.format(chemistryScoreRate)); + } + if (!examCoversionTotal.getShengwuCoversion().toString().equals("0.0")){ + comprehensiveScore =+ examCoversionTotal.getShengwuCoversion(); + comprehensiveStandardScore += subjectFullScore.getShengwu(); + double biologicalScoreRate = examCoversionTotal.getShengwuCoversion() / subjectFullScore.getShengwu(); + allSubjectRateMap.put("biological",df.format(biologicalScoreRate)); + } + if (!examCoversionTotal.getLishiCoversion().toString().equals("0.0") ){ + comprehensiveScore =+ examCoversionTotal.getLishiCoversion(); + comprehensiveStandardScore += subjectFullScore.getLishi(); + double historyScoreRate = examCoversionTotal.getLishiCoversion() / subjectFullScore.getLishi(); + allSubjectRateMap.put("history",df.format(historyScoreRate)); + } + if (!examCoversionTotal.getDiliCoversion().toString().equals("0.0")){ + comprehensiveScore =+ examCoversionTotal.getDiliCoversion(); + comprehensiveStandardScore += subjectFullScore.getDili(); + double geographyScoreRate = examCoversionTotal.getDiliCoversion() / subjectFullScore.getDili(); + allSubjectRateMap.put("geography",df.format(geographyScoreRate)); + } + if (!examCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")){ + comprehensiveScore =+ examCoversionTotal.getZhengzhiCoversion(); + comprehensiveStandardScore += subjectFullScore.getZhengzhi(); + double biologicalScoreRate = examCoversionTotal.getZhengzhiCoversion() / subjectFullScore.getZhengzhi(); + allSubjectRateMap.put("biological",df.format(biologicalScoreRate)); + } + + List list = new ArrayList<>(); + AsahiChartAllRateDTO asahiChartAllRateDTO = new AsahiChartAllRateDTO(); + asahiChartAllRateDTO.setTotalScoreRate(df.format(examCoversionTotal.getCoversionTotal() / sum)); + asahiChartAllRateDTO.setThreeSubjectsRate(df.format(threeSubject)); + asahiChartAllRateDTO.setComprehensiveRate(df.format(comprehensiveScore / comprehensiveStandardScore)); + asahiChartAllRateDTO.setAllSubjectRateMap(allSubjectRateMap); + + list.add(asahiChartAllRateDTO); + return list; + } + + @Override + public List getScoreReport(String stuNumber, String examType) { + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examType); + if (null == examCoversionTotal) { + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName(); + //保留两位小数 + DecimalFormat df = new DecimalFormat("#0.00"); + int examTnfoId = examInfoDao.findByExamName(examType); + SubjectFullScore subjectFullScore = subjectFullScoreDao.findById(examTnfoId); + // 本次考试的全科总分 + int sum = Math.toIntExact(subjectFullScore.getYuwen() + subjectFullScore.getShuxue() + subjectFullScore.getYingyu() + subjectFullScore.getWuli() + subjectFullScore.getHuaxue() + + subjectFullScore.getShengwu() + subjectFullScore.getZhengzhi() + subjectFullScore.getDili() + subjectFullScore.getLishi()) - 300; + //获取年级平均分 + String totalAverage = examCoversionTotalDao.totalAverageByExamType(examType,schoolName,gradeName); + //查询单科的所有年级平均分 + List subjectDTOList = subjectDTODao.avgSubject(examType); + SubjectDTO subjectDTO = subjectDTOList.get(0); + logger.info(String.valueOf(subjectDTO)); + // Map> map = new HashMap<>(); +// Map> map = new TreeMap<>(); + //LinkedHashMap将map中的顺序按照添加顺序排列 + Map> map = new LinkedHashMap<>(); + //定义九门课的map + Map yuwenMap = new HashMap<>(); + Map shuxueMap = new HashMap<>(); + Map yingyuMap = new HashMap<>(); + Map wuliMap = new HashMap<>(); + Map huaxueMap = new HashMap<>(); + Map shengwuMap = new HashMap<>(); + Map diliMap = new HashMap<>(); + Map lishiMap = new HashMap<>(); + Map zhengzhiMap = new HashMap<>(); + + List yuwenScoreGrade = examCoversionTotalDao.findByYuwenScore(examType,schoolName,gradeName); + yuwenMap.put("title", "语文"); + yuwenMap.put("score", String.valueOf(examCoversionTotal.getYuwenScore())); + yuwenMap.put("gradeRank", String.valueOf(yuwenScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getYuwenScore().toString())) + 1)); + List yuwenScoreClass = examCoversionTotalDao.findByClassIdAndYuwenScore(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + yuwenMap.put("classRank", String.valueOf(yuwenScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getYuwenScore().toString())) + 1)); + yuwenMap.put("fullscoreStandard", subjectFullScore.getYuwen().toString()); + yuwenMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getYuwen()))); + // 数学 + List shuxueScoreGrade = examCoversionTotalDao.findByShuxueScore(examType,schoolName,gradeName); + shuxueMap.put("title", "数学"); + shuxueMap.put("score", String.valueOf(examCoversionTotal.getShuxueScore())); + shuxueMap.put("gradeRank", String.valueOf(shuxueScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getShuxueScore().toString())) + 1)); + List shuxueScoreClass = examCoversionTotalDao.findByClassIdAndShuxueScore(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + shuxueMap.put("classRank", String.valueOf(shuxueScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getShuxueScore().toString())) + 1)); + shuxueMap.put("fullscoreStandard", subjectFullScore.getShuxue().toString()); + shuxueMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getShengwu()))); + // 英语 + List yingyuScoreGrade = examCoversionTotalDao.findByYingyuScore(examType,schoolName,gradeName); + yingyuMap.put("title", "英语"); + yingyuMap.put("score", String.valueOf(examCoversionTotal.getYingyuScore())); + yingyuMap.put("gradeRank", String.valueOf(yingyuScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getYingyuScore().toString())) + 1)); + List yingyuScoreClass = examCoversionTotalDao.findByClassIdAndYingyuScore(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + yingyuMap.put("classRank", String.valueOf(yingyuScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getYingyuScore().toString())) + 1)); + yingyuMap.put("fullscoreStandard", subjectFullScore.getYingyu().toString()); + yingyuMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getYingyu()))); + // 学生具体选择的科目 + if (!examCoversionTotal.getWuliCoversion().toString().equals("0.0")){ + wuliMap.put("title", "物理"); + List wuliScoreGrade = examCoversionTotalDao.findByWuliCoversion(examType,schoolName,gradeName); + wuliMap.put("score", String.valueOf(examCoversionTotal.getWuliCoversion())); + wuliMap.put("gradeRank", String.valueOf(wuliScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getWuliCoversion().toString())) + 1)); + List wuliScoreClass = examCoversionTotalDao.findByClassIdAndWuliCoversion(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + wuliMap.put("classRank", String.valueOf(wuliScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getWuliCoversion().toString())) + 1)); + wuliMap.put("fullscoreStandard", subjectFullScore.getWuli().toString()); + wuliMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getWuli()))); + } + if (!examCoversionTotal.getHuaxueCoversion().toString().equals("0.0")){ + huaxueMap.put("title", "化学"); + List huaxueScoreGrade = examCoversionTotalDao.findByHuaxueCoversion(examType,schoolName,gradeName); + huaxueMap.put("score", String.valueOf(examCoversionTotal.getHuaxueCoversion())); + huaxueMap.put("gradeRank", String.valueOf(huaxueScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getHuaxueCoversion().toString())) + 1)); + List huaxueScoreClass = examCoversionTotalDao.findByClassIdAndHuaxueCoversion(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + huaxueMap.put("classRank", String.valueOf(huaxueScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getHuaxueCoversion().toString())) + 1)); + huaxueMap.put("fullscoreStandard", subjectFullScore.getHuaxue().toString()); + huaxueMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getHuaxue()))); + } + if (!examCoversionTotal.getShengwuCoversion().toString().equals("0.0")){ + shengwuMap.put("title", "生物"); + List shengwuScoreGrade = examCoversionTotalDao.findByShengwuCoversion(examType,schoolName,gradeName); + shengwuMap.put("score", String.valueOf(examCoversionTotal.getShengwuCoversion())); + shengwuMap.put("gradeRank", String.valueOf(shengwuScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getShengwuCoversion().toString())) + 1)); + List shengwuScoreClass = examCoversionTotalDao.findByClassIdAndShengwuCoversion(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + shengwuMap.put("classRank", String.valueOf(shengwuScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getShengwuCoversion().toString())) + 1)); + shengwuMap.put("fullscoreStandard", subjectFullScore.getShengwu().toString()); + shengwuMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getShengwu()))); + } + if (!examCoversionTotal.getLishiCoversion().toString().equals("0.0") ){ + lishiMap.put("title", "历史"); + List lishiScoreGrade = examCoversionTotalDao.findByLishiCoversion(examType,schoolName,gradeName); + lishiMap.put("score", String.valueOf(examCoversionTotal.getLishiCoversion())); + lishiMap.put("gradeRank", String.valueOf(lishiScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getLishiCoversion().toString())) + 1)); + List lishiScoreClass = examCoversionTotalDao.findByClassIdAndLishiCoversion(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + lishiMap.put("classRank", String.valueOf(lishiScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getLishiCoversion().toString())) + 1)); + lishiMap.put("fullscoreStandard", subjectFullScore.getLishi().toString()); + lishiMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getLishi()))); + } + if (!examCoversionTotal.getDiliCoversion().toString().equals("0.0")){ + diliMap.put("title", "地理"); + List diliScoreGrade = examCoversionTotalDao.findByDiliCoversion(examType,schoolName,gradeName); + diliMap.put("score", String.valueOf(examCoversionTotal.getDiliCoversion())); + diliMap.put("gradeRank", String.valueOf(diliScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getDiliCoversion().toString())) + 1)); + List lishiScoreClass = examCoversionTotalDao.findByClassIdAndDiliCoversion(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + diliMap.put("classRank", String.valueOf(lishiScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getDiliCoversion().toString())) + 1)); + diliMap.put("fullscoreStandard", subjectFullScore.getDili().toString()); + diliMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getDili()))); + } + if (!examCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")){ + List zhengzhiScoreGrade = examCoversionTotalDao.findByZhengzhiCoversion(examType,schoolName,gradeName); + zhengzhiMap.put("title", "政治"); + zhengzhiMap.put("score", String.valueOf(examCoversionTotal.getZhengzhiCoversion())); + zhengzhiMap.put("gradeRank", String.valueOf(zhengzhiScoreGrade.indexOf(Float.parseFloat(examCoversionTotal.getZhengzhiCoversion().toString())) + 1)); + List zhengzhiScoreClass = examCoversionTotalDao.findByClassIdAndZhengzhiCoversion(examCoversionTotal.getClassId(), examType,schoolName,gradeName); + zhengzhiMap.put("classRank", String.valueOf(zhengzhiScoreClass.indexOf(Float.parseFloat(examCoversionTotal.getZhengzhiCoversion().toString())) + 1)); + zhengzhiMap.put("fullscoreStandard", subjectFullScore.getZhengzhi().toString()); + zhengzhiMap.put("subjectAvg", df.format(Double.parseDouble(subjectDTO.getZhengzhi()))); + } + + //班级总人数 + int totalClassNumber = yuwenScoreClass.size(); + //年级总人数 + int totalGradeNumber = yuwenScoreGrade.size(); + + + List list = new ArrayList<>(); + ScoreReportDTO scoreReportDTO = new ScoreReportDTO(); + scoreReportDTO.setTotalScore(df.format(examCoversionTotal.getCoversionTotal())); + scoreReportDTO.setTotalScoreGradeRank(examCoversionTotal.getSchoolIndex()); + scoreReportDTO.setTotalScoreClassRank(examCoversionTotal.getClassIndex()); + //总分满分标准 + scoreReportDTO.setTotalScoreStandard(df.format(sum)); + scoreReportDTO.setTotalClassNumber(totalClassNumber); + scoreReportDTO.setTotalGradeNumber(totalGradeNumber); + map.put("yuwenMap", yuwenMap); + map.put("shuxueMap",shuxueMap); + map.put("yingyuMap",yingyuMap); + if (wuliMap.size() != 0){ + map.put("wuliMap",wuliMap); + } + if (zhengzhiMap.size() != 0){ + map.put("zhengzhiMap",zhengzhiMap); + } + + if (huaxueMap.size() != 0){ + map.put("huaxueMap",huaxueMap); + } + if (lishiMap.size() != 0){ + map.put("lishiMap",lishiMap); + } + + if (shengwuMap.size() != 0){ + map.put("shengwuMap",shengwuMap); + } + if (diliMap.size() != 0){ + map.put("diliMap",diliMap); + } + + //总分的年级平均分 + // scoreReportDTO.setTotalAverage(df.format(totalAverage)); + scoreReportDTO.setTotalAverage(df.format(Double.parseDouble(totalAverage))); + scoreReportDTO.setMap(map); + + list.add(scoreReportDTO); + //打印出哪个接口,参数值是什么,当前时间,以便记录下当前访问哪个接口等信息,如有有openid则也记录下, 使用占位符,logger支持占位符 + logger.info("getScoreReport---> stuNumber:{}, examType:{}, time:{}", stuNumber,examType,getNowTime()); + return list; + } } diff --git a/src/main/java/com/zgczx/service/scoretwo/ScoreTwoService.java b/src/main/java/com/zgczx/service/scoretwo/ScoreTwoService.java new file mode 100644 index 0000000..0cdfb53 --- /dev/null +++ b/src/main/java/com/zgczx/service/scoretwo/ScoreTwoService.java @@ -0,0 +1,70 @@ +package com.zgczx.service.scoretwo; + +import com.alibaba.fastjson.JSONObject; +import com.zgczx.repository.mysql1.score.dto.ManuallyEnterGradesDTO; +import com.zgczx.repository.mysql1.score.dto.MonthByYearListDTO; +import com.zgczx.repository.mysql1.score.model.GoalSet; +import com.zgczx.repository.mysql1.score.model.ManuallyEnterGrades; +import com.zgczx.repository.mysql1.user.model.StudentInfo; +import com.zgczx.repository.mysql2.scoretwo.dto.CommentValueDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.LocationComparisonDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.SingleContrastInfoDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.TotalScoreInfoDTO; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; + +/** + * @author aml + * @date 2019/10/29 12:31 + */ + +public interface ScoreTwoService { + + ManuallyEnterGrades saveEntity(String wechatOpneid, + String studenNumber, + String subject, + String score, + String classRank, + String gradeRank, + String examName); + + List saveList(List list); + + List getYearList(String openid); + + List getMonthByYearList(String openid, String year); + + List getExamNameByYearMonthList(String openid,String yearMonth); + + List findAll(String openid, String examName); + + StudentInfo verifyStudentCode(String openid, String studentId); + + List getGapValue(String openid, String stuNumber, String examName); + + List getCommentValue(String openid, String stuNumber, String examName); + + List getTotalScoreInfo(String openid, String stuNumber, String examName,String targetRank); + + List getSubjectCollection(String openid, String stuNumber, String examName); + + //List getSingleContrastInfo(String openid, String stuNumber, String examName, String list); + + //JSONObject getSingleContrastInfo(Map map); + + List getSingleContrastInfo(Map map); + + GoalSet findTargetValue(String stuNumber, String examName); + + @Transactional + @Modifying + int deleteManuallyEnter(String stuNumber, String openid,String examName,String subject); + + ManuallyEnterGrades updateManuallyEnter(String stuNumber, String openid,String oldexamName,String subject,ManuallyEnterGrades manuallyEnterGrades); + + + +} diff --git a/src/main/java/com/zgczx/service/scoretwo/impl/ScoreTwoServiceImpl.java b/src/main/java/com/zgczx/service/scoretwo/impl/ScoreTwoServiceImpl.java new file mode 100644 index 0000000..6e8d038 --- /dev/null +++ b/src/main/java/com/zgczx/service/scoretwo/impl/ScoreTwoServiceImpl.java @@ -0,0 +1,913 @@ +package com.zgczx.service.scoretwo.impl; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.zgczx.mapper.ManuallyEnterGradesMapper; +import com.zgczx.repository.mysql1.score.dao.GoalSetDao; +import com.zgczx.repository.mysql1.score.dto.ManuallyEnterGradesDTO; +import com.zgczx.repository.mysql1.score.dto.MonthByYearListDTO; +import com.zgczx.repository.mysql1.score.model.GoalSet; +import com.zgczx.repository.mysql1.score.model.ManuallyEnterGrades; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.repository.mysql1.score.dao.ManuallyEnterGradesDao; +import com.zgczx.repository.mysql1.user.dao.StudentInfoDao; +import com.zgczx.repository.mysql1.user.model.StudentInfo; +import com.zgczx.repository.mysql2.scoretwo.dao.ExamCoversionTotalDao; +import com.zgczx.repository.mysql2.scoretwo.dto.CommentValueDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.LocationComparisonDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.SingleContrastInfoDTO; +import com.zgczx.repository.mysql2.scoretwo.dto.TotalScoreInfoDTO; +import com.zgczx.repository.mysql2.scoretwo.model.ExamCoversionTotal; +import com.zgczx.service.scoretwo.ScoreTwoService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.util.*; + +/** + * dao还是用原来的dao,就是impl不超过2000行 + * @author aml + * @date 2019/10/29 12:32 + */ +@Service +public class ScoreTwoServiceImpl implements ScoreTwoService { + + private static final Logger logger = LoggerFactory.getLogger(ScoreTwoServiceImpl.class); + + @Autowired + private ManuallyEnterGradesDao manuallyEnterGradesDao; + + // 导入mybatis映射SQL语句,不能加private + @Autowired + ManuallyEnterGradesMapper manuallyEnterGradesMapper; + + @Autowired + StudentInfoDao studentInfoDao; + + @Autowired + private ExamCoversionTotalDao examCoversionTotalDao; + + @Autowired + private GoalSetDao goalSetDao; + + private String info; + @Override + public ManuallyEnterGrades saveEntity(String wechatOpneid, String studenNumber, String subject, String score, String classRank, String gradeRank, String examName) { + ManuallyEnterGrades manuallyEnterGrades = new ManuallyEnterGrades(); + manuallyEnterGrades.setWechatOpenid(wechatOpneid); + manuallyEnterGrades.setStudentNumber(studenNumber); + manuallyEnterGrades.setSubjectName(subject); + manuallyEnterGrades.setScore(score); + manuallyEnterGrades.setClassRank(classRank); + manuallyEnterGrades.setGradeRank(gradeRank); + manuallyEnterGrades.setExamName(examName); + Timestamp time = new Timestamp(System.currentTimeMillis()); + manuallyEnterGrades.setInserttime(time); + manuallyEnterGrades.setUpdatetime(time); + logger.info("【实体对象】: {}", manuallyEnterGrades); + ManuallyEnterGrades save = manuallyEnterGradesDao.save(manuallyEnterGrades); + + + // try { +// save = manuallyEnterGradesDao.save(manuallyEnterGrades); +// }catch (Exception e){ +// info = "学号和考试名称已经存在,不能重复插入"; +// logger.error("【{}】 {}",info, e); +// throw new ScoreException(ResultEnum.DATABASE_OP_EXCEPTION,info); +// } + + if (save == null){ + throw new ScoreException(ResultEnum.DATA_IS_WRONG,"数据为null"); + } + + return save; + } + + @Override + public List saveList(List list) { + if (list == null || list.size() == 0){ + info = "list为空"; + logger.error("批量录入list={} ,为空", list); + throw new ScoreException(ResultEnum.DATA_IS_WRONG,"数据为null"); + } + + for (ManuallyEnterGrades model : list){ + String studentNumber = model.getStudentNumber(); + String subjectName = model.getSubjectName(); + String examName = model.getExamName(); + ManuallyEnterGrades manuallyEnterGrades = manuallyEnterGradesDao.findAllByStudentNumberAndExamNameAndSubjectName(studentNumber, examName, subjectName); + + if (manuallyEnterGrades != null){ + manuallyEnterGradesDao.delete(manuallyEnterGrades);//将之前录入过的成绩,删除 +// info = "您已经录过此数据,暂不允许重复录入,请重新核对再录入"; +// logger.error("重复数据为={} ", manuallyEnterGrades); +// throw new ScoreException(ResultEnum.DATA_ALREADY_EXISTED,info); + } + } + logger.info("【打印传参的list】: {}",list); + + List save = manuallyEnterGradesDao.save(list); + if (save == null || save.size() == 0){ + info = "批量插入手动录入成绩出错"; + logger.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.SPECIFIED_QUESTIONED_BULK_INSERT_FAILED,info); + } + return save; + } + + @Override + public List getYearList(String openid) { + List years = manuallyEnterGradesMapper.getYears(openid); + if (years == null || years.size() == 0){ + info = "您未录入数据"; + logger.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE,info); + } + return years; + } + + @Override + public List getMonthByYearList(String openid, String year) { + String nameYear = "%"+year+"%" ; + // 通过mybatis方式查询数据 + //List months = manuallyEnterGradesMapper.getMonths(openid, nameYear); + //通过jpa方式查询数据 + List months = manuallyEnterGradesDao.getExamNameByWechatOpenidAndYear(openid, nameYear); + List list = new ArrayList<>(); + for (int i = 0 ; i < months.size(); i++){ + int c = months.get(i).indexOf("月"); + String substring = months.get(i).substring(5, c + 1); + list.add(substring); + } + int countTimes = manuallyEnterGradesDao.countByWechatOpenidAndExamName(openid, nameYear); + List listDTOS = new ArrayList<>(); + MonthByYearListDTO monthByYearListDTO = new MonthByYearListDTO(); + monthByYearListDTO.setList(list); + monthByYearListDTO.setCountTimes(countTimes); + + listDTOS.add(monthByYearListDTO); + return listDTOS; + } + + + @Override + public List getExamNameByYearMonthList(String openid, String yearMonth) { + String nameYear = "%"+yearMonth+"%" ; + List months = manuallyEnterGradesDao.getExamNameByYearMonthAndWechatOpenid(openid, nameYear); + List list = new ArrayList<>(); + for (int i = 0 ; i < months.size(); i++){ + int c = months.get(i).indexOf("月"); + String substring = months.get(i).substring(c+1, months.get(i).length()); + list.add(substring); + } + return list; + } + + @Override + public List findAll(String openid, String examName) { + List allByWechatOpenidAndExamName = manuallyEnterGradesDao.findAllByWechatOpenidAndExamName(openid, examName); + if (allByWechatOpenidAndExamName == null || allByWechatOpenidAndExamName.size() == 0){ + info = "您未录入数据"; + logger.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE,info); + } + + // 这种才是真正的list,之前都放到map中是不太对的,这样的话才真正用了DTO的返回结构 + List gradesDTOList = new ArrayList<>(); + for (ManuallyEnterGrades manuallyEnterGrades : allByWechatOpenidAndExamName){ + + ManuallyEnterGradesDTO manuallyEnterGradesDTO = new ManuallyEnterGradesDTO(); + manuallyEnterGradesDTO.setManuallyEnterGrades(manuallyEnterGrades); + List stringList = new ArrayList<>(); + String imgurl = manuallyEnterGrades.getImgs(); + String[] split = null; + if (imgurl != null){ + split = imgurl.split(","); + + for (String s : split){ + stringList.add(s); + } + } + manuallyEnterGradesDTO.setImgurllist(stringList); + gradesDTOList.add(manuallyEnterGradesDTO); + } + + + /* List stringList = new ArrayList<>(); + String imgurl = allByWechatOpenidAndExamName.get(0).getImgurl(); + String[] split = null; + if (imgurl != null){ + split = imgurl.split(","); + + for (String s : split){ + stringList.add(s); + } + } + + List list = new ArrayList<>(); + ManuallyEnterGradesDTO manuallyEnterGradesDTO = new ManuallyEnterGradesDTO(); + manuallyEnterGradesDTO.setManuallyEnterGrades(allByWechatOpenidAndExamName.get(0)); + manuallyEnterGradesDTO.setImgurllist(stringList); + + list.add(manuallyEnterGradesDTO);*/ + return gradesDTOList; + } + + @Override + public StudentInfo verifyStudentCode(String openid, String studentId) { + StudentInfo studentInfoByStudentNumber = studentInfoDao.getStudentInfoByStudentNumber(studentId); + if (studentInfoByStudentNumber == null){ + info = "暂无学校提供数据"; + logger.warn("【您暂无和学校合作】,{}",openid); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE,info); + } + + return studentInfoByStudentNumber; + } + + @Override + public List getGapValue(String openid, String stuNumber, String examName) { + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examName); + if (examCoversionTotal == null){ + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName(); + //年级总分降序数组,用数组下标获取年级排名 + List gradeRankList = examCoversionTotalDao.findAllBySchoolNameAndGradeNameAndExamType(schoolName, gradeName, examName); + if (gradeRankList == null){ + logger.error("【暂无此】'{}',【总的年级排名信息】; 【此用户:】{}",schoolName,openid); + info = "【暂无此学校总的年级排名信息】"; + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + Map> map = new HashMap<>(); + //Map gradeMap = new LinkedHashMap<>();//排名map + Map scoreMap = new LinkedHashMap<>();//分数map + Map gapValueMap = new LinkedHashMap<>();//差值map + + + Integer schoolIndex = examCoversionTotal.getSchoolIndex();//获取此用户总分的年级排名 + Double total = examCoversionTotal.getCoversionTotal();//获取此用户总分 + //第一名 + String firstOneValue = String.valueOf(gradeRankList.get(0));//获取年级第一名的总分分数 + String firstOneGap = String.valueOf(total - Double.parseDouble(firstOneValue) );//与第一名的差值 + //第50名,这里调成动态的,由前端传要看第几名 + String secondValue = String.valueOf(gradeRankList.get(49));//获取的分数,动态的就是 i - 1 + String secondGap = String.valueOf(total - Double.parseDouble(secondValue));//与第二位(可能是50名)的差值 + //第100名,这里调成动态的,由前端传要看第几名 + String thirdValue = String.valueOf(gradeRankList.get(99));//获取的分数,动态的就是 j - 1 + String thirdGap = String.valueOf(total - Double.parseDouble(thirdValue));//与第三位(可能是100名)的差值 + //第150名,这里调成动态的,由前端传要看第几名 + String fourValue = String.valueOf(gradeRankList.get(149));//获取的分数,动态的就是 z - 1 + String fourGap = String.valueOf(total - Double.parseDouble(fourValue));//与第四位(可能是150名)的差值 + + scoreMap.put("I", String.valueOf(total));//自己的分数 + scoreMap.put("150",fourValue);//第150的分数,可以为动态: z + scoreMap.put("100",thirdValue);//第100的分数,可以为动态: j + scoreMap.put("50",secondValue);//第50的分数,可以为动态: i + scoreMap.put("1",firstOneValue);//第1的分数,这个就固定下来 + + map.put("scoreMap", scoreMap); + + gapValueMap.put("I", "--"); + gapValueMap.put("150",fourGap); + gapValueMap.put("100",thirdGap); + gapValueMap.put("50",secondGap); + gapValueMap.put("1",firstOneGap); + + map.put("gapValueMap",gapValueMap); + + List list = new ArrayList<>(); + LocationComparisonDTO locationComparisonDTO = new LocationComparisonDTO(); + locationComparisonDTO.setStringMap(map); + list.add(locationComparisonDTO); + + return list; + } + + @Override + public List getCommentValue(String openid, String stuNumber, String examName) { + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examName); + if (examCoversionTotal == null){ + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName(); + String classid = examCoversionTotal.getClassId(); + List classTotalRank = examCoversionTotalDao.findClassTotalByClassIdAndExamType(classid, examName, schoolName, gradeName); + if (classTotalRank == null){ + info = "暂无此班级排名信息"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + //保留两位小数 + DecimalFormat df = new DecimalFormat("#0.00"); + // 班级最高分 + String classRankFirst = String.valueOf(classTotalRank.get(0));//班级第一名分数 + //班级总人数 + int classCount = examCoversionTotalDao.countByClassIdAndExamTypeAndValidAndSchoolNameAndGradeName(classid, examName, 1, schoolName, gradeName); + //班级总分累加和 + float classTotalSum = examCoversionTotalDao.sumCoversionTotalByClassIdAndExamTypeAndValidAndSchoolName(classid, examName, 1, schoolName, gradeName); + //班级平均分, 保留两位小数 + String classAvg = String.valueOf(classTotalSum / classCount); + + //年级平均分 + String gradeAvg = examCoversionTotalDao.totalAverageByExamType(examName, schoolName, gradeName); + //总分的年级排名 + List gradeTotalRank = examCoversionTotalDao.findByTotalScore(examName, schoolName, gradeName); + //年级最高分 + String gradeRankFirst = String.valueOf(gradeTotalRank.get(0)); + + //封装DTO + List list = new ArrayList<>(); + CommentValueDTO commentValueDTO = new CommentValueDTO(); + commentValueDTO.setClassHighScore(classRankFirst); + commentValueDTO.setClassAvgScore(String.format("%.2f",Float.parseFloat(classAvg))); + commentValueDTO.setGradeHighScore(gradeRankFirst); + commentValueDTO.setGradeAvgScore(String.format("%.2f",Float.parseFloat(gradeAvg))); + commentValueDTO.setTotalScore(String.valueOf(examCoversionTotal.getCoversionTotal())); + + list.add(commentValueDTO); + return list; + } + + @Override + public List getTotalScoreInfo(String openid, String stuNumber, String examName, String targetRank) { + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examName); + if (examCoversionTotal == null){ + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName(); + Double myTotalScore = examCoversionTotal.getCoversionTotal();//自己总分值 + // 本次考试的年级总人数 + int gradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolNameAndGradeName(examName, 1, schoolName, gradeName); + if (Integer.valueOf(targetRank) > gradeNumber){ + info = "您设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //年级排名数组 + List gradeRankList = examCoversionTotalDao.findAllBySchoolNameAndGradeNameAndExamType(schoolName, gradeName, examName); + //我的排名 + int myRank = gradeRankList.indexOf(myTotalScore) + 1; + //可能有并列,但是并列也是自己的排名 + if (targetRank.equals(myRank)){ + info = "您设定的目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int target = Integer.valueOf(targetRank) - 1; + // 目标分数 + String targetScore = String.valueOf(gradeRankList.get(target)); + // 差值:我的分数 - 目标分数 + String scoreDifferentValue = String.valueOf(myTotalScore - Double.parseDouble(targetScore)); + + List list = new ArrayList<>(); + TotalScoreInfoDTO totalScoreInfoDTO = new TotalScoreInfoDTO(); + totalScoreInfoDTO.setMyRank(myRank); + totalScoreInfoDTO.setMyScore(String.valueOf(myTotalScore)); + totalScoreInfoDTO.setTargetRank(Integer.parseInt(targetRank)); + totalScoreInfoDTO.setTargetScore(targetScore); + totalScoreInfoDTO.setScoreDifferentValue(scoreDifferentValue); + list.add(totalScoreInfoDTO); + + return list; + } + + @Override + public List getSubjectCollection(String openid, String stuNumber, String examName) { + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examName); + if (examCoversionTotal == null){ + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + List list = new LinkedList<>(); + list.add("语文"); + list.add("数学"); + list.add("英语"); + + if (!examCoversionTotal.getWuliCoversion().toString().equals("0.0")){ + list.add("物理"); + } + if (!examCoversionTotal.getHuaxueCoversion().toString().equals("0.0")){ + list.add("化学"); + } + if (!examCoversionTotal.getShengwuCoversion().toString().equals("0.0")){ + list.add("生物"); + } + if (!examCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")){ + list.add("政治"); + } + if (!examCoversionTotal.getLishiCoversion().toString().equals("0.0") ){ + list.add("历史"); + } + if (!examCoversionTotal.getDiliCoversion().toString().equals("0.0")){ + list.add("地理"); + } + +// List> list1 = new ArrayList<>(); +// SubjectCollectionDTO subjectCollectionDTO = new SubjectCollectionDTO(); +// subjectCollectionDTO.setList(list); +// list1.add(list); + + return list; + } + + @Override + @Transactional + public List getSingleContrastInfo(Map map) { + JSONObject jsonObject = new JSONObject(); + String stuNumber = null; + if (!map.containsKey("stuNumber")) { + jsonObject.put("errno", ResultEnum.RESULE_DATA_NONE); + jsonObject.put("errmsg", "stuNumber not exit!"); + // return jsonObject; + } else { + stuNumber = map.get("stuNumber").toString().trim(); + } + String examName = null; + if (!map.containsKey("examName")) { + jsonObject.put("errno", ResultEnum.RESULE_DATA_NONE); + jsonObject.put("errmsg", "examName not exit!"); + // return jsonObject; + } else { + examName = map.get("examName").toString().trim(); + } + String openid = null;// 用户openid + if (!map.containsKey("openid")) { + jsonObject.put("errno", ResultEnum.RESULE_DATA_NONE); + jsonObject.put("errmsg", "openid not exit!"); + // return jsonObject; + } else { + openid = map.get("openid").toString().trim(); + } + + // 创建目标设定表的实体,往里面存放设定的目标值 + GoalSet goalSet = new GoalSet(); + goalSet.setStudentNumber(stuNumber); + goalSet.setExamName(examName); + goalSet.setOpenid(openid); + + //LinkedHashMap将map中的顺序按照添加顺序排列 + Map> hashMap = new LinkedHashMap<>(); + + Map totalMap = new HashMap<>();//总分map + //定义九门课的map + Map yuwenMap = new HashMap<>(); + Map shuxueMap = new HashMap<>(); + Map yingyuMap = new HashMap<>(); + Map wuliMap = new HashMap<>(); + Map huaxueMap = new HashMap<>(); + Map shengwuMap = new HashMap<>(); + Map diliMap = new HashMap<>(); + Map lishiMap = new HashMap<>(); + Map zhengzhiMap = new HashMap<>(); + ExamCoversionTotal examCoversionTotal = examCoversionTotalDao.findByStudentNumberAndExamType(stuNumber, examName); + if (examCoversionTotal == null){ + info = "查询此学生的所有信息失败"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String schoolName = examCoversionTotal.getSchoolName(); + String gradeName = examCoversionTotal.getGradeName(); + //语文分数 + Double yuwenScore = examCoversionTotal.getYuwenScore(); + //语文年级排名 + List yuwenRankList = examCoversionTotalDao.findByYuwenScoreAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //语文年级人数 + int yuwenNum = yuwenRankList.size(); + String yuwenTargeRank = map.get("yuwen").toString().trim(); + goalSet.setYuwen(yuwenTargeRank);// 语文目标名次 + if (Integer.valueOf(yuwenTargeRank) > yuwenNum){ + info = "您语文设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int myyuwenRank = yuwenRankList.indexOf(Float.valueOf(yuwenScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (yuwenTargeRank.equals(myyuwenRank)){ + info = "您设定的语文目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int yuwentarget = Integer.valueOf(yuwenTargeRank) - 1; + // 目标分数 + String yuwenTargetScore = String.valueOf(yuwenRankList.get(yuwentarget)); + // 差值:我的分数 - 目标分数 + String yuwenScoreDifferentValue = String.valueOf(yuwenScore - Double.parseDouble(yuwenTargetScore)); + + yuwenMap.put("myRank", String.valueOf(myyuwenRank)); + yuwenMap.put("targetRank",yuwenTargeRank); + yuwenMap.put("myScore", String.valueOf(yuwenScore)); + yuwenMap.put("targetScore",yuwenTargetScore); + yuwenMap.put("scoreDifferentValue",yuwenScoreDifferentValue); + yuwenMap.put("title", "语文"); + hashMap.put("yuwen",yuwenMap); + //数学分数 + Double shuxueScore = examCoversionTotal.getShuxueScore(); + //数学年级排名 + List shuxueRankList = examCoversionTotalDao.findByShuxueScoreAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //数学年级人数 + int shuxueNum = shuxueRankList.size(); + String shuxueTargeRank = map.get("shuxue").toString().trim(); + goalSet.setShuxue(shuxueTargeRank);//数学目标名次 + if (Integer.valueOf(shuxueTargeRank) > shuxueNum){ + info = "您数学设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int myshuxueRank = shuxueRankList.indexOf(Float.valueOf(shuxueScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (shuxueTargeRank.equals(myshuxueRank)){ + info = "您设定的数学目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int shuxuetarget = Integer.valueOf(shuxueTargeRank) - 1; + // 目标分数 + String shuxueTargetScore = String.valueOf(shuxueRankList.get(shuxuetarget)); + // 差值:我的分数 - 目标分数 + String shuxueScoreDifferentValue = String.valueOf(shuxueScore - Double.parseDouble(shuxueTargetScore)); + shuxueMap.put("myRank", String.valueOf(myshuxueRank)); + shuxueMap.put("targetRank",shuxueTargeRank); + shuxueMap.put("myScore", String.valueOf(shuxueScore)); + shuxueMap.put("targetScore",shuxueTargetScore); + shuxueMap.put("scoreDifferentValue",shuxueScoreDifferentValue); + shuxueMap.put("title", "数学"); + hashMap.put("shuxue",shuxueMap); + + //英语分数 + Double yingyuScore = examCoversionTotal.getYingyuScore(); + //英语年级排名 + List yingyuRankList = examCoversionTotalDao.findByYingyuScoreAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //英语年级人数 + int yingyuNum = yingyuRankList.size(); + String yingyuTargeRank = map.get("yingyu").toString().trim(); + goalSet.setYingyu(yingyuTargeRank);//英语目标名次 + if (Integer.valueOf(yingyuTargeRank) > yingyuNum){ + info = "您英语设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int myyingyuRank = yingyuRankList.indexOf(Float.valueOf(yingyuScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (yingyuTargeRank.equals(myyingyuRank)){ + info = "您设定的英语目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int yingyutarget = Integer.valueOf(yingyuTargeRank) - 1; + // 目标分数 + String yingyuTargetScore = String.valueOf(yingyuRankList.get(yingyutarget)); + // 差值:我的分数 - 目标分数 + String yingyuScoreDifferentValue = String.valueOf(yingyuScore - Double.parseDouble(yingyuTargetScore)); + yingyuMap.put("myRank", String.valueOf(myyingyuRank)); + yingyuMap.put("targetRank",yingyuTargeRank); + yingyuMap.put("myScore", String.valueOf(yingyuScore)); + yingyuMap.put("targetScore",yingyuTargetScore); + yingyuMap.put("scoreDifferentValue",yingyuScoreDifferentValue); + yingyuMap.put("title", "英语"); + hashMap.put("yingyu",yingyuMap); + + if (!examCoversionTotal.getWuliCoversion().toString().equals("0.0")){ + //物理分数 + Double wuliScore = examCoversionTotal.getWuliCoversion(); + //物理年级排名 + List wuliRankList = examCoversionTotalDao.findByWuliCoversionAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //物理年级人数 + int wuliNum = wuliRankList.size(); + String wuliTargeRank = map.get("wuli").toString().trim(); + goalSet.setWuli(wuliTargeRank);//物理目标名次 + if (Integer.valueOf(wuliTargeRank) > wuliNum){ + info = "您物理设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int mywuliRank = wuliRankList.indexOf(Float.valueOf(wuliScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (wuliTargeRank.equals(mywuliRank)){ + info = "您设定的物理目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int wulitarget = Integer.valueOf(wuliTargeRank) - 1; + // 目标分数 + String wuliTargetScore = String.valueOf(wuliRankList.get(wulitarget)); + // 差值:我的分数 - 目标分数 + String wuliScoreDifferentValue = String.valueOf(wuliScore - Double.parseDouble(wuliTargetScore)); + wuliMap.put("myRank", String.valueOf(mywuliRank)); + wuliMap.put("targetRank",wuliTargeRank); + wuliMap.put("myScore", String.valueOf(wuliScore)); + wuliMap.put("targetScore",wuliTargetScore); + wuliMap.put("scoreDifferentValue",wuliScoreDifferentValue); + wuliMap.put("title", "物理"); + hashMap.put("wuli",wuliMap); + } + + if (!examCoversionTotal.getHuaxueCoversion().toString().equals("0.0")){ + //化学分数 + Double huaxueScore = examCoversionTotal.getHuaxueCoversion(); + //化学年级排名 + List huaxueRankList = examCoversionTotalDao.findByHuaxueCoversionAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //化学年级人数 + int huaxueNum = huaxueRankList.size(); + String huaxueTargeRank = map.get("huaxue").toString().trim(); + goalSet.setHuaxue(huaxueTargeRank);//化学目标名次 + if (Integer.valueOf(huaxueTargeRank) > huaxueNum){ + info = "您化学设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int myhuaxueRank = huaxueRankList.indexOf(Float.valueOf(huaxueScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (huaxueTargeRank.equals(myhuaxueRank)){ + info = "您设定的化学目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int huaxuetarget = Integer.valueOf(huaxueTargeRank) - 1; + // 目标分数 + String huaxueTargetScore = String.valueOf(huaxueRankList.get(huaxuetarget)); + // 差值:我的分数 - 目标分数 + String huaxueScoreDifferentValue = String.valueOf(huaxueScore - Double.parseDouble(huaxueTargetScore)); + huaxueMap.put("myRank", String.valueOf(myhuaxueRank)); + huaxueMap.put("targetRank",huaxueTargeRank); + huaxueMap.put("myScore", String.valueOf(huaxueScore)); + huaxueMap.put("targetScore",huaxueTargetScore); + huaxueMap.put("scoreDifferentValue",huaxueScoreDifferentValue); + huaxueMap.put("title", "化学"); + hashMap.put("huaxue",huaxueMap); + } + if (!examCoversionTotal.getShengwuCoversion().toString().equals("0.0")){ + //生物分数 + Double shengwuScore = examCoversionTotal.getShengwuCoversion(); + //生物年级排名 + List shengwuRankList = examCoversionTotalDao.findByShengwuCoversionAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //生物年级人数 + int shengwuNum = shengwuRankList.size(); + String shengwuTargeRank = map.get("shengwu").toString().trim(); + goalSet.setShengwu(shengwuTargeRank);//生物目标名次 + if (Integer.valueOf(shengwuTargeRank) > shengwuNum){ + info = "您生物设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int myshengwuRank = shengwuRankList.indexOf(Float.valueOf(shengwuScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (shengwuTargeRank.equals(myshengwuRank)){ + info = "您设定的生物目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int shengwutarget = Integer.valueOf(shengwuTargeRank) - 1; + // 目标分数 + String shengwuTargetScore = String.valueOf(shengwuRankList.get(shengwutarget)); + // 差值:我的分数 - 目标分数 + String shengwuScoreDifferentValue = String.valueOf(shengwuScore - Double.parseDouble(shengwuTargetScore)); + shengwuMap.put("myRank", String.valueOf(myshengwuRank)); + shengwuMap.put("targetRank",shengwuTargeRank); + shengwuMap.put("myScore", String.valueOf(shengwuScore)); + shengwuMap.put("targetScore",shengwuTargetScore); + shengwuMap.put("scoreDifferentValue",shengwuScoreDifferentValue); + shengwuMap.put("title", "生物"); + hashMap.put("shengwu",shengwuMap); + } + if (!examCoversionTotal.getLishiCoversion().toString().equals("0.0") ){ + //历史分数 + Double lishiScore = examCoversionTotal.getLishiCoversion(); + //历史年级排名 + List lishiRankList = examCoversionTotalDao.findByLishiCoversionAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //历史年级人数 + int lishiNum = lishiRankList.size(); + String lishiTargeRank = map.get("lishi").toString().trim(); + goalSet.setLishi(lishiTargeRank);//历史目标名次 + if (Integer.valueOf(lishiTargeRank) > lishiNum){ + info = "您历史设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int mylishiRank = lishiRankList.indexOf(Float.valueOf(lishiScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (lishiTargeRank.equals(mylishiRank)){ + info = "您设定的历史目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int lishitarget = Integer.valueOf(lishiTargeRank) - 1; + // 目标分数 + String lishiTargetScore = String.valueOf(lishiRankList.get(lishitarget)); + // 差值:我的分数 - 目标分数 + String lishiScoreDifferentValue = String.valueOf(lishiScore - Double.parseDouble(lishiTargetScore)); + lishiMap.put("myRank", String.valueOf(mylishiRank)); + lishiMap.put("targetRank",lishiTargeRank); + lishiMap.put("myScore", String.valueOf(lishiScore)); + lishiMap.put("targetScore",lishiTargetScore); + lishiMap.put("scoreDifferentValue",lishiScoreDifferentValue); + lishiMap.put("title", "历史"); + hashMap.put("lishi",lishiMap); + } + if (!examCoversionTotal.getDiliCoversion().toString().equals("0.0")){ + //地理分数 + Double diliScore = examCoversionTotal.getDiliCoversion(); + //地理年级排名 + List diliRankList = examCoversionTotalDao.findByDiliCoversionAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //地理年级人数 + int diliNum = diliRankList.size(); + String diliTargeRank = map.get("dili").toString().trim(); + goalSet.setDili(diliTargeRank);//地理目标名次 + if (Integer.valueOf(diliTargeRank) > diliNum){ + info = "您地理设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int mydiliRank = diliRankList.indexOf(Float.valueOf(diliScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (diliTargeRank.equals(mydiliRank)){ + info = "您设定的地理目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int dilitarget = Integer.valueOf(diliTargeRank) - 1; + // 目标分数 + String diliTargetScore = String.valueOf(diliRankList.get(dilitarget)); + // 差值:我的分数 - 目标分数 + String diliScoreDifferentValue = String.valueOf(diliScore - Double.parseDouble(diliTargetScore)); + diliMap.put("myRank", String.valueOf(mydiliRank)); + diliMap.put("targetRank",diliTargeRank); + diliMap.put("myScore", String.valueOf(diliScore)); + diliMap.put("targetScore",diliTargetScore); + diliMap.put("scoreDifferentValue",diliScoreDifferentValue); + diliMap.put("title", "地理"); + hashMap.put("dili",diliMap); + } + if (!examCoversionTotal.getZhengzhiCoversion().toString().equals("0.0")){ + //政治分数 + Double zhengzhiScore = examCoversionTotal.getZhengzhiCoversion(); + //政治年级排名 + List zhengzhiRankList = examCoversionTotalDao.findByZhengzhiCoversionAndSchoolNameAndValid(examName, schoolName, 1, gradeName); + //政治年级人数 + int zhengzhiNum = zhengzhiRankList.size(); + String zhengzhiTargeRank = map.get("zhengzhi").toString().trim(); + goalSet.setZhengzhi(zhengzhiTargeRank);//政治目标名次 + if (Integer.valueOf(zhengzhiTargeRank) > zhengzhiNum){ + info = "您政治设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //我的排名 + int myzhengzhiRank = zhengzhiRankList.indexOf(Float.valueOf(zhengzhiScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (zhengzhiTargeRank.equals(myzhengzhiRank)){ + info = "您设定的政治目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int zhengzhitarget = Integer.valueOf(zhengzhiTargeRank) - 1; + // 目标分数 + String zhengzhiTargetScore = String.valueOf(zhengzhiRankList.get(zhengzhitarget)); + // 差值:我的分数 - 目标分数 + String zhengzhiScoreDifferentValue = String.valueOf(zhengzhiScore - Double.parseDouble(zhengzhiTargetScore)); + zhengzhiMap.put("myRank", String.valueOf(myzhengzhiRank)); + zhengzhiMap.put("targetRank",zhengzhiTargeRank); + zhengzhiMap.put("myScore", String.valueOf(zhengzhiScore)); + zhengzhiMap.put("targetScore",zhengzhiTargetScore); + zhengzhiMap.put("scoreDifferentValue",zhengzhiScoreDifferentValue); + zhengzhiMap.put("title", "政治"); + hashMap.put("zhengzhi",zhengzhiMap); + } + + Double myTotalScore = examCoversionTotal.getCoversionTotal();//自己总分值 + String targetRank = map.get("total").toString().trim();//总分目标设定 + goalSet.setTotalScore(targetRank);//总分目标名次 + // 本次考试的年级总人数 + int gradeNumber = examCoversionTotalDao.countByExamTypeAndValidAndSchoolNameAndGradeName(examName, 1, schoolName, gradeName); + if (Integer.valueOf(targetRank) > gradeNumber){ + info = "您设定的目标值大于总人数,请核对后再设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_OUT_RANGE, info); + } + //年级排名数组 + List gradeRankList = examCoversionTotalDao.findAllBySchoolNameAndGradeNameAndExamType(schoolName, gradeName, examName); + //我的排名 + int myRank = gradeRankList.indexOf(Float.valueOf(myTotalScore.toString())) + 1; + //可能有并列,但是并列也是自己的排名 + if (targetRank.equals(myRank)){ + info = "您设定的目标值为您自己的排名,请重新设定"; + logger.error(info); + throw new ScoreException(ResultEnum.DATA_IS_WRONG, info); + } + // 目标排名要从 list中获取分数值 时的值 + int target = Integer.valueOf(targetRank) - 1; + // 目标分数 + String targetScore = String.valueOf(gradeRankList.get(target)); + // 差值:我的分数 - 目标分数 + String scoreDifferentValue = String.valueOf(myTotalScore - Double.parseDouble(targetScore)); + totalMap.put("myRank", String.valueOf(myRank)); + totalMap.put("targetRank",targetRank); + totalMap.put("myScore", String.valueOf(myTotalScore)); + totalMap.put("targetScore",targetScore); + totalMap.put("scoreDifferentValue",scoreDifferentValue); + totalMap.put("title", "总分"); + hashMap.put("total",totalMap); + + //保存目标名次表数据 + GoalSet save = goalSetDao.save(goalSet); + logger.info("【保存的各科目标数据:】,{}",save); + + logger.info("map: {}",map); + List list = new ArrayList<>(); + SingleContrastInfoDTO singleContrastInfoDTO = new SingleContrastInfoDTO(); + singleContrastInfoDTO.setMap(hashMap); + list.add(singleContrastInfoDTO); + return list; + } + + @Override + public GoalSet findTargetValue(String stuNumber, String examName) { + List targetValue = goalSetDao.findTargetValue(stuNumber, examName); + if (targetValue.size() == 0){ + info = "您为首次使用此功能,请您设定目标对比值"; + logger.error(info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + + return targetValue.get(0); + } + + @Transactional + @Modifying + @Override + public int deleteManuallyEnter(String stuNumber, String openid, String examName,String subject) { + ManuallyEnterGrades allByWechatOpenidAndExamName = manuallyEnterGradesDao.findAllByStudentNumberAndExamNameAndSubjectName(stuNumber, examName,subject); + if (allByWechatOpenidAndExamName == null){ + info = "您未录入此数据"; + logger.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE,info); + } + // 是否还需要 记录谁 操作的,openid + //int a = manuallyEnterGradesDao.deleteByStudentNumberAndExamNameAndSubjectName(stuNumber, examName, subject); + return manuallyEnterGradesDao.deleteByStudentNumberAndExamNameAndSubjectName(stuNumber, examName, subject); + + } + + @Override + public ManuallyEnterGrades updateManuallyEnter(String stuNumber, String openid, String oldexamName,String subject,ManuallyEnterGrades manuallyEnterGrades) { + // ManuallyEnterGrades model = manuallyEnterGradesDao.findByWechatOpenidAndStudentNumberAndExamName(openid, stuNumber,oldexamName); + ManuallyEnterGrades model = manuallyEnterGradesDao.findAllByStudentNumberAndExamNameAndSubjectName(stuNumber, oldexamName,subject); + if (model == null ){ + info = "您未录入此数据"; + logger.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE,info); + } + + model.setSubjectName(manuallyEnterGrades.getSubjectName()); + model.setScore(manuallyEnterGrades.getScore()); + model.setClassRank(manuallyEnterGrades.getClassRank()); + model.setGradeRank(manuallyEnterGrades.getGradeRank()); + model.setExamName(manuallyEnterGrades.getExamName()); + model.setImgs(manuallyEnterGrades.getImgs()); + + Timestamp date = new Timestamp(System.currentTimeMillis()); + model.setUpdatetime(date); + + ManuallyEnterGrades save = manuallyEnterGradesDao.save(model); + + return save; + } +} diff --git a/src/main/java/com/zgczx/service/user/UserService.java b/src/main/java/com/zgczx/service/user/UserService.java new file mode 100644 index 0000000..672a413 --- /dev/null +++ b/src/main/java/com/zgczx/service/user/UserService.java @@ -0,0 +1,26 @@ +package com.zgczx.service.user; + +import com.zgczx.repository.mysql1.user.model.UserFeedBack; +import com.zgczx.repository.mysql1.user.model.WechatStudent; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author aml + * @date 2019/11/8 19:41 + */ +public interface UserService { + + WechatStudent login(String openid, HttpServletRequest request,HttpServletResponse response); + + String logout(HttpServletRequest request, HttpServletResponse response); + + WechatStudent registerWechatStudent(String openid, String foreignKeId); + + /** + * 新增 用户反馈问题表 + * @return + */ + UserFeedBack addUserFeedBack(UserFeedBack userFeedBack); +} diff --git a/src/main/java/com/zgczx/service/user/impl/UserServiceImpl.java b/src/main/java/com/zgczx/service/user/impl/UserServiceImpl.java new file mode 100644 index 0000000..b2315cb --- /dev/null +++ b/src/main/java/com/zgczx/service/user/impl/UserServiceImpl.java @@ -0,0 +1,138 @@ +package com.zgczx.service.user.impl; + +import com.zgczx.constans.CookieConstant; +import com.zgczx.constans.RedisConstans; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.repository.mysql1.user.dao.UserFeedBackDao; +import com.zgczx.repository.mysql1.user.dao.WechatStudentDao; +import com.zgczx.repository.mysql1.user.model.UserFeedBack; +import com.zgczx.repository.mysql1.user.model.WechatStudent; +import com.zgczx.service.user.UserService; +import com.zgczx.utils.CookieUtil; +import com.zgczx.utils.EmojiUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + + +import javax.annotation.Resource; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.sql.Timestamp; +import java.util.Date; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + + +/** + * @author aml + * @date 2019/11/8 19:41 + */ +@Service +@Slf4j +public class UserServiceImpl implements UserService { + + @Autowired + WechatStudentDao wechatStudentDao; + + @Autowired + StringRedisTemplate stringRedisTemplate; + + @Autowired + private UserFeedBackDao userFeedBackDao; + + private String info; + @Override + public WechatStudent login(String openid, + HttpServletRequest request, + HttpServletResponse response) { + // 1. openid去和数据库里的数据匹配 + WechatStudent wechatStudent = wechatStudentDao.findByOpenid(openid); + if (wechatStudent == null){ + info = "您还没有授权,暂无法登录"; + log.error("WechatStudent实体未找到,{} ", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE,info); + } + // 设置Redis切换db + JedisConnectionFactory jedisConnectionFactory = (JedisConnectionFactory) stringRedisTemplate.getConnectionFactory(); + log.info("默认的当前所在的db= {} ", jedisConnectionFactory.getDatabase()); + jedisConnectionFactory.setDatabase(1);// 设置切换到指定的db上 + stringRedisTemplate.setConnectionFactory(jedisConnectionFactory);// 执行切换操作 + log.info("指定的db: {}", jedisConnectionFactory.getDatabase()); + + // 2. 设置token至Redis + String token = UUID.randomUUID().toString(); + Integer expire = RedisConstans.EXPIPE;// 过期时间 +// stringRedisTemplate.opsForValue().set("abc", "dsdsfdfsf"); + //设置:key,value,过期时间,时间单位 s + //String类的format()方法用于创建格式化的字符串以及连接多个字符串对象 + //String.format(RedisConstans.TOKEN_PREFIX,token):将TOKEN_PREFIX和token(UUID)拼接起来组合成为Redis的key + stringRedisTemplate.opsForValue().set(String.format(RedisConstans.TOKEN_PREFIX,token),openid,expire, TimeUnit.SECONDS); + // 3. 设置token至cookie + //设置cookie的name为:CookieConstant.TOKEN即为token; value为:token(UUID) + CookieUtil.set(response, CookieConstant.TOKEN,token,CookieConstant.EXPIPE); + + return wechatStudent; + } + + @Override + public String logout(HttpServletRequest request, HttpServletResponse response) { + + // 1. 从cookie查询 + Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN); + if (cookie != null){ + //2. 清除Redis + // cookie中的:(name + value == Redis的key) + //String类的format()方法用于创建格式化的字符串以及连接多个字符串对象 + stringRedisTemplate.opsForValue().getOperations().delete(String.format(RedisConstans.TOKEN_PREFIX,cookie.getValue())); + + // 3. 清除cookie + CookieUtil.del(response,CookieConstant.TOKEN); + + } + info = "清除cookie成功!"; + + return info; + } + +// @Override +// public WechatStudent registerWechatStudent(WechatStudent wechatStudent) { +// if (wechatStudent == null){ +// info = "【wechatStudent】实体为空"; +// log.error(info); +// throw new ScoreException(ResultEnum.PARAM_IS_INVALID.getCode(),info); +// } +// if (StringUtils.isEmpty(wechatStudent.getOpenid())){ +// log.error("【学生注册】openid 为空,openid={}",wechatStudent.getOpenid()); +// throw new ScoreException(ResultEnum.PARAM_EXCEPTION.getCode(),ResultEnum.PARAM_EXCEPTION.getMessage()); +// } +// +// WechatStudent save = wechatStudentDao.save(wechatStudent); +// +// return save; +// } + + + @Override + public WechatStudent registerWechatStudent(String openid, String foreignKeId) { + WechatStudent wechatStudent = new WechatStudent(); + wechatStudent.setOpenid(openid); + wechatStudent.setForeignKeId(Integer.parseInt(foreignKeId)); + WechatStudent save = wechatStudentDao.save(wechatStudent); + return save; + } + + @Override + public UserFeedBack addUserFeedBack(UserFeedBack userFeedBack) { + Timestamp timestamp = new Timestamp(System.currentTimeMillis()); + log.info("参数-->"+ userFeedBack); + userFeedBack.setContent( EmojiUtil.emojiConverterToAlias(userFeedBack.getContent())); + userFeedBack.setInsertTime(new Date()); + return userFeedBackDao.save(userFeedBack); + } +} diff --git a/src/main/java/com/zgczx/service/wechat/WeChatService.java b/src/main/java/com/zgczx/service/wechat/WeChatService.java new file mode 100644 index 0000000..301746a --- /dev/null +++ b/src/main/java/com/zgczx/service/wechat/WeChatService.java @@ -0,0 +1,35 @@ +package com.zgczx.service.wechat; + +import com.alibaba.fastjson.JSONObject; + +import javax.servlet.http.HttpSession; + +/** + * @author aml + * @date 2019/11/21 15:31 + */ +public interface WeChatService { + + String getJsapiTicket(HttpSession session); + + JSONObject getSign(String url, HttpSession session); + + /** + * 从微信公众号获取授权 + * + * @param returnUrl + * @param path + * @return + */ + String getAuthorizeFromWechat(String returnUrl, String path); + + /** + * 从微信公众号获取用户信息 + * + * @param code + * @param returnUrl + * @param path + * @return + */ + String getUserInfoFromWechat(String code,String returnUrl,String path); +} diff --git a/src/main/java/com/zgczx/service/wechat/impl/WeChatServiceImpl.java b/src/main/java/com/zgczx/service/wechat/impl/WeChatServiceImpl.java new file mode 100644 index 0000000..7f9f436 --- /dev/null +++ b/src/main/java/com/zgczx/service/wechat/impl/WeChatServiceImpl.java @@ -0,0 +1,347 @@ +package com.zgczx.service.wechat.impl; + +import com.alibaba.fastjson.JSONObject; +import com.zgczx.config.wechatconfig.ProjectUrlConfig; +import com.zgczx.config.wechatconfig.WeChatAccountConfig; +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.WechatException; +import com.zgczx.repository.mysql3.unifiedlogin.dao.WechatLoginDao; +import com.zgczx.repository.mysql3.unifiedlogin.model.WechatLogin; +import com.zgczx.service.wechat.WeChatService; +import com.zgczx.utils.CharacterVerifiyUtil; +import com.zgczx.utils.EmojiUtil; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import javax.servlet.http.HttpSession; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Timestamp; +import java.util.Formatter; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author aml + * @date 2019/11/21 15:41 + */ +@Service +@Slf4j +public class WeChatServiceImpl implements WeChatService { + + private final static Logger logger = LoggerFactory.getLogger(WeChatServiceImpl.class); + + @Autowired + private WeChatService weChatService; + + @Autowired + private WeChatAccountConfig weChatAccountConfig; + + @Autowired + private ProjectUrlConfig projectUrlConfig; + + @Autowired + private WechatLoginDao wechatLoginDao; + + /** + * 注入微信第三方工具类 + */ + @Autowired + WxMpService wxMpService; + + /** + * RestTemplate:是spring用于同步客户端HTTP访问的中心类 + * 1. 它简化了与HTTP服务器的通信,并实施RESTful原则。 + * 2. 它处理HTTP连接,留下应用程序代码来提供url + * (使用可能的模板变量)并提取结果。 + * @return + */ + @Bean + public RestTemplate restTemplate(){ + return new RestTemplate(); + } + + + /** + * 从微信公众号拿授权 + * + * @param returnUrl + * @param path + * @return + */ + @Override + public String getAuthorizeFromWechat(String returnUrl, String path) { + + /* + * url:用户授权完成后的重定向链接,即用户自己定义的回调地址 + * + * String url = "http://zhongkeruitong.top/wechat/userInfo?path="+path; + */ + String url = projectUrlConfig.getWechatMpAuthorize()+path; + + logger.info("returnUrl: "+ returnUrl); + logger.info("Path: " + path); + + /* + * 用户在调用authorize方法时,需传入一个回调地址; 微信服务器会请求这个地址,并把参数附在这个地址后面 + * + * 调用微信第三方SDK的oauth2buildAuthorizationUrl方法,封装了直接请求微信API的方法 + * 其中 redirectUrl 中,包含获取用户头像,姓名等信息所需要的code等参数 + * + * oauth2授权的url连接 + * String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect"; + * + * 前端请求此接口的一个例子,其中returnUrl为 + * returnUrl: /index.html + * Path: menu + * + * 请求微信的授权接口,微信执行完后,会请求我们传给它的回调地址(回调地址此处我们定义为请求/userInfo接口) + * 微信会在此回调地址后附上一些参数(比如code) + * + * redirectUrl: https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0b6356c5690adc27&redirect_uri=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttp%2Fzhongkeruitong.top%2Fwechat%2FuserInfo%3Fpath%3Dmenu&response_type=code&scope=snsapi_userinfo&state=%2Findex.html#wechat_redirect + */ + + String redirectUrl = wxMpService.oauth2buildAuthorizationUrl(url, WxConsts.OAUTH2_SCOPE_USER_INFO, URLEncoder.encode(returnUrl)); + + logger.info("redirectUrl ---- "+redirectUrl); + + /*请求 /userInfo 接口*/ + + return redirectUrl; + } + + /** + * 获取用户信息 + * + * @param code + * @param returnUrl + * @param path + * @return + */ + @Override + public String getUserInfoFromWechat(String code, String returnUrl, String path) { + + WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken(); + try { + /* + * 用code换取oauth2的access token + * + * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息 + */ + wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code); + } catch (WxErrorException e) { + logger.error("【微信网页授权】{}", e); + throw new WechatException(ResultEnum.WECHAT_MP_ERROR.getCode(), e.getError().getErrorMsg()); + } + + /* + * useropenid: 用户openid(每个用户,对于一个公众号都有一个微信的id号) + * access_token: 授权凭证 + */ + String useropenid = wxMpOAuth2AccessToken.getOpenId(); + String access_token = wxMpOAuth2AccessToken.getAccessToken(); + + WxMpUser wxMpUser = new WxMpUser(); + try { + /* + * 用oauth2获取用户信息, 当前面引导授权时的scope是snsapi_userinfo的时候才可以 + * + * @param lang zh_CN, zh_TW, en + */ + wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null); + } catch (WxErrorException e) { + logger.error("【微信网页授权】{}", e); + throw new WechatException(ResultEnum.WECHAT_MP_ERROR.getCode(), e.getError().getErrorMsg()); + } + /* + * nickname: 用户微信名 + * headimgurl: 用户微信头像 + */ + String nickname = wxMpUser.getNickname(); + String headimgurl = wxMpUser.getHeadImgUrl(); + + + logger.info("nickname: "+ nickname); + logger.info("headimgurl: "+ headimgurl); + logger.info("useropenid: "+ useropenid); + logger.info("access_token: "+ access_token); + + + //UserLogin userLogin = userDao.findAllByWechatId(useropenid); + WechatLogin userLogin = wechatLoginDao.findAllByOpenid(useropenid); + + if (userLogin != null){ + logger.info("path的参数:{}",path); + logger.info("跳转url-1:{}","http://zhongkeruitong.top/score_analysis/index.html#/home" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path); + + if (path.equals("menu3")){ + // 试试跳转到 此项目的首页面url + return "http://zhongkeruitong.top/score_analysis/index.html#/bbs/hot" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path; + } + if (path.equals("menu2")){ + // 试试跳转到 此项目的首页面url + return "http://zhongkeruitong.top/score_analysis/index.html#/lineCourse" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path; + } + // 试试跳转到 此项目的首页面url + return "http://zhongkeruitong.top/score_analysis/index.html#/home" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path; + } + //微信端首次授权获取信息,并存入到wechat_login(微信-学号关联表)表中去 + WechatLogin wechatLogin = new WechatLogin(); + wechatLogin.setOpenid(useropenid); + + // 验证用户昵称上是否有特殊字符 + boolean emoji = CharacterVerifiyUtil.findEmoji(nickname); + if (emoji){ + nickname = EmojiUtil.emojiConverterToAlias(nickname); + } + + wechatLogin.setNickName(nickname); + wechatLogin.setHeadimgurl(headimgurl); + Timestamp date = new Timestamp(System.currentTimeMillis()); + wechatLogin.setInserttime(date); + wechatLogin.setUpdatetime(date); + wechatLoginDao.save(wechatLogin); + + + logger.info(projectUrlConfig.getUserWebURL()+"?useropenid="+useropenid+ + "&access_token="+access_token+"&path="+path+"&headimgurl="+headimgurl); + logger.info("跳转url-2:{}","http://zhongkeruitong.top/score_analysis/index.html#/home" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path); + + if (path.equals("menu3")){ + // 试试跳转到 此项目的首页面url + return "http://zhongkeruitong.top/score_analysis/index.html#/bbs/hot" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path; + } + if (path.equals("menu2")){ + // 试试跳转到 此项目的首页面url + return "http://zhongkeruitong.top/score_analysis/index.html#/lineCourse" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path; + } + // 试试跳转到 此项目的首页面url + return "http://zhongkeruitong.top/score_analysis/index.html#/home" +"?useropenid="+useropenid+ + "&access_token="+access_token+"&headimgurl="+headimgurl+"&path="+path; + + +// return projectUrlConfig.getUserWebURL()+"?useropenid="+useropenid+ +// "&access_token="+access_token+"&path="+path+"&headimgurl="+headimgurl; + + } + + + + + @Override + public String getJsapiTicket(HttpSession session) { + //获取AccessToken + Map params = new HashMap(); + params.put("grant_type","client_credential"); + params.put("appid", weChatAccountConfig.getMpAppId()); + params.put("secret",weChatAccountConfig.getMpAppSecret()); + //输出access_token的参数等 + log.info("token参数:{}", params); + log.info("获取token的网址: {}", projectUrlConfig.getAccessToken() ); + log.info("JSONObject.class: {}", JSONObject.class ); + + //ResponseEntity标识整个http相应:状态码、头部信息以及相应体内容。因此我们可以使用其对http响应实现完整配置。 + ResponseEntity responseEntity = restTemplate().getForEntity(projectUrlConfig.getAccessToken(), JSONObject.class,params); + log.info("【输出responseEntity访问链接:】{}",responseEntity); + //从微信的返回链接 获取 access_token的值 + String accessToken = responseEntity.getBody().getString("access_token"); + //将token存放到session中 + session.setAttribute("accessToken",accessToken); + log.info("【打印access_token: 】{}",accessToken); + //访问微信获取js通行证的链接,获取返回code + ResponseEntity forEntity = restTemplate().getForEntity(projectUrlConfig.getticket, JSONObject.class, accessToken); + String ticket = forEntity.getBody().getString("ticket"); + log.info("【打印ticket: 】{}",ticket); + + return ticket; + } + + @Override + public JSONObject getSign(String url, HttpSession session) { + //1. 获取jsapi的许可证 + String jsapiTicket = weChatService.getJsapiTicket(session); + //2. 生成签名的随机串 + String nonceStr = createNonceStr(); + //3. 生成签名的时间戳 + String timestamp = createTimestamp(); + //4. 加密后的签名 + String signature = ""; + String finalUrl = url; + //5. 当前网页的URL,不包含“#”和其后面 + if (url.indexOf("#") > 0){ + finalUrl = url.substring(0,url.indexOf("#")); + } + //6. 注意参数名称必须小写,并且有序 + String params = "jsapi_ticket="+jsapiTicket + + "&noncestr="+nonceStr + + "×tamp="+timestamp + + "&url="+finalUrl; + log.info("【打印params: 】,{}",params); + log.info("【打印jsapi_ticket: 】,{}",jsapiTicket); + log.info("【打印出url: 】,{}",url); + + try { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + messageDigest.reset(); + messageDigest.update(params.getBytes("UTF-8")); + //获取加密后的签名, 最终完成hash值的计算 + signature = byteToHex(messageDigest.digest()); + + } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { + e.printStackTrace(); + } + + //封装数据,严格按照微信要求 + JSONObject json = new JSONObject(); + json.put("appId", weChatAccountConfig.getMpAppId()); + json.put("url", finalUrl); + json.put("jsapi_ticket", jsapiTicket); + json.put("nonceStr", nonceStr); + json.put("timestamp", timestamp); + json.put("signature", signature); + log.info("json-->" + json.toJSONString()); + return json; + } + + //2. 生成签名的随机串 + private static String createNonceStr(){ + return UUID.randomUUID().toString(); + } + //3. 生成签名的时间戳 + private static String createTimestamp(){ + return Long.toString(System.currentTimeMillis() / 1000); + } + + //获取加密后的签名 + private static String byteToHex(byte[] hash){ + Formatter formatter = new Formatter(); + for (byte b : hash) { + // “%02”: 以十六进制输出, “2”: 为指定的输出字段的宽度,如果位数小于2,则左端补0 + formatter.format("%02x", b); + } + String s = formatter.toString(); + formatter.close(); + return s; + } +} diff --git a/src/main/java/com/zgczx/swagger2/Swagger2.java b/src/main/java/com/zgczx/swagger2/Swagger2.java new file mode 100644 index 0000000..a258433 --- /dev/null +++ b/src/main/java/com/zgczx/swagger2/Swagger2.java @@ -0,0 +1,40 @@ +package com.zgczx.swagger2; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * @author aml + * @date 2019/11/6 23:34 + */ +@ComponentScan(basePackages = "com.zgczx.controller") +@EnableSwagger2 +@Configuration +public class Swagger2 { + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) +// .pathMapping("/score_analysis") //本地将这里注销,线上需要将这里打开,线上的url通过nginx代理的 + .select() + .apis(RequestHandlerSelectors.basePackage("com.zgczx.controller")) //Controller所在包(必须新建包) + .paths(PathSelectors.any()) + .build(); + } + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("java-demo构建api文档") //标题 + .description("swagger description") //描述 + .version("1.0") + .build(); + } +} diff --git a/src/main/java/com/zgczx/utils/CookieUtil.java b/src/main/java/com/zgczx/utils/CookieUtil.java new file mode 100644 index 0000000..49b1113 --- /dev/null +++ b/src/main/java/com/zgczx/utils/CookieUtil.java @@ -0,0 +1,80 @@ +package com.zgczx.utils; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; + +/** + * EXPLAN: cookie工具类, + * cookie的set、get、clean(清除) + * @author aml + * @date 2019/11/8 21:23 + */ +public class CookieUtil { + + /** + * explain:清除cookie就是重新设置cookie + * 将cookie设置为null,过期时间为:0 + * @param response + * @param name + */ + public static void del(HttpServletResponse response, + String name){ + + set(response,name,null,0); + } + + /** + * 设置cookie + * @param response + * @param name + * @param value + * @param maxAge 过期时间 + */ + public static void set(HttpServletResponse response, + String name, + String value, + int maxAge){ + Cookie cookie = new Cookie(name,value); + cookie.setPath("/"); + cookie.setMaxAge(maxAge);//设置过期时间 + response.addCookie(cookie); + } + + /** + * explain: 获取cookie + * @param request + * @param name + * @return + */ + public static Cookie get(HttpServletRequest request, + String name){ + Map cookieMap = readCookieMap(request); + if (cookieMap.containsKey(name)){ + Cookie cookie = cookieMap.get(name); + return cookie; + }else { + return null; + } + + } + + /** + * explain:将cookie数组封装成map,方便获取 + * @param request + * @return + */ + private static Map readCookieMap(HttpServletRequest request){ + Map cookieMap = new HashMap<>(); + Cookie[] cookies = request.getCookies(); + if (cookies != null){ + for (Cookie cookie:cookies){ + cookieMap.put(cookie.getName(),cookie); + } + } + + return cookieMap; + } +} diff --git a/src/main/java/com/zgczx/utils/DateFormatUtil.java b/src/main/java/com/zgczx/utils/DateFormatUtil.java new file mode 100644 index 0000000..e5cd39b --- /dev/null +++ b/src/main/java/com/zgczx/utils/DateFormatUtil.java @@ -0,0 +1,94 @@ +package com.zgczx.utils; + +import com.zgczx.repository.mysql1.score.model.ExamInfo; +import com.zgczx.repository.mysql1.score.dao.ExamInfoDao; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 日期格式化工具 + * 将考试名称中的日期格式化为: xxxx年xx月 + * + * @author aml + * @date 2019/10/24 10:56 + */ +@Slf4j +public class DateFormatUtil { + + @Autowired + ExamInfoDao examInfoDao; + + /** + * 将库中不规范的考试名称封装为正确规范格式 + * @param dateString 数据库中的考试名称 + * @return + * @throws Exception + */ + public String dateFormat(String dateString) throws Exception { + log.info("原始dataString字符串: {}", dateString); + int year = dateString.indexOf("年"); + if (year == 4){ + return dateString; + } + if (year == 2) { + dateString = "20" + dateString; + } else if (year == 3) { + dateString = "2" + dateString; + } + int c = dateString.indexOf("月"); + String substring = dateString.substring(c + 1, dateString.length()); + dateString = dateString.substring(0, c + 1); + + log.info("截取的前部分字符中: {}", dateString); + log.info("截取的后部分字符中: {}", substring); + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月"); + String format = null; + if (dateString.indexOf("年") != -1) { + Date parse = null; + parse = dateFormat.parse(dateString); + format = dateFormat.format(parse); + } + String standardFormat = format+substring; + log.info("正确格式的字符串: {}",standardFormat ); + + return standardFormat; + } + + + /** + * 将前端传来的正确规范的考试名称,拆分为数据库中的考试名称,用于真正调用接口 + * @param dateString 规范的考试名称格式 + * @return + */ + public String recoveryString(String dateString) { + //1. 先用传来的参数,查库 + ExamInfo examName = examInfoDao.getByExamName(dateString); + System.out.println(examName); + + if (examName != null) { + //2. 查出 + if (examName.getExamName().equals(dateString)) { + System.out.println("查出来了: " + dateString); + return dateString; + } + } + //3. 查不出 + dateString = dateString.substring(2, dateString.length()); + //3.2 用截取过后的字符串,再查库 + ExamInfo examName1 = examInfoDao.getByExamName(dateString); + if (examName1 != null) { + if (dateString.equals(examName1.getExamName())) { + System.out.println(dateString); + return dateString; + } + } + //替换字符串中的第一个0, + dateString = dateString.replaceFirst("0", ""); + return dateString; + } + +} diff --git a/src/main/java/com/zgczx/utils/DateUtil.java b/src/main/java/com/zgczx/utils/DateUtil.java new file mode 100644 index 0000000..7e8afab --- /dev/null +++ b/src/main/java/com/zgczx/utils/DateUtil.java @@ -0,0 +1,18 @@ +package com.zgczx.utils; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +/** + * @author aml + * @date 2019/9/27 19:37 + */ +public class DateUtil { + + + public static String getNowTime(){ + Calendar calendar = Calendar.getInstance(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return dateFormat.format(calendar.getTime()); + } +} diff --git a/src/main/java/com/zgczx/utils/DoQuestionInfoDTOUtil.java b/src/main/java/com/zgczx/utils/DoQuestionInfoDTOUtil.java new file mode 100644 index 0000000..58dc276 --- /dev/null +++ b/src/main/java/com/zgczx/utils/DoQuestionInfoDTOUtil.java @@ -0,0 +1,98 @@ +//package com.zgczx.utils; +// +//import com.zgczx.enums.ResultEnum; +//import com.zgczx.exception.ScoreException; +//import com.zgczx.repository.mysql1.exam.dao.ExamPaperDao; +//import com.zgczx.repository.mysql1.exam.dao.UserQuestionRecordDao; +//import com.zgczx.repository.mysql1.exam.dto.DoQuestionInfoDTO; +//import com.zgczx.repository.mysql1.exam.model.ExamPaper; +//import com.zgczx.repository.mysql1.exam.model.UserQuestionRecord; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.web.bind.annotation.RestController; +// +//import java.util.ArrayList; +//import java.util.List; +// +//import static com.zgczx.utils.FilterStringUtil.filterMiddleBrackets; +// +///** +// * 将 调用的 dao的东西放到这里,报错: 反射调用错误,所以不能放此位置 +// * 将六、动态实时呈现用户做题详情 并记录用户所有的做题情况 接口中 +// * 获取 做题情况抽出来,作为一个 公共的函数 +// * @author aml +// * @date 2019/12/18 15:02 +// */ +//@Slf4j +//@RestController +//public class DoQuestionInfoDTOUtil { +// +// @Autowired +// private ExamPaperDao examPaperDao; +// +// @Autowired +// private UserQuestionRecordDao userQuestionRecordDao; +// +// private String info; +// +// public DoQuestionInfoDTO getDto(String studentNumber,String examName, String subject) { +// ExamPaper examPaper = examPaperDao.getBy(examName, subject, 1); +// if (examPaper == null) { +// info = "暂时没有此科目的此试卷"; +// log.error("【错误信息】: {}", info); +// throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); +// } +// // 去除[] 和 空格,或者从插库时处理,直接就存1,2,3... ;而不是存成[1, 2, 3...] +// String[] questionList = filterMiddleBrackets(examPaper.getQuestionList()).split(","); +// +// List idList = new ArrayList<>(); +// for (int i = 0; i < questionList.length; i++) { +// int integer = Integer.parseInt(questionList[i]); +// idList.add(integer); +// } +// // 这一份试卷的 题的数量 +// int questionCount = idList.size(); +// // 获取某学生->某科目 -> 某试卷的所有做题记录; +// List stulist = userQuestionRecordDao.getByStudentNumberAndSubjectAndExamPaperId(studentNumber, subject, examPaper.getId()); +// int doRight = 0; +// int doError = 0; +// List doRightList = new ArrayList<>(); // 做对的题号 +// List doErrorList = new ArrayList<>(); // 做错的题号 +// List notDoList = new ArrayList<>(); +// for (UserQuestionRecord questionRecord : stulist) { +// if (questionRecord.getDoRight() == 1) { +// if (!doRightList.contains(questionRecord.getQuestionId())) { +// doRightList.add(questionRecord.getQuestionId()); +// } +// doRight++; +// } else { +// if (!doErrorList.contains(questionRecord.getQuestionId())) { +// doErrorList.add(questionRecord.getQuestionId()); +// } +// doError++; +// } +// } +// int notDo = questionCount - doRight - doError; +// for (int i = 1; i <= questionCount; i++) { +// if (!doRightList.contains(i) && !doErrorList.contains(i)) { +// notDoList.add(i); +// } +// } +// log.info("【总共做题数量:】{}", questionCount); +// log.info("【作对题的数量:】{}", doRight); +// log.info("【作错题的数量:】{}", doError); +// log.info("【未做题的数量:】{}", notDo); +// +// //List dtoList = new ArrayList<>(); +// DoQuestionInfoDTO dto = new DoQuestionInfoDTO(); +// dto.setQuestionCount(questionCount); +// dto.setDoRight(doRight); +// dto.setDoError(doError); +// dto.setNotDo(notDo); +// dto.setDoRightList(doRightList); +// dto.setDoErrorList(doErrorList); +// dto.setNotDoList(notDoList); +// return dto; +// } +// +//} diff --git a/src/main/java/com/zgczx/utils/EmojiUtil.java b/src/main/java/com/zgczx/utils/EmojiUtil.java new file mode 100644 index 0000000..54ba95e --- /dev/null +++ b/src/main/java/com/zgczx/utils/EmojiUtil.java @@ -0,0 +1,31 @@ +package com.zgczx.utils; + +import com.github.binarywang.java.emoji.EmojiConverter; + +/** + * @author aml + * @date 2019/7/25 17:10 + */ +public class EmojiUtil { + + private static EmojiConverter emojiConverter = EmojiConverter.getInstance(); + + /** + * 将emojiStr 转为 带有表情的字符,将数据库中的字符还原(带有表情)并展示给前端 + * @param emojiStr 原始数据(带有表情) + * @return + */ + public static String emojiConverterUnicodeStr(String emojiStr){ + return emojiConverter.toUnicode(emojiStr); + } + + /** + * 将带有表情的字符串转换为编码存入数据库中 + * @param str 带有表情的字符 + * @return + */ + public static String emojiConverterToAlias(String str){ + return emojiConverter.toAlias(str); + } + +} diff --git a/src/main/java/com/zgczx/utils/FilterStringUtil.java b/src/main/java/com/zgczx/utils/FilterStringUtil.java new file mode 100644 index 0000000..a95c3cb --- /dev/null +++ b/src/main/java/com/zgczx/utils/FilterStringUtil.java @@ -0,0 +1,286 @@ +package com.zgczx.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 正则匹配string中所需要的内容 + * + * @author aml + * @date 2019/12/12 11:00 + */ +public class FilterStringUtil { + + + /** + * @param str + * @return + * @Title : filterNumber + * @Type : FilterStr + * @date : 2014年3月12日 下午7:23:03 + * @Description : 过滤出数字 + */ + public static String filterNumber(String number) { + number = number.replaceAll("[^(0-9)]", ""); + return number; + } + + /** + * @param alph + * @return + * @Title : filterAlphabet + * @Type : FilterStr + * @date : 2014年3月12日 下午7:28:54 + * @Description : 过滤出字母 + */ + public static String filterAlphabet(String alph) { + alph = alph.replaceAll("[^(A-Za-z)]", ""); + return alph; + } + + public static String filterAlphabetCapital(String alph) { + alph = alph.replaceAll("[^(A-Z)]", ""); + return alph; + } + + // 去除 [] + public static String filterMiddleBrackets(String alph) { + alph = alph.replaceAll("\\[|\\]|\\s", ""); + return alph; + } + + // 1)去除 指定的字符串,切记 要加上();里面写要匹配的 字符串内容 + public static String filter1(String alph) { + alph = alph.replaceAll("(\\},\"randomOption\":\\[)", ",\"randomOption\":"); + return alph; + } + + // 2)去除 指定的字符串,切记 要加上();里面写要匹配的 字符串内容 + public static String filter2(String alph) { + alph = alph.replaceAll("(\\],\"rightOption\":)", ",\"rightOption\":"); + return alph; + } + //3) 去除 指定的字符串,切记 要加上();里面写要匹配的 字符串内容 + public static String filter3(String alph) { + String b = alph.replaceAll("(\",\"B)", "B"); + String c = b.replaceAll("(\",\"C)", "C"); + String d = c.replaceAll("(\",\"D)", "D"); + return d; + } + + // 去掉 大括号 + public static String braces(String alph) { + alph = alph.replaceAll("(\\{|\\}|\")", ""); + return alph; + } + + /** + * 专门用于 获取题的接口,筛选选项中的 特殊字符 + * // 去除\s,\t,\n 和 t ,n 等符号 + * @param alph + * @return + */ + public static String filterspecial(String alph) { +// Pattern p = Pattern.compile("\\s*|\\t|\\r|\\n"); + Pattern p = Pattern.compile("\\\\s*|\\t|\\r|\\n|t|n"); + Matcher m = p.matcher(alph); + boolean b = m.find(); + String s = null; + if (b == true){ + s = m.replaceAll(""); + }else { + s = alph; + } + + + // alph = alph.replaceAll("\\s*|\\t|\\r|\\n", ""); + return s; + } + public static String filterspecial2(String alph) { +// Pattern p = Pattern.compile("\\s*|\\t|\\r|\\n"); + Pattern p = Pattern.compile("\\\\s*|\\t|\\r|\\n"); + Matcher m = p.matcher(alph); + boolean b = m.find(); + String s = null; + if (b == true){ + s = m.replaceAll(""); + }else { + s = alph; + } + + + // alph = alph.replaceAll("\\s*|\\t|\\r|\\n", ""); + return s; + } + /** + * @param chin + * @return + * @Title : filterChinese + * @Type : FilterStr + * @date : 2014年3月12日 下午9:12:37 + * @Description : 过滤出中文 + */ + public static String filterChinese(String chin) { + chin = chin.replaceAll("[^(\\u4e00-\\u9fa5)]", ""); + return chin; + } + + /** + * @param character + * @return + * @Title : filter + * @Type : FilterStr + * @date : 2014年3月12日 下午9:17:22 + * @Description : 过滤出字母、数字和中文 + */ + public static String filter(String character) { + character = character.replaceAll("[^(a-zA-Z0-9\\u4e00-\\u9fa5)]", ""); + return character; + } + + public static String optionLetter(String character) { + character = character.replaceAll("A.|B.|C.|D.|E.|A.|B.|C.|D.|E.", ""); + return character; + } + + // 只留中文和数字 还有 逗号, + public static String filterChineseAndMath(String character) { + character = character.replaceAll("[^(0-9\\u4e00-\\u9fa5)|\\,]", ""); + return character; + } + + + // 去除题的 题号和点,只留题的内容; 最大题号为 10000 + public static String filterTitleNumber(String string){ + //以数字开头并且包含.表示一个新的题目开始 + String regex = "^\\d{1,10000}\\."; + Pattern pattern = Pattern.compile(regex); + Matcher m = pattern.matcher(string); + if (m.find()){ + String string1 = m.replaceAll(""); + return string1; + }else { + /* //以数字开头并且包含.表示一个新的题目开始 + String regex1 = "^\\d{1,100}\\."; + Pattern pattern1 = Pattern.compile(regex1); + Matcher m1 = pattern.matcher(string); + if (m1.find()){ + String string1 = m1.replaceAll(""); + return string1; + }*/ + string = string.replaceAll("^\\d{1,10000}\\.", ""); + return string; + } + } + /** + * 去除字符串中头部和尾部所包含的空格(包括:空格(全角,半角)、制表符、换页符等) + * @param s + * @return + */ + public static String trim(String s){ + String result = ""; + if(null!=s && !"".equals(s)){ + result = s.replaceAll("^[ *| *| *|//s*]*", "").replaceAll("[ *| *| *|//s*]*$", ""); + } + return result; + } + + + public static String optionLetter2(String character) { + character = character.replaceAll("A.|B.|C.|D.|E.", ""); + return character; + } + /** + * @param args + * @Title : main + * @Type : FilterStr + * @date : 2014年3月12日 下午7:18:22 + * @Description : + */ + public static void main(String[] args) { +// /** +// * 声明字符串you +// */ +// String you = "^&^&^you123$%$%你好"; +// /** +// * 调用过滤出数字的方法 +// */ +// you = filterNumber(you); +// /** +// * 打印结果 +// */ +// System.out.println("过滤出数字:" + you); +// +// /** +// * 声明字符串hai +// */ +// String hai = "¥%……4556ahihdjsadhj$%$%你好吗wewewe"; +// /** +// * 调用过滤出字母的方法 +// */ +// hai = filterAlphabet(hai); +// /** +// * 打印结果 +// */ +// System.out.println("过滤出字母:" + hai); +// +// /** +// * 声明字符串dong +// */ +// String dong = "$%$%$张三34584yuojk李四@#¥#%%¥……%&"; +// /** +// * 调用过滤出中文的方法 +// */ +// dong = filterChinese(dong); +// /** +// * 打印结果 +// */ +// System.out.println("过滤出中文:" + dong); +// +// /** +// * 声明字符串str +// */ +// String str = "$%$%$张三34584yuojk李四@#¥#%%¥……%&"; +// /** +// * 调用过滤出字母、数字和中文的方法 +// */ +// str = filter(str); +// /** +// * 打印结果 +// */ +// System.out.println("过滤出字母、数字和中文:" + str); +// +// +// String s = filterMiddleBrackets("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); +// System.out.println("sssssssssssssssssssss: " + s); +// +// String s1 = "A.一定的流动性\\t\\t\\t\\t\\t\\t\\t\\tB.选择透性\\nC.较大的稳定性\\t\\t\\t\\t\\t\\t\\t\\tD.运输物质的功能\\n"; +// String filterspecial = filterspecial(s1); +// System.out.println(filterspecial); +// +// String s2 = optionLetter("A.C.B.D.E.一定的流动性"); +// System.out.println("s2: "+ s2); + +// String s3 = filter1("},\"randomOption\":["); +// System.out.println("ddd: "+s3); +// +// String s4 = filter2("],\"rightOption\":"); +// System.out.println("444: "+s4); + + /* String braces = braces("{\"0\":\"\",\"1\":\"\",\"2\":\"\",\"3\":\"\",\"4\":\"\",\"5\":\"\",\"6\":\"\",\"7\":\"\",\"8\":\"\",\"9\":\"\"}"); + System.out.println(braces); + + String string = filterChineseAndMath("第3章细胞的基本结构,第1节细胞膜的结构和功能"); + System.out.println(string);*/ + +// String string1 = filterTitleNumber("1.科学家研究发现,当温度升高到一定程度时,细胞膜的厚度变薄且面积增大。说明(  )"); +// System.out.println(string1); + + String string2 = filterTitleNumber("2.以下关于细胞膜结构的叙述中,不正确的是(  )"); + System.out.println(string2); + + + } + + +} diff --git a/src/main/java/com/zgczx/utils/FullPermutationUtil.java b/src/main/java/com/zgczx/utils/FullPermutationUtil.java new file mode 100644 index 0000000..cfd0046 --- /dev/null +++ b/src/main/java/com/zgczx/utils/FullPermutationUtil.java @@ -0,0 +1,45 @@ +package com.zgczx.utils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * int[] 的全排列, int[]可以改为 char[] + * 并且使用了 一个 全局变量 接收 递归结果 + * 可以在其他类中使用 + * @author aml + * @date 2019/12/17 10:17 + */ +public class FullPermutationUtil { + + // 定义一个 全局变量,来存放递归打印的 结果 +// public static List list = new ArrayList<>(); 定义为list的变量名的话,有问题,多放进去了两个 int[]的值 + public static List l = new ArrayList<>(); + + public static void permute2(int[] array, int start) { + //System.out.println(l.size()); + + if (start == array.length) { // 输出 + System.out.println(Arrays.toString(array)); + l.add(Arrays.toString(array)); + } else { + for (int i = start; i < array.length; ++i) { + swap(array, start, i); // 交换元素 + permute2(array, start + 1); //交换后,再进行全排列算法 + swap(array, start, i); //还原成原来的数组,便于下一次的全排列 + } + } + } + private static void swap(int[] array, int s, int i) { + int t = array[s]; + array[s] = array[i]; + array[i] = t; + } + public static void main(String[] args) { + int[] arrays = new int[]{1, 2, 3, 4}; + permute2(arrays, 0); + System.out.println(l.size()); + System.out.println(l); + } +} diff --git a/src/main/java/com/zgczx/utils/JDBCDao.java b/src/main/java/com/zgczx/utils/JDBCDao.java new file mode 100644 index 0000000..d918d94 --- /dev/null +++ b/src/main/java/com/zgczx/utils/JDBCDao.java @@ -0,0 +1,88 @@ +package com.zgczx.utils; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author aml + * @date 2019/11/1 18:43 + */ +public class JDBCDao { + +/* *//** + * * 增加,删除,修改 + *//* + public static void insertOrDeleteOrUpdate(String sql) { + try { + Connection connection = com.zgczx.utils.JDBCDao.getConnection(); + PreparedStatement pst = connection.prepareStatement(sql); + int execute = pst.executeUpdate(); + System.out.println("执行语句:" + sql + "," + execute + "行数据受影响"); + com.zgczx.utils.JDBCDao.close(null, pst, connection); + } catch (SQLException e) { + System.out.println("异常提醒:" + e); + } + }*/ +/* *//** + * * 查询,返回结果集 + *//* + public static List> select(String sql) { + List> returnResultToList = null; + try { + Connection connection = com.zgczx.utils.JDBCDao.getConnection(); + PreparedStatement pst = connection.prepareStatement(sql); + ResultSet resultSet = pst.executeQuery(); +// returnResultToList = returnResultToList(resultSet); + com.zgczx.utils.JDBCDao.close(resultSet, pst, connection); + } catch (SQLException e) { + System.out.println("异常提醒:" + e); + } + return returnResultToList; + }*/ + /** + * * 数据返回集合 * @param resultSet * @return * @throws SQLException + */ + public static List> returnResultToList(ResultSet resultSet) { + List> values = null; + try { + // 键: 存放列的别名, 值: 存放列的值. + values = new ArrayList<>(); + // 存放字段名 + List columnName = new ArrayList<>(); + ResultSetMetaData rsmd = resultSet.getMetaData(); + for (int i = 0; i < rsmd.getColumnCount(); i++) { + // 字段名 + columnName.add(rsmd.getColumnLabel(i + 1)); + } + System.out.println("表字段为:"); + System.out.println(columnName); + System.out.println("表数据为:"); + Map map = null; + // 处理 ResultSet, 使用 while 循环 + while (resultSet.next()) { + map = new HashMap<>(); + for (String column : columnName) { + Object value = resultSet.getObject(column); + map.put(column, value); + System.out.print(value + "\t"); + } + // 把一条记录的 Map 对象放入准备的 List 中 + values.add(map); + System.out.println(); + } + } catch (SQLException e) { + System.out.println("异常提醒:" + e); + } + return values; + } +} diff --git a/src/main/java/com/zgczx/utils/MapUtil.java b/src/main/java/com/zgczx/utils/MapUtil.java index 04c4346..4a5648a 100644 --- a/src/main/java/com/zgczx/utils/MapUtil.java +++ b/src/main/java/com/zgczx/utils/MapUtil.java @@ -13,6 +13,52 @@ public class MapUtil { + public static Map relationOption(String[] strings){ + + Map map = new HashMap<>(); + map.put("a","A"); + map.put("b","B"); + map.put("c","C"); + map.put("d","D"); + return map; + } + //静态方法 + public static Map meal(){ + Map mealid = new HashMap<>(); + //对应的k-v + mealid.put("1", "早餐"); + mealid.put("2", "午餐"); + mealid.put("3", "晚餐"); + return mealid; + } + + public static Map dishclass(){ + Map dishclassid = new HashMap<>(); + dishclassid.put("1", "套餐"); + dishclassid.put("2", "小炒"); + dishclassid.put("3", "盖饭"); + dishclassid.put("4", "面点"); + dishclassid.put("5", "小吃"); + dishclassid.put("6", "清真"); + dishclassid.put("7", "其他"); + return dishclassid; + } + + public static Map campus(){ + Map campusid = new HashMap<>(); + //对应的k-v + campusid.put("1", "校本部"); + campusid.put("2", "清华园校区"); + campusid.put("3", "双榆树校区"); + return campusid; + } + + public static Map role(){ + Map roleid = new HashMap<>(); + //对应的k-v + roleid.put(1, "老师"); + roleid.put(2, "学生"); + return roleid; + } - } diff --git a/src/main/java/com/zgczx/utils/Param.java b/src/main/java/com/zgczx/utils/Param.java new file mode 100644 index 0000000..f6034c8 --- /dev/null +++ b/src/main/java/com/zgczx/utils/Param.java @@ -0,0 +1,30 @@ +package com.zgczx.utils; + +import javax.servlet.http.HttpServletRequest; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +public class Param { + + /** + * 获取请求的参数 + * @param request + * @return + */ + public static Map getParam(HttpServletRequest request){ + Map map = new HashMap(); + Enumeration em = request.getParameterNames(); + while (em.hasMoreElements()) { + String name = (String) em.nextElement(); + String value = request.getParameter(name); + + System.out.println("请求参数名: " + name); + System.out.println("请求参数值: " + value); + + map.put(name, value); + } + return map; + } + +} diff --git a/src/main/java/com/zgczx/utils/RecursionTreeUtil.java b/src/main/java/com/zgczx/utils/RecursionTreeUtil.java new file mode 100644 index 0000000..d86704d --- /dev/null +++ b/src/main/java/com/zgczx/utils/RecursionTreeUtil.java @@ -0,0 +1,104 @@ +package com.zgczx.utils; + +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * 字符串的全排列 + * + * @author aml + * @date 2019/12/15 18:22 + */ +@Slf4j +public class RecursionTreeUtil { + + // 定义一个 全局变量,来存放递归打印的 结果 + public static List list = new ArrayList<>(); + + /** + * @param s 字符串 + * @param from 开始下标 + * @param to 结束下标 + */ + public static void permutation(char[] s, int from, int to) { + List list = new ArrayList<>(); + if (to <= 1) + return; + if (from == to) { + System.out.println(s); + } else { + for (int i = from; i <= to; i++) { + swap(s, i, from); //交换前缀,使其产生下一个前缀 + permutation(s, from + 1, to); + swap(s, from, i); //将前缀换回,继续做上一个前缀的排列 + } + } + + } + + public static void swap(char[] s, int i, int j) { + char tmp = s[i]; + s[i] = s[j]; + s[j] = tmp; + } + + + public static void permute(int[] array, int start) { + + if (start == array.length) { // 输出 + System.out.println(Arrays.toString(array)); + +// list.add(Arrays.toString(array));// 全局变量接收 递归结果 + } else { + for (int i = start; i < array.length; ++i) { + swap(array, start, i); // 交换元素 + permute(array, start + 1); //交换后,再进行全排列算法 + swap(array, start, i); //还原成原来的数组,便于下一次的全排列 + + } + } + + } + + /** + * #19.12.16 + * 让每道题选项随机的 函数,但这个方法不太好 + * + * @param array 有几个选项 + * @param start 从 0 开始 + * @return + */ + public static int[] randomSort(int[] array, int start) { + + int random = (int) (Math.random() * (array.length - 1) + 1); + swap(array, start, random); // 交换元素 + // System.out.println(Arrays.toString(array)); + log.info("【输出此次选项的顺序:】{}", Arrays.toString(array)); + return array; + } + + private static void swap(int[] array, int s, int i) { + int t = array[s]; + array[s] = array[i]; + array[i] = t; + } + + + public static void main(String[] args) { +// char[] s = {'a','b','c','d'}; +// permutation(s, 0, 3); + + int[] array = new int[]{1, 2, 3, 4}; +// randomSort(array, 0); + + permute(array, 0); + + + } + + +} diff --git a/src/main/java/com/zgczx/utils/SplitPaperUtil.java b/src/main/java/com/zgczx/utils/SplitPaperUtil.java new file mode 100644 index 0000000..a54a867 --- /dev/null +++ b/src/main/java/com/zgczx/utils/SplitPaperUtil.java @@ -0,0 +1,132 @@ +package com.zgczx.utils; + +import com.zgczx.enums.ResultEnum; +import com.zgczx.exception.ScoreException; +import com.zgczx.repository.mysql1.exam.dao.ChapterDao; +import com.zgczx.repository.mysql1.exam.dao.ExamPaperDao; +import com.zgczx.repository.mysql1.exam.dao.QuestionDao; +import com.zgczx.repository.mysql1.exam.model.ExamPaper; +import com.zgczx.repository.mysql1.exam.model.Question; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +import static com.zgczx.utils.FilterStringUtil.filterAlphabetCapital; + +/** + * 切分试卷工具类 + * + * @author aml + * @date 2019/12/12 15:24 + */ +@Slf4j +public class SplitPaperUtil { + + @Autowired + private ChapterDao chapterDao; + + @Autowired + private QuestionDao questionDao; + + @Autowired + private ExamPaperDao examPaperDao; + + private String info; + + @Transactional + public List splitExam(String examName, String subject) { + ExamPaper examPaper = examPaperDao.findByExamNameAndSubjectAndValid(examName, subject, 1); + if (examPaper == null) { + info = "暂时没有此科目的此试卷"; + log.error("【错误信息】: {}", info); + throw new ScoreException(ResultEnum.RESULE_DATA_NONE, info); + } + String examContent = examPaper.getExamContent(); + List stringList = new ArrayList<>(); + int i1 = examContent.indexOf("1."); + int i2 = examContent.indexOf("2."); + int i3 = examContent.indexOf("3."); + int i4 = examContent.indexOf("4."); + int i5 = examContent.indexOf("5."); + int i6 = examContent.indexOf("6."); + int i7 = examContent.indexOf("7."); + int i8 = examContent.indexOf("8."); + int i9 = examContent.indexOf("9."); + int i10 = examContent.indexOf("10."); + String str1 = examContent.substring(i1, i2); + String str2 = examContent.substring(i2, i3); + String str3 = examContent.substring(i3, i4); + String str4 = examContent.substring(i4, i5); + String str5 = examContent.substring(i5, i6); + String str6 = examContent.substring(i6, i7); + String str7 = examContent.substring(i7, i8); + String str8 = examContent.substring(i8, i9); + String str9 = examContent.substring(i9, i10); + String str10 = examContent.substring(i10, examContent.length()); + stringList.add(str1); + stringList.add(str2); + stringList.add(str3); + stringList.add(str4); + stringList.add(str5); + stringList.add(str6); + stringList.add(str7); + stringList.add(str8); + stringList.add(str9); + stringList.add(str10); + + for (int i = 0; i < stringList.size(); i++) { + Question question = new Question(); + String s = stringList.get(i); + question.setExamId(examPaper.getId()); + question.setQuestionSource("模拟考试"); + question.setExamName("3.1 细胞膜的结构和功能"); + question.setExamLocation("北京"); + question.setQuestionId(i + 1); + question.setQuestionType("单选"); + question.setQuestionDifficult("一般"); + question.setQuestionContext(s); + question.setQuestionAttribute("细胞膜的结构和功能"); + int a = s.indexOf("A"); + int b = s.indexOf("【答案】"); + int c = s.indexOf("【解析】"); + String option = s.substring(a, b); + String correctOption1 = s.substring(b, c);//此题的正确答案选项; + String correctOption = filterAlphabetCapital(correctOption1); + //切分所有选项 A-D,判断答案是哪个选项,然后存哪个选项的文本; + int b1 = s.indexOf("B"); + int c1 = s.indexOf("C"); + int d1 = s.indexOf("D"); + String contentA = s.substring(a, b1); + String contentB = s.substring(b1, c1); + String contentC = s.substring(c1, d1); + String contentD = s.substring(d1, b); + question.setQuestionOption(option);//题的选项 + question.setCorrectOption(correctOption);//题的正确答案选项 + question.setCorrectAnalysis(s.substring(c, s.length()));//答案的正确内容 + if (correctOption.trim().equals("A")) { + question.setCorrectText(contentA);//正确答案的文本 + } else if (correctOption.trim().equals("B")) { + question.setCorrectText(contentB); + } else if (correctOption.trim().equals("C")) { + question.setCorrectText(contentC); + } else { + question.setCorrectText(contentD); + } + question.setValid(1);//1:此数据有效 + Question save = questionDao.save(question); + } + List list = questionDao.findByExamName("3.1 细胞膜的结构和功能"); + List list1 = new ArrayList<>(); + for (Question question : list) { + list1.add(question.getId()); + } + examPaper.setQuestionList(String.valueOf(list1)); + ExamPaper save = examPaperDao.save(examPaper); + log.info("【试卷表的详细信息:】 {}", save); + return list; + + } +} diff --git a/src/main/java/com/zgczx/utils/SpringUtil.java b/src/main/java/com/zgczx/utils/SpringUtil.java new file mode 100644 index 0000000..ab3c54f --- /dev/null +++ b/src/main/java/com/zgczx/utils/SpringUtil.java @@ -0,0 +1,64 @@ +package com.zgczx.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * 获取注入spring中的bean的各种方式 + * @author aml + * @date 2019/11/1 16:13 + */ + +@Component +public class SpringUtil implements ApplicationContextAware { + + private static Logger logger = LoggerFactory.getLogger(SpringUtil.class); + + private static ApplicationContext applicationContext; + + // 1. 获取applicationContext + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + + if(SpringUtil.applicationContext == null) { + + SpringUtil.applicationContext = applicationContext; + + } + + logger.info("ApplicationContext配置成功,applicationContext对象:"+SpringUtil.applicationContext); + + } + + public static ApplicationContext getApplicationContext() { + + return applicationContext; + + } + + // 2. 根据注入bean中的别名获取,例如: DataSource dataSource= (DataSource)SpringUtil.getBean("db2DataSource"); + public static Object getBean(String name) { + + return getApplicationContext().getBean(name); + + } + + // 2。根据类类型获取对应的bean,这里好像没法获取相同类型中指定的的bean, + public static T getBean(Class clazz) { + + return getApplicationContext().getBean(clazz); + + } + + // 2. 根据类型和bean的别名获取指定的bean + public static T getBean(String name,Class clazz) { + + return getApplicationContext().getBean(name,clazz); + + } + +} \ No newline at end of file diff --git a/src/main/java/com/zgczx/utils/StringToMapUtil.java b/src/main/java/com/zgczx/utils/StringToMapUtil.java new file mode 100644 index 0000000..3985f7e --- /dev/null +++ b/src/main/java/com/zgczx/utils/StringToMapUtil.java @@ -0,0 +1,32 @@ +package com.zgczx.utils; + +import java.util.HashMap; +import java.util.Map; + +import static com.zgczx.utils.FilterStringUtil.braces; + +/** + * 将 json(k-v)格式的string,转为map + * + * @author aml + * @date 2019/12/24 14:28 + */ +public class StringToMapUtil { + + public Map stringToMap(String mapText) { + if (mapText == null || mapText.equals("")) { + return null; + } + Map map = new HashMap(); + //1. 首先 先去掉 大括号 + String braces = braces(mapText); + String[] split = braces.split(","); + for (String s : split){ + int i = s.indexOf(":"); + String key = s.substring(0, i); + String value = s.substring(i + 1, s.length()); + map.put(key,value); + } + return map; + } +} diff --git a/src/main/java/com/zgczx/utils/WordRedUtil.java b/src/main/java/com/zgczx/utils/WordRedUtil.java new file mode 100644 index 0000000..ee5ad2e --- /dev/null +++ b/src/main/java/com/zgczx/utils/WordRedUtil.java @@ -0,0 +1,173 @@ +package com.zgczx.utils; + +import com.alibaba.fastjson.JSONObject; +import com.microsoft.schemas.vml.CTShape; +import lombok.extern.slf4j.Slf4j; + +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.xwpf.extractor.XWPFWordExtractor; +import org.apache.poi.xwpf.usermodel.*; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject; +import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTObject; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * 读取Word 的 util + * //以数字开头并且包含.表示一个新的题目开始 + * String regex = "^\\d{1,10}\\."; + * * Pattern pattern = Pattern.compile(regex); + * * pattern.matcher(line) + * @author aml + * @date 2019/12/11 15:23 + */ +@Slf4j +public class WordRedUtil { + + private final static String doc = "doc"; + private final static String docx = "docx"; + + public static JSONObject readWord(MultipartFile file) throws IOException { + JSONObject jsonObject = new JSONObject(); + //1. 检查文件 + checkFile(file); + //2.创建输入流读取DOC文件 + String filename = file.getOriginalFilename(); + System.out.println("文件名称: " + filename); + InputStream inputStream = file.getInputStream(); + String text = ""; + if (filename.endsWith("doc")){ + //FileInputStream fis = new FileInputStream((File) file); + HWPFDocument doc = new HWPFDocument(inputStream); + text = doc.getDocumentText(); + + }else { +//3. 创建wordExtractor + XWPFDocument xdoc = new XWPFDocument(inputStream); + XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc); + + //WordExtractor extractor = new WordExtractor(inputStream); + //4. 对doc文件进行提取 + text = extractor.getText(); + int i = 1;// 第一个图片 + //用XWPFDocument的getAllPictures来获取所有图片 + List pictureDataList = xdoc.getAllPictures(); + List imgList = new ArrayList<>(); + for (XWPFPictureData pic : pictureDataList) { + byte[] fileBytes = pic.getData(); + + String fileName = filename + "_" + i + "_" + pic.getFileName(); + i++; + + if (fileBytes.length > 500) {//文件大于 500 字节,筛选出一些莫名其妙的小图片 + // 文件上传路径,这个路径是13服务器上的地址,而工程是在14服务器上,所以暂时都是手动存图片。 + //图片上传值13上,/home/bigdata/application/canteen-system-image +// String uploadPath = "/home/bigdata/application/canteen-system-image/"; + String uploadPath = "J:\\A"; + // 上传文件 + File upload = new File(uploadPath, fileName); + OutputStream out = new FileOutputStream(upload); + out.write(fileBytes); + out.flush(); + System.out.println("download success"); + out.close(); + + // 上传到服务器上的url,可直接拿到浏览器直接打开的url + String fileUrl = "http://zhongkeruitong.top/image/" + fileName; +// returnMsg = "http://zhongkeruitong.top/image/" + fileName; + log.info("===> 图片上传地址:" + fileUrl); + imgList.add(fileUrl); + } + } + jsonObject.put("imgList", imgList); + } + jsonObject.put("doctext", text); + System.out.println(jsonObject); + + jsonObject.put("title",filename); + +// return text; + return jsonObject; + } + + + private static void checkFile(MultipartFile file) throws IOException { + //判断文件是否存在 + if (null == file) { + log.error("文件不存在!"); + throw new FileNotFoundException("文件不存在!"); + } + //获得文件名 + String fileName = file.getOriginalFilename(); + //判断文件是否是excel文件 + if (!fileName.endsWith(doc) && !fileName.endsWith(docx)) { + log.error(fileName + "不是word文件"); + throw new IOException(fileName + "不是word文件"); + } + } + + + //获取某一个段落中的所有图片索引 + public static List readImageInParagraph(XWPFParagraph paragraph) { + //图片索引List + List imageBundleList = new ArrayList(); + //段落中所有XWPFRun + List runList = paragraph.getRuns(); + for (XWPFRun run : runList) { + //XWPFRun是POI对xml元素解析后生成的自己的属性,无法通过xml解析,需要先转化成CTR + CTR ctr = run.getCTR(); + //对子元素进行遍历 + XmlCursor c = ctr.newCursor(); + //这个就是拿到所有的子元素: + c.selectPath("./*"); + while (c.toNextSelection()) { + XmlObject o = c.getObject(); + //如果子元素是这样的形式,使用CTDrawing保存图片 + if (o instanceof CTDrawing) { + CTDrawing drawing = (CTDrawing) o; + CTInline[] ctInlines = drawing.getInlineArray(); + for (CTInline ctInline : ctInlines) { + CTGraphicalObject graphic = ctInline.getGraphic(); + // + XmlCursor cursor = graphic.getGraphicData().newCursor(); + cursor.selectPath("./*"); + while (cursor.toNextSelection()) { + XmlObject xmlObject = cursor.getObject(); +// 如果子元素是这样的形式 + if (xmlObject instanceof CTPicture) { + org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture picture = (org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture) xmlObject; + //拿到元素的属性 + imageBundleList.add(picture.getBlipFill().getBlip().getEmbed()); + } + } + } + } + //使用CTObject保存图片 +//形式 + if (o instanceof CTObject) { + CTObject object = (CTObject) o; + System.out.println(object); + XmlCursor w = object.newCursor(); + w.selectPath("./*"); + while (w.toNextSelection()) { + XmlObject xmlObject = w.getObject(); + if (xmlObject instanceof CTShape) { + CTShape shape = (CTShape) xmlObject; + //imageBundleList.add(shape.getImagedataArray()[0]); + } + } + } + } + } + return imageBundleList; + } +} diff --git a/src/main/java/com/zgczx/utils/XWPFUtils.java b/src/main/java/com/zgczx/utils/XWPFUtils.java new file mode 100644 index 0000000..357c030 --- /dev/null +++ b/src/main/java/com/zgczx/utils/XWPFUtils.java @@ -0,0 +1,207 @@ +package com.zgczx.utils; + +/** + * @author aml + * @date 2019/12/12 17:04 + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.*; + +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFPictureData; +import org.apache.poi.xwpf.usermodel.XWPFRun; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject; +import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture; +import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTObject; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; + +import com.microsoft.schemas.vml.CTShape; + +import javax.servlet.http.HttpServletRequest; + +/** + * 获取docx中图片的索引 + * docx本质上就是xml数据 + * 可以将docx文件用压缩工具打卡就可以看到数据存储的本质 + * 获取2007word中的图片索引(例:Ird4,Ird5) + * + * @author aml + * @date 2019/12/11 15:23 + */ +public class XWPFUtils { + + //获取某一个段落中的所有图片索引 + public static List readImageInParagraph(XWPFParagraph paragraph) { + //图片索引List + List imageBundleList = new ArrayList(); + + //段落中所有XWPFRun + List runList = paragraph.getRuns(); + for (XWPFRun run : runList) { + //XWPFRun是POI对xml元素解析后生成的自己的属性,无法通过xml解析,需要先转化成CTR + CTR ctr = run.getCTR(); + //对子元素进行遍历 + XmlCursor c = ctr.newCursor(); + //这个就是拿到所有的子元素: + c.selectPath("./*"); + while (c.toNextSelection()) { + XmlObject o = c.getObject(); + //如果子元素是这样的形式,使用CTDrawing保存图片 + if (o instanceof CTDrawing) { + CTDrawing drawing = (CTDrawing) o; + CTInline[] ctInlines = drawing.getInlineArray(); + for (CTInline ctInline : ctInlines) { + CTGraphicalObject graphic = ctInline.getGraphic(); + // + XmlCursor cursor = graphic.getGraphicData().newCursor(); + cursor.selectPath("./*"); + while (cursor.toNextSelection()) { + XmlObject xmlObject = cursor.getObject(); + //重点:图片的标签格式 如果子元素是这样的形式 + if (xmlObject instanceof CTPicture) { + org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture picture = (org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture) xmlObject; + //拿到元素的属性 + imageBundleList.add(picture.getBlipFill().getBlip().getEmbed()); + } + } + } + } + //使用CTObject保存图片 + //形式 + if (o instanceof CTObject) { + CTObject object = (CTObject) o; + XmlCursor w = object.newCursor(); + w.selectPath("./*"); + while (w.toNextSelection()) { + XmlObject xmlObject = w.getObject(); + if (xmlObject instanceof CTShape) { + CTShape shape = (CTShape) xmlObject; + /*imageBundleList.add(shape.getImagedataArray()[0].getId2());*/ + } + } + } + } + } + return imageBundleList; + } + + + /** + * 获取word中图片上传到文件服务器 + * @return + * @throws + */ + public static List> getImgUrl(List> imgMsgList, HttpServletRequest request) throws Exception{ + /* * 实现思路 + * 1、根据段落docx获取图片索引 + * 2、根据获取到的图片数据标识,在总的docx中获取图片data数据 + * 3.上传图片返回访问路径;*/ + //未分割之前的总文件地址 + ResourceBundle resource = ResourceBundle.getBundle("URL"); + String imgLocalPath = resource.getString("imgLocalPath"); + String Indexdocx =request.getSession().getAttribute("wordRootPath").toString(); + //读取总文件 + InputStream in = new FileInputStream(Indexdocx); + XWPFDocument xwpfDocumentIndex = new XWPFDocument(in); + in.close(); + List list = xwpfDocumentIndex.getAllPackagePictures(); + //需要获取数据的图片名称 + String paraPicName = ""; + //总文档中的图片名称 + String pictureName =""; + //上传到图片服务器之后的图片名称 + //图片索引rId1/rId2/rId3.. + String id =""; + String uuidName = ""; + String endName = ""; + byte[] bd = null; + //方法返回的List包含,题目序号,上传之后图片名称 + List> resMapList = new ArrayList>(); + Map imgUploadNameMap = new HashMap(); + for (XWPFPictureData xwpfPictureData : list) { + uuidName = UUID.randomUUID().toString(); + id = xwpfPictureData.getParent().getRelationId(xwpfPictureData); + pictureName = xwpfPictureData.getFileName(); + endName = pictureName.substring(pictureName.lastIndexOf(".")); + bd = xwpfPictureData.getData(); + FileOutputStream fos = new FileOutputStream(new File(imgLocalPath+uuidName+endName)); + fos.write(bd); + fos.flush(); + fos.close(); + // ImageSizer.imageZip(new File(imgLocalPath+uuidName+endName), new File(imgLocalPath+uuidName+"-e"+endName), "", 130, 130, 1); + imgUploadNameMap.put(id, uuidName+endName); + } + //遍历参数 + String tempPicName = ""; + String tempValue =""; + for (Map map : imgMsgList) { + tempPicName = map.get("pictureName"); + tempValue = imgUploadNameMap.get(tempPicName); + if(tempValue!=null){ + map.put("pictureName", tempValue); + }else{ + map.put("pictureName", ""); + } + resMapList.add(map); + } + return resMapList; + } + + +/* *//** + * 将word切割 + * @param + * @return + * @throws + *//* + private void splitWord(HttpServletRequest request) throws Exception{ + InputStream in = null; + try { + in = new FileInputStream(new File(request.getSession().getAttribute("wordRootPath").toString())); + } catch (Exception e) { + e.printStackTrace(); + } + WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(in); + //获取word所有内容 + List list= wordMLPackage.getMainDocumentPart().getContent(); + WordprocessingMLPackage doc1 =null; + int count =0; + for (int i = 0; i < list.size(); i++) { + String tempFileName = null; + String regex = "^\\d{1,100}\\."; + Pattern pattern = Pattern.compile(regex); + Matcher m = pattern.matcher(list.get(i).toString()); + if(m.find()){//判断当前内容是否为题干 + count++; + if(count==1){//第一题开始 + doc1 = WordprocessingMLPackage.createPackage(); + doc1.getMainDocumentPart().addObject(list.get(i)); + }else{//非第一题 + tempFileName=count-1+""; + doc1.save(new File(request.getSession().getAttribute("wordUUIDFileName")+"/"+tempFileName+".docx")); + doc1 = WordprocessingMLPackage.createPackage(); + doc1.getMainDocumentPart().addObject(list.get(i)); + } + }else{ + if(count>0){ + doc1.getMainDocumentPart().addObject(list.get(i)); + } + } + if(i==list.size()-1){ + tempFileName=count+""; + doc1.save(new File(request.getSession().getAttribute("wordUUIDFileName")+"/"+tempFileName+".docx")); + } + } + }*/ + + +} diff --git a/src/main/resources/mybatis/mapper/ManuallyEnterGradesMapper.xml b/src/main/resources/mybatis/mapper/ManuallyEnterGradesMapper.xml new file mode 100644 index 0000000..c8d2003 --- /dev/null +++ b/src/main/resources/mybatis/mapper/ManuallyEnterGradesMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mybatis-config.xml b/src/main/resources/mybatis/mybatis-config.xml new file mode 100644 index 0000000..b3ca45b --- /dev/null +++ b/src/main/resources/mybatis/mybatis-config.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/zgczx/ScoreAnalysisApplicationTests.java b/src/test/java/com/zgczx/ScoreAnalysisApplicationTests.java index ab2ed72..e533cb9 100644 --- a/src/test/java/com/zgczx/ScoreAnalysisApplicationTests.java +++ b/src/test/java/com/zgczx/ScoreAnalysisApplicationTests.java @@ -1,16 +1,84 @@ package com.zgczx; +import com.zgczx.mapper.ManuallyEnterGradesMapper; +import com.zgczx.repository.mysql1.score.dao.ManuallyEnterGradesDao; +import com.zgczx.repository.mysql1.score.model.ExamInfo; +import com.zgczx.repository.mysql1.score.dao.ExamInfoDao; +import com.zgczx.repository.mysql1.score.model.ManuallyEnterGrades; import org.junit.Test; import org.junit.runner.RunWith; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +//使用MapperScan批量扫描所有的Mapper接口; +@MapperScan(value = "com.zgczx.mapper") @RunWith(SpringRunner.class) @SpringBootTest public class ScoreAnalysisApplicationTests { + @Autowired + ExamInfoDao examInfoDao; + + @Autowired + DataSource dataSource; + + // 用mybatis写的接口方法,查询方法 + @Autowired + ManuallyEnterGradesMapper manuallyEnterGradesMapper; + + @Autowired + ManuallyEnterGradesDao manuallyEnterGradesDao; @Test public void contextLoads() { +// String dateString = "19年4月期中"; +// //1. 先用传来的参数,查库 +//// ExamInfo examName = examInfoDao.getByExamName(dateString); +// int byExamName = examInfoDao.findByExamName(dateString); +// System.out.println(byExamName); +//// System.out.println(examName); + + List one = examInfoDao.findAll(); + System.out.println(one); + } + + @Test + public void contextLoads1()throws SQLException { + System.out.println(dataSource.getClass()); + + Connection connection = dataSource.getConnection(); + System.out.println(connection); + connection.close(); + + } + + @Test + public void getManuallyEnterGrades(){ + + ManuallyEnterGrades manuallyEnterGradesById = manuallyEnterGradesMapper.getManuallyEnterGradesById(16); + System.out.println(manuallyEnterGradesById); + List manuallyEnterGrades = manuallyEnterGradesMapper.getManuallyEnterGrades(); + System.out.println(manuallyEnterGrades); + + } + @Test + public void getAllByOpenid(){ + List stringList = new ArrayList<>(); + stringList.add("111"); + stringList.add("121"); + List byWechatOpenidIn = manuallyEnterGradesDao.findByWechatOpenidIn(stringList); + System.out.println(byWechatOpenidIn); + + List byWechatOpenidInAndStudentNumber = manuallyEnterGradesDao.findByWechatOpenidInAndStudentNumber(stringList, "111"); + System.out.println(byWechatOpenidInAndStudentNumber); + } } diff --git a/src/test/java/com/zgczx/repository/score/ExamFullScoreSetDaoTest.java b/src/test/java/com/zgczx/repository/score/ExamFullScoreSetDaoTest.java new file mode 100644 index 0000000..918f613 --- /dev/null +++ b/src/test/java/com/zgczx/repository/score/ExamFullScoreSetDaoTest.java @@ -0,0 +1,16 @@ +package com.zgczx.repository.score; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author aml + * @date 2019/10/24 21:04 + */ +public class ExamFullScoreSetDaoTest { + + @Test + public void findByExaminfoId() { + } +} \ No newline at end of file diff --git a/src/test/java/com/zgczx/test/ExamInfoDaoTest.java b/src/test/java/com/zgczx/test/ExamInfoDaoTest.java new file mode 100644 index 0000000..3489297 --- /dev/null +++ b/src/test/java/com/zgczx/test/ExamInfoDaoTest.java @@ -0,0 +1,53 @@ +package com.zgczx.test; + +import com.zgczx.repository.mysql1.score.model.ExamInfo; +import com.zgczx.repository.mysql1.score.dao.ExamInfoDao; +import com.zgczx.repository.mysql2.scoretwo.dao.ExamCoversionTotalDao; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +/** + * 单元测试Junit步骤 + * @author aml + * @date 2019/10/24 13:54 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +public class ExamInfoDaoTest { + @Autowired + ExamInfoDao examInfoDao; + + @Autowired + ExamCoversionTotalDao examCoversionTotalDao; + @Test + public void findByExamName() { + String dateString = "19年4月期中"; + //1. 先用传来的参数,查库 +// int byExamName = examInfoDao.findByExamName(dateString); +// System.out.println(byExamName); +// List one = examInfoDao.findAll(); +// System.out.println(one); +// int byExamName = examInfoDao.findByExamName(dateString); +// System.out.println("查询出来的id为: "+byExamName); + + ExamInfo examName = examInfoDao.getByExamName(dateString); + ExampleMatcher matching = ExampleMatcher.matching(); + examCoversionTotalDao.findAll((Iterable) matching); + String s = "exam_type"; + String s1 = "2019年3月考试"; +//// List byYuwenScore = examCoversionTotalDao.findByYuwenScore(s, s1); +// +// System.out.println(byYuwenScore); + + } + + @Test + public void getByExamName() { + } +} \ No newline at end of file diff --git a/src/test/java/com/zgczx/utils/DateFormatUtilTest.java b/src/test/java/com/zgczx/utils/DateFormatUtilTest.java new file mode 100644 index 0000000..54cd938 --- /dev/null +++ b/src/test/java/com/zgczx/utils/DateFormatUtilTest.java @@ -0,0 +1,48 @@ +package com.zgczx.utils; + +import com.zgczx.repository.mysql1.score.model.ExamInfo; +import com.zgczx.repository.mysql1.score.dao.ExamInfoDao; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author aml + * @date 2019/10/24 13:33 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +public class DateFormatUtilTest { + @Autowired + ExamInfoDao examInfoDao; + + @Test + public void recoveryString() { + String dateString = "2019年010月月考"; + //1. 先用传来的参数,查库 + ExamInfo examName = examInfoDao.getByExamName(dateString); + System.out.println(examName); + if (examName != null) { + if (examName.getExamName().equals(dateString)) { + System.out.println("查出来了: " + dateString); +// return dateString; + } + } + //3. 查不出 + dateString = dateString.substring(2, dateString.length()); + ExamInfo examName1 = examInfoDao.getByExamName(dateString); + if (examName1 != null) { + if (dateString.equals(examName1.getExamName())) { + System.out.println(dateString); + + } + } + + dateString = dateString.replaceFirst("0", ""); + + System.out.println("替换0的个数: " + dateString); + + } +} \ No newline at end of file