|
|
@@ -0,0 +1,177 @@
|
|
|
+package com.uas.sso.service.impl;
|
|
|
+
|
|
|
+import com.uas.sso.support.SystemSession;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import com.uas.sso.core.Status;
|
|
|
+import com.uas.sso.dao.ApplyUserSpaceDao;
|
|
|
+import com.uas.sso.dao.UserDao;
|
|
|
+import com.uas.sso.dao.UserspaceDao;
|
|
|
+import com.uas.sso.entity.*;
|
|
|
+import com.uas.sso.exception.VisibleError;
|
|
|
+import com.uas.sso.service.AppService;
|
|
|
+import com.uas.sso.service.ApplyUserSpaceService;
|
|
|
+import com.uas.sso.service.UserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wangmh
|
|
|
+ * @create 2018-01-12 16:19
|
|
|
+ * @desc
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class ApplyUserSpaceServiceImpl implements ApplyUserSpaceService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplyUserSpaceDao applyUserSpaceDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserDao userDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserspaceDao userspaceDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AppService appService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void applyBindUserSpace(String mobile, String spaceName, String businessCode) {
|
|
|
+ // 找到用户信息
|
|
|
+ User user = userDao.findByMobile(mobile);
|
|
|
+ if (user == null) {
|
|
|
+ throw new VisibleError("手机号未注册");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找到企业信息
|
|
|
+ Userspace userspace = userspaceDao.findBySpaceName(spaceName);
|
|
|
+ if (userspace == null) {
|
|
|
+ throw new VisibleError("该企业未注册");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断用户是否在该企业
|
|
|
+ for (Userspace us : user.getUserspaces()) {
|
|
|
+ if (us.getSpaceUU().equals(userspace.getSpaceUU())) {
|
|
|
+ throw new VisibleError("你已在该企业");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否已申请
|
|
|
+ List<ApplyUserSpace> applyUserSpaces = applyUserSpaceDao.findByUserUUAndSpaceUUAndStatus(user.getUserUU(), userspace.getSpaceUU(), Status.UNAUDIT.getCode());
|
|
|
+ if (!CollectionUtils.isEmpty(applyUserSpaces)) {
|
|
|
+ throw new VisibleError("你已申请该企业,请耐心等待管理员审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加绑定状态
|
|
|
+ ApplyUserSpace applyUserSpace = new ApplyUserSpace(user, userspace);
|
|
|
+ applyUserSpaceDao.save(applyUserSpace);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ApplyUserSpace> findApplyAll(Integer pageNumber, Integer pageSize, Long spaceUU) {
|
|
|
+ Pageable pageable = new PageRequest(pageNumber, pageSize);
|
|
|
+ Page<ApplyUserSpace> page = applyUserSpaceDao.findAll(new Specification<ApplyUserSpace>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<ApplyUserSpace> root,
|
|
|
+ CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ list.add(cb.equal(root.get("spaceUU").as(Long.class), spaceUU));
|
|
|
+ Predicate[] predicates = new Predicate[list.size()];
|
|
|
+ predicates = list.toArray(predicates);
|
|
|
+ return cb.and(predicates);
|
|
|
+ }
|
|
|
+ }, pageable);
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Integer> applyCount(Long spaceUU) {
|
|
|
+ List<Map<String, Object>> list = applyUserSpaceDao.applyCountByStatus(spaceUU);
|
|
|
+ Map<String, Integer> data = new HashMap<>(list.size());
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ data.put(String.valueOf(map.get("status")), Integer.valueOf(map.get("count").toString()));
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ApplyUserSpace> findUserApply(Integer pageNumber, Integer pageSize, Long userUU) {
|
|
|
+ Pageable pageable = new PageRequest(pageNumber, pageSize);
|
|
|
+ return applyUserSpaceDao.findAll(new Specification<ApplyUserSpace>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<ApplyUserSpace> root,
|
|
|
+ CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ list.add(cb.equal(root.get("userUU").as(String.class), userUU));
|
|
|
+ Predicate[] predicates = new Predicate[list.size()];
|
|
|
+ predicates = list.toArray(predicates);
|
|
|
+ return cb.and(predicates);
|
|
|
+ }
|
|
|
+ }, pageable);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void agreeApply(Long userUU, Long id) {
|
|
|
+ // 判断当前用户是否为管理员
|
|
|
+ UserAccount loginUser = SystemSession.getUserAccount();
|
|
|
+ Userspace userspace = userspaceDao.findOne(loginUser.getSpaceUU());
|
|
|
+ if (loginUser.getSpaceUU().equals(userspace.getAdminUU())) {
|
|
|
+ throw new VisibleError("不是管理员,不允许操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找到申请信息
|
|
|
+ ApplyUserSpace applyUserSpace = applyUserSpaceDao.findOne(id);
|
|
|
+ if (!userUU.equals(applyUserSpace.getUserUU())) {
|
|
|
+ // 简单的校验下参数
|
|
|
+ throw new VisibleError("参数错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改状态
|
|
|
+ applyUserSpace.setStatus(Status.AGREE.getCode());
|
|
|
+ applyUserSpace.setProcessTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+ applyUserSpaceDao.save(applyUserSpace);
|
|
|
+
|
|
|
+ // 将用户添加到企业
|
|
|
+ userService.bindUserspace(userUU, loginUser.getSpaceUU());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void disagreeApply(Long userUU, Long id) {
|
|
|
+ // 判断当前用户是否为管理员
|
|
|
+ UserAccount loginUser = SystemSession.getUserAccount();
|
|
|
+ Userspace userspace = userspaceDao.findOne(loginUser.getSpaceUU());
|
|
|
+ if (loginUser.getSpaceUU().equals(userspace.getAdminUU())) {
|
|
|
+ throw new VisibleError("不是管理员,不允许操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找到申请信息
|
|
|
+ ApplyUserSpace applyUserSpace = applyUserSpaceDao.findOne(id);
|
|
|
+ if (!userUU.equals(applyUserSpace.getUserUU())) {
|
|
|
+ // 简单的校验下参数
|
|
|
+ throw new VisibleError("参数错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改状态
|
|
|
+ applyUserSpace.setStatus(Status.DISAGREE.getCode());
|
|
|
+ applyUserSpace.setProcessTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+ applyUserSpaceDao.save(applyUserSpace);
|
|
|
+ }
|
|
|
+}
|