|
|
|
@@ -1,21 +1,8 @@ |
|
|
|
package com.iformall.controller; |
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
import com.iformall.domain.po.WxAppinfo; |
|
|
|
import com.iformall.domain.po.WxCUser; |
|
|
|
import com.iformall.domain.po.WxCUserBasicInfo; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.interceptor.AuthHandshakeInterceptor; |
|
|
|
import com.iformall.service.WxAppinfoService; |
|
|
|
import com.iformall.service.WxCUserBasicInfoService; |
|
|
|
import com.iformall.service.WxCUserService; |
|
|
|
import com.iformall.service.wechat.FmOpenService; |
|
|
|
import com.iformall.utils.IPUtil; |
|
|
|
import com.iformall.utils.MaUtil; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
import org.springframework.web.bind.annotation.InitBinder; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
@@ -27,24 +14,9 @@ import java.beans.PropertyEditorSupport; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@RestController |
|
|
|
public class BaseController { |
|
|
|
@Autowired |
|
|
|
private boolean isFmOpen; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserService wxCUserService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxAppinfoService wxAppinfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FmOpenService openService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserBasicInfoService wxCUserBasicInfoService; |
|
|
|
|
|
|
|
@InitBinder |
|
|
|
public void InitBinder(WebDataBinder dataBinder) { |
|
|
|
@@ -69,20 +41,11 @@ public class BaseController { |
|
|
|
} |
|
|
|
|
|
|
|
public Long getUserId() { |
|
|
|
ServletRequestAttributes ll = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); |
|
|
|
HttpServletRequest request = ll.getRequest(); |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
Long cUserId = (Long) request.getAttribute(AuthHandshakeInterceptor.LOGIN_USER_KEY); |
|
|
|
return cUserId; |
|
|
|
} |
|
|
|
|
|
|
|
public WxCUser getUser() { |
|
|
|
Long cUserId = getUserId(); |
|
|
|
WxCUser user = wxCUserService.getById(cUserId); |
|
|
|
if (user == null) |
|
|
|
throw new MallinkException(ErrorCode.USER_IS_EMPTY); |
|
|
|
return user; |
|
|
|
} |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public String getTenantId() { |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
@@ -106,72 +69,6 @@ public class BaseController { |
|
|
|
return tenantEntity; |
|
|
|
} |
|
|
|
|
|
|
|
public WxAppinfo getAppInfo(String appId) { |
|
|
|
return wxAppinfoService.getByAppId(appId); |
|
|
|
} |
|
|
|
|
|
|
|
public WxMaService getWeappService(String appId) { |
|
|
|
if(isFmOpen) { |
|
|
|
return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); |
|
|
|
} else { |
|
|
|
WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); |
|
|
|
if (appinfo == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
WxMaService service = MaUtil.getWeappService(appinfo); |
|
|
|
return service; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { |
|
|
|
if(!isFmOpen) { |
|
|
|
WxMaService service = MaUtil.getWeappService(appinfo); |
|
|
|
return service; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void saveToBasicInfo(WxCUser user) { |
|
|
|
TenantEntity tenantEntity = getTenantInfo(); |
|
|
|
String phone = user.getPhone(); |
|
|
|
if (phone != null && phone.contains("*")) { |
|
|
|
phone = user.getVerifyCodePhone(); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(phone)) |
|
|
|
return; |
|
|
|
|
|
|
|
List<WxCUserBasicInfo> list = wxCUserBasicInfoService.findByPhone(tenantEntity, phone); |
|
|
|
if (list.size() > 0) { |
|
|
|
WxCUserBasicInfo basicInfo = list.get(0); |
|
|
|
// 微信名称 |
|
|
|
if (basicInfo.getNickName() == null || basicInfo.getNickName().equals(user.getNickName())) { |
|
|
|
basicInfo.setNickName(user.getNickName()); |
|
|
|
} |
|
|
|
// 性别 |
|
|
|
if (basicInfo.getSex() == null) { |
|
|
|
basicInfo.setSex(user.getGender()); |
|
|
|
} |
|
|
|
// 成长值 |
|
|
|
if (basicInfo.getPoins() == null) { |
|
|
|
basicInfo.setPoins(user.getScore()); |
|
|
|
} |
|
|
|
wxCUserBasicInfoService.updateObj(basicInfo, user); |
|
|
|
} else { |
|
|
|
Date cur = new Date(); |
|
|
|
WxCUserBasicInfo basicInfo = new WxCUserBasicInfo(); |
|
|
|
basicInfo.setId(user.getId()); |
|
|
|
basicInfo.updateTenantInfo(tenantEntity); |
|
|
|
basicInfo.setPhone(phone); |
|
|
|
basicInfo.setNickName(user.getNickName()); |
|
|
|
basicInfo.setSex(user.getGender()); |
|
|
|
basicInfo.setPoins(user.getScore()); |
|
|
|
basicInfo.setCreateDate(cur); |
|
|
|
basicInfo.setUpdateDate(cur); |
|
|
|
wxCUserBasicInfoService.save(basicInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String getIpAddr() { |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
String ipaddress = IPUtil.getIpAddr(request); |
|
|
|
|