Bladeren bron

修改公司人员上限为10人,添加公司人员添加人员上限判断,返回会员有效剩余时间(时间戳)

wutt 5 jaren geleden
bovenliggende
commit
c4e9a3b45e

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/vo/UserVO.java

@@ -6,4 +6,5 @@ import lombok.Data;
 @Data
 public class UserVO extends User {
     private String companyName;
+    private Long remainingTime;
 }

+ 20 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -28,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.*;
+import java.time.ZoneOffset;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -83,7 +84,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             UserVO userVO = new UserVO();
             BeanUtils.copyProperties(userList.get(0), userVO);
             //还要多返回一个公司名字
-            userVO.setCompanyName(companyMapper.selectById(userVO.getCompanyId()).getCompanyName());
+            userVO.setCompanyName(company.getCompanyName());
+            LocalDateTime remainingTime = company.getExpirationDate() == null ? LocalDateTime.now() : company.getExpirationDate();
+            userVO.setRemainingTime(remainingTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() - LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
             httpRespMsg.data = userVO;
         } else {
             httpRespMsg.setError("密码错误");
@@ -116,13 +119,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                     }
                 } else {
                     if (company.getExpirationDate().isBefore(LocalDateTime.now())) {
-                            httpRespMsg.setError("账号会员已到期,请联系公司负责人续费会员套餐");
-                            return httpRespMsg;
+                        httpRespMsg.setError("账号会员已到期,请联系公司负责人续费会员套餐");
+                        return httpRespMsg;
                     }
                 }
             }
             //检测密码正确时
-            httpRespMsg.data = userList.get(0);
+            UserVO userVO = new UserVO();
+            BeanUtils.copyProperties(userList.get(0), userVO);
+            //还要多返回一个公司名字
+            LocalDateTime remainingTime = company.getExpirationDate() == null ? LocalDateTime.now() : company.getExpirationDate();
+            userVO.setRemainingTime(remainingTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() - LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
+            httpRespMsg.data = userVO;
         } else {
             httpRespMsg.setError("密码错误");
         }
@@ -219,6 +227,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             Company company = new Company().setCompanyName(companyName)
                     .setExpirationDate(LocalDateTime.now().plusDays(3));
             companyMapper.insert(company);
+            if (userMapper.selectCount(new QueryWrapper<User>().eq("company_id", company.getId())) >= (companyMapper.selectById(company.getId()).getStaffCountMax())) {
+                httpRespMsg.setError("公司人员已达上限");
+                return httpRespMsg;
+            }
             //然后生成一个负责人
             Long id = SnowFlake.nextId();
             User user = new User()
@@ -262,6 +274,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                                 .setPhone(phone)
                                 .setRole(role)
                                 .setCompanyId(creator.getCompanyId());
+                        if (userMapper.selectCount(new QueryWrapper<User>().eq("company_id", creator.getCompanyId())) >= (companyMapper.selectById(creator.getCompanyId()).getStaffCountMax())) {
+                            httpRespMsg.setError("公司人员已达上限");
+                            return httpRespMsg;
+                        }
                         if (userMapper.insert(user) == 0) {
                             httpRespMsg.setError("操作失败");
                         }