业务编写

pull/1/head
陈沅 2 years ago
parent df21f57c9d
commit 3745f560ff

@ -64,6 +64,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
JwtUser currentUser; JwtUser currentUser;
try { try {
currentUser = tokenProvider.getJWTUser(token); currentUser = tokenProvider.getJWTUser(token);
response.setCharacterEncoding("UTF-8");
} catch (ExpiredJwtException e1) { } catch (ExpiredJwtException e1) {
response.setStatus(HttpStatus.UNAUTHORIZED.value()); response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Origin", "*");
@ -75,6 +76,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
response.getWriter().print("不支持的Token"); response.getWriter().print("不支持的Token");
return; return;
} catch (MalformedJwtException e3) { } catch (MalformedJwtException e3) {
response.setStatus(HttpStatus.UNAUTHORIZED.value()); response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Origin", "*");
response.getWriter().print("无效的Token格式"); response.getWriter().print("无效的Token格式");

@ -4,6 +4,8 @@ import com.sztzjy.forex.trading_trading.config.Constant;
import com.sztzjy.forex.trading_trading.config.exception.UnAuthorizedException; import com.sztzjy.forex.trading_trading.config.exception.UnAuthorizedException;
import io.jsonwebtoken.*; import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.security.Keys;
import io.jsonwebtoken.security.SignatureException;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -57,6 +59,14 @@ public class TokenProvider {
jwtUser.setUsername(claims.get("username").toString()); jwtUser.setUsername(claims.get("username").toString());
jwtUser.setAuthorityCodes((List<String>) claims.get("authorityCodes")); jwtUser.setAuthorityCodes((List<String>) claims.get("authorityCodes"));
return jwtUser; return jwtUser;
} catch (ExpiredJwtException e1) {
throw new ExpiredJwtException(null, null, "token过期");
} catch (UnsupportedJwtException e2) {
throw new UnsupportedJwtException("不支持的token");
} catch (MalformedJwtException e3) {
throw new MalformedJwtException("token格式错误");
} catch (SignatureException e4) {
throw new SignatureException("签名失败");
} catch (Exception e) { } catch (Exception e) {
throw new UnAuthorizedException("无效token"); throw new UnAuthorizedException("无效token");
} }

@ -23,6 +23,7 @@ import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -192,7 +193,7 @@ public class TrainingController {
memberService.insert(member); memberService.insert(member);
buildPracticeMember(member); buildPracticeMember(member);
}); });
trainingService.updatePeopleNum(true,trainingId); trainingService.updatePeopleNum(true, trainingId);
return new ResultEntity(HttpStatus.OK); return new ResultEntity(HttpStatus.OK);
} }
@ -204,7 +205,7 @@ public class TrainingController {
Assert.notNull(trainingId, "实训记录不存在"); Assert.notNull(trainingId, "实训记录不存在");
Assert.notNull(memberId, "参赛用户不存在"); Assert.notNull(memberId, "参赛用户不存在");
memberService.deleteById(memberId); memberService.deleteById(memberId);
trainingService.updatePeopleNum(false,trainingId); trainingService.updatePeopleNum(false, trainingId);
return new ResultEntity(HttpStatus.OK); return new ResultEntity(HttpStatus.OK);
} }
@ -289,4 +290,39 @@ public class TrainingController {
} }
return new ResultEntity<>(HttpStatus.OK, memberService.selectTrainingListByClassId(classId)); return new ResultEntity<>(HttpStatus.OK, memberService.selectTrainingListByClassId(classId));
} }
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_EDIT)
@Transactional(rollbackFor = Exception.class)
@ApiOperation("更新参赛人员")
@GetMapping("/updateMember")
public ResultEntity updateMember(@ApiParam("实训记录id") @RequestParam String trainingId) {
JwtUser user = TokenProvider.getJWTUser(request);
List<Map<String, Object>> classList = memberService.selectClassListByTrainingId(trainingId);
List<String> insertNames = new ArrayList<>();
if (classList == null || classList.size() == 0) {
return new ResultEntity(HttpStatus.OK);
}
List<Map<String, Object>> resultInfos = new ArrayList<>();
List<String> studentNos = new ArrayList<>();
String classIdResult = classList.stream()
.map(classMap -> classMap.get("class_id").toString())
.collect(Collectors.joining(","));
List<Map<String, Object>> studentInfos = TzApi.GetStudentInfoByClassIdForForeignExchangeTrading(classIdResult, user);
Training training = trainingService.findById(trainingId);
for (Map<String, Object> studentInfo : studentInfos) {
String studentNo = studentInfo.get("studentNo").toString();
studentNos.add(studentNo);
Member existsInMember = memberService.findByTrainingIdAndStudentNumber(trainingId,studentNo);
if (existsInMember!=null) continue;
insertNames.add(studentInfo.get("name").toString());
resultInfos.add(studentInfo);
}
if(resultInfos==null||resultInfos.size()==0){
return new ResultEntity(HttpStatus.OK,new ArrayList<>());
}
memberService.insertAll(buildMembers(resultInfos, training));
memberService.deleteMembersByTrainingIdNotInStudentInfos(trainingId,studentNos);
return new ResultEntity(HttpStatus.OK, insertNames);
}
} }

@ -7,6 +7,7 @@ import com.sztzjy.forex.trading_trading.entity.MemberExample;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
@ -147,4 +148,11 @@ public interface MemberMapper {
@Select("select training_id,training_name from sys_member where school_id=#{schoolId} " + @Select("select training_id,training_name from sys_member where school_id=#{schoolId} " +
"group by training_id,training_name") "group by training_id,training_name")
List<Map<String, Object>> selectAllTrainingList(int schoolId); List<Map<String, Object>> selectAllTrainingList(int schoolId);
@Delete("delete from sys_member where training_id=#{trainingId} and student_number not in" +
" <foreach collection='list' item='item' index='index' open='(' separator=',' close=')'> " +
" #{item} " +
" </foreach> ")
void deleteMembersByTrainingIdNotInStudentInfos(@Param("trainingId") String trainingId, @Param("list") List<String> list);
} }

@ -84,11 +84,14 @@ public class GradeWeightService {
} }
public Double findReportScore(String id,Double score) { public Double findReportScore(String id,Double score) {
GradeWeight gradeWeight = gradeWeightMapper.selectByPrimaryKey(id); GradeWeightExample example = new GradeWeightExample();
if (gradeWeight == null) { GradeWeightExample.Criteria criteria = example.createCriteria();
criteria.andWeightIdEqualTo(id);
List<GradeWeight> gradeWeightList = gradeWeightMapper.selectByExample(example);
if (gradeWeightList == null||gradeWeightList.size()==0) {
return null; return null;
} }
return gradeWeight.getReportScoreScale() * score / 100; return gradeWeightList.get(0).getReportScoreScale() * score / 100;
} }
} }

@ -211,4 +211,35 @@ public class MemberService {
public List<Map<String, Object>> selectAllTrainingList(int schoolId) { public List<Map<String, Object>> selectAllTrainingList(int schoolId) {
return memberMapper.selectAllTrainingList(schoolId); return memberMapper.selectAllTrainingList(schoolId);
} }
public List<Member> findByTrainingId(String trainingId){
MemberExample example = new MemberExample();
example.createCriteria().andTrainingIdEqualTo(trainingId);
return memberMapper.selectByExample(example);
}
public Member findByTrainingIdAndStudentNumber(String trainingId,String studentNumber){
MemberExample example = new MemberExample();
example.createCriteria().andTrainingIdEqualTo(trainingId).andStudentNumberEqualTo(studentNumber);
List<Member> members = memberMapper.selectByExample(example);
return members.size()>0?members.get(0):null;
}
// 分批处理删除业务防止当studentNumbers过多时生成的SQL语句可能会超过数据库支持的最大长度限制从而导致SQL执行失败
public void deleteMembersByTrainingIdNotInStudentInfos(String trainingId, List<String> studentNumbers) {
int batchSize = 100; // 每个批次的大小
int totalBatches = (studentNumbers.size() + batchSize - 1) / batchSize;
for (int batch = 0; batch < totalBatches; batch++) {
int fromIndex = batch * batchSize;
int toIndex = Math.min((batch + 1) * batchSize, studentNumbers.size());
List<String> currentBatch = studentNumbers.subList(fromIndex, toIndex);
deleteBatchByTrainingIdNotInStudentInfos(trainingId, currentBatch);
}
}
private void deleteBatchByTrainingIdNotInStudentInfos(String trainingId, List<String> studentNumbers) {
MemberExample example = new MemberExample();
example.createCriteria().andTrainingIdEqualTo(trainingId).andStudentNumberNotIn(studentNumbers);
memberMapper.deleteByExample(example);
}
} }

@ -162,7 +162,7 @@ public class ReportService {
Training training = trainingService.findById(member.getTrainingId()); Training training = trainingService.findById(member.getTrainingId());
Assert.isTrue(training != null && training.getWeightId() != null, "数据异常"); Assert.isTrue(training != null && training.getWeightId() != null, "数据异常");
member.setReportScore(gradeWeightService.findReportScore(training.getWeightId(), score)); member.setReportScore(gradeWeightService.findReportScore(training.getWeightId(), score));
memberMapper.updateByPrimaryKey(member); memberMapper.updateByPrimaryKeySelective(member);
} }

Loading…
Cancel
Save