瀏覽代碼

模拟考成绩

小么熊🐻 3 年之前
父節點
當前提交
48ee7b2a3b

+ 142 - 0
twzd-admin/src/main/java/com/miaxis/system/controller/h5/ScoreInfoController.java

@@ -0,0 +1,142 @@
+package com.miaxis.system.controller.h5;
+
+import com.miaxis.common.annotation.Log;
+import com.miaxis.common.constant.Constants;
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.common.enums.BusinessTypeEnum;
+import com.miaxis.common.utils.SecurityUtils;
+import com.miaxis.score.domain.ScoreInfo;
+import com.miaxis.score.dto.ScoreInfoAllDTO;
+import com.miaxis.score.dto.ScoreInfoDTO;
+import com.miaxis.score.service.IScoreInfoService;
+import io.swagger.annotations.*;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 【模拟考成绩】Controller
+ *
+ * @author miaxis
+ * @date 2021-08-23
+ */
+@RestController
+@RequestMapping("/score/info")
+@Api(tags={"【H5-模拟考成绩】"})
+public class ScoreInfoController extends BaseController {
+    @Autowired
+    private IScoreInfoService scoreInfoService;
+
+    /**
+     * 查询模拟考成绩列表
+     */
+    @GetMapping("/list")
+    @ApiOperation("查询模拟考成绩列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
+            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
+    })
+    public ResponsePageInfo<ScoreInfo> list(){
+        startPage();
+        ScoreInfo scoreInfo = new ScoreInfo();
+        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+        System.out.println();
+        List<ScoreInfo> list = scoreInfoService.selectScoreInfoList(scoreInfo);
+        return toResponsePageInfo(list);
+    }
+
+
+
+    /**
+     * 获取模拟考成绩详细信息
+     */
+    @GetMapping(value = "/{id}")
+    @ApiOperation("获取模拟考成绩详细信息")
+    public Response<ScoreInfo> getInfo(
+            @ApiParam(name = "id", value = "模拟考成绩参数", required = true)
+            @PathVariable("id") Long id
+    ){
+        return Response.success(scoreInfoService.getById(id));
+    }
+
+    /**
+     * 新增模拟考成绩
+     */
+    @Log(title = "模拟考成绩", businessType = BusinessTypeEnum.INSERT)
+    @PostMapping
+    @ApiOperation("新增模拟考成绩")
+    public Response<Integer> add(@RequestBody ScoreInfoDTO scoreInfoDTO){
+        ScoreInfo scoreInfo = new ScoreInfo();
+        BeanUtils.copyProperties(scoreInfoDTO,scoreInfo);
+        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+        return toResponse(scoreInfoService.save(scoreInfo) ? 1 : 0);
+    }
+
+    /**
+     * 修改模拟考成绩
+     */
+    @Log(title = "模拟考成绩", businessType = BusinessTypeEnum.UPDATE)
+    @PutMapping
+    @ApiOperation("修改模拟考成绩")
+    public Response<Integer> edit(@RequestBody ScoreInfo scoreInfo){
+        return toResponse(scoreInfoService.updateById(scoreInfo) ? 1 : 0);
+    }
+
+    /**
+     * 删除模拟考成绩
+     */
+    @Log(title = "模拟考成绩", businessType = BusinessTypeEnum.DELETE)
+	@DeleteMapping("/{ids}")
+    @ApiOperation("删除模拟考成绩")
+    public Response<Integer> remove(
+            @ApiParam(name = "ids", value = "模拟考成绩ids参数", required = true)
+            @PathVariable Long[] ids
+    ){
+        return toResponse(scoreInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+    }
+
+
+    /**
+     * 获取预测成功
+     */
+//    @GetMapping(value = "/forecastScore")
+//    @ApiOperation("获取预测成绩")
+//    public Response<Integer> getInfo(){
+//        ScoreInfo scoreInfo = new ScoreInfo();
+//        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+//        int forecastScore = scoreInfoService.getForecastScore(scoreInfo);
+//        return Response.success(forecastScore);
+//    }
+
+
+    /**
+     * 获取预测成功
+     */
+//    @GetMapping(value = "/avgScore")
+//    @ApiOperation("获取平均成绩")
+//    public Response<Integer> getAvgScore(){
+//        ScoreInfo scoreInfo = new ScoreInfo();
+//        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+//        int aveScore = scoreInfoService.getAveScore(scoreInfo);
+//        return Response.success(aveScore);
+//    }
+
+
+
+    /**
+     * 获取最大成绩,平均成绩,预测成绩
+     */
+    @GetMapping(value = "/getScoreInfoAll")
+    @ApiOperation("获取最大成绩,平均成绩,预测成绩")
+    public Response<ScoreInfoAllDTO> getScoreInfoAll(){
+        ScoreInfo scoreInfo = new ScoreInfo();
+        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+        ScoreInfoAllDTO scoreInfoAllDTO = scoreInfoService.getScoreInfoAll(scoreInfo);
+        return Response.success(scoreInfoAllDTO);
+    }
+}

+ 103 - 0
twzd-service/src/main/java/com/miaxis/score/domain/ScoreInfo.java

@@ -0,0 +1,103 @@
+package com.miaxis.score.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.miaxis.common.annotation.Excel;
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+/**
+ * 模拟考成绩对象 score_info
+ *
+ * @author miaxis
+ * @date 2021-08-23
+ */
+@Data
+@TableName("score_info")
+@ApiModel(value = "ScoreInfo", description = "模拟考成绩对象 score_info")
+public class ScoreInfo extends BaseBusinessEntity {
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    @TableId(value = "id")
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    /** 用户ID */
+    @Excel(name = "用户ID")
+    @TableField("user_id")
+    @ApiModelProperty(value = "用户ID")
+    private Long userId;
+
+    /** 考试车型 */
+    @Excel(name = "考试车型")
+    @TableField("type")
+    @ApiModelProperty(value = "考试车型")
+    private String type;
+
+    /** 考试科目 */
+    @Excel(name = "考试科目")
+    @TableField("kskm")
+    @ApiModelProperty(value = "考试科目")
+    private String kskm;
+
+    /** 分数 */
+    @Excel(name = "分数")
+    @TableField("score")
+    @ApiModelProperty(value = "分数")
+    private Long score;
+
+    public void setId(Long id){
+        this.id = id;
+    }
+
+    public Long getId(){
+        return id;
+    }
+    public void setUserId(Long userId){
+        this.userId = userId;
+    }
+
+    public Long getUserId(){
+        return userId;
+    }
+    public void setType(String type){
+        this.type = type;
+    }
+
+    public String getType(){
+        return type;
+    }
+    public void setKskm(String kskm){
+        this.kskm = kskm;
+    }
+
+    public String getKskm(){
+        return kskm;
+    }
+    public void setScore(Long score){
+        this.score = score;
+    }
+
+    public Long getScore(){
+        return score;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("userId", getUserId())
+            .append("type", getType())
+            .append("kskm", getKskm())
+            .append("score", getScore())
+            .append("createTime", getCreateTime())
+            .append("updateTime", getUpdateTime())
+            .toString();
+    }
+}

+ 30 - 0
twzd-service/src/main/java/com/miaxis/score/dto/ScoreInfoAllDTO.java

@@ -0,0 +1,30 @@
+package com.miaxis.score.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 模拟考成绩对象 score_info
+ *
+ * @author miaxis
+ * @date 2021-08-23
+ */
+@Data
+public class ScoreInfoAllDTO {
+    private static final long serialVersionUID = 1L;
+
+
+
+    /** 最大成绩 */
+    @ApiModelProperty(value = "最大成绩")
+    private Integer maxScore;
+
+    /** 平均成绩 */
+    @ApiModelProperty(value = "平均成绩")
+    private Integer avgScore;
+
+    /** 预测成绩 */
+    @ApiModelProperty(value = "预测成绩")
+    private Integer forecastScore;
+
+}

+ 34 - 0
twzd-service/src/main/java/com/miaxis/score/dto/ScoreInfoDTO.java

@@ -0,0 +1,34 @@
+package com.miaxis.score.dto;
+
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 模拟考成绩对象 score_info
+ *
+ * @author miaxis
+ * @date 2021-08-23
+ */
+@Data
+public class ScoreInfoDTO extends BaseBusinessEntity {
+    private static final long serialVersionUID = 1L;
+
+
+//    /** 用户ID */
+//    private Long userId;
+
+    /** 考试车型 */
+    @ApiModelProperty(value = "考试车型(小车、客车、货车、摩托车)")
+    private String type;
+
+    /** 考试科目 */
+    @ApiModelProperty(value = "考试科目(科目一、科目二、科目三、科目四)")
+    private String kskm;
+
+    /** 分数 */
+    @ApiModelProperty(value = "分数")
+    private Long score;
+
+
+}

+ 45 - 0
twzd-service/src/main/java/com/miaxis/score/mapper/ScoreInfoMapper.java

@@ -0,0 +1,45 @@
+package com.miaxis.score.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.miaxis.score.domain.ScoreInfo;
+
+import java.util.List;
+
+/**
+ * 模拟考成绩Mapper接口
+ *
+ * @author miaxis
+ * @date 2021-08-23
+ */
+public interface ScoreInfoMapper extends BaseMapper<ScoreInfo> {
+    /**
+     * 查询模拟考成绩列表
+     *
+     * @param scoreInfo 模拟考成绩
+     * @return 模拟考成绩集合
+     */
+    public List<ScoreInfo> selectScoreInfoList(ScoreInfo scoreInfo);
+
+
+    /**
+     * 返回
+     * @param scoreInfo
+     * @return
+     */
+    public int getAvgScore(ScoreInfo scoreInfo);
+
+
+    /**
+     * 返回
+     * @param scoreInfo
+     * @return
+     */
+    public List<Integer> getLast10Score(ScoreInfo scoreInfo);
+
+    /**
+     * 返回最大成绩
+     * @param scoreInfo
+     * @return
+     */
+    public int getMaxScore(ScoreInfo scoreInfo);
+}

+ 55 - 0
twzd-service/src/main/java/com/miaxis/score/service/IScoreInfoService.java

@@ -0,0 +1,55 @@
+package com.miaxis.score.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.miaxis.score.domain.ScoreInfo;
+import com.miaxis.score.dto.ScoreInfoAllDTO;
+
+import java.util.List;
+
+/**
+ * 模拟考成绩Service接口
+ *
+ * @author miaxis
+ * @date 2021-08-23
+ */
+public interface IScoreInfoService extends IService<ScoreInfo>{
+    /**
+     * 查询模拟考成绩列表
+     *
+     * @param scoreInfo 模拟考成绩
+     * @return 模拟考成绩集合
+     */
+    public List<ScoreInfo> selectScoreInfoList(ScoreInfo scoreInfo);
+
+    /**
+     * 查询模拟考试平均成绩
+     * @param scoreInfo
+     * @return
+     */
+    public int getAveScore(ScoreInfo scoreInfo);
+
+    /**
+     * 查询模拟考试预测成绩
+     * @param scoreInfo
+     * @return
+     */
+    public int getForecastScore(ScoreInfo scoreInfo);
+
+
+    /**
+     * 最大成绩
+     * @param scoreInfo
+     * @return
+     */
+    public int getMaxScore(ScoreInfo scoreInfo);
+
+
+
+    /**
+     * 同时返回
+     * 最小成绩,最大成绩,平均成绩,预测成绩
+     * @param scoreInfo
+     * @return
+     */
+    public ScoreInfoAllDTO getScoreInfoAll(ScoreInfo scoreInfo);
+}

+ 78 - 0
twzd-service/src/main/java/com/miaxis/score/service/impl/ScoreInfoServiceImpl.java

@@ -0,0 +1,78 @@
+package com.miaxis.score.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.miaxis.score.domain.ScoreInfo;
+import com.miaxis.score.dto.ScoreInfoAllDTO;
+import com.miaxis.score.mapper.ScoreInfoMapper;
+import com.miaxis.score.service.IScoreInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 模拟考成绩Service业务层处理
+ *
+ * @author miaxis
+ * @date 2021-08-23
+ */
+@Service
+public class ScoreInfoServiceImpl extends ServiceImpl<ScoreInfoMapper, ScoreInfo> implements IScoreInfoService {
+    @Autowired
+    private ScoreInfoMapper scoreInfoMapper;
+
+    /**
+     * 查询模拟考成绩列表
+     *
+     * @param scoreInfo 模拟考成绩
+     * @return 模拟考成绩
+     */
+    @Override
+    public List<ScoreInfo> selectScoreInfoList(ScoreInfo scoreInfo){
+        return scoreInfoMapper.selectScoreInfoList(scoreInfo);
+    }
+
+    @Override
+    public int getAveScore(ScoreInfo scoreInfo) {
+        int avgScore= scoreInfoMapper.getAvgScore(scoreInfo);
+        return avgScore;
+    }
+
+    @Override
+    public int getForecastScore(ScoreInfo scoreInfo) {
+        List<Integer> list = scoreInfoMapper.getLast10Score(scoreInfo);
+        if(list!=null && list.size()>=3) {
+            list.remove(0);
+            list.remove(list.size() - 1);
+        }
+        int total = 0;
+        for (int a: list) {
+            total +=a;
+        }
+        if(total==0){
+            return 0;
+        } else {
+            int forecastScore= total/list.size();
+            return forecastScore;
+        }
+    }
+
+
+
+    @Override
+    public int getMaxScore(ScoreInfo scoreInfo) {
+        int maxScore = scoreInfoMapper.getMaxScore(scoreInfo);
+        return maxScore;
+    }
+
+
+    @Override
+    public ScoreInfoAllDTO getScoreInfoAll(ScoreInfo scoreInfo) {
+        ScoreInfoAllDTO scoreInfoAllDTO = new ScoreInfoAllDTO();
+        scoreInfoAllDTO.setAvgScore(this.getAveScore(scoreInfo));
+        scoreInfoAllDTO.setForecastScore(this.getForecastScore(scoreInfo));
+        scoreInfoAllDTO.setMaxScore(this.getMaxScore(scoreInfo));
+        return scoreInfoAllDTO;
+    }
+
+}

+ 58 - 0
twzd-service/src/main/resources/mapper/score/ScoreInfoMapper.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.miaxis.score.mapper.ScoreInfoMapper">
+
+    <resultMap type="ScoreInfo" id="ScoreInfoResult">
+        <result property="id"    column="id"    />
+        <result property="userId"    column="user_id"    />
+        <result property="type"    column="type"    />
+        <result property="kskm"    column="kskm"    />
+        <result property="score"    column="score"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateTime"    column="update_time"    />
+    </resultMap>
+
+    <sql id="selectScoreInfoVo">
+        select * from score_info
+    </sql>
+
+    <select id="selectScoreInfoList" parameterType="ScoreInfo" resultMap="ScoreInfoResult">
+        <include refid="selectScoreInfoVo"/>
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+            <if test="type != null  and type != ''"> and type = #{type}</if>
+            <if test="kskm != null  and kskm != ''"> and kskm = #{kskm}</if>
+            <if test="score != null "> and score = #{score}</if>
+        </where>
+    </select>
+
+
+    <select id="getLast10Score" parameterType="ScoreInfo" resultType="java.lang.Integer">
+        select score from
+        (select score from score_info s
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+        </where>
+        order by id desc limit 0,10) x order by score
+    </select>
+
+    <select id="getAvgScore" parameterType="ScoreInfo" resultType="int">
+        select IFNULL(ROUND(avg(score),0),0) from score_info s
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+        </where>
+    </select>
+
+
+
+    <select id="getMaxScore" parameterType="ScoreInfo" resultType="int">
+        select IFNULL(max(score),0) from score_info s
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+        </where>
+    </select>
+
+
+</mapper>