|
@@ -11,13 +11,11 @@ import com.rf.psychological.dao.model.AnswerEntity;
|
|
|
import com.rf.psychological.dao.model.CategorySubjectEntity;
|
|
|
import com.rf.psychological.dao.model.CognitiveTaskEntity;
|
|
|
import com.rf.psychological.enums.UserRole;
|
|
|
-import com.rf.psychological.file.excel.ExcelClass;
|
|
|
-import com.rf.psychological.group.dao.model.GroupAuthEntity;
|
|
|
-import com.rf.psychological.group.dao.model.GroupEntity;
|
|
|
import com.rf.psychological.group.service.GroupAuthService;
|
|
|
import com.rf.psychological.group.service.GroupInfoService;
|
|
|
-import com.rf.psychological.institution.model.InstitutionAuthEntity;
|
|
|
+import com.rf.psychological.institution.model.InstitutionEntity;
|
|
|
import com.rf.psychological.institution.service.InstitutionAuthService;
|
|
|
+import com.rf.psychological.institution.service.InstitutionService;
|
|
|
import com.rf.psychological.plan.service.TestPlanContendService;
|
|
|
import com.rf.psychological.scale.dao.model.ScaleEntity;
|
|
|
import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
|
|
@@ -27,7 +25,6 @@ import com.rf.psychological.scale.service.*;
|
|
|
import com.rf.psychological.security.SafetyProcess;
|
|
|
import com.rf.psychological.socket.MyClient;
|
|
|
import com.rf.psychological.user.dao.model.UserEntity;
|
|
|
-import com.rf.psychological.user.service.UserRepeatNameNumService;
|
|
|
import com.rf.psychological.user.service.UserService;
|
|
|
import com.rf.psychological.utils.*;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -39,11 +36,11 @@ import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
|
|
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
|
|
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
|
|
|
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.DigestUtils;
|
|
@@ -96,9 +93,6 @@ public class ServerController extends BaseController {
|
|
|
@Autowired
|
|
|
private InstitutionAuthService institutionAuthService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private UserRepeatNameNumService userRepeatNameNumService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private CategorySubjectService categorySubjectService;
|
|
|
|
|
@@ -114,6 +108,9 @@ public class ServerController extends BaseController {
|
|
|
@Autowired
|
|
|
private GroupInfoService groupInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InstitutionService institutionService;
|
|
|
+
|
|
|
@SafetyProcess
|
|
|
@GetMapping("server")
|
|
|
public Result scanServer() {
|
|
@@ -1029,130 +1026,97 @@ public class ServerController extends BaseController {
|
|
|
if (institutionNo == null) {
|
|
|
return fail("机构编号为空");
|
|
|
}
|
|
|
- //String message = "提交成功";
|
|
|
- String filePath = "";//用户信息上传之后生成的用户名密码文件保存路径
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
List<List<Object>> datas = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
|
|
|
- //插入数据库信息
|
|
|
- List<UserEntity> userListDB = new ArrayList<>();
|
|
|
- //生成导入后用户信息
|
|
|
- List<UserEntity> userLists = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isEmpty(datas)){
|
|
|
+ return fail("内容为空");
|
|
|
+ }
|
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
- result.append("账号:");
|
|
|
//判断是否有已经存在数据库的
|
|
|
boolean isExist = false;
|
|
|
- //UserEntity tempUserDB;
|
|
|
- String defaultGroupId = null;
|
|
|
try {
|
|
|
+ int y = 0;
|
|
|
for (int i = 0; i < datas.size(); i++) {
|
|
|
List<Object> users = datas.get(i);
|
|
|
- //北京师范大学亚太实验学校, 陈亚浩2, 男, 2001-10-01, 学生, , 六年级一班, null, null
|
|
|
- //插入数据库的信息
|
|
|
- UserEntity tempUserDB = new UserEntity();
|
|
|
- //导入成功用户信息
|
|
|
- UserEntity userEntity = new UserEntity();
|
|
|
- tempUserDB.setInstitutionName(users.get(0).toString());
|
|
|
- tempUserDB.setPetName(users.get(1).toString());
|
|
|
- userEntity.setInstitutionName(users.get(0).toString());
|
|
|
- userEntity.setPetName(users.get(1).toString());
|
|
|
- userEntity.setGender(users.get(2).toString());
|
|
|
- if ("男".equals(users.get(2).toString())) {
|
|
|
- tempUserDB.setGender("0");
|
|
|
- } else {
|
|
|
- tempUserDB.setGender("1");
|
|
|
+ if (users.size()<7) {
|
|
|
+ y = i + 1;
|
|
|
+ result.append("第" + y +"条数据信息不完整").append("\r\n");
|
|
|
+ isExist = true;
|
|
|
+ continue;
|
|
|
}
|
|
|
- tempUserDB.setBirthday(users.get(3).toString());
|
|
|
- tempUserDB.setProfession(users.get(4).toString());
|
|
|
- userEntity.setBirthday(users.get(3).toString());
|
|
|
- userEntity.setProfession(users.get(4).toString());
|
|
|
- int repeatNum = userRepeatNameNumService.testOrNotNamePinyin(institutionNo, getPinyin(users.get(1).toString()));
|
|
|
- if (users.size() > 6){
|
|
|
- if (null == users.get(6) || users.get(6).equals("")) {
|
|
|
- tempUserDB.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
|
|
|
- userEntity.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
|
|
|
- }else {
|
|
|
- tempUserDB.setPhone(users.get(6).toString());
|
|
|
- userEntity.setPhone(users.get(6).toString());
|
|
|
- }
|
|
|
- }else {
|
|
|
- tempUserDB.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
|
|
|
- userEntity.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
|
|
|
+ Object petName = users.get(0);
|
|
|
+ Object phone = users.get(1);
|
|
|
+ Object password = users.get(2);
|
|
|
+ Object gender = users.get(3);
|
|
|
+ Object idCard = users.get(4);
|
|
|
+ Object mobile = users.get(5);
|
|
|
+ Object orgNum = users.get(6);
|
|
|
+ if (petName == null || petName == "" ||
|
|
|
+ phone == null || phone == "" ||
|
|
|
+ password == null || password == "" ||
|
|
|
+ gender == null || gender == "" ||
|
|
|
+ idCard == null || idCard == "" ||
|
|
|
+ mobile == null || mobile == "" ||
|
|
|
+ orgNum == null || orgNum == "") {
|
|
|
+ y = i + 1;
|
|
|
+ result.append("第" + y +"条数据信息不完整").append("\r\n");
|
|
|
+ isExist = true;
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (users.size() > 7){
|
|
|
- if (null == users.get(7) || users.get(7).equals("")) {
|
|
|
- tempUserDB.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)));
|
|
|
- userEntity.setPassword(Constant.DEFAULT_PASSWORD);
|
|
|
- } else {
|
|
|
- tempUserDB.setPassword(DigestUtils.md5DigestAsHex(users.get(7).toString().getBytes(StandardCharsets.UTF_8)));
|
|
|
- userEntity.setPassword(users.get(7).toString());
|
|
|
- }
|
|
|
- }else {
|
|
|
- tempUserDB.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)));
|
|
|
- userEntity.setPassword(Constant.DEFAULT_PASSWORD);
|
|
|
- }
|
|
|
-
|
|
|
-// tempUserDB.setPhone(getPinyin(users.get(1).toString()));
|
|
|
- tempUserDB.setInstitutionNo(institutionNo);
|
|
|
- tempUserDB.setUserStatus("2");
|
|
|
- userEntity.setInstitutionNo(institutionNo);
|
|
|
- userEntity.setUserStatus("2");
|
|
|
- //设置组id,未分组时组id为0
|
|
|
- if (defaultGroupId == null) {
|
|
|
- GroupEntity groupByInstitutionNoAndName = this.groupInfoService.findGroupByInstitutionNoAndName(tempUserDB.getInstitutionNo(), Constant.DEFAULT_GROUP_NAME);
|
|
|
- if (groupByInstitutionNoAndName == null) {
|
|
|
- GroupEntity groupEntity = new GroupEntity();
|
|
|
- groupEntity.setGroupName(Constant.DEFAULT_GROUP_NAME);
|
|
|
- groupEntity.setInstitutionNo(tempUserDB.getInstitutionNo());
|
|
|
- groupEntity = this.groupInfoService.addGroup(groupEntity);
|
|
|
- //创建权限
|
|
|
- List<InstitutionAuthEntity> institutionAuthEntityList = this.institutionAuthService.getByInstitutionNo(tempUserDB.getInstitutionNo());
|
|
|
- for (int mi = 0; mi < institutionAuthEntityList.size(); mi++) {
|
|
|
- InstitutionAuthEntity institutionAuthEntity = new InstitutionAuthEntity();
|
|
|
- GroupAuthEntity groupAuthEntity = new GroupAuthEntity();
|
|
|
- groupAuthEntity.setBId(institutionAuthEntity.getBId());
|
|
|
- groupAuthEntity.setGroupId(groupEntity.getId());
|
|
|
- groupAuthEntity.setType(institutionAuthEntity.getType());
|
|
|
- this.groupAuthService.addGroupAuth(groupAuthEntity);
|
|
|
- }
|
|
|
- defaultGroupId = groupEntity.getId();
|
|
|
- } else {
|
|
|
- defaultGroupId = groupByInstitutionNoAndName.getId();
|
|
|
- }
|
|
|
+ if (petName.toString().length() > 18 || petName.toString().contains(" ")){
|
|
|
+ y = i + 1;
|
|
|
+ result.append("第" + y +"条数据姓名长度大于18位或有空格").append("\r\n");
|
|
|
+ isExist = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (phone.toString().length() > 18 || phone.toString().length() < 3 || phone.toString().contains(" ")){
|
|
|
+ y = i + 1;
|
|
|
+ result.append("第" + y +"条数据账号长度未在3~18位之间或有空格").append("\r\n");
|
|
|
+ isExist = true;
|
|
|
+ continue;
|
|
|
}
|
|
|
- tempUserDB.setGId(defaultGroupId);
|
|
|
- tempUserDB.setModel("0");
|
|
|
+ if (password.toString().length() < 6 || password.toString().length() > 18 || password.toString().contains(" ")){
|
|
|
+ y = i + 1;
|
|
|
+ result.append("第" + y +"条数据密码长度未在6~18位之间或有空格").append("\r\n");
|
|
|
+ isExist = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //插入数据库的信息
|
|
|
+ UserEntity tempUserDB = new UserEntity();
|
|
|
+ //设置组id,未分组时组id为0
|
|
|
+ InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
|
|
|
+ tempUserDB.setInstitutionName(institutionEntity.getInstitutionName());
|
|
|
+ //姓名、账号、密码格式未效验
|
|
|
+ tempUserDB.setPetName(petName.toString());
|
|
|
+ tempUserDB.setPhone(phone.toString());
|
|
|
+ tempUserDB.setPassword(DigestUtils.md5DigestAsHex(password.toString().getBytes(StandardCharsets.UTF_8)));
|
|
|
+ tempUserDB.setGender(gender.toString());
|
|
|
+ tempUserDB.setInstitutionNo(institutionNo);
|
|
|
+ tempUserDB.setUserStatus(Constant.USER_STATUS_NORMAL);
|
|
|
+ tempUserDB.setGId(orgNum.toString());
|
|
|
+ tempUserDB.setModel(mobile.toString());
|
|
|
tempUserDB.setRoleType(UserRole.COMMON.getType());
|
|
|
- userEntity.setGId(defaultGroupId);
|
|
|
- userEntity.setModel("0");
|
|
|
- userEntity.setRoleType(UserRole.COMMON.getType());
|
|
|
-
|
|
|
+ String idCardStr = idCard.toString();
|
|
|
+ tempUserDB.setBirthday(idCardStr.substring(6,10)+"-"+idCardStr.substring(10,12)+"-"+idCardStr.substring(12,14));
|
|
|
+ tempUserDB.setIdCard(idCardStr);
|
|
|
//查看当前用户是否已经在数据库存在
|
|
|
- UserEntity phoneAndInstitutionNo = userService.findPhoneAndInstitutionNo(tempUserDB.getPhone(), institutionNo);
|
|
|
+ UserEntity phoneAndInstitutionNo = userService.findPhoneAndInstitutionNoAndRoleType(tempUserDB.getPhone(), institutionNo,Constant.DEFAULT_VALUE_ONE);
|
|
|
if (phoneAndInstitutionNo != null) {
|
|
|
- result.append(phoneAndInstitutionNo.getPhone()).append(" ");
|
|
|
+ y = i + 1;
|
|
|
+ result.append("第" + y +"条数据账号" + phoneAndInstitutionNo.getPhone() + "已存在").append("\r\n");
|
|
|
isExist = true;
|
|
|
continue;
|
|
|
}
|
|
|
this.userService.save(tempUserDB);
|
|
|
- userListDB.add(tempUserDB);
|
|
|
- userLists.add(userEntity);
|
|
|
-
|
|
|
- }
|
|
|
- if (OSUtil.isLinux()) {
|
|
|
- filePath = "./userImport/" + institutionNo + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
|
|
|
- } else {
|
|
|
- filePath = "./userImport/" + institutionNo + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
|
|
|
}
|
|
|
- ExcelUtil.createExcelFileForPublic(UserEntity.class, userLists, null, new ExcelClass().userExportExcel(), fileName, filePath);
|
|
|
if (isExist) {
|
|
|
- result.append("已存在,跳过该账号。(请检查账号信息)");
|
|
|
- return success(filePath + fileName, result.toString());
|
|
|
+ result.append(",跳过该信息。(请检查该信息)");
|
|
|
+ return success("", result.toString());
|
|
|
} else {
|
|
|
- return success(filePath + fileName, "批量导入成功");
|
|
|
+ return success("", "批量导入成功");
|
|
|
}
|
|
|
} catch (Exception exception) {
|
|
|
-
|
|
|
exception.printStackTrace();
|
|
|
return fail("导入失败,请联系管理员");
|
|
|
}
|