Commit 7dde60e7 by duanhq

手机号传入格式限制,商户列表修改,新增商户同时新增组织 by duanht 2019/3/13

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@18488 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 7d67097d
......@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.groups.Default;
import com.glsx.common.utils.UserUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.ExcessiveAttemptsException;
......@@ -188,6 +189,10 @@ public class UserController extends BaseController {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
if (!AccountValidatorUtil.isMobile(sysManager.getPhoneNumber())) {
return new ResultObject(ResultCodeEnum.PHONE_NUMBER_ERROR.getCode(), ResultCodeEnum.PHONE_NUMBER_ERROR.getMsg());
}
if (sysManager.getOrgId() != null) {
//根据组织id查询出所属集团
Integer groupId = iSysOrganizationService.getGroupIdByOrgId(sysManager.getOrgId());
......@@ -255,6 +260,10 @@ public class UserController extends BaseController {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
if (!AccountValidatorUtil.isMobile(sysMerchant.getPhoneNumber())) {
return new ResultObject(ResultCodeEnum.PHONE_NUMBER_ERROR.getCode(), ResultCodeEnum.PHONE_NUMBER_ERROR.getMsg());
}
if (sysMerchant.getOrgId() != null) {
//根据组织id查询出所属集团
Integer groupId = iSysOrganizationService.getGroupIdByOrgId(sysMerchant.getOrgId());
......@@ -275,7 +284,11 @@ public class UserController extends BaseController {
List<Integer> roleIds = new ArrayList<>();
roleIds.add(roleId);
sysMerchant.setRolesId(roleIds);
} else {
int orgId = user.getOrgId();
sysMerchant.setOrgId(orgId);
}
sysMerchant.setUserType(Constants.USER_TYPE_MERCHANT);
sysMerchant.setUpdateBy(ShiroUtil.getUsername());
sysMerchant.setUpdateTime(DateUtil.getCurrentTime());
......@@ -297,6 +310,11 @@ public class UserController extends BaseController {
Map<String, String> errorMap = getErrors(bindingResult);
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
}
if (!AccountValidatorUtil.isMobile(sysMechanic.getPhoneNumber())) {
return new ResultObject(ResultCodeEnum.PHONE_NUMBER_ERROR.getCode(), ResultCodeEnum.PHONE_NUMBER_ERROR.getMsg());
}
//通过pc注册的技工归属在当前账号下,serviceId为空表示通过pc端注册,审核状态为通过
if (serviceId == null) {
serviceId = ShiroUtil.getUserId();
......@@ -324,8 +342,8 @@ public class UserController extends BaseController {
sysMechanic.setPassword(sysUserService.encryptPassword(sysMechanic.getPhoneNumber()));
sysMechanic.setCreateTime(DateUtil.getCurrentTime());
//小程序端注册创建人是自己
if (StringUtils.isEmpty(ShiroUtil.getUsername())) {
sysMechanic.setCreateBy(sysMechanic.getUsername());
if (StringUtils.isEmpty(UserUtils.getUserName(request))) {
sysMechanic.setCreateBy(UserUtils.getUserName(request));
} else {
sysMechanic.setCreateBy(ShiroUtil.getUsername());
}
......@@ -668,15 +686,15 @@ public class UserController extends BaseController {
List<SysUser> users = sysUserService.findByUserName(username);
SysUser user = null;
if (users != null && !users.isEmpty()) {
user = users.get(0);
user = users.get(0);
}
if (user == null) {
throw new UnknownAccountException();
}
String pwd = user.getPassword();
if (pwd != null && !pwd.equals(sysUserService.encryptPassword(password))) {
throw new IncorrectCredentialsException();
}
throw new IncorrectCredentialsException();
}
String userStatus = user.getUserStatus();
//账号被停用或注销
if (!com.glsx.common.constants.Constants.SYS_USER_STATUS_NORMAL.equals(userStatus)) {
......@@ -691,8 +709,8 @@ public class UserController extends BaseController {
System.out.println("登录用户" + sess.getAttribute("username"));
if (username.equals(sess.getAttribute("username"))) {
redisSessionDAO.delete(sess); //session清除
sess.setTimeout(0);
redisSessionDAO.delete(sess); //session清除
sess.setTimeout(0);
}
}
/*
......@@ -701,15 +719,15 @@ public class UserController extends BaseController {
Integer userType = user.getUserType();
logger.info("用户类型=" + userType);
if (terminalType != userType) {
if (Constants.USER_TYPE_MANAGER == terminalType ) {
if (Constants.USER_TYPE_MECHANIC == userType) {
logger.info("登录后台管理系统,该账号暂无权限登录");
return new ResultObject(ResultCodeEnum.USER_LOGIN_NO_AUTH.getCode(), ResultCodeEnum.USER_LOGIN_NO_AUTH.getMsg());
}
}else {
logger.info("该账号暂无权限登录");
return new ResultObject(ResultCodeEnum.USER_LOGIN_NO_AUTH.getCode(), ResultCodeEnum.USER_LOGIN_NO_AUTH.getMsg());
}
if (Constants.USER_TYPE_MANAGER == terminalType) {
if (Constants.USER_TYPE_MECHANIC == userType) {
logger.info("登录后台管理系统,该账号暂无权限登录");
return new ResultObject(ResultCodeEnum.USER_LOGIN_NO_AUTH.getCode(), ResultCodeEnum.USER_LOGIN_NO_AUTH.getMsg());
}
} else {
logger.info("该账号暂无权限登录");
return new ResultObject(ResultCodeEnum.USER_LOGIN_NO_AUTH.getCode(), ResultCodeEnum.USER_LOGIN_NO_AUTH.getMsg());
}
}
/*
* shiro登录校验
......@@ -721,7 +739,7 @@ public class UserController extends BaseController {
session.setAttribute(com.glsx.common.constants.Constants.SESSION_USERID_KEY, user.getId());
map.put("JSESSIONID", subject.getSession().getId());
result.setData(map);
logger.info("用户登录成功:username="+ username);
logger.info("用户登录成功:username=" + username);
} catch (UnknownAccountException uae) {
logger.info("用户名和密码不匹配");
result = new ResultObject(ResultCodeEnum.USERNAME_OR_PASSWORD_NOT_RIGHT.getCode(), ResultCodeEnum.USERNAME_OR_PASSWORD_NOT_RIGHT.getMsg());
......
......@@ -47,6 +47,8 @@ public interface SysUserMapper {
List<SysMerchant> getSysMerchantList(UserQueryVo userQueryVo);
List<SysMerchant> getSysMerchantBindList(UserQueryVo userQueryVo);
int deleteUserById(UserQueryVo userQueryVo);
List<SysMechanic> getSysMechanicList(UserQueryVo userQueryVo);
......@@ -78,4 +80,5 @@ public interface SysUserMapper {
List<SysMechanic> getServiceMechanicList(SysMechanic mechanic);
List<SysMechanic> getCheckSysMechanicList(UserQueryVo userQueryVo);
}
\ No newline at end of file
......@@ -45,7 +45,6 @@ public class SysUser extends BaseModel implements Serializable{
* 手机号
*/
@NotBlank(message="{param.not.null}", groups={Default.class, GroupA.class})
@Size(min=11,max=11,message="手机格式不正确")
private String phoneNumber;
/**
......
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import com.glsx.usercenter.service.ISysOrganizationService;
import com.glsx.usercenter.utils.ShiroUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.LockedAccountException;
......@@ -143,7 +144,15 @@ public class SysUserServiceImpl implements SysUserService {
}
}
List<SysMerchant> sysMerchantList = sysUserMapper.getSysMerchantList(userQueryVo);
//判断列表类型
List<SysMerchant> sysMerchantList = new ArrayList<>();
//商户管理列表
if (Constants.LIST_TYPE_MERCHANT_MANANGE.equals(userQueryVo.getListType())) {
sysMerchantList = sysUserMapper.getSysMerchantList(userQueryVo);
//资源绑定列表
} else {
sysMerchantList = sysUserMapper.getSysMerchantBindList(userQueryVo);
}
for (SysMerchant sysMerchant : sysMerchantList) {
//设置省市区
......@@ -155,10 +164,9 @@ public class SysUserServiceImpl implements SysUserService {
SysOrganization sysOrganization = sysOrganizationMapper.selectByPrimaryKey(sysMerchant.getGroupId());
sysMerchant.setOrgName(sysOrganization.getName());
}
//设置服务商名
SysUser sysUser = sysUserMapper.selectByPrimaryKey(sysMerchant.getUserId());
if (sysUser != null){
if (sysUser != null) {
sysMerchant.setServiceName(sysUser.getName());
}
}
......@@ -321,15 +329,30 @@ public class SysUserServiceImpl implements SysUserService {
try {
if (sysMerchant.getId() == null || sysMerchant.getId() == 0) {
// 新增商户
//先将商户添加到组织机构中并获取组织id
int orgId = addOrganization(sysMerchant);
sysMerchant.setOrgId(orgId);
sysUserMapper.insertSelective(sysMerchant);
sysMerchant.setUserId(sysMerchant.getId());
sysUserMapper.insertSysMerchant(sysMerchant);
userId = sysMerchant.getUserId();
//当前用户获取该商户组织的数据权限
SysUserOrg sysUserOrg = new SysUserOrg();
sysUserOrg.setUserId(ShiroUtil.getUserId());
sysUserOrg.setOrgId(orgId);
sysUserOrgMapper.insertSelective(sysUserOrg);
} else {
//更新主表
sysUserMapper.updateSysUser(sysMerchant);
//更新商户详细表
sysUserMapper.updateSysMerchant(sysMerchant);
//更新组织名称
SysOrganization sysOrganization = new SysOrganization();
sysOrganization.setId(sysMerchant.getOrgId());
sysOrganization.setName(sysMerchant.getShopName());
sysOrganizationMapper.updateByPrimaryKeySelective(sysOrganization);
}
// 更新角色和服务项
SysUser sysUser = new SysUser();
......@@ -342,6 +365,22 @@ public class SysUserServiceImpl implements SysUserService {
return 1;
}
private int addOrganization(SysMerchant sysMerchant) {
SysOrganization sysOrganization = new SysOrganization();
sysOrganization.setParentId(sysMerchant.getOrgId());
sysOrganization.setName(sysMerchant.getShopName());
sysOrganization.setOrgStatus((byte)1);
sysOrganization.setOrgType((byte)2);
sysOrganization.setCreateBy(sysMerchant.getCreateBy());
sysOrganization.setCreateTime(sysMerchant.getCreateTime());
//排序为目前最大排序加1
List<SysOrganization> sysOrganizations = sysOrganizationMapper.findOrgByParentId(sysMerchant.getOrgId());
int sort = sysOrganizations.get(sysOrganizations.size()-1).getSort()+1;
sysOrganization.setSort(sort);
sysOrganizationMapper.insertSelective(sysOrganization);
return sysOrganization.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public int saveSysMechanic(SysMechanic sysMechanic, Integer serviceId) {
......
......@@ -24,7 +24,7 @@ public class AccountValidatorUtil {
/**
* 正则表达式:验证手机号
*/
public static final String REGEX_MOBILE = "^((17[0-9])|(14[0-9])|(19[0-9])|(13[0-9])|(15[0-9])|(18[0-9]))\\d{8}$";
public static final String REGEX_MOBILE = "^[1]([3-9])[0-9]{9}$";
/**
* 正则表达式:验证邮箱
......
......@@ -643,6 +643,7 @@
ORDER BY u.id DESC
</select>
<select id="getSysMerchantList" parameterType="com.glsx.usercenter.pojo.vo.UserQueryVo"
resultType="com.glsx.usercenter.pojo.user.SysMerchant">
<if test="merchantId != null ">
......@@ -661,10 +662,100 @@
phone_number phoneNumber,
sm.district district,
sm.address address,
GROUP_CONCAT(sdd.data_value SEPARATOR '/') serviceItems,
GROUP_CONCAT(sdd.data_key ) serviceKey,
sm.merchant_status merchantStatus,
u.group_id groupId
<choose>
<when test="userId != 0 and userId!=''">
FROM
sys_user_org suo
LEFT JOIN sys_organization so ON suo.org_id = so.id
LEFT JOIN sys_user u ON u.org_id = so.id
LEFT JOIN sys_merchant sm ON sm.user_id = u.id
LEFT JOIN sys_user_services sms ON sm.user_id = sms.user_id
LEFT JOIN sys_dict_data sdd ON sms.service_key = sdd.data_key
WHERE suo.user_id = #{userId,jdbcType=INTEGER}
AND u.user_type = 2
</when>
<otherwise>
FROM
sys_user u
LEFT JOIN sys_organization so ON u.org_id = so.id
LEFT JOIN sys_merchant sm ON sm.user_id = u.id
LEFT JOIN sys_user_services sms ON sm.user_id = sms.user_id
LEFT JOIN sys_dict_data sdd ON sms.service_key = sdd.data_key
WHERE u.user_type = 2
</otherwise>
</choose>
<if test="id != null and id!=''">
and u.id = #{id,jdbcType=INTEGER}
</if>
<if test="merchantId != null ">
and u.id like #{merchantId}
</if>
<if test="shopName != null and shopName!=''">
and sm.shop_name like "%"#{shopName,jdbcType=VARCHAR}"%"
</if>
<if test="serviceType != null and serviceType!=''">
and sm.service_type = #{serviceType,jdbcType=VARCHAR}
</if>
<if test="name != null and name!=''">
and u.name like "%"#{name,jdbcType=VARCHAR}"%"
</if>
<if test="phoneNumber != null and phoneNumber!=''">
and u.phone_number like "%"#{phoneNumber,jdbcType=VARCHAR}"%"
</if>
<if test="groupId != null and groupId!=''">
and u.group_id = #{groupId,jdbcType=INTEGER}
</if>
<if test="sTime != null and eTime!=null and sTime !='' and eTime !=''">
and u.create_time between #{sTime,jdbcType=TIMESTAMP} and #{eTime,jdbcType=TIMESTAMP}
</if>
<choose>
<when test="userStatus != null and userStatus!=''">
and u.user_status = #{userStatus,jdbcType=VARCHAR}
</when>
<otherwise>
and u.user_status IN ('sys_user_status_nonuse','sys_user_status_normal')
</otherwise>
</choose>
GROUP BY u.id
ORDER BY u.id DESC
</select>
<select id="getSysMerchantBindList" parameterType="com.glsx.usercenter.pojo.vo.UserQueryVo"
resultType="com.glsx.usercenter.pojo.user.SysMerchant">
<if test="merchantId != null ">
<bind name="merchantId" value="'%' + merchantId + '%'"/>
</if>
SELECT
DISTINCT
u.id,
u.username,
u.password,
u.org_id orgId,
sm.shop_name shopName,
user_status userStatus,
sm.service_type serviceType,
u. NAME,
phone_number phoneNumber,
sm.district district,
sm.address address,
sdd.data_key serviceKey,
sdd.data_value serviceItems,
sm.merchant_status merchantStatus,
u.org_id groupId,
u.group_id groupId,
srm.user_id userId
<choose>
<when test="userId != 0 and userId!=''">
......@@ -675,7 +766,7 @@
LEFT JOIN sys_merchant sm ON sm.user_id = u.id
LEFT JOIN sys_user_services sms ON sm.user_id = sms.user_id
LEFT JOIN sys_dict_data sdd ON sms.service_key = sdd.data_key
LEFT JOIN sys_resource_matching srm ON srm.merchant_id = u.id
LEFT JOIN sys_resource_matching srm ON srm.merchant_id = u.id AND srm.service_key = sms.service_key
WHERE suo.user_id = #{userId,jdbcType=INTEGER}
AND u.user_type = 2
</when>
......@@ -686,7 +777,7 @@
LEFT JOIN sys_merchant sm ON sm.user_id = u.id
LEFT JOIN sys_user_services sms ON sm.user_id = sms.user_id
LEFT JOIN sys_dict_data sdd ON sms.service_key = sdd.data_key
LEFT JOIN sys_resource_matching srm ON srm.merchant_id = u.id
LEFT JOIN sys_resource_matching srm ON srm.merchant_id = u.id AND srm.service_key = sms.service_key
WHERE u.user_type = 2
</otherwise>
</choose>
......@@ -727,17 +818,6 @@
and u.create_time between #{sTime,jdbcType=TIMESTAMP} and #{eTime,jdbcType=TIMESTAMP}
</if>
<if test="listType == 2">
<choose>
<when test="userStatus != null and userStatus!=''">
and u.user_status = #{userStatus,jdbcType=VARCHAR}
</when>
<otherwise>
and u.user_status IN ('sys_user_status_nonuse','sys_user_status_normal')
</otherwise>
</choose>
</if>
<if test="listType == 3">
and u.user_status IN ('sys_user_status_normal')
<choose>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!