Skip to content

Commit

Permalink
添加计算分数 设置最大虚假
Browse files Browse the repository at this point in the history
  • Loading branch information
wjinliang committed Mar 27, 2018
1 parent f8e99cf commit 0f616dc
Show file tree
Hide file tree
Showing 12 changed files with 542 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ public Result submit(@RequestBody PaperAnswerDto paperAnswerDto) {
// 多选
String logic = scoreItem.getOptionLogic();
}
Integer indexId = iScoreItemService.selectByKey(a.getItemId()).getIndexId();
sa.setIndexId(indexId);
iScoreAnswerService.saveNotNull(sa);
// TODO 计算分数
}
Expand Down Expand Up @@ -435,6 +437,7 @@ public Result getAnswer(@RequestParam(value = "paperId") Integer paperId,
public Result getPaperOptions() {
Example example = new Example(ScorePaper.class);
example.setOrderByClause("create_time desc");
//TODO 查询编辑状态的
List<ScorePaper> list = iScorePaperService.selectByExample(example);
List<Map> maps = new ArrayList<Map>();
for (ScorePaper s : list) {
Expand All @@ -447,6 +450,30 @@ public Result getPaperOptions() {
return ResponseUtil.success(maps);
}

/**
* 获取所有评价表 下拉框
*
* @return
*/
@RequestMapping(value = "/getPaperSelect")
@ResponseBody
public Object getPaperSelect(String status) {
Example example = new Example(ScorePaper.class);
example.setOrderByClause("create_time desc");
//TODO 查询编辑状态的
List<ScorePaper> list = iScorePaperService.selectByExample(example);
List<Map> maps = new ArrayList<Map>();
for (ScorePaper s : list) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("text", s.getTitle());
map.put("value", s.getId());
map.put("score", s.getScore());
map.put("status", s.getStatus());
maps.add(map);
}
return maps;
}

/**
* 获取所有答题不真实的item
*
Expand Down Expand Up @@ -480,6 +507,9 @@ public Result updateAnswerReal(Integer paperId,Integer userId,Integer itemId,Boo
if(list.size()>0){
ScoreAnswer one = list.get(0);
one.setAnswerReal(answerReal);
if(!answerReal){
one.setAnswerScore(new BigDecimal(0));
}
iScoreAnswerService.updateAll(one);
return ResponseUtil.success();
}
Expand All @@ -503,11 +533,64 @@ public Result updateAnswerScore(Integer paperId,Integer userId,Integer itemId,Bi
if(list.size()>0){
ScoreAnswer one = list.get(0);
one.setAnswerScore(answerScore);
if(!one.getAnswerReal()){
one.setAnswerScore(new BigDecimal(0));
iScoreAnswerService.updateAll(one);
return ResponseUtil.error("信息虚假,不能修改分数");
}
iScoreAnswerService.updateAll(one);
return ResponseUtil.success();
}
return ResponseUtil.error();
}

/**
* 计算得分
*
* @return
*/
@RequestMapping(value = "/getUserScore", method = RequestMethod.GET)
@ResponseBody
public Result getUserScore(Integer paperId,Integer userId) {
BigDecimal score = this.iScoreAnswerService.getUserScore(paperId,userId);
Example example = new Example(ScorePaperUser.class);
example.createCriteria().andEqualTo("paperId",paperId).andEqualTo("userId",userId);
List<ScorePaperUser> list = this.iScorePagerUserService.selectByExample(example);
if(list.size()>0){
ScorePaperUser user = list.get(0);
user.setScore(score);
iScorePagerUserService.updateNotNull(user);
}
return ResponseUtil.success(score);
}

/**
* 计算所有得分
*
* @return
*/
@RequestMapping(value = "/updatePaperScore", method = RequestMethod.GET)
@ResponseBody
public Result updateUserScore(Integer paperId) {
this.iScorePagerUserService.updatePaperScore(paperId);
return ResponseUtil.success();
}
/**
* 更新附加分数 主观分
*/
@RequestMapping(value = "/updateSubjectiveScore", method = RequestMethod.GET)
@ResponseBody
public Result updateSubjectiveScore(Integer paperId,Integer userId,BigDecimal subjectiveScore) {
Example example = new Example(ScorePaperUser.class);
example.createCriteria().andEqualTo("paperId",paperId).andEqualTo("userId",userId);
List<ScorePaperUser> list = this.iScorePagerUserService.selectByExample(example);
if(list.size()>0){
ScorePaperUser user = list.get(0);
user.setSubjectiveScore(subjectiveScore);
iScorePagerUserService.updateNotNull(user);
}
return ResponseUtil.success();
}


}
38 changes: 38 additions & 0 deletions src/main/java/com/topie/zhongkexie/core/dto/PagerUserDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.topie.zhongkexie.core.dto;

import java.math.BigDecimal;
import java.util.Date;

public class PagerUserDto {
Expand Down Expand Up @@ -78,6 +79,35 @@ public class PagerUserDto {
* 提交人 (学会)
*/
private String userName;

private Integer paperId;
/**
* 总分
*/
private BigDecimal score;
/**
* 主观分 附加分
*/
private BigDecimal subjectiveScore;

public BigDecimal getSubjectiveScore() {
return subjectiveScore;
}

public void setSubjectiveScore(BigDecimal subjectiveScore) {
this.subjectiveScore = subjectiveScore;
}


public Integer getPaperId() {
return paperId;
}

public void setPaperId(Integer paperId) {
this.paperId = paperId;
}


/**
*
* @return
Expand Down Expand Up @@ -108,6 +138,14 @@ public void setBegin(Date begin) {
this.begin = begin;
}

public BigDecimal getScore() {
return score;
}

public void setScore(BigDecimal score) {
this.score = score;
}

public Date getEnd() {
return end;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.topie.zhongkexie.core.service;

import java.math.BigDecimal;
import java.util.List;

import com.github.pagehelper.PageInfo;
import com.topie.zhongkexie.common.baseservice.IService;
import com.topie.zhongkexie.database.core.model.ScoreAnswer;

import java.util.List;

/**
* Created by chenguojun on 2017/4/19.
*/
Expand All @@ -15,4 +16,6 @@ public interface IScoreAnswerService extends IService<ScoreAnswer> {

List<ScoreAnswer> selectByFilter(ScoreAnswer scoreAnswer);

BigDecimal getUserScore(Integer paperId, Integer userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ PageInfo<PagerUserDto> selectAllUserCommit(PagerUserDto pagerUserDto,
* @return
*/
ScorePaperUser getCurrentUserScorePaperUser(Integer paperId);
void updatePaperScore(Integer paperId);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.topie.zhongkexie.core.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tk.mybatis.mapper.entity.Example;
Expand All @@ -11,32 +14,85 @@
import com.github.pagehelper.PageInfo;
import com.topie.zhongkexie.common.baseservice.impl.BaseService;
import com.topie.zhongkexie.core.service.IScoreAnswerService;
import com.topie.zhongkexie.core.service.IScorePaperService;
import com.topie.zhongkexie.database.core.model.ScoreAnswer;
import com.topie.zhongkexie.database.core.model.ScorePaper;

/**
* Created by chenguojun on 2017/4/19.
*/
@Service
public class ScoreAnswerServiceImpl extends BaseService<ScoreAnswer> implements IScoreAnswerService {

@Override
public PageInfo<ScoreAnswer> selectByFilterAndPage(ScoreAnswer scoreAnswer, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<ScoreAnswer> list = selectByFilter(scoreAnswer);
return new PageInfo<>(list);
}

@Override
public List<ScoreAnswer> selectByFilter(ScoreAnswer scoreAnswer) {
Example example = new Example(ScoreAnswer.class);
Example.Criteria criteria = example.createCriteria();
if (scoreAnswer.getIndexId() != null) criteria.andEqualTo("indexId", scoreAnswer.getItemId());
if (scoreAnswer.getItemId() != null) criteria.andEqualTo("itemId", scoreAnswer.getItemId());
if (scoreAnswer.getPaperId() != null) criteria.andEqualTo("paperId", scoreAnswer.getPaperId());
if (scoreAnswer.getUserId() != null) criteria.andEqualTo("userId", scoreAnswer.getUserId());
if (StringUtils.isNotEmpty(scoreAnswer.getSortWithOutOrderBy()))
example.setOrderByClause(scoreAnswer.getSortWithOutOrderBy());
return getMapper().selectByExample(example);
}
public class ScoreAnswerServiceImpl extends BaseService<ScoreAnswer> implements
IScoreAnswerService {
@Autowired
IScorePaperService iScorePaperService;

@Override
public PageInfo<ScoreAnswer> selectByFilterAndPage(ScoreAnswer scoreAnswer,
int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<ScoreAnswer> list = selectByFilter(scoreAnswer);
return new PageInfo<>(list);
}

@Override
public List<ScoreAnswer> selectByFilter(ScoreAnswer scoreAnswer) {
Example example = new Example(ScoreAnswer.class);
Example.Criteria criteria = example.createCriteria();
if (scoreAnswer.getIndexId() != null)
criteria.andEqualTo("indexId", scoreAnswer.getItemId());
if (scoreAnswer.getItemId() != null)
criteria.andEqualTo("itemId", scoreAnswer.getItemId());
if (scoreAnswer.getPaperId() != null)
criteria.andEqualTo("paperId", scoreAnswer.getPaperId());
if (scoreAnswer.getUserId() != null)
criteria.andEqualTo("userId", scoreAnswer.getUserId());
if (StringUtils.isNotEmpty(scoreAnswer.getSortWithOutOrderBy()))
example.setOrderByClause(scoreAnswer.getSortWithOutOrderBy());
return getMapper().selectByExample(example);
}

@Override
public BigDecimal getUserScore(Integer paperId, Integer userId) {
ScorePaper scorePaper = iScorePaperService.selectByKey(paperId);
int maxFilse = scorePaper.getFalsityCountItem();// 一个指标下试题虚假次数
int maxIndexFilse = scorePaper.getFalsityCount();// 指标虚假次数
ScoreAnswer scoreAnswer = new ScoreAnswer();
scoreAnswer.setPaperId(paperId);
scoreAnswer.setUserId(userId);
scoreAnswer.setSort_("indexId_asc");
List<ScoreAnswer> list = selectByFilter(scoreAnswer);
int indexId = 0;
int count = 0;
int indexCount = 0;
BigDecimal totalScore = new BigDecimal(0);
List<BigDecimal> indexScores = new ArrayList<BigDecimal>();
for (ScoreAnswer an : list) {
int index = an.getIndexId();
if (index != indexId) {
if (count >= maxFilse) {
// 试题虚假
for (BigDecimal arg0 : indexScores) {
totalScore = totalScore.subtract(arg0);
}
indexCount++;
if (indexCount >= maxIndexFilse) {// 指标虚假次数过多
return new BigDecimal(0);
}
}
indexId = an.getIndexId();
count = 0;
indexScores.clear();
}
if(!an.getAnswerReal()){
count++;
}
BigDecimal score = an.getAnswerScore();
indexScores.add(score);
totalScore = totalScore.add(score);
}
return totalScore;

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.topie.zhongkexie.core.service.impl;


import java.math.BigDecimal;
import java.util.List;

import javax.inject.Inject;
Expand All @@ -13,6 +14,7 @@
import com.topie.zhongkexie.common.baseservice.impl.BaseService;
import com.topie.zhongkexie.common.exception.DefaultBusinessException;
import com.topie.zhongkexie.core.dto.PagerUserDto;
import com.topie.zhongkexie.core.service.IScoreAnswerService;
import com.topie.zhongkexie.core.service.IScorePagerUserService;
import com.topie.zhongkexie.core.service.IScorePaperService;
import com.topie.zhongkexie.database.core.dao.ScorePaperUserMapper;
Expand All @@ -32,6 +34,8 @@ public class ScorePagerUserServiceImpl extends BaseService<ScorePaperUser> impl
IScorePaperService iScorePaperService;
@Autowired
UserService userService;
@Autowired
IScoreAnswerService iScoreAnswerService;

@Override
public void check(int id, short result,String feedback) {
Expand Down Expand Up @@ -164,6 +168,17 @@ public ScorePaperUser getCurrentUserScorePaperUser(Integer paperId) {
ScorePaperUser su = getMapper().selectOne(scorePagerUser);
return su;
}
@Override
public void updatePaperScore(Integer paperId) {
List<ScorePaperUser> list = this.scorePagerUserMapper.selectByPagerId(paperId);
for(ScorePaperUser pu:list){
Integer userId = pu.getUserId();
BigDecimal score = this.iScoreAnswerService.getUserScore(paperId, userId);
pu.setScore(score);
this.updateNotNull(pu);
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
public interface ScorePaperUserMapper extends Mapper<ScorePaperUser> {

List<PagerUserDto> selectUserCommitPaper(PagerUserDto pagerUserDto);

List<ScorePaperUser> selectByPagerId(Integer paperId);
}
Loading

0 comments on commit 0f616dc

Please sign in to comment.