Commit b4e939ac authored by zhangzc's avatar zhangzc

添加消息推送接口

parent 8e16155a
......@@ -25,24 +25,23 @@ public class ProtocolComponent {
/**
* description 校验Http请求的Header
* Map<String,String> map = new HashMap<>();
* map.put("requestSource", "2"); // 终端类型:2-Android端、3-iOS
* map.put("Source-Type", "2"); // 访问端来源:1-浏览器端、2-Android端、3-iOS端、4-后台服务
* map.put("Union-Authorization", AppConfig.getInstance().getToken()); // token
* map.put("osType", osType); // 客户端操作系统名称
* map.put("osVer", osVer); // 客户端操作系统版本
* map.put("mobileId", mobileId); // 手机唯一标识
* map.put("cVer", cVer); // 客户端版本
* map.put("accountType", "1"); // 帐号身份类型:1-司机、2-货主
* map.put("tenantId", "1"); // 租户ID:1-司机、2-货主
* map.put("tenantId", "1"); // 租户ID:
* param [request]
* return void
* author Administrator
* createTime 2020/05/14 16:00
**/
public void checkReqHeader(HttpServletRequest request) throws EException {
if (!String.valueOf(AccountConstants.APP_TYPE_ANDROID).equals(request.getHeader("requestSource"))
&& !String.valueOf(AccountConstants.APP_TYPE_IOS).equals(request.getHeader("requestSource"))) {
throw new EException(ECode.PROTOCOL_ILLEGAL.code(), "请求头[requestSource]不符合协议");
}
if (String.valueOf(AccountConstants.APP_TYPE_ANDROID).equals(request.getHeader("Source-Type"))
|| String.valueOf(AccountConstants.APP_TYPE_IOS).equals(request.getHeader("Source-Type"))) {
if (StringUtils.isBlank(request.getHeader("osType"))) {
throw new EException(ECode.PROTOCOL_ILLEGAL.code(), "请求头[osType]不符合协议");
}
......@@ -63,5 +62,6 @@ public class ProtocolComponent {
throw new EException(ECode.PROTOCOL_ILLEGAL.code(), "请求头[accountType]不符合协议");
}
}
}
}
......@@ -72,7 +72,7 @@ public class TokenComponent {
// 构建Token信息
tokenInfoPojo.setIp(ReqUtils.getHttpClientIp());
tokenInfoPojo.setSn(ReqUtils.getRequestHeader("mobileId"));
tokenInfoPojo.setDeviceType(Integer.parseInt(ReqUtils.getRequestHeader("requestSource")));
tokenInfoPojo.setDeviceType(Integer.parseInt(ReqUtils.getRequestHeader("Source-Type")));
tokenInfoPojo.setOsType(ReqUtils.getRequestHeader("osType"));
tokenInfoPojo.setOsVersion(ReqUtils.getRequestHeader("osVer"));
tokenInfoPojo.setAppVersion(ReqUtils.getRequestHeader("cVer"));
......@@ -104,7 +104,7 @@ public class TokenComponent {
// 构建Token信息
tokenInfoPojo.setIp(ReqUtils.getHttpClientIp());
tokenInfoPojo.setSn(ReqUtils.getRequestHeader("mobileId"));
tokenInfoPojo.setDeviceType(Integer.parseInt(ReqUtils.getRequestHeader("requestSource")));
tokenInfoPojo.setDeviceType(Integer.parseInt(ReqUtils.getRequestHeader("Source-Type")));
tokenInfoPojo.setOsType(ReqUtils.getRequestHeader("osType"));
tokenInfoPojo.setOsVersion(ReqUtils.getRequestHeader("osVer"));
tokenInfoPojo.setAppVersion(ReqUtils.getRequestHeader("cVer"));
......
......@@ -47,4 +47,9 @@ public class AccountConstants {
public static final Integer AUDIT_STATUS_CHECK_PENDING = 0;
public static final Integer AUDIT_STATUS_CHECK_SUCCESS = 1;
public static final Integer AUDIT_STATUS_CHECK_FAIL = 2;
/**
* 消息类型
**/
public static final Integer MESSAGE_TYPE_BILL_CONFIRM = 101; // 账单生成后用户确认消息
}
......@@ -32,9 +32,16 @@ public class AuthFilter implements Filter {
/**
* 不需要TOKEN校验的URL
**/
private static final String[] NOT_TOKEN_URL = new String[]{"/app/ownerBackend/account/login/loginBySms", "/app/ownerBackend/account/login/loginByPwd",
"/app/driverBackend/account/login/loginBySms", "/app/driverBackend/account/login/loginByPwd", "/app/driverBackend/account/login/check/phone",
"/app/driverBackend/account/carrier/list","/app/driverBackend/grab/find/list","/app/ownerBackend/password/reset","/app/driverBackend/password/reset"};
private static final String[] NOT_TOKEN_URL = new String[]{"/app/ownerBackend/account/login/loginBySms",
"/app/ownerBackend/account/login/loginByPwd",
"/app/driverBackend/account/login/loginBySms",
"/app/driverBackend/account/login/loginByPwd",
"/app/driverBackend/account/login/check/phone",
"/app/driverBackend/account/carrier/list",
"/app/driverBackend/grab/find/list",
"/app/ownerBackend/password/reset",
"/app/message/push2Account",
"/app/driverBackend/password/reset"};
@Autowired
private ProtocolComponent protocolComponent;
......
......@@ -48,7 +48,7 @@ public class FeignConfigure {
RequestInterceptor requestInterceptor = ((requestTemplate -> {
requestTemplate.header("trace_id", MDC.get("traceId"));
requestTemplate.header("application_name", applicationName);
requestTemplate.header("Source-Type", ReqUtils.getRequestHeader("requestSource"));
requestTemplate.header("Source-Type", "4");
requestTemplate.header("esv_data_perm", "0");
requestTemplate.header("esv_system", "app");
requestTemplate.header("esv_department", "5");
......
package com.esv.freight.app.config.mybatis;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Parenthesis;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.*;
import java.util.List;
/**
* @description:
* @project: spring-cloud-single-template
* @name: com.esv.springcloud.single.template.config.mybatis.DataPermParser
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/4/7 17:00
* @version:1.0
*/
@Slf4j
public class DataPermParser extends TenantSqlParser {
/**
* 目前仅支持:in, between, >, <, =, !=等比较操作,处理多租户的字段加上表别名
*
* @param expression
* @param table
* @return
*/
protected Expression processTableAlias(Expression expression, Table table) {
String tableAliasName;
if (table.getAlias() == null) {
tableAliasName = table.getName();
} else {
tableAliasName = table.getAlias().getName();
}
if (expression instanceof InExpression) {
InExpression in = (InExpression) expression;
if (in.getLeftExpression() instanceof Column) {
setTableAliasNameForColumn((Column) in.getLeftExpression(), tableAliasName);
}
} else if (expression instanceof BinaryExpression) {
BinaryExpression compare = (BinaryExpression) expression;
if (compare.getLeftExpression() instanceof Column) {
setTableAliasNameForColumn((Column) compare.getLeftExpression(), tableAliasName);
} else if (compare.getRightExpression() instanceof Column) {
setTableAliasNameForColumn((Column) compare.getRightExpression(), tableAliasName);
}
} else if (expression instanceof Between) {
Between between = (Between) expression;
if (between.getLeftExpression() instanceof Column) {
setTableAliasNameForColumn((Column) between.getLeftExpression(), tableAliasName);
}
}
return expression;
}
private void setTableAliasNameForColumn(Column column, String tableAliasName) {
column.setColumnName(tableAliasName + "." + column.getColumnName());
}
/**
* 默认是按 tenant_id=1 按等于条件追加
*
* @param currentExpression 现有的条件:比如你原来的sql查询条件
* @param table
* @return
*/
@Override
protected Expression builderExpression(Expression currentExpression, Table table) {
final Expression tenantExpression = this.getTenantHandler().getTenantId(true);
Expression appendExpression;
if (!(tenantExpression instanceof SupportsOldOracleJoinSyntax)) {
appendExpression = new EqualsTo();
((EqualsTo) appendExpression).setLeftExpression(this.getAliasColumn(table));
((EqualsTo) appendExpression).setRightExpression(tenantExpression);
} else {
appendExpression = processTableAlias(tenantExpression, table);
}
if (currentExpression == null) {
return appendExpression;
}
if (currentExpression instanceof BinaryExpression) {
BinaryExpression binaryExpression = (BinaryExpression) currentExpression;
if (binaryExpression.getLeftExpression() instanceof FromItem) {
processFromItem((FromItem) binaryExpression.getLeftExpression());
}
if (binaryExpression.getRightExpression() instanceof FromItem) {
processFromItem((FromItem) binaryExpression.getRightExpression());
}
} else if (currentExpression instanceof InExpression) {
InExpression inExp = (InExpression) currentExpression;
ItemsList rightItems = inExp.getRightItemsList();
if (rightItems instanceof SubSelect) {
processSelectBody(((SubSelect) rightItems).getSelectBody());
}
}
if (currentExpression instanceof OrExpression) {
return new AndExpression(new Parenthesis(currentExpression), appendExpression);
} else {
return new AndExpression(currentExpression, appendExpression);
}
}
@Override
protected void processPlainSelect(PlainSelect plainSelect, boolean addColumn) {
FromItem fromItem = plainSelect.getFromItem();
if (fromItem instanceof Table) {
Table fromTable = (Table) fromItem;
if (!this.getTenantHandler().doTableFilter(fromTable.getName() + "|select")) {
plainSelect.setWhere(builderExpression(plainSelect.getWhere(), fromTable));
if (addColumn) {
plainSelect.getSelectItems().add(new SelectExpressionItem(new Column(this.getTenantHandler().getTenantIdColumn())));
}
}
} else {
processFromItem(fromItem);
}
List<Join> joins = plainSelect.getJoins();
if (joins != null && joins.size() > 0) {
joins.forEach(j -> {
processJoin(j);
processFromItem(j.getRightItem());
});
}
}
}
package com.esv.freight.app.config.mybatis;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @description:
* @project: esv-cc
* @name: com.esv.cc.config.mybatis.MetaHandler
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/4/7 20:15
* @version:1.0
*/
@Slf4j
@Component
public class EsvMetaObjectHandler implements MetaObjectHandler {
private static final String CREATE_TIME_NAME = "createTime";
private static final String UPDATE_TIME_NAME = "updateTime";
@Override
public void insertFill(MetaObject metaObject) {
if (metaObject.hasSetter(CREATE_TIME_NAME)) {
this.setFieldValByName(CREATE_TIME_NAME, new Date(), metaObject);
}
if (metaObject.hasSetter(UPDATE_TIME_NAME)) {
this.setFieldValByName(UPDATE_TIME_NAME, new Date(), metaObject);
}
}
@Override
public void updateFill(MetaObject metaObject) {
if (metaObject.hasSetter(UPDATE_TIME_NAME)) {
this.setFieldValByName(UPDATE_TIME_NAME, new Date(), metaObject);
}
}
}
......@@ -23,6 +23,14 @@ public interface NoticeInterface {
*/
@PostMapping(value = "/notice/sms/captcha/check")
JSONObject checkSmsCaptcha(JSONObject bodyJson);
/**
* 给指定帐号推送消息
* @param bodyJson
* @return
*/
@PostMapping(value = "/notice/message/push2Device")
JSONObject push2Device(JSONObject bodyJson);
}
......@@ -7,17 +7,14 @@ import com.esv.freight.app.common.constants.AccountConstants;
import com.esv.freight.app.common.response.EResponse;
import com.esv.freight.app.common.util.FeignUtils;
import com.esv.freight.app.common.util.ReqUtils;
import com.esv.freight.app.common.validator.groups.ValidatorInsert;
import com.esv.freight.app.common.validator.groups.ValidatorUpdate;
import com.esv.freight.app.feign.CarrierInterface;
import com.esv.freight.app.feign.DriverInterface;
import com.esv.freight.app.feign.NoticeInterface;
import com.esv.freight.app.module.account.CustomToken;
import com.esv.freight.app.module.account.form.DriverAuthForm;
import com.esv.freight.app.module.account.form.LoginForm;
import com.esv.freight.app.module.account.form.RefreshTokenForm;
import com.esv.freight.app.module.account.pojo.DriverAccountInfoPojo;
import com.esv.freight.app.module.account.pojo.OwnerAccountInfoPojo;
import com.esv.freight.app.module.account.pojo.TokenInfoPojo;
import com.esv.freight.app.module.account.service.AppLoginService;
import com.esv.freight.app.module.account.validator.groups.ValidatorAccountExist;
......@@ -27,9 +24,9 @@ import com.esv.freight.app.module.account.vo.AccountExistVO;
import com.esv.freight.app.module.account.vo.CarrierInfoBriefVO;
import com.esv.freight.app.module.account.vo.DriverAccountDetailVO;
import com.esv.freight.app.module.account.vo.LoginVO;
import com.esv.freight.app.module.message.form.AccountDeviceForm;
import com.esv.freight.app.module.message.service.AccountDeviceInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -57,14 +54,16 @@ public class DriverAccountController {
private AppLoginService appLoginService;
private CarrierInterface carrierInterface;
private TokenComponent tokenComponent;
private AccountDeviceInfoService accountDeviceInfoService;
@Autowired
public DriverAccountController(TokenComponent tokenComponent, CarrierInterface carrierInterface, DriverInterface driverInterface, NoticeInterface noticeInterface, AppLoginService appLoginService) {
public DriverAccountController(TokenComponent tokenComponent, AccountDeviceInfoService accountDeviceInfoService, CarrierInterface carrierInterface, DriverInterface driverInterface, NoticeInterface noticeInterface, AppLoginService appLoginService) {
this.noticeInterface = noticeInterface;
this.appLoginService = appLoginService;
this.driverInterface = driverInterface;
this.carrierInterface = carrierInterface;
this.tokenComponent = tokenComponent;
this.accountDeviceInfoService = accountDeviceInfoService;
}
/**
......@@ -127,6 +126,14 @@ public class DriverAccountController {
pojo.setAccount(loginForm.getPhone());
pojo.setLoginMode(AccountConstants.ACCOUNT_LOGIN_MODE_SMS);
LoginVO vo = appLoginService.driverLogin(pojo);
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(loginForm.getPhone());
accountDeviceForm.setAccountId(pojo.getId());
accountDeviceForm.setDeviceSn(loginForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(vo);
}
......@@ -146,6 +153,13 @@ public class DriverAccountController {
driverAccountInfoPojo.setLoginMode(AccountConstants.ACCOUNT_LOGIN_MODE_SMS);
LoginVO vo = appLoginService.driverLogin(driverAccountInfoPojo);
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(loginForm.getPhone());
accountDeviceForm.setAccountId(driverAccountInfoPojo.getId());
accountDeviceForm.setDeviceSn(loginForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(vo);
}
......@@ -187,6 +201,13 @@ public class DriverAccountController {
driverAccountInfoPojo.setLoginMode(AccountConstants.ACCOUNT_LOGIN_MODE_PWD);
LoginVO vo = appLoginService.driverLogin(driverAccountInfoPojo);
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(loginForm.getPhone());
accountDeviceForm.setAccountId(driverAccountInfoPojo.getId());
accountDeviceForm.setDeviceSn(loginForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(vo);
}
......@@ -233,6 +254,7 @@ public class DriverAccountController {
**/
@PostMapping("/logout")
public EResponse logout() {
accountDeviceInfoService.accountLogout();
appLoginService.logout();
return EResponse.ok();
}
......@@ -245,9 +267,18 @@ public class DriverAccountController {
* createTime 2020/04/13 09:00
**/
@PostMapping("/token/refresh")
public EResponse refresh(@RequestBody(required=false) @Validated(ValidatorInsert.class) RefreshTokenForm refreshTokenForm) {
public EResponse refresh(@RequestBody(required=false) @Validated(ValidatorUpdate.class) RefreshTokenForm refreshTokenForm) {
LoginVO loginByPwdVO = appLoginService.refreshToken(refreshTokenForm);
TokenInfoPojo tokenInfoPojo = tokenComponent.getTokenInfo();
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(tokenInfoPojo.getAccount());
accountDeviceForm.setAccountId(tokenInfoPojo.getAccountId());
accountDeviceForm.setDeviceSn(refreshTokenForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(loginByPwdVO);
}
......
......@@ -8,7 +8,6 @@ import com.esv.freight.app.common.util.ReqUtils;
import com.esv.freight.app.common.validator.groups.ValidatorUpdate;
import com.esv.freight.app.feign.GoodsOwnerInterface;
import com.esv.freight.app.feign.NoticeInterface;
import com.esv.freight.app.module.account.CustomToken;
import com.esv.freight.app.module.account.form.*;
import com.esv.freight.app.module.account.pojo.OwnerAccountInfoPojo;
import com.esv.freight.app.module.account.pojo.TokenInfoPojo;
......@@ -17,10 +16,10 @@ import com.esv.freight.app.module.account.validator.groups.ValidatorAccountExist
import com.esv.freight.app.module.account.validator.groups.ValidatorLoginByPwd;
import com.esv.freight.app.module.account.validator.groups.ValidatorLoginBySms;
import com.esv.freight.app.module.account.vo.OwnerAccountDetailVO;
import com.esv.freight.app.common.response.ECode;
import com.esv.freight.app.common.response.EResponse;
import com.esv.freight.app.common.validator.groups.ValidatorInsert;
import com.esv.freight.app.module.account.vo.LoginVO;
import com.esv.freight.app.module.message.form.AccountDeviceForm;
import com.esv.freight.app.module.message.service.AccountDeviceInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
......@@ -45,13 +44,15 @@ public class OwnerAccountController {
private NoticeInterface noticeInterface;
private AppLoginService appLoginService;
private TokenComponent tokenComponent;
private AccountDeviceInfoService accountDeviceInfoService;
@Autowired
public OwnerAccountController(TokenComponent tokenComponent, GoodsOwnerInterface goodsOwnerInterface, NoticeInterface noticeInterface, AppLoginService appLoginService) {
public OwnerAccountController(TokenComponent tokenComponent, AccountDeviceInfoService accountDeviceInfoService, GoodsOwnerInterface goodsOwnerInterface, NoticeInterface noticeInterface, AppLoginService appLoginService) {
this.goodsOwnerInterface = goodsOwnerInterface;
this.noticeInterface = noticeInterface;
this.appLoginService = appLoginService;
this.tokenComponent = tokenComponent;
this.accountDeviceInfoService = accountDeviceInfoService;
}
/**
......@@ -112,6 +113,14 @@ public class OwnerAccountController {
pojo.setAccount(loginForm.getPhone());
pojo.setLoginMode(AccountConstants.ACCOUNT_LOGIN_MODE_SMS);
LoginVO vo = appLoginService.ownerLogin(pojo);
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(loginForm.getPhone());
accountDeviceForm.setAccountId(pojo.getId());
accountDeviceForm.setDeviceSn(loginForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(vo);
}
......@@ -132,6 +141,13 @@ public class OwnerAccountController {
ownerAccountInfoPojo.setLoginMode(AccountConstants.ACCOUNT_LOGIN_MODE_SMS);
LoginVO vo = appLoginService.ownerLogin(ownerAccountInfoPojo);
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(loginForm.getPhone());
accountDeviceForm.setAccountId(ownerAccountInfoPojo.getId());
accountDeviceForm.setDeviceSn(loginForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(vo);
}
......@@ -174,6 +190,12 @@ public class OwnerAccountController {
ownerAccountInfoPojo.setLoginMode(AccountConstants.ACCOUNT_LOGIN_MODE_PWD);
LoginVO vo = appLoginService.ownerLogin(ownerAccountInfoPojo);
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(loginForm.getPhone());
accountDeviceForm.setAccountId(ownerAccountInfoPojo.getId());
accountDeviceForm.setDeviceSn(loginForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(vo);
}
......@@ -186,7 +208,9 @@ public class OwnerAccountController {
**/
@PostMapping("/logout")
public EResponse logout() {
accountDeviceInfoService.accountLogout();
appLoginService.logout();
return EResponse.ok();
}
......@@ -198,9 +222,18 @@ public class OwnerAccountController {
* createTime 2020/04/13 09:00
**/
@PostMapping("/token/refresh")
public EResponse refresh(@RequestBody(required=false) @Validated(ValidatorInsert.class) RefreshTokenForm refreshTokenForm) {
public EResponse refresh(@RequestBody(required=false) @Validated(ValidatorUpdate.class) RefreshTokenForm refreshTokenForm) {
LoginVO loginByPwdVO = appLoginService.refreshToken(refreshTokenForm);
TokenInfoPojo tokenInfoPojo = tokenComponent.getTokenInfo();
// 提交推送标识
AccountDeviceForm accountDeviceForm = new AccountDeviceForm();
accountDeviceForm.setAccount(tokenInfoPojo.getAccount());
accountDeviceForm.setAccountId(tokenInfoPojo.getAccountId());
accountDeviceForm.setDeviceSn(refreshTokenForm.getPushId());
accountDeviceInfoService.saveAccountDevice(accountDeviceForm);
return EResponse.ok(loginByPwdVO);
}
......
......@@ -29,6 +29,14 @@ public class AppLoginEntity implements Serializable {
* 手机号码
*/
private String phone;
/**
* 帐号ID
*/
private Long accountId;
/**
* 租户ID
*/
private Long tenantId;
/**
* 帐号身份类型:1-司机、2-货主
*/
......
package com.esv.freight.app.module.account.form;
import com.esv.freight.app.common.validator.groups.ValidatorUpdate;
import com.esv.freight.app.module.account.validator.groups.*;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
......@@ -48,6 +49,12 @@ public class LoginForm {
@NotNull(message = "参数carrierId不能为空", groups = {ValidatorDriverLoginBySms.class})
private Long carrierId;
/**
* 推送设备ID
*/
@NotBlank(message = "参数pushId不能为空", groups = {ValidatorResetPwd.class, ValidatorLoginByPwd.class, ValidatorLoginBySms.class, ValidatorDriverLoginBySms.class})
private String pushId;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
......
package com.esv.freight.app.module.account.form;
import com.esv.freight.app.common.validator.groups.ValidatorUpdate;
import com.esv.freight.app.module.account.validator.groups.ValidatorLoginBySms;
import com.esv.freight.app.module.account.validator.groups.ValidatorResetPwd;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
......@@ -19,6 +23,12 @@ public class RefreshTokenForm {
/**
* 刷新token
*/
@NotNull(message = "参数refreshToken不能为空")
@NotBlank(message = "参数refreshToken不能为空", groups = {ValidatorUpdate.class})
private String refreshToken;
/**
* 推送设备ID
*/
@NotBlank(message = "参数pushId不能为空", groups = {ValidatorUpdate.class})
private String pushId;
}
......@@ -69,5 +69,5 @@ public interface AppLoginService extends IService<AppLoginEntity> {
* author 张志臣
* createTime 2020/04/13 16:48
**/
AppLoginEntity getAccountByPhone(String phone);
AppLoginEntity getAccountById(Long accountId);
}
\ No newline at end of file
......@@ -50,6 +50,8 @@ public class AppLoginServiceImpl extends ServiceImpl<AppLoginDao, AppLoginEntity
appLoginEntity.setRefreshTime(appLoginEntity.getLoginTime());
appLoginEntity.setAccessTokenValidTime(new Date(tokenInfoPojo.getAccessTokenValidTime()));
appLoginEntity.setRefreshTokenValidTime(new Date(tokenInfoPojo.getRefreshTokenValidTime()));
appLoginEntity.setAccountId(tokenInfoPojo.getAccountId());
appLoginEntity.setTenantId(Long.parseLong(ReqUtils.getRequestHeader("tenantId")));
if (null == record) {
this.baseMapper.insert(appLoginEntity);
......@@ -84,6 +86,8 @@ public class AppLoginServiceImpl extends ServiceImpl<AppLoginDao, AppLoginEntity
appLoginEntity.setRefreshTime(appLoginEntity.getLoginTime());
appLoginEntity.setAccessTokenValidTime(new Date(tokenInfoPojo.getAccessTokenValidTime()));
appLoginEntity.setRefreshTokenValidTime(new Date(tokenInfoPojo.getRefreshTokenValidTime()));
appLoginEntity.setAccountId(tokenInfoPojo.getAccountId());
appLoginEntity.setTenantId(Long.parseLong(ReqUtils.getRequestHeader("tenantId")));
if (null == record) {
this.baseMapper.insert(appLoginEntity);
......@@ -160,9 +164,7 @@ public class AppLoginServiceImpl extends ServiceImpl<AppLoginDao, AppLoginEntity
}
@Override
public AppLoginEntity getAccountByPhone(String phone) {
QueryWrapper<AppLoginEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("phone", phone);
return this.baseMapper.selectOne(queryWrapper);
public AppLoginEntity getAccountById(Long accountId) {
return lambdaQuery().eq(AppLoginEntity::getAccountId, accountId).one();
}
}
package com.esv.freight.app.module.message.controller;
import com.esv.freight.app.common.response.EResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @description: 司机消息Controller
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.controller.MessageController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/10 09:40
* @version:1.0
*/
@RestController
@RequestMapping("/driverBackend/message")
@Slf4j
@Validated
public class DriverMessageController {
public EResponse getMessageType() {
return EResponse.ok();
}
public EResponse getMessageList(Integer type) {
return EResponse.ok();
}
public EResponse getMessageDetail(Long messageId) {
return EResponse.ok();
}
public EResponse deleteMessage(Long messageId) {
return EResponse.ok();
}
public EResponse setAllRead() {
return EResponse.ok();
}
}
package com.esv.freight.app.module.message.controller;
import com.esv.freight.app.common.response.EResponse;
import com.esv.freight.app.common.validator.groups.ValidatorInsert;
import com.esv.freight.app.module.message.form.PushMessageForm;
import com.esv.freight.app.module.message.service.BusinessMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @description: 消息Controller
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.controller.MessagePushController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/10 09:40
* @version:1.0
*/
@RestController
@RequestMapping("/message")
@Slf4j
@Validated
public class MessagePushController {
private BusinessMessageService businessMessageService;
@Autowired
public MessagePushController(BusinessMessageService businessMessageService) {
this.businessMessageService = businessMessageService;
}
@PostMapping("/push2Account")
public EResponse push2Account(@RequestHeader @RequestBody(required=false) @Validated(ValidatorInsert.class) PushMessageForm pushMessageForm) {
businessMessageService.insertMessage(pushMessageForm);
return EResponse.ok();
}
}
package com.esv.freight.app.module.message.controller;
import com.esv.freight.app.common.response.EResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @description: 货主消息Controller
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.controller.MessageController
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/10 09:40
* @version:1.0
*/
@RestController
@RequestMapping("/ownerBackend/message")
@Slf4j
@Validated
public class OwnerMessageController {
public EResponse getMessageType() {
return EResponse.ok();
}
public EResponse getMessageList(Integer type) {
return EResponse.ok();
}
public EResponse getMessageDetail(Long messageId) {
return EResponse.ok();
}
public EResponse deleteMessage(Long messageId) {
return EResponse.ok();
}
public EResponse setAllRead() {
return EResponse.ok();
}
}
package com.esv.freight.app.module.message.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.esv.freight.app.module.message.entity.AccountDeviceInfoEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @description: APP帐号设备信息表
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.dao.AccountDeviceInfoDao
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/09 17:05
* @version:1.0
*/
@Mapper
public interface AccountDeviceInfoDao extends BaseMapper<AccountDeviceInfoEntity> {
}
package com.esv.freight.app.module.message.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.esv.freight.app.module.message.entity.BusinessMessageEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @description: APP业务消息表
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.dao.BusinessMessageDao
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/10 11:15
* @version:1.0
*/
@Mapper
public interface BusinessMessageDao extends BaseMapper<BusinessMessageEntity> {
}
package com.esv.freight.app.module.message.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @description: APP帐号设备信息表
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.entity.AccountDeviceInfoEntity
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/09 17:00
* @version:1.0
*/
@Data
@TableName("account_device_info")
public class AccountDeviceInfoEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId
private Long id;
/**
* 租户ID
*/
private Long tenantId;
/**
* 部门ID
*/
private Long departmentId;
/**
* 帐号
*/
private String account;
/**
* 帐号ID
*/
private Long accountId;
/**
* 帐号类型:1-司机、2-货主
*/
private Integer accountType;
/**
* 设备类型:2-android、3-ios
*/
private Integer deviceType;
/**
* 设备序列号
*/
private String deviceSn;
/**
* 修改时间
*/
private Date updateTime;
}
package com.esv.freight.app.module.message.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @description: APP业务消息表
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.entity.BusinessMessageEntity
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/09 17:00
* @version:1.0
*/
@Data
@TableName("app_business_message")
public class BusinessMessageEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId
private Long id;
/**
* 租户ID
*/
private Long tenantId;
/**
* 部门ID
*/
private Long departmentId;
/**
* 帐号ID
*/
private Long accountId;
/**
* 帐号类型:1-司机、2-货主
*/
private Integer accountType;
/**
* 消息本文内容
*/
private String messageContent;
/**
* 消息类型 101-货主账单对账消息、102-司机账单对账消息
*/
private Integer messageType;
/**
* 消息标题
*/
private String messageTitle;
/**
* 消息内容(根据message_type由终端自行解析)
*/
private String messageData;
/**
* 推送成功第三方返回的ID
*/
private String msgId;
/**
* 是否删除 0-否;1-是
*/
@TableLogic
private Boolean deleted;
/**
* 是否已读 0-未读;1-已读
*/
private Boolean isRead;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
package com.esv.freight.app.module.message.form;
import lombok.Data;
/**
* @description: 设备信息
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.form.AccountDeviceForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/09 17:40
* @version:1.0
*/
@Data
public class AccountDeviceForm {
/**
* 帐号
*/
private String account;
/**
* 帐号ID
*/
private Long accountId;
/**
* 设备序列号
*/
private String deviceSn;
}
package com.esv.freight.app.module.message.form;
import com.esv.freight.app.common.validator.groups.ValidatorInsert;
import com.esv.freight.app.common.validator.groups.ValidatorUpdate;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @description: 推送消息
* @project: freight-app-service
* @name: com.esv.freight.app.module.message.form.PushMessageForm
* @author: 张志臣
* @email: zhangzhichen@esvtek.com
* @createTime: 2020/06/10 10:15
* @version:1.0
*/
@Data
public class PushMessageForm {
/**
* 帐号ID
**/
@NotNull(message = "参数accountId不能为空", groups = {ValidatorInsert.class})
private Long accountId;
/**
* APP类型:1-司机、2-货主
*/
@NotNull(message = "参数appType不能为空", groups = {ValidatorInsert.class})
@Range(min = 1, max = 2, message = "无效的appType", groups = {ValidatorInsert.class})
private Integer appType;
/**
* 消息类型,具体请参考文档
*/
@NotNull(message = "参数messageType不能为空", groups = {ValidatorInsert.class})
private Integer messageType;
/**
* 业务数据,根据业务自定义JSON
*/
private String messageData;
}
package com.esv.freight.app.module.message.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.app.module.message.entity.AccountDeviceInfoEntity;
import com.esv.freight.app.module.message.form.AccountDeviceForm;
/**
* APP帐号设备信息表
*
* @author 张志臣
* @email zhangzhichen@esvtek.com
* @date 2020-06-09 17:07
*/
public interface AccountDeviceInfoService extends IService<AccountDeviceInfoEntity> {
/**
* description 保存设备信息
* param [accountDeviceForm]
* return
* author Administrator
* createTime 2020/06/09 17:42
**/
void saveAccountDevice(AccountDeviceForm accountDeviceForm);
/**
* description 查询设备ID
* param [accountId, deviceType]
* return
* author Administrator
* createTime 2020/06/10 10:40
**/
String getDeviceSn(Long accountId, Integer deviceType);
/**
* description 账号登出
* param
* return
* author Administrator
* createTime 2020/06/10 09:12
**/
void accountLogout();
}
package com.esv.freight.app.module.message.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.app.module.message.entity.BusinessMessageEntity;
import com.esv.freight.app.module.message.form.AccountDeviceForm;
import com.esv.freight.app.module.message.form.PushMessageForm;
/**
* APP业务消息表
*
* @author 张志臣
* @email zhangzhichen@esvtek.com
* @date 2020-06-10 11:17
*/
public interface BusinessMessageService extends IService<BusinessMessageEntity> {
/**
* description 添加消息
* param [pushMessageForm]
* return
* author Administrator
* createTime 2020/06/10 11:19
**/
void insertMessage(PushMessageForm pushMessageForm);
}
package com.esv.freight.app.module.message.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.app.common.component.TokenComponent;
import com.esv.freight.app.common.exception.EException;
import com.esv.freight.app.common.util.ReqUtils;
import com.esv.freight.app.module.account.pojo.TokenInfoPojo;
import com.esv.freight.app.module.message.dao.AccountDeviceInfoDao;
import com.esv.freight.app.module.message.entity.AccountDeviceInfoEntity;
import com.esv.freight.app.module.message.form.AccountDeviceForm;
import com.esv.freight.app.module.message.service.AccountDeviceInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service("AccountDeviceInfoService")
public class AccountDeviceInfoServiceImpl extends ServiceImpl<AccountDeviceInfoDao, AccountDeviceInfoEntity> implements AccountDeviceInfoService {
private TokenComponent tokenComponent;
@Autowired
public AccountDeviceInfoServiceImpl(TokenComponent tokenComponent) {
this.tokenComponent = tokenComponent;
}
@Override
public void saveAccountDevice(AccountDeviceForm accountDeviceForm) {
QueryWrapper<AccountDeviceInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda()
.eq(AccountDeviceInfoEntity::getAccountId, accountDeviceForm.getAccountId());
this.remove(queryWrapper);
AccountDeviceInfoEntity accountDeviceInfoEntity = new AccountDeviceInfoEntity();
BeanUtils.copyProperties(accountDeviceForm, accountDeviceInfoEntity);
accountDeviceInfoEntity.setUpdateTime(new Date());
accountDeviceInfoEntity.setAccountType(Integer.parseInt(ReqUtils.getRequestHeader("accountType")));
accountDeviceInfoEntity.setDeviceType(Integer.parseInt(ReqUtils.getRequestHeader("Source-Type")));
accountDeviceInfoEntity.setTenantId(Long.parseLong(ReqUtils.getRequestHeader("tenantId")));
save(accountDeviceInfoEntity);
}
@Override
public String getDeviceSn(Long accountId, Integer deviceType) {
AccountDeviceInfoEntity entity = lambdaQuery().eq(AccountDeviceInfoEntity::getAccountId, accountId)
.eq(AccountDeviceInfoEntity::getDeviceType, deviceType).one();
if(entity == null) {
throw new EException(1001, "无效的账号ID");
}
return entity.getDeviceSn();
}
@Override
public void accountLogout() {
TokenInfoPojo tokenInfoPojo = this.tokenComponent.getTokenInfo();
QueryWrapper<AccountDeviceInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda()
.eq(AccountDeviceInfoEntity::getAccountId, tokenInfoPojo.getAccountId());
this.remove(queryWrapper);
}
}
package com.esv.freight.app.module.message.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.app.common.constants.AccountConstants;
import com.esv.freight.app.common.exception.EException;
import com.esv.freight.app.common.util.ReqUtils;
import com.esv.freight.app.feign.NoticeInterface;
import com.esv.freight.app.module.account.entity.AppLoginEntity;
import com.esv.freight.app.module.account.service.AppLoginService;
import com.esv.freight.app.module.message.dao.BusinessMessageDao;
import com.esv.freight.app.module.message.entity.BusinessMessageEntity;
import com.esv.freight.app.module.message.form.PushMessageForm;
import com.esv.freight.app.module.message.service.AccountDeviceInfoService;
import com.esv.freight.app.module.message.service.BusinessMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service("BusinessMessageService")
public class BusinessMessageServiceImpl extends ServiceImpl<BusinessMessageDao, BusinessMessageEntity> implements BusinessMessageService {
private NoticeInterface noticeInterface;
private AccountDeviceInfoService accountDeviceInfoService;
private AppLoginService appLoginService;
@Autowired
public BusinessMessageServiceImpl(AppLoginService appLoginService, NoticeInterface noticeInterface, AccountDeviceInfoService accountDeviceInfoService) {
this.noticeInterface = noticeInterface;
this.accountDeviceInfoService = accountDeviceInfoService;
this.appLoginService = appLoginService;
}
@Override
public void insertMessage(PushMessageForm pushMessageForm) {
// 1:保存消息
BusinessMessageEntity entity = new BusinessMessageEntity();
BeanUtils.copyProperties(pushMessageForm, entity);
entity.setAccountType(pushMessageForm.getAppType());
JSONObject jo;
if(pushMessageForm.getMessageType() == AccountConstants.MESSAGE_TYPE_BILL_CONFIRM) {
jo = get101Message(pushMessageForm);
}
else {
throw new EException(1001, "无效的消息类型");
}
entity.setMessageContent(jo.getString("msg_content"));
entity.setMessageTitle(jo.getString("title"));
entity.setMessageData(pushMessageForm.getMessageData());
save(entity);
// 2:调用给指定设备推送消息接口
AppLoginEntity appLoginEntity = appLoginService.getAccountById(pushMessageForm.getAccountId());
if(appLoginEntity == null) {
return;
}
JSONObject reqJson = new JSONObject();
if(pushMessageForm.getAppType() == AccountConstants.ACCOUNT_TYPE_DRIVER) {
reqJson.put("appType", 2); // 给指定设备推送消息接口APP类型:1-货主、2-司机
}
else {
reqJson.put("appType", 1);
}
if(appLoginEntity.getDeviceType() == AccountConstants.APP_TYPE_ANDROID) {
reqJson.put("deviceType", 1); // 设备类型:1-android、2-ios
}
else {
reqJson.put("deviceType", 2);
}
reqJson.put("registrationId", accountDeviceInfoService.getDeviceSn(pushMessageForm.getAccountId(), appLoginEntity.getDeviceType()));
reqJson.put("message", jo);
JSONObject result;
log.info(reqJson.toJSONString());
result = noticeInterface.push2Device(reqJson);
log.info(result.toJSONString());
if(result.getInteger("code") == 200) {
String msgId = result.getJSONObject("data").getString("msgId");
lambdaUpdate()
.eq(BusinessMessageEntity::getId, entity.getId())
.set(BusinessMessageEntity::getMsgId, msgId)
.update();
}
}
private JSONObject get101Message(PushMessageForm pushMessageForm) {
JSONObject jo = JSONObject.parseObject(pushMessageForm.getMessageData());
String billNo = jo.getString("billNo");
JSONObject reqMessage = new JSONObject();
reqMessage.put("title", "账单提醒");
String content = "您的新账单"+billNo+"已经生成,请尽快确认";
reqMessage.put("msg_content", content);
JSONObject extras = new JSONObject();
extras.put("messageType", AccountConstants.MESSAGE_TYPE_BILL_CONFIRM);
extras.put("data", jo);
reqMessage.put("extras", extras);
return reqMessage;
}
}
......@@ -49,7 +49,7 @@ public class BaseTestController {
httpHeaders.add("esv_department_children", "1,2,3");
httpHeaders.add("esv_user", "1");
httpHeaders.add("esv_account", "admin");
httpHeaders.add("requestSource", "2");
httpHeaders.add("Source-Type", "2");
httpHeaders.add("osType", "Android_test");
httpHeaders.add("osVer", "10.0.0_test");
httpHeaders.add("mobileId", "1234ASDFOWEF_test");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment