|
|
@@ -3,6 +3,8 @@ package cn.iselab.mooctest.site.service.application.impl;
|
|
|
import cn.iselab.mooctest.site.common.constant.MailConstants;
|
|
|
import cn.iselab.mooctest.site.dao.*;
|
|
|
import cn.iselab.mooctest.site.models.*;
|
|
|
+import cn.iselab.mooctest.site.service.ExamService;
|
|
|
+import cn.iselab.mooctest.site.service.User2RoleService;
|
|
|
import cn.iselab.mooctest.site.service.application.WechatService;
|
|
|
import cn.iselab.mooctest.site.util.data.EncryptionUtil;
|
|
|
import net.sf.json.JSON;
|
|
|
@@ -38,12 +40,30 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Autowired
|
|
|
private ManagerDao managerDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserDao userDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private User2RoleService user2RoleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamDao examDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Task2GroupDao task2GroupDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamGroupUserDao examGroupUserDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamService examService;
|
|
|
+
|
|
|
@Override
|
|
|
public String checkAccount(String account, String password) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
String encryptedPassword = EncryptionUtil.encryptMD5(password);
|
|
|
- Worker worker = workerDao.findByAccount(account);
|
|
|
- if (worker == null || (!worker.getPassword().equals(encryptedPassword))){
|
|
|
+ User user=userDao.findByEmail(account);
|
|
|
+ if (user == null || (!user.getPassword().equals(encryptedPassword))){
|
|
|
result.put("success", false);
|
|
|
}
|
|
|
else{
|
|
|
@@ -56,25 +76,22 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Override
|
|
|
public String getTaskInfo(String account) {
|
|
|
JSONArray result = new JSONArray();
|
|
|
-
|
|
|
- Worker worker = workerDao.findByAccount(account);
|
|
|
- if (worker == null){
|
|
|
+ User user=userDao.findByEmail(account);
|
|
|
+ if (user == null){
|
|
|
return null;
|
|
|
}
|
|
|
- List<AssignedTask> assignedTaskList = assignedTaskDao.findByWorkerId(worker.getId());
|
|
|
-
|
|
|
- for (AssignedTask assignedTask : assignedTaskList){
|
|
|
- Task task = taskDao.findOne(assignedTask.getTaskId());
|
|
|
-
|
|
|
+ List<ExamGroupUser> examGroupUsers=examGroupUserDao.findByParticipantId(user.getId());
|
|
|
+ for(ExamGroupUser examGroupUser:examGroupUsers){
|
|
|
+ Task task = examService.getExamByName(examGroupUser.getName());
|
|
|
Timestamp currentTimestamp = new Timestamp(System.currentTimeMillis());
|
|
|
if (task.getEndTime().after(currentTimestamp)){
|
|
|
JSONObject taskObj = new JSONObject();
|
|
|
taskObj.put("id", task.getId());
|
|
|
taskObj.put("taskName", task.getName());
|
|
|
- taskObj.put("workerId", worker.getId());
|
|
|
+ taskObj.put("workerId", user.getId());
|
|
|
taskObj.put("taskId", task.getId());
|
|
|
try {
|
|
|
- taskObj.put("password", EncryptionUtil.encryptDES(task.getId() + "_" + worker.getId()));
|
|
|
+ taskObj.put("password", EncryptionUtil.encryptDES(task.getId() + "_" + user.getId()));
|
|
|
} catch (Exception e) {
|
|
|
// e.printStackTrace();
|
|
|
return null;
|
|
|
@@ -88,23 +105,19 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Override
|
|
|
public String getFinishedTaskInfo(String account) {
|
|
|
JSONArray result = new JSONArray();
|
|
|
-
|
|
|
- Worker worker = workerDao.findByAccount(account);
|
|
|
- if (worker == null){
|
|
|
+ User user=userDao.findByEmail(account);
|
|
|
+ if (user == null){
|
|
|
return null;
|
|
|
}
|
|
|
- List<AssignedTask> assignedTaskList = assignedTaskDao.findByWorkerId(worker.getId());
|
|
|
-
|
|
|
+ List<AssignedTask> assignedTaskList = assignedTaskDao.findByParticipantId(user.getId());
|
|
|
for (AssignedTask assignedTask : assignedTaskList){
|
|
|
Task task = taskDao.findOne(assignedTask.getTaskId());
|
|
|
-
|
|
|
Timestamp currentTimestamp = new Timestamp(System.currentTimeMillis());
|
|
|
if (task.getEndTime().before(currentTimestamp)){
|
|
|
JSONObject taskObj = new JSONObject();
|
|
|
taskObj.put("id", task.getId());
|
|
|
taskObj.put("taskName", task.getName());
|
|
|
taskObj.put("score", assignedTask.getScore());
|
|
|
-
|
|
|
result.put(taskObj);
|
|
|
}
|
|
|
}
|
|
|
@@ -115,11 +128,11 @@ public class WechatServiceImpl implements WechatService {
|
|
|
public String getGroupList(String account) {
|
|
|
JSONArray result = new JSONArray();
|
|
|
|
|
|
- Worker worker = workerDao.findByAccount(account);
|
|
|
- if (worker == null){
|
|
|
+ User user=userDao.findByEmail(account);
|
|
|
+ if (user == null){
|
|
|
return null;
|
|
|
}
|
|
|
- List<Group2Worker> group2Workers = group2WorkerDao.findByWorkerId(worker.getId());
|
|
|
+ List<Group2Worker> group2Workers = group2WorkerDao.findByParticipantId(user.getId());
|
|
|
|
|
|
for (Group2Worker group2Worker : group2Workers){
|
|
|
Group group = groupDao.findOne(group2Worker.getGroupId());
|
|
|
@@ -127,8 +140,8 @@ public class WechatServiceImpl implements WechatService {
|
|
|
JSONObject groupObj = new JSONObject();
|
|
|
groupObj.put("id", group.getId());
|
|
|
groupObj.put("groupName", group.getName());
|
|
|
- Manager manager = managerDao.findOne(group.getManagerId());
|
|
|
- groupObj.put("managerName", manager.getName());
|
|
|
+ User user1 = userDao.findOne(group.getOwnerId());
|
|
|
+ groupObj.put("managerName", user1.getName());
|
|
|
|
|
|
result.put(groupObj);
|
|
|
}
|
|
|
@@ -139,27 +152,28 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Override
|
|
|
public String joinGroup(String account, Long groupId, String managerName) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
- Worker worker = workerDao.findByAccount(account);
|
|
|
+ User user=userDao.findByEmail(account);
|
|
|
Group group = groupDao.findOne(groupId);
|
|
|
- if (worker == null || group == null){
|
|
|
+ if (user == null || group == null){
|
|
|
result.put("success", false);
|
|
|
result.put("message", "group or worker not found");
|
|
|
}
|
|
|
else{
|
|
|
- Manager manager = managerDao.findOne(group.getManagerId());
|
|
|
- if (!manager.getName().equals(managerName)){
|
|
|
+ User user2= userDao.findOne(group.getOwnerId());
|
|
|
+ if (!user2.getName().equals(managerName)){
|
|
|
result.put("success", false);
|
|
|
result.put("message", "manager name mismatch");
|
|
|
}
|
|
|
else{
|
|
|
// Join group
|
|
|
Group2Worker group2Worker = new Group2Worker();
|
|
|
- if (group2WorkerDao.findByWorkerIdAndGroupId(worker.getId(), group.getId()) != null){
|
|
|
+ if (group2WorkerDao.findByParticipantIdAndGroupId(user.getId(), group.getId()) != null){
|
|
|
result.put("success", false);
|
|
|
result.put("message", "worker already in group");
|
|
|
}
|
|
|
group2Worker.setGroupId(group.getId());
|
|
|
- group2Worker.setWorkerId(worker.getId());
|
|
|
+ group2Worker.setWorkerId(user.getId());
|
|
|
+ group2Worker.setParticipantId(user.getId());
|
|
|
group2Worker.setRecordCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
group2WorkerDao.save(group2Worker);
|
|
|
|
|
|
@@ -173,60 +187,48 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Override
|
|
|
public String getGroupsByManager(long managerId) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
- Manager manager = managerDao.findOne(managerId);
|
|
|
- if (manager == null){
|
|
|
+ User user=userDao.findById(managerId);
|
|
|
+ if (user == null){
|
|
|
return null;
|
|
|
+ }else {
|
|
|
+ boolean isManager=false;
|
|
|
+ List<User2Role> user2Roles=user2RoleService.getByUserId(user.getId());
|
|
|
+ for(User2Role user2Role:user2Roles){
|
|
|
+ if(user2Role.getRoleId()==2)
|
|
|
+ isManager=true;
|
|
|
+ }
|
|
|
+ if(!isManager)
|
|
|
+ result.put("message", "manager not found");
|
|
|
+ else {
|
|
|
+ JSONArray groupArr = new JSONArray();
|
|
|
+ List<Group> groups = groupDao.findByOwnerId(user.getId());
|
|
|
+ for (Group group : groups) {
|
|
|
+ JSONObject groupObj = new JSONObject();
|
|
|
+ groupObj.put("id", group.getId());
|
|
|
+ groupObj.put("groupName", group.getName());
|
|
|
+ groupObj.put("managerName", user.getName());
|
|
|
+
|
|
|
+ groupArr.put(groupObj);
|
|
|
+ }
|
|
|
+ result.put("groups", groupArr);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- JSONArray groupArr = new JSONArray();
|
|
|
- List<Group> groups = groupDao.findByManagerId(manager.getId());
|
|
|
- for (Group group : groups){
|
|
|
- JSONObject groupObj = new JSONObject();
|
|
|
- groupObj.put("id", group.getId());
|
|
|
- groupObj.put("groupName", group.getName());
|
|
|
- groupObj.put("managerName", manager.getName());
|
|
|
-
|
|
|
- groupArr.put(groupObj);
|
|
|
- }
|
|
|
-
|
|
|
- result.put("groups", groupArr);
|
|
|
return result.toString();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getUserInfoWechat(long userId, String identity) {
|
|
|
+ public String getUserInfoWechat(long userId) {
|
|
|
JSONObject resultObj = new JSONObject();
|
|
|
|
|
|
- if (identity.equals("manager")){
|
|
|
- Manager manager = managerDao.findOne(userId);
|
|
|
- if (manager == null){
|
|
|
- resultObj.put("message", "manager not found");
|
|
|
- }
|
|
|
- else {
|
|
|
- resultObj.put("email", manager.getEmail());
|
|
|
- resultObj.put("mobile", manager.getMobile());
|
|
|
- resultObj.put("level", manager.getLevel());
|
|
|
- resultObj.put("name", manager.getName());
|
|
|
- resultObj.put("company", manager.getInformation());
|
|
|
- }
|
|
|
- }
|
|
|
- else if (identity.equals("worker")){
|
|
|
- Worker worker = workerDao.findOne(userId);
|
|
|
- if (worker == null){
|
|
|
- resultObj.put("message", "worker not found");
|
|
|
- }
|
|
|
- else {
|
|
|
- resultObj.put("email", worker.getEmail());
|
|
|
- resultObj.put("mobile", worker.getMobile());
|
|
|
- resultObj.put("level", worker.getLevel());
|
|
|
- resultObj.put("name", worker.getName());
|
|
|
- resultObj.put("company", worker.getInformation());
|
|
|
- }
|
|
|
+ User user=userDao.findById(userId);
|
|
|
+ if(user==null){
|
|
|
+ resultObj.put("message", "user not found");
|
|
|
+ }else {
|
|
|
+ resultObj.put("email", user.getEmail());
|
|
|
+ resultObj.put("mobile", user.getMobile());
|
|
|
+ resultObj.put("name", user.getName());
|
|
|
+ resultObj.put("company", user.getSchool());
|
|
|
}
|
|
|
- else{
|
|
|
- resultObj.put("message", "no such identity");
|
|
|
- }
|
|
|
-
|
|
|
return resultObj.toString();
|
|
|
}
|
|
|
|
|
|
@@ -242,16 +244,16 @@ public class WechatServiceImpl implements WechatService {
|
|
|
JSONArray workerArr = new JSONArray();
|
|
|
List<Group2Worker> group2Workers = group2WorkerDao.findByGroupId(groupId);
|
|
|
for (Group2Worker group2Worker : group2Workers){
|
|
|
- Worker worker = workerDao.findOne(group2Worker.getWorkerId());
|
|
|
- JSONObject workerObj = new JSONObject();
|
|
|
- workerObj.put("id", worker.getId());
|
|
|
- workerObj.put("email", worker.getEmail());
|
|
|
- workerObj.put("mobile", worker.getMobile());
|
|
|
- workerObj.put("workerName", worker.getName());
|
|
|
- workerObj.put("university", worker.getInformation());
|
|
|
- workerObj.put("grade", worker.getSchoolYear());
|
|
|
-
|
|
|
- workerArr.put(workerObj);
|
|
|
+ if(group2Worker.getParticipantId()!=null) {
|
|
|
+ User user = userDao.findOne(group2Worker.getParticipantId());
|
|
|
+ JSONObject workerObj = new JSONObject();
|
|
|
+ workerObj.put("id", user.getId());
|
|
|
+ workerObj.put("email", user.getEmail());
|
|
|
+ workerObj.put("mobile", user.getMobile());
|
|
|
+ workerObj.put("workerName", user.getName());
|
|
|
+ workerObj.put("university", user.getSchool());
|
|
|
+ workerArr.put(workerObj);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
result.put("workers", workerArr);
|
|
|
@@ -261,16 +263,26 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Override
|
|
|
public String checkManager(String account, String password) {
|
|
|
JSONObject resultObj = new JSONObject();
|
|
|
- Manager manager = managerDao.findByAccount(account);
|
|
|
- if (manager == null){
|
|
|
+ User user=userDao.findByEmail(account);
|
|
|
+ if (user == null) {
|
|
|
resultObj.put("message", "manager not found");
|
|
|
}
|
|
|
else {
|
|
|
- String encryptedPassword = EncryptionUtil.encryptMD5(password);
|
|
|
- if (manager.getPassword().equals(encryptedPassword)) {
|
|
|
- resultObj.put("id", manager.getId());
|
|
|
- } else {
|
|
|
- resultObj.put("message", "password not match");
|
|
|
+ boolean isManager=false;
|
|
|
+ List<User2Role> user2Roles=user2RoleService.getByUserId(user.getId());
|
|
|
+ for(User2Role user2Role:user2Roles){
|
|
|
+ if(user2Role.getRoleId()==2)
|
|
|
+ isManager=true;
|
|
|
+ }
|
|
|
+ if(!isManager)
|
|
|
+ resultObj.put("message", "manager not found");
|
|
|
+ else {
|
|
|
+ String encryptedPassword = EncryptionUtil.encryptMD5(password);
|
|
|
+ if (user.getPassword().equals(encryptedPassword)) {
|
|
|
+ resultObj.put("id", user.getId());
|
|
|
+ } else {
|
|
|
+ resultObj.put("message", "password not match");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -280,14 +292,14 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Override
|
|
|
public String checkWorker(String account, String password) {
|
|
|
JSONObject resultObj = new JSONObject();
|
|
|
- Worker worker = workerDao.findByAccount(account);
|
|
|
- if (worker == null){
|
|
|
+ User user = userDao.findByEmail(account);
|
|
|
+ if (user == null){
|
|
|
resultObj.put("message", "worker not found");
|
|
|
}
|
|
|
else {
|
|
|
String encryptedPassword = EncryptionUtil.encryptMD5(password);
|
|
|
- if (worker.getPassword().equals(encryptedPassword)) {
|
|
|
- resultObj.put("id", worker.getId());
|
|
|
+ if (user.getPassword().equals(encryptedPassword)) {
|
|
|
+ resultObj.put("id", user.getId());
|
|
|
} else {
|
|
|
resultObj.put("message", "password not match");
|
|
|
}
|
|
|
@@ -299,35 +311,43 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Override
|
|
|
public String getManagerTask(long userId) {
|
|
|
JSONObject resultObj = new JSONObject();
|
|
|
- Manager manager = managerDao.findOne(userId);
|
|
|
- if (manager == null){
|
|
|
+ User user = userDao.findById(userId);
|
|
|
+ if (user == null){
|
|
|
resultObj.put("message", "manager not found");
|
|
|
}
|
|
|
else {
|
|
|
- JSONArray taskArr = new JSONArray();
|
|
|
- List<Task> tasks = taskDao.findByManagerId(userId);
|
|
|
- for (Task task : tasks){
|
|
|
- JSONObject taskObj = new JSONObject();
|
|
|
- taskObj.put("id", task.getId());
|
|
|
- taskObj.put("taskName", task.getName());
|
|
|
-
|
|
|
- // check task status - UPCOMING/ONGOING/FINISHED
|
|
|
- Timestamp currentTimestamp = new Timestamp(System.currentTimeMillis());
|
|
|
- if (task.getBeginTime().after(currentTimestamp)){
|
|
|
- // UPCOMING
|
|
|
- taskObj.put("status", 0);
|
|
|
- }
|
|
|
- else if (task.getEndTime().before(currentTimestamp)){
|
|
|
- // FINISHED
|
|
|
- taskObj.put("status", 2);
|
|
|
- }
|
|
|
- else{
|
|
|
- taskObj.put("status", 1);
|
|
|
+ boolean isManager=false;
|
|
|
+ List<User2Role> user2Roles=user2RoleService.getByUserId(user.getId());
|
|
|
+ for(User2Role user2Role:user2Roles){
|
|
|
+ if(user2Role.getRoleId()==2)
|
|
|
+ isManager=true;
|
|
|
+ }
|
|
|
+ if(!isManager)
|
|
|
+ resultObj.put("message", "manager not found");
|
|
|
+ else {
|
|
|
+ JSONArray taskArr = new JSONArray();
|
|
|
+ List<Task> tasks = examDao.findByOwnerId(userId);
|
|
|
+ for (Task task : tasks) {
|
|
|
+ JSONObject taskObj = new JSONObject();
|
|
|
+ taskObj.put("id", task.getId());
|
|
|
+ taskObj.put("taskName", task.getName());
|
|
|
+
|
|
|
+ // check task status - UPCOMING/ONGOING/FINISHED
|
|
|
+ Timestamp currentTimestamp = new Timestamp(System.currentTimeMillis());
|
|
|
+ if (task.getBeginTime().after(currentTimestamp)) {
|
|
|
+ // UPCOMING
|
|
|
+ taskObj.put("status", 0);
|
|
|
+ } else if (task.getEndTime().before(currentTimestamp)) {
|
|
|
+ // FINISHED
|
|
|
+ taskObj.put("status", 2);
|
|
|
+ } else {
|
|
|
+ taskObj.put("status", 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ taskArr.put(taskObj);
|
|
|
}
|
|
|
-
|
|
|
- taskArr.put(taskObj);
|
|
|
+ resultObj.put("tasks", taskArr);
|
|
|
}
|
|
|
- resultObj.put("tasks", taskArr);
|
|
|
}
|
|
|
|
|
|
return resultObj.toString();
|
|
|
@@ -342,21 +362,22 @@ public class WechatServiceImpl implements WechatService {
|
|
|
}
|
|
|
else {
|
|
|
JSONArray passwordArr = new JSONArray();
|
|
|
- List<AssignedTask> assignedTasks = assignedTaskDao.findByTaskId(taskId);
|
|
|
- for (AssignedTask assignedTask : assignedTasks){
|
|
|
+ List<Task2Group> task2Groups=task2GroupDao.findByTaskId(taskId);
|
|
|
+ List<Group2Worker> workers=group2WorkerDao.findByGroupId(task2Groups.get(0).getGroupId());
|
|
|
+ for (Group2Worker group2Worker:workers){
|
|
|
JSONObject passwordObj = new JSONObject();
|
|
|
-
|
|
|
- Worker worker = workerDao.findOne(assignedTask.getWorkerId());
|
|
|
- passwordObj.put("workerId", worker.getId());
|
|
|
- passwordObj.put("workerName", worker.getName());
|
|
|
- try {
|
|
|
- String password = EncryptionUtil.encryptDES(taskId + "_" + assignedTask.getWorkerId());
|
|
|
- passwordObj.put("password", password);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if(group2Worker.getParticipantId()!=null) {
|
|
|
+ User user = userDao.findOne(group2Worker.getParticipantId());
|
|
|
+ passwordObj.put("workerId", user.getId());
|
|
|
+ passwordObj.put("workerName", user.getName());
|
|
|
+ try {
|
|
|
+ String password = EncryptionUtil.encryptDES(taskId + "_" + group2Worker.getParticipantId());
|
|
|
+ passwordObj.put("password", password);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ passwordArr.put(passwordObj);
|
|
|
}
|
|
|
-
|
|
|
- passwordArr.put(passwordObj);
|
|
|
}
|
|
|
resultObj.put("passwords", passwordArr);
|
|
|
}
|
|
|
@@ -376,13 +397,15 @@ public class WechatServiceImpl implements WechatService {
|
|
|
List<AssignedTask> assignedTasks = assignedTaskDao.findByTaskId(taskId);
|
|
|
for (AssignedTask assignedTask : assignedTasks){
|
|
|
JSONObject gradeObj = new JSONObject();
|
|
|
-
|
|
|
- Worker worker = workerDao.findOne(assignedTask.getWorkerId());
|
|
|
- gradeObj.put("workerId", worker.getId());
|
|
|
- gradeObj.put("workerName", worker.getName());
|
|
|
- gradeObj.put("grade", assignedTask.getScore());
|
|
|
-
|
|
|
- gradeArr.put(gradeObj);
|
|
|
+ if(assignedTask.getParticipantId()!=null) {
|
|
|
+ User user = userDao.findOne(assignedTask.getParticipantId());
|
|
|
+ if (user != null) {
|
|
|
+ gradeObj.put("workerId", user.getId());
|
|
|
+ gradeObj.put("workerName", user.getName());
|
|
|
+ gradeObj.put("grade", assignedTask.getScore());
|
|
|
+ gradeArr.put(gradeObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
resultObj.put("grades", gradeArr);
|
|
|
}
|