|
@@ -1,13 +1,13 @@
|
|
|
package com.kmall.common.service.impl;
|
|
|
|
|
|
+import com.google.common.collect.ImmutableBiMap;
|
|
|
import com.kmall.common.Global;
|
|
|
import com.kmall.common.dao.SysUserDao;
|
|
|
import com.kmall.common.entity.SysUserEntity;
|
|
|
import com.kmall.common.service.SysRoleService;
|
|
|
import com.kmall.common.service.SysUserRoleService;
|
|
|
import com.kmall.common.service.SysUserService;
|
|
|
-import com.kmall.common.utils.Constant;
|
|
|
-import com.kmall.common.utils.RRException;
|
|
|
+import com.kmall.common.utils.*;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.shiro.crypto.hash.Sha256Hash;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -70,6 +70,35 @@ public class SysUserServiceImpl implements SysUserService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void save(SysUserEntity user) {
|
|
|
+ Map<String, Object> valideDate = MapBeanUtil.fromObject(user);
|
|
|
+ ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
|
|
|
+ builder.put("username", "用户名");
|
|
|
+ builder.put("email", "邮箱");
|
|
|
+ builder.put("mobile", "手机号");
|
|
|
+ builder.put("roleType", "数据角色类型");
|
|
|
+ builder.put("status", "状态");
|
|
|
+ builder.put("roleId", "角色");
|
|
|
+
|
|
|
+ R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ } else {
|
|
|
+ if (!"1".equals(user.getRoleType())) {
|
|
|
+ builder.put("storeId", "门店");
|
|
|
+ }
|
|
|
+ r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!user.getEmail().matches("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$")) {
|
|
|
+ throw new RRException("邮箱格式错误!");
|
|
|
+ }
|
|
|
+ if (!PhoneFormatCheckUtils.isPhoneLegal(user.getMobile())) {
|
|
|
+ throw new RRException("手机号格式错误!");
|
|
|
+ }
|
|
|
+
|
|
|
user.setCreateTime(new Date());
|
|
|
//sha256加密
|
|
|
user.setPassword(new Sha256Hash(Global.DEFAULT_PASS_WORD).toHex());
|
|
@@ -79,12 +108,41 @@ public class SysUserServiceImpl implements SysUserService {
|
|
|
checkRole(user);
|
|
|
|
|
|
//保存用户与角色关系
|
|
|
- sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
|
|
+ sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void update(SysUserEntity user) {
|
|
|
+ Map<String, Object> valideDate = MapBeanUtil.fromObject(user);
|
|
|
+ ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
|
|
|
+ builder.put("username", "用户名");
|
|
|
+ builder.put("email", "邮箱");
|
|
|
+ builder.put("mobile", "手机号");
|
|
|
+ builder.put("roleType", "数据角色类型");
|
|
|
+ builder.put("status", "状态");
|
|
|
+ builder.put("roleId", "角色");
|
|
|
+
|
|
|
+ R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ } else {
|
|
|
+ if (!"1".equals(user.getRoleType())) {
|
|
|
+ builder.put("storeId", "门店");
|
|
|
+ }
|
|
|
+ r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!user.getEmail().matches("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$")) {
|
|
|
+ throw new RRException("邮箱格式错误!");
|
|
|
+ }
|
|
|
+ if (!PhoneFormatCheckUtils.isPhoneLegal(user.getMobile())) {
|
|
|
+ throw new RRException("手机号格式错误!");
|
|
|
+ }
|
|
|
+
|
|
|
if (StringUtils.isBlank(user.getPassword())) {
|
|
|
user.setPassword(new Sha256Hash(Global.DEFAULT_PASS_WORD).toHex());
|
|
|
} else {
|
|
@@ -96,7 +154,7 @@ public class SysUserServiceImpl implements SysUserService {
|
|
|
checkRole(user);
|
|
|
|
|
|
//保存用户与角色关系
|
|
|
- sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
|
|
+ sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleId());
|
|
|
}
|
|
|
|
|
|
@Override
|