完成登录和同步用户数据

de'v
whb 10 months ago
parent 4f2d24630f
commit dab1edda24

@ -1,33 +1,40 @@
//package com.sztzjy.digital_credit.config.security;
//
//import com.sztzjy.financial_bigdata.entity.User;
//import com.sztzjy.financial_bigdata.service.IUserService;
//import io.jsonwebtoken.lang.Assert;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//
//
//@Service
//public class AuthenticationService implements UserDetailsService {
// @Resource
// private IUserService userService;
//
//
// @Override
// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// User user = userService.findByUsername(username);
// Assert.notNull(user, "用户不存在");
//
// JwtUser jwtUser = new JwtUser();
// jwtUser.setUsername(user.getUsername());
// jwtUser.setPassword(user.getPassword());
// jwtUser.setUserId(user.getUserid());
// jwtUser.setName(user.getName());
// jwtUser.setRoleId(user.getRoleId());
// return jwtUser;
// }
//}
package com.sztzjy.digital_credit.config.security;
import com.sztzjy.digital_credit.entity.StuUser;
import com.sztzjy.digital_credit.entity.StuUserExample;
import com.sztzjy.digital_credit.mapper.StuUserMapper;
import io.jsonwebtoken.lang.Assert;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class AuthenticationService implements UserDetailsService {
@Resource
private StuUserMapper stuUserMapper;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
StuUserExample stuUserExample = new StuUserExample();
stuUserExample.createCriteria().andStudentIdEqualTo(username);
List<StuUser> list = stuUserMapper.selectByExample(stuUserExample);
Assert.notNull(list, "用户不存在");
StuUser user = list.get(0);
JwtUser jwtUser = new JwtUser();
jwtUser.setUsername(user.getStudentId());
jwtUser.setPassword(new BCryptPasswordEncoder().encode(user.getPassword())); //不加密会报错Encoded password does not look like BCrypt
jwtUser.setUserId(user.getUserId());
jwtUser.setName(user.getName());
jwtUser.setRoleId(user.getRoleId());
return jwtUser;
}
}

@ -82,4 +82,6 @@ public interface StuUserMapper {
void updateComprehensiveCaseRank(String schoolId);
List<String> getClassNameBySchoolId(String schoolId);
void batchInsertStudents(List<StuUser> users);
}

@ -1,8 +1,10 @@
package com.sztzjy.digital_credit.service;
import com.github.pagehelper.PageInfo;
import com.sztzjy.digital_credit.config.security.JwtUser;
import com.sztzjy.digital_credit.controller.tch.StuUserDto;
import com.sztzjy.digital_credit.entity.StuUser;
import com.sztzjy.digital_credit.entity.ZYUserInfo;
import com.sztzjy.digital_credit.entity.tchdto.ScoreOverviewParametesDTO;
import com.sztzjy.digital_credit.entity.tchdto.TchGeneralViewDTO;
import com.sztzjy.digital_credit.entity.tchdto.TchGeneralViewWeightDTO;
@ -82,4 +84,8 @@ public interface StuUserService {
//班级下拉框
List<String> getClassNameBySchoolId(@Param("schoolId") String schoolId);
void insertAll(JwtUser user);
void insertAllByAuto(List<ZYUserInfo> studentList);
}

@ -3,13 +3,12 @@ package com.sztzjy.digital_credit.service.impl;/**
* @date 2024-05-07 9:58
*/
import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sztzjy.digital_credit.config.security.JwtUser;
import com.sztzjy.digital_credit.controller.tch.StuUserDto;
import com.sztzjy.digital_credit.entity.StuUser;
import com.sztzjy.digital_credit.entity.StuUserExample;
import com.sztzjy.digital_credit.entity.TchModuleWeith;
import com.sztzjy.digital_credit.entity.TchModuleWeithExample;
import com.sztzjy.digital_credit.entity.*;
import com.sztzjy.digital_credit.entity.tchdto.ScoreOverviewParametesDTO;
import com.sztzjy.digital_credit.entity.tchdto.TchGeneralViewDTO;
import com.sztzjy.digital_credit.entity.tchdto.TchGeneralViewWeightDTO;
@ -20,15 +19,14 @@ import com.sztzjy.digital_credit.mapper.TchModuleWeithMapper;
import com.sztzjy.digital_credit.service.StuUserService;
import com.sztzjy.digital_credit.util.PageUtil;
import com.sztzjy.digital_credit.util.ResultEntity;
import com.sztzjy.digital_credit.util.TzApi;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
@Service
public class StuUserServiceImpl implements StuUserService {
@ -275,15 +273,15 @@ public class StuUserServiceImpl implements StuUserService {
List<StuUser> stuUsers = userMapper.selectByExample(example);
return stuUsers;
}
/**
*
* @param manualRatingByTeacherDTO
* @return
*/
*
*
* @param manualRatingByTeacherDTO
* @return
*/
@Override
public void manualRatingByTeacher(TchManualRatingByTeacherDTO manualRatingByTeacherDTO) {
@ -292,14 +290,14 @@ public class StuUserServiceImpl implements StuUserService {
StuUser stuUser = userMapper.selectByPrimaryKey(manualRatingByTeacherDTO.getUserId());
//将老师评分手动写入对应分数
if ("个人征信案例主观成绩".equals(manualRatingByTeacherDTO.getModule())){
if ("个人征信案例主观成绩".equals(manualRatingByTeacherDTO.getModule())) {
stuUser.setCasePersonalCreditSubScore(manualRatingByTeacherDTO.getScore());
stuUser.setCasePersonalCreditScore(manualRatingByTeacherDTO.getScore().add(stuUser.getCasePersonalCreditObjScore()));
}
if ("企业征信案例主观成绩".equals(manualRatingByTeacherDTO.getModule())){
if ("企业征信案例主观成绩".equals(manualRatingByTeacherDTO.getModule())) {
stuUser.setCaseCorporateCreditSubScore(manualRatingByTeacherDTO.getScore());
@ -317,7 +315,7 @@ public class StuUserServiceImpl implements StuUserService {
@Override
public PageInfo<StuUserDto> getScoreReport(String schoolId, Integer index, Integer size, String module, String name, String studentId, String className, String keyWord) {
List<StuUserDto>userDtoList= stuUserDtoMapper.selectByCondition(name,studentId,className,module,keyWord,schoolId);
List<StuUserDto> userDtoList = stuUserDtoMapper.selectByCondition(name, studentId, className, module, keyWord, schoolId);
PageInfo<StuUserDto> pageInfo = PageUtil.pageHelper(userDtoList, index, size);
return pageInfo;
}
@ -325,8 +323,157 @@ public class StuUserServiceImpl implements StuUserService {
//班级下拉框
@Override
public List<String> getClassNameBySchoolId(String schoolId) {
return userMapper.getClassNameBySchoolId(schoolId);
return userMapper.getClassNameBySchoolId(schoolId);
}
@Override
public void insertAll(JwtUser user) {
List<Map<String, Object>> classList = TzApi.GetClassBySchoolIdForForeignExchangeTrading(user);
if (classList == null || classList.size() == 0) {
return;
}
List<StuUser> users = new ArrayList<>();
Set<String> userIds = new HashSet<>();
String schoolId = String.valueOf(user.getSchoolId());
for (Map<String, Object> classes : classList) {
String classId = classes.get("id").toString();
List<Map<String, Object>> studentList = TzApi.GetStudentInfoByClassIdForForeignExchangeTrading(classId, user);
if (studentList == null || studentList.size() == 0) continue;
for (Map<String, Object> student : studentList) {
StuUser stuUser = new StuUser();
stuUser.setUserId(student.get("userId").toString());
if (student.get("userId").toString().equals("null") || student.get("userId").toString().equals("8184") || student.get("userId").toString().equals("8238") || student.get("userId").toString().equals("8258") || student.get("userId").toString().equals("8259") || student.get("userId").toString().equals("8260") || student.get("userId").toString().equals("8270")) {
continue;
}
if (!userIds.add(stuUser.getUserId())) {
continue;
}
stuUser.setStudentId(student.get("studentId").toString());
stuUser.setStudentId(student.get("studentNo").toString());
stuUser.setSchoolName(student.get("schoolName").toString());
// stuUser.setMajor(student.get("majorName").toString());
stuUser.setName(student.get("name").toString());
stuUser.setClassId(classId);
stuUser.setClassName(classes.get("name").toString());
stuUser.setSchoolId(schoolId);
stuUser.setPassword("123qwe");
stuUser.setLoanCasesScore(BigDecimal.valueOf(0));
stuUser.setPerSituationScore(BigDecimal.valueOf(0));
stuUser.setRepaymentBehaviorScore(BigDecimal.valueOf(0));
stuUser.setPerInfluenceFactorScore(BigDecimal.valueOf(0));
stuUser.setPerCreditOptimizationSocre(BigDecimal.valueOf(0));
stuUser.setPerCreditRatingSocre(BigDecimal.valueOf(0));
stuUser.setEntInfluenceFactorSocre(BigDecimal.valueOf(0));
stuUser.setEntCreditOptimizationSocre(BigDecimal.valueOf(0));
stuUser.setEntCreditRatingSocre(BigDecimal.valueOf(0));
stuUser.setCaseUserProfileSocre(BigDecimal.valueOf(0));
stuUser.setCasePersonalCreditScore(BigDecimal.valueOf(0));
stuUser.setCaseCorporateCreditScore(BigDecimal.valueOf(0));
stuUser.setCaseCorporateCreditSubScore(BigDecimal.valueOf(0));
stuUser.setCaseCorporateCreditObjScore(BigDecimal.valueOf(0));
stuUser.setCasePersonalCreditSubScore(BigDecimal.valueOf(0));
stuUser.setCasePersonalCreditObjScore(BigDecimal.valueOf(0));
stuUser.setCreditPortraitScore(BigDecimal.valueOf(0));
stuUser.setPersonalCreditScore(BigDecimal.valueOf(0));
stuUser.setCorporateCreditScore(BigDecimal.valueOf(0));
stuUser.setComprehensiveCaseScore(BigDecimal.valueOf(0));
stuUser.setTotalScore(BigDecimal.valueOf(0));
users.add(stuUser);
}
}
userMapper.batchInsertStudents(users);
//根据学校id 查询成绩总览权重表中是否有数据 有则不进行操作 没有则新增权重
TchModuleWeithExample resultsExample = new TchModuleWeithExample();
resultsExample.createCriteria().andSchoolIdEqualTo(schoolId);
List<TchModuleWeith> resultsWeights = tchModuleWeithMapper.selectByExample(resultsExample);
if (resultsWeights.isEmpty()) {
TchModuleWeith tchModuleWeith = new TchModuleWeith(schoolId);
tchModuleWeithMapper.insertSelective(tchModuleWeith);
}
}
}
/**
* ,
*
* @param studentList
* @return
*/
@Override
public void insertAllByAuto(List<ZYUserInfo> studentList) {
if (studentList.isEmpty()) {
return;
}
List<StuUser> users = new ArrayList<>();
for (ZYUserInfo student : studentList) {
StuUser stuUser = new StuUser();
//基本信息
stuUser.setUserId(student.getUserId().toString());
if (student.getUserId().equals("null") || student.getUserId().equals("8184")
|| student.getUserId().equals("8238")
|| student.getUserId().equals("8258") || student.getUserId().equals("8259")
|| student.getUserId().equals("8260") || student.getUserId().equals("8270")) {
continue;
}
stuUser.setName(student.getUsername());
stuUser.setPassword(student.getPassword());
stuUser.setRoleId(student.getRoleId());
stuUser.setSchoolId(student.getSchoolId().toString());
stuUser.setSchoolName(student.getSchoolName());
stuUser.setClassId(student.getClassId().toString());
stuUser.setClassName(student.getClassName());
stuUser.setLoanCasesScore(BigDecimal.valueOf(0));
stuUser.setPerSituationScore(BigDecimal.valueOf(0));
stuUser.setRepaymentBehaviorScore(BigDecimal.valueOf(0));
stuUser.setPerInfluenceFactorScore(BigDecimal.valueOf(0));
stuUser.setPerCreditOptimizationSocre(BigDecimal.valueOf(0));
stuUser.setPerCreditRatingSocre(BigDecimal.valueOf(0));
stuUser.setEntInfluenceFactorSocre(BigDecimal.valueOf(0));
stuUser.setEntCreditOptimizationSocre(BigDecimal.valueOf(0));
stuUser.setEntCreditRatingSocre(BigDecimal.valueOf(0));
stuUser.setCaseUserProfileSocre(BigDecimal.valueOf(0));
stuUser.setCasePersonalCreditScore(BigDecimal.valueOf(0));
stuUser.setCaseCorporateCreditScore(BigDecimal.valueOf(0));
stuUser.setCaseCorporateCreditSubScore(BigDecimal.valueOf(0));
stuUser.setCaseCorporateCreditObjScore(BigDecimal.valueOf(0));
stuUser.setCasePersonalCreditSubScore(BigDecimal.valueOf(0));
stuUser.setCasePersonalCreditObjScore(BigDecimal.valueOf(0));
stuUser.setCreditPortraitScore(BigDecimal.valueOf(0));
stuUser.setPersonalCreditScore(BigDecimal.valueOf(0));
stuUser.setCorporateCreditScore(BigDecimal.valueOf(0));
stuUser.setComprehensiveCaseScore(BigDecimal.valueOf(0));
stuUser.setTotalScore(BigDecimal.valueOf(0));
users.add(stuUser);
}
userMapper.batchInsertStudents(users);
//根据学校id 查询成绩总览权重表中是否有数据 有则不进行操作 没有则新增权重
TchModuleWeithExample resultsExample = new TchModuleWeithExample();
resultsExample.createCriteria().andSchoolIdEqualTo(users.get(0).getSchoolId());
List<TchModuleWeith> resultsWeights = tchModuleWeithMapper.selectByExample(resultsExample);
if (resultsWeights.isEmpty()) {
TchModuleWeith tchModuleWeith = new TchModuleWeith(users.get(0).getSchoolId());
tchModuleWeithMapper.insertSelective(tchModuleWeith);
}
}
}

@ -158,12 +158,13 @@ public class TzApi {
if (dataNode.isArray()) {
for (JsonNode node : dataNode) {
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("id", node.get("userid").asText());
dataMap.put("userId", node.get("userid").asText());
dataMap.put("studentId", node.get("studentid").asText());
dataMap.put("name", node.get("name").asText());
dataMap.put("majorName",node.get("majorname").asText());
dataMap.put("className",node.get("classname").asText());
dataMap.put("classId",node.get("classid").asText());
dataMap.put("studentNo",node.get("studentno").asText());
dataMap.put("className", node.get("classname").asText());
dataMap.put("classId", node.get("classid").asText());
dataMap.put("studentNo", node.get("studentno").asText());
dataMap.put("schoolName", node.get("schoolname").asText());
dataList.add(dataMap);
}
}

@ -395,6 +395,7 @@
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.sztzjy.digital_credit.entity.StuUserExample" resultType="java.lang.Long">
select count(*) from stu_user
<if test="_parameter != null">
@ -828,4 +829,42 @@
group by class_name
</select>
<insert id="batchInsertStudents" parameterType="java.util.List">
INSERT IGNORE INTO stu_user (user_id, student_id, name,
password, role_id, class_id,
class_name, major, school_id,
school_name, loan_cases_score, per_situation_score,
repayment_behavior_score, per_influence_factor_score,
per_credit_optimization_socre, per_credit_rating_socre,
ent_influence_factor_socre, ent_credit_optimization_socre,
ent_credit_rating_socre, case_user_profile_socre,
case_personal_credit_score, case_corporate_credit_score,
case_corporate_credit_sub_score, case_corporate_credit_obj_score,
case_personal_credit_sub_score, case_personal_credit_obj_score,
credit_portrait_score, credit_portrait_rank,
personal_credit_score, personal_credit_rank,
corporate_credit_score, corporate_credit_rank,
comprehensive_case_score, comprehensive_case_rank,
total_rank, total_score) VALUES
<foreach collection="list" item="student" separator=",">
(#{student.userId,jdbcType=VARCHAR}, #{student.studentId,jdbcType=VARCHAR}, #{student.name,jdbcType=VARCHAR},
#{student.password,jdbcType=VARCHAR}, #{student.roleId,jdbcType=INTEGER}, #{student.classId,jdbcType=VARCHAR},
#{student.className,jdbcType=VARCHAR}, #{student.major,jdbcType=VARCHAR}, #{student.schoolId,jdbcType=VARCHAR},
#{student.schoolName,jdbcType=VARCHAR}, #{student.loanCasesScore,jdbcType=DECIMAL}, #{student.perSituationScore,jdbcType=DECIMAL},
#{student.repaymentBehaviorScore,jdbcType=DECIMAL}, #{student.perInfluenceFactorScore,jdbcType=DECIMAL},
#{student.perCreditOptimizationSocre,jdbcType=DECIMAL}, #{student.perCreditRatingSocre,jdbcType=DECIMAL},
#{student.entInfluenceFactorSocre,jdbcType=DECIMAL}, #{student.entCreditOptimizationSocre,jdbcType=DECIMAL},
#{student.entCreditRatingSocre,jdbcType=DECIMAL}, #{student.caseUserProfileSocre,jdbcType=DECIMAL},
#{student.casePersonalCreditScore,jdbcType=DECIMAL}, #{student.caseCorporateCreditScore,jdbcType=DECIMAL},
#{student.caseCorporateCreditSubScore,jdbcType=DECIMAL}, #{student.caseCorporateCreditObjScore,jdbcType=DECIMAL},
#{student.casePersonalCreditSubScore,jdbcType=DECIMAL}, #{student.casePersonalCreditObjScore,jdbcType=DECIMAL},
#{student.creditPortraitScore,jdbcType=DECIMAL}, #{student.creditPortraitRank,jdbcType=INTEGER},
#{student.personalCreditScore,jdbcType=DECIMAL}, #{student.personalCreditRank,jdbcType=INTEGER},
#{student.corporateCreditScore,jdbcType=DECIMAL}, #{student.corporateCreditRank,jdbcType=INTEGER},
#{student.comprehensiveCaseScore,jdbcType=DECIMAL}, #{student.comprehensiveCaseRank,jdbcType=INTEGER},
#{student.totalRank,jdbcType=INTEGER}, #{student.totalScore,jdbcType=DECIMAL})
</foreach>
</insert>
</mapper>
Loading…
Cancel
Save