Commit ad119a45 by zhanghj

V1.3.0--提交订单助手登录相关代码

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@22619 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 7213d45e
......@@ -90,6 +90,7 @@ public interface Constants {
public static final int USER_TYPE_SP = 1;
public static final int USER_TYPE_MERCHANT = 2;
public static final int USER_TYPE_MECHANIC = 3;
public static final int USER_TYPE_ORDER_ASSISTANT = 4;
/**
* 技工接单状态:1:可接单,2:不可接单
......@@ -113,18 +114,30 @@ public interface Constants {
* 包活干公众号的appsecret
*/
public static final String WECHAT_BHG_PUBLIC_SECRET = "wechat_bhg_public_secret";
/*
* 微信小程序相关配置
*/
/**
* 微信小程序appid
* 服务商小程序配置
*/
public static final String WECHAT_bhg_MINI_APPID = "wechat_bhg_mini_appid";
public static final String WECHAT_MINI_SERVICE_APPID = "wechat.mini.service.appid";
public static final String WECHAT_MINI_SERVICE_SECRET = "wechat.mini.service.secret";
/**
* 微信跳转页面
* 商户小程序配置
*/
public static final String WECHAT_bhg_MINI_REPAY_PAGE_PATH = "wechat_bhg_mini_repay_page_path";
public static final String WECHAT_MINI_MERCHANT_APPID = "wechat.mini.merchant.appid";
public static final String WECHAT_MINI_MERCHANT_SECRET = "wechat.mini.merchant.secret";
/**
* 微信推送还款公众号模板id
* 技工小程序配置
*/
public static final String WECHAT_bhg_REPAY_TEMPLATEID = "wechat_bhg_templateid";
public static final String WECHAT_MINI_MECHANIC_APPID = "wechat.mini.mechanic.appid";
public static final String WECHAT_MINI_MECHANIC_SECRET = "wechat.mini.mechanic.secret";
/**
* 订单助手小程序配置
*/
public static final String WECHAT_MINI_ORDER_ASSISTANT_APPID = "wechat.mini.order.assistant.appid";
public static final String WECHAT_MINI_ORDER_ASSISTANT_SECRET = "wechat.mini.order.assistant.secret";
/**
* 高德地图用户key
......@@ -163,4 +176,6 @@ public interface Constants {
* 设备类型(700F)
*/
public static final String DEVICE_TYPE_700F = "sys_order_service_item_gps_GT700F";
}
......@@ -130,6 +130,8 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/user/isBindWechat", "anon");
//获取技工所属服务商id
filterChainDefinitionMap.put("/user/getMechanicSP", "anon");
//微信登陆
filterChainDefinitionMap.put("/user/wxLogin", "anon");
//退出
// filterChainDefinitionMap.put("/user/logout", "logout");
filterChainDefinitionMap.put("/**", "authc");
......
......@@ -32,8 +32,9 @@ public enum ResultCodeEnum {
USER_LOGIN_NO_AUTH(2008, "该账号暂无权限登录"),
USER_RELATE_ORDER(2009, "该用户已关联订单,无法删除"),
MERCHANIC_EXPORT_OUTOFNUMBER(2010,"技工导出超过10000条请重新选择筛选条件"),
USER_BIND_WECHAT_MINI_REPEAT(2020, "该账号已被绑定,不可继续绑定"),
USER_BIND_WECHAT_MINI_REPEAT(2020, "该微信已被绑定,不可继续绑定"),
SHOPNAME_REPETITION(2021, "该根组织下存在同名商户,请勿重复创建"),
USER_GET_MINI_OPENID_FAIL(2022, "微信小程序获取openid失败"),
/**
* 参数相关提示
......
......@@ -33,7 +33,7 @@ public class ReportController extends BaseReportController{
userQueryVo.setUserId(ShiroUtil.getUserId());
List<SysMechanic> list = sysUserService.getSysMechanicList(userQueryVo);
if (list.size()>10000) {
throw SysException.create(String.valueOf(ResultCodeEnum.MERCHANIC_EXPORT_OUTOFNUMBER.getCode()),ResultCodeEnum.MERCHANIC_EXPORT_OUTOFNUMBER.getMsg());
throw SysException.create(ResultCodeEnum.MERCHANIC_EXPORT_OUTOFNUMBER.getCode(),ResultCodeEnum.MERCHANIC_EXPORT_OUTOFNUMBER.getMsg());
}
if(list!=null){
for(SysMechanic sysMechanic:list){
......
......@@ -2,7 +2,6 @@ package com.glsx.usercenter.controller;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -17,7 +16,6 @@ import org.apache.shiro.authc.ExcessiveAttemptsException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.crazycake.shiro.RedisSessionDAO;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -834,7 +832,7 @@ public class UserController extends BaseController {
Map<String, Object> map = new HashMap<String, Object>();
try {
if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password) || terminalType == null) {
return new ResultObject(ResultCodeEnum.ERROR.getCode(), ResultCodeEnum.ERROR.getMsg());
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
List<SysUser> users = sysUserService.findByUserName(username);
SysUser user = null;
......@@ -1189,4 +1187,46 @@ public class UserController extends BaseController {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
}
/**
*
* @author zhanghj
* @Title: wxLogin
* @Description: TODO 微信登录(直接帮用户注册登录)
* @param mechanicId
* @param serviceId
* @return
* ResultObject
*
*/
@RequestMapping(value = "/wxLogin", method = {RequestMethod.POST})
@ResponseBody
public ResultObject wxLogin(HttpServletRequest request, HttpSession session, @RequestParam(defaultValue = "4")Integer userType, String miniCode) {
logger.info("微信登录传的小程序code=" + miniCode);
if (StringUtil.isEmpty(miniCode)) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(),
ResultCodeEnum.PARAM_ERROR.getMsg());
}
String jsessionid = null;
ResultObject result = new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
Map<String, Object> map = new HashMap<String, Object>();
SysUser user = sysUserService.wxLogin(request, userType, miniCode);
String username = user.getUsername();
String password = user.getPassword();
/*
* shiro登录校验
*/
Subject subject = SecurityUtils.getSubject();
CustomToken token = new CustomToken(username, password, LoginType.NOPASSWD, false, null);
subject.login(token);
session.setAttribute(com.glsx.common.constants.Constants.SESSION_USERNAME_KEY, username);
session.setAttribute(com.glsx.common.constants.Constants.SESSION_USERID_KEY, user.getId());
jsessionid = (String) subject.getSession().getId();
map.put("JSESSIONID", jsessionid);
result.setData(map);
return result;
}
}
......@@ -23,12 +23,12 @@ public class BusinessException extends RuntimeException {
public static BusinessException create(String message) {
int value= (int) (MIN_AUTO_CODE + Math.round((Integer.MAX_VALUE - MIN_AUTO_CODE) * Math.random()));
return create(value + "",message);
return create(value,message);
}
public static BusinessException create(String returnCode,String message){
public static BusinessException create(int returnCode,String message){
BusinessException businessException = new BusinessException(null);
businessException.resultEntity = ResultObject.err(Integer.parseInt(returnCode)).message(message);
businessException.resultEntity = ResultObject.err(returnCode).message(message);
return businessException;
}
public static BusinessException create(ResultObject resultEntity){
......
......@@ -193,4 +193,16 @@ public interface SysUserMapper {
* @Description: TODO 根据商户名和根组织id查询商户信息
*/
SysUser getByShopNameAndGroupId(@Param("shopName")String shopName, @Param("groupId")Integer groupId);
/**
*
* @author zhanghj
* @Title: get
* @Description: TODO 获取用户主信息
* @param user
* @return
* SysUser
*
*/
SysUser get(SysUser user);
}
\ No newline at end of file
......@@ -353,4 +353,18 @@ public interface SysUserService {
* @Description: TODO 根据商户名和根组织id查询商户信息
*/
SysUser getByShopNameAndGroupId(String shopName, Integer groupId);
/**
*
* @author zhanghj
* @Title: wxLogin
* @Description: TODO
* @param request
* @param userType
* @param miniCode
* @return
* SysUser
*
*/
SysUser wxLogin(HttpServletRequest request, Integer userType, String miniCode);
}
package com.glsx.usercenter.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -30,6 +31,7 @@ import com.glsx.common.utils.wehcat.WechatUtils;
import com.glsx.usercenter.constants.Constants;
import com.glsx.usercenter.constants.ResultCodeEnum;
import com.glsx.usercenter.dto.ServiceInfo;
import com.glsx.usercenter.exception.BusinessException;
import com.glsx.usercenter.exception.SysException;
import com.glsx.usercenter.mapper.SysOrganizationMapper;
import com.glsx.usercenter.mapper.SysResourceMatchingMapper;
......@@ -398,7 +400,7 @@ public class SysUserServiceImpl implements SysUserService {
JSONObject jsonObject = orderClient.updateOrdersBindShop(sysMerchant.getOrderId(), userId,sysMerchant.getServiceType());
String code = jsonObject.get("code").toString();
if (!"200".equals(code)) {
throw SysException.create(String.valueOf(ResultCodeEnum.RPC_ERROR.getCode()),"订单服务调用异常");
throw SysException.create(ResultCodeEnum.RPC_ERROR.getCode(),"订单服务调用异常");
}
}
} catch (Exception e) {
......@@ -870,14 +872,17 @@ public class SysUserServiceImpl implements SysUserService {
String miniAppid = null;
String miniSecret = null;
if (com.glsx.common.constants.Constants.USER_TYPE_SP == userType) {
miniAppid = PropertiesUtil.getProperty("wechat.mini.service.appid");
miniSecret = PropertiesUtil.getProperty("wechat.mini.service.secret");
} else if(com.glsx.common.constants.Constants.USER_TYPE_MERCHANT == userType) {
miniAppid = PropertiesUtil.getProperty("wechat.mini.merchant.appid");
miniSecret = PropertiesUtil.getProperty("wechat.mini.merchant.secret");
}else if(com.glsx.common.constants.Constants.USER_TYPE_MECHANIC == userType) {
miniAppid = PropertiesUtil.getProperty("wechat.mini.mechanic.appid");
miniSecret = PropertiesUtil.getProperty("wechat.mini.mechanic.secret");
miniAppid = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_SERVICE_APPID);
miniSecret = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_SERVICE_SECRET);
} else if (com.glsx.common.constants.Constants.USER_TYPE_MERCHANT == userType) {
miniAppid = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_MERCHANT_APPID);
miniSecret = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_MERCHANT_SECRET);
} else if (com.glsx.common.constants.Constants.USER_TYPE_MECHANIC == userType) {
miniAppid = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_MECHANIC_APPID);
miniSecret = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_MECHANIC_SECRET);
} else if (com.glsx.common.constants.Constants.USER_TYPE_ORDER_ASSISTANT == userType) {
miniAppid = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_ORDER_ASSISTANT_APPID);
miniSecret = PropertiesUtil.getProperty(com.glsx.common.constants.Constants.WECHAT_MINI_ORDER_ASSISTANT_SECRET);
}
map.put("appid", miniAppid);
map.put("secret", miniSecret);
......@@ -923,4 +928,37 @@ public class SysUserServiceImpl implements SysUserService {
public SysUser getByShopNameAndGroupId(String shopName, Integer groupId) {
return sysUserMapper.getByShopNameAndGroupId(shopName,groupId);
}
@Override
@Transactional
public SysUser wxLogin(HttpServletRequest request, Integer userType, String miniCode) {
// TODO Auto-generated method stub
SysUser sysUser = new SysUser();
String miniOpenId = null;
Map<String, String> map = getWechatMiniProperties(userType);
String appid = map.get("appid");
String secret = map.get("secret");
try {
Map<String, Object> result = WechatMiniUtils.getWechatMiniOpenId(appid, secret, miniCode);
if (result != null) {
miniOpenId = (String) result.get("openid");
}
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error("微信登录获取微信小程序openid失败", e);
}
if (!org.springframework.util.StringUtils.isEmpty(miniOpenId)) {
sysUser.setUsername(miniOpenId);
SysUser user = sysUserMapper.get(sysUser);
if (user == null) {
sysUser.setUserType(userType);
sysUser.setPhoneNumber("");
sysUser.setCreateTime(new Date());
sysUserMapper.insert(sysUser);
}
} else {
throw BusinessException.create(ResultCodeEnum.USER_GET_MINI_OPENID_FAIL.getCode(), ResultCodeEnum.USER_GET_MINI_OPENID_FAIL.getMsg());
}
return sysUser;
}
}
......@@ -1422,4 +1422,23 @@
WHERE su.group_id = #{groupId} AND sm.shop_name = #{shopName}
</select>
<select id="get" parameterType="com.glsx.usercenter.pojo.user.SysUser" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from sys_user
<where>
<if test="id != null">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="miniOpenId != null and miniOpenId != ''">
and mini_openId = #{miniOpenId}
</if>
<if test="userType != null">
and user_type = #{userType}
</if>
<if test="username != null and username != ''">
and username = #{username}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!