|
@@ -11,94 +11,136 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class UserService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private MgrUserDao mgrUserDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MgrUserRoleDao mgrUserRoleDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MgrOrganizationDao mgrOrganizationDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private AttendanceDao attendanceDao;
|
|
|
-
|
|
|
- public MgrUser getById(long id) {
|
|
|
- MgrUser user = mgrUserDao.getById(id);
|
|
|
- user.setMgrOrganization(mgrOrganizationDao.get(user.getLastOrganizationId()));
|
|
|
- return user;
|
|
|
- }
|
|
|
-
|
|
|
- public MgrUser getByPhone(String phone) {
|
|
|
- return mgrUserDao.getByPhone(phone);
|
|
|
- }
|
|
|
-
|
|
|
- public int update(MgrUser user) {
|
|
|
- return mgrUserDao.update(user);
|
|
|
- }
|
|
|
-
|
|
|
- public int banUser(long id, int status) {
|
|
|
- return mgrUserDao.banUser(id, status);
|
|
|
- }
|
|
|
-
|
|
|
- public MgrUser insertUser(MgrUser user) {
|
|
|
- MgrUser userByPhone = mgrUserDao.getUserByPhone(user.getPhone());
|
|
|
- if (userByPhone != null) {
|
|
|
- return userByPhone;
|
|
|
- }
|
|
|
- mgrUserDao.insert(user);
|
|
|
- return user;
|
|
|
- }
|
|
|
-
|
|
|
- public int deleteUser(long id) {
|
|
|
- return mgrUserDao.delete(id);
|
|
|
- }
|
|
|
-
|
|
|
- public int checkFace(long id) {
|
|
|
- return mgrUserDao.checkFace(id);
|
|
|
- }
|
|
|
-
|
|
|
- public List<MgrUser> getUserByOrganizationId(long organizationId) {
|
|
|
- List<MgrUserRole> list = mgrUserRoleDao.getOrganizationId(organizationId);
|
|
|
- List<Long> ids = new ArrayList<>();
|
|
|
- list.forEach(ls -> ids.add(ls.getUserId()));
|
|
|
- return mgrUserDao.getIds(ids);
|
|
|
- }
|
|
|
-
|
|
|
- public void insertUserRole(long userId, long organizationId, String roles) {
|
|
|
- MgrUserRole mur = mgrUserRoleDao.getUser(userId, organizationId);
|
|
|
- if (mur != null) {
|
|
|
- StringBuffer sb = new StringBuffer(mur.getRoles() == null ? "-1" : mur.getRoles());
|
|
|
- sb.append("," + roles);
|
|
|
- mur.setRoles(sb.toString());
|
|
|
- mgrUserRoleDao.update(mur);
|
|
|
- } else {
|
|
|
- MgrUserRole userRole = new MgrUserRole();
|
|
|
- userRole.setUserId(userId);
|
|
|
- userRole.setOrganizationId(organizationId);
|
|
|
- userRole.setRoles(roles);
|
|
|
- mgrUserRoleDao.insert(userRole);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void updateResources(MgrUserRole userRole) {
|
|
|
- mgrUserRoleDao.updateResources(userRole);
|
|
|
- }
|
|
|
-
|
|
|
- public int saveAttendance(Attendance attendance) {
|
|
|
- return attendanceDao.insert(attendance);
|
|
|
- }
|
|
|
-
|
|
|
- public List<Attendance> getAttendance(Attendance attendance) {
|
|
|
- if (attendance.getEndDate() != null) {
|
|
|
- attendance.setEndDate(attendance.getEndDate() + " 23:59:59");
|
|
|
- }
|
|
|
- return attendanceDao.getByUser(attendance);
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private MgrUserDao mgrUserDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MgrUserRoleDao mgrUserRoleDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MgrOrganizationDao mgrOrganizationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AttendanceDao attendanceDao;
|
|
|
+
|
|
|
+ public MgrUser getById(long id) {
|
|
|
+ MgrUser user = mgrUserDao.getById(id);
|
|
|
+ user.setMgrOrganization(mgrOrganizationDao.get(user.getLastOrganizationId()));
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public MgrUser getByPhone(String phone) {
|
|
|
+ return mgrUserDao.getByPhone(phone);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int update(MgrUser user) {
|
|
|
+ return mgrUserDao.update(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateResources(MgrUserRole userRole) {
|
|
|
+ mgrUserRoleDao.updateResources(userRole);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int banUser(long id, int status) {
|
|
|
+ return mgrUserDao.banUser(id, status);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int checkFace(long id) {
|
|
|
+ return mgrUserDao.checkFace(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteUser(long organizationId, long userId) {
|
|
|
+ MgrUserRole mgrUserRole = mgrUserRoleDao.getUser(userId, organizationId);
|
|
|
+ if (mgrUserRole != null) {
|
|
|
+ mgrUserRoleDao.delete(mgrUserRole.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<MgrUser> getUserList(long organizationId, String identity) {
|
|
|
+ List<MgrUserRole> list = mgrUserRoleDao.getOrganizationId(organizationId);
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ for (MgrUserRole mur : list) {
|
|
|
+ if (mur.getIdentity() != null) {
|
|
|
+ if (Arrays.asList(mur.getIdentity().split(",")).contains(identity)) {
|
|
|
+ ids.add(mur.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ return mgrUserDao.getIds(ids);
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<MgrUser> getUserByOrganizationId(long organizationId) {
|
|
|
+ List<MgrUserRole> list = mgrUserRoleDao.getOrganizationId(organizationId);
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ for (MgrUserRole mur : list) {
|
|
|
+ ids.add(mur.getUserId());
|
|
|
+ }
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ return mgrUserDao.getIds(ids);
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addClient(long userId, long organizationId, String identity) {
|
|
|
+ MgrUserRole mur = mgrUserRoleDao.getUser(userId, organizationId);
|
|
|
+ if (mur != null) {
|
|
|
+ if (mur.getIdentity() == null) {
|
|
|
+ mur.setIdentity(identity);
|
|
|
+ } else {
|
|
|
+ List<String> list = new ArrayList<>(Arrays.asList(mur.getIdentity().split(",")));
|
|
|
+ if (list.contains(identity)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ list.add(identity);
|
|
|
+ mur.setIdentity(String.join(",", list));
|
|
|
+ }
|
|
|
+ mgrUserRoleDao.update(mur);
|
|
|
+ } else {
|
|
|
+ MgrUserRole userRole = new MgrUserRole();
|
|
|
+ userRole.setUserId(userId);
|
|
|
+ userRole.setOrganizationId(organizationId);
|
|
|
+ userRole.setIdentity(identity);
|
|
|
+ mgrUserRoleDao.insert(userRole);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateUserRole(MgrUserRole userRole) {
|
|
|
+ MgrUserRole mur = mgrUserRoleDao.getUser(userRole.getUserId(), userRole.getOrganizationId());
|
|
|
+ if (mur.getRoles() == null) {
|
|
|
+ mur.setRoles(userRole.getRoles());
|
|
|
+ } else {
|
|
|
+ List<String> list = new ArrayList<>(Arrays.asList(mur.getIdentity().split(",")));
|
|
|
+ String[] split = userRole.getRoles().split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (!list.contains(s)) {
|
|
|
+ list.add(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mur.setRoles(String.join(",", list));
|
|
|
+ mgrUserRoleDao.update(mur);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int saveAttendance(Attendance attendance) {
|
|
|
+ return attendanceDao.insert(attendance);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Attendance> getAttendance(Attendance attendance) {
|
|
|
+ if (attendance.getEndDate() != null) {
|
|
|
+ attendance.setEndDate(attendance.getEndDate() + " 23:59:59");
|
|
|
+ }
|
|
|
+ return attendanceDao.getByUser(attendance);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|