22 changed files with 516 additions and 87 deletions
@ -0,0 +1,24 @@ |
|||||
|
package cc.hiver.core.common.constant; |
||||
|
|
||||
|
/** |
||||
|
* 用户常量 |
||||
|
* |
||||
|
* @author Yazhi Li |
||||
|
*/ |
||||
|
public interface WorkerConstant { |
||||
|
|
||||
|
/** |
||||
|
* 抢单工正常抢单状态 |
||||
|
*/ |
||||
|
Integer WORKER_STATUS_NORMAL = 1; |
||||
|
/** |
||||
|
* 抢单工不可接单状态(押金不足) |
||||
|
*/ |
||||
|
Integer USER_STATUS_LOCK = 2; |
||||
|
|
||||
|
/** |
||||
|
* 抢单工禁用状态(管理员直接禁用) |
||||
|
*/ |
||||
|
Integer USER_STATUS_DISABLE = 3; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,69 @@ |
|||||
|
package cc.hiver.core.common.vo; |
||||
|
|
||||
|
import cc.hiver.core.entity.Member; |
||||
|
import cc.hiver.core.entity.Worker; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.security.core.GrantedAuthority; |
||||
|
import org.springframework.security.core.userdetails.UserDetails; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Collection; |
||||
|
|
||||
|
/** |
||||
|
* 会员令牌(前端) |
||||
|
* @author Yazhi Li |
||||
|
*/ |
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
public class TokenWorker implements UserDetails, Serializable { |
||||
|
private String workerId; |
||||
|
|
||||
|
private String workerName; |
||||
|
|
||||
|
private String mobile; |
||||
|
|
||||
|
private String signPerson; |
||||
|
|
||||
|
private Boolean platform; |
||||
|
|
||||
|
public TokenWorker(Worker worker,Boolean platform) { |
||||
|
this.workerId = worker.getWorkerId(); |
||||
|
this.platform = platform; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Collection<? extends GrantedAuthority> getAuthorities() { |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getPassword() { |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getUsername() { |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isAccountNonExpired() { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isAccountNonLocked() { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isCredentialsNonExpired() { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isEnabled() { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -1,8 +1,9 @@ |
|||||
package cc.hiver.mall.dao; |
package cc.hiver.core.dao; |
||||
|
|
||||
|
|
||||
import cc.hiver.core.base.HiverBaseDao; |
import cc.hiver.core.base.HiverBaseDao; |
||||
import cc.hiver.mall.entity.Worker; |
import cc.hiver.core.entity.Worker; |
||||
|
|
||||
public interface WorkerDao extends HiverBaseDao<Worker, String> { |
public interface WorkerDao extends HiverBaseDao<Worker, String> { |
||||
|
Worker findByMobile(String mobile); |
||||
} |
} |
||||
@ -1,36 +1,7 @@ |
|||||
package cc.hiver.core.service; |
package cc.hiver.core.service; |
||||
|
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
public interface JPushService { |
||||
import org.springframework.stereotype.Service; |
|
||||
|
|
||||
import cn.jpush.api.JPushClient; |
void sendPushNotification(String registrationId, String message); |
||||
import cn.jpush.api.push.PushResult; |
|
||||
import cn.jpush.api.push.model.Message; |
|
||||
import cn.jpush.api.push.model.PushPayload; |
|
||||
import cn.jpush.api.push.model.notification.Notification; |
|
||||
|
|
||||
@Service |
|
||||
public class JPushService { |
|
||||
|
|
||||
private final JPushClient jPushClient; |
|
||||
|
|
||||
@Autowired |
|
||||
public JPushService(JPushClient jPushClient) { |
|
||||
this.jPushClient = jPushClient; |
|
||||
} |
|
||||
|
|
||||
public void sendPushNotification(String registrationId, String message) { |
|
||||
PushPayload payload = PushPayload.newBuilder() |
|
||||
.setPlatform(cn.jpush.api.push.model.Platform.all()) |
|
||||
.setAudience(cn.jpush.api.push.model.audience.Audience.registrationId(registrationId)) |
|
||||
.setNotification(Notification.alert(message)) |
|
||||
.build(); |
|
||||
|
|
||||
try { |
|
||||
PushResult result = jPushClient.sendPush(payload); |
|
||||
System.out.println("Push result: " + result); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
|
|||||
@ -0,0 +1,29 @@ |
|||||
|
package cc.hiver.core.vo; |
||||
|
|
||||
|
import cc.hiver.core.entity.Worker; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("抢单工登录后明细") |
||||
|
public class WorkerDetailVO { |
||||
|
|
||||
|
/** |
||||
|
* 抢单工详细信息 |
||||
|
*/ |
||||
|
@ApiModelProperty("抢单工详情") |
||||
|
private Worker worker; |
||||
|
|
||||
|
/** |
||||
|
* 当前token |
||||
|
*/ |
||||
|
@ApiModelProperty("登录成功token") |
||||
|
private String workerToken; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,128 @@ |
|||||
|
package cc.hiver.mall.controller; |
||||
|
|
||||
|
import cc.hiver.core.common.annotation.RateLimiter; |
||||
|
import cc.hiver.core.common.annotation.SystemLog; |
||||
|
import cc.hiver.core.common.constant.CommonConstant; |
||||
|
import cc.hiver.core.common.constant.MessageConstant; |
||||
|
import cc.hiver.core.common.constant.SettingConstant; |
||||
|
import cc.hiver.core.common.enums.LogType; |
||||
|
import cc.hiver.core.common.exception.HiverException; |
||||
|
import cc.hiver.core.common.redis.RedisTemplateHelper; |
||||
|
import cc.hiver.core.common.sms.SmsUtil; |
||||
|
import cc.hiver.core.common.utils.*; |
||||
|
import cc.hiver.core.common.vo.PageVo; |
||||
|
import cc.hiver.core.common.vo.Result; |
||||
|
import cc.hiver.core.common.vo.SearchVo; |
||||
|
import cc.hiver.core.entity.Worker; |
||||
|
import cc.hiver.core.service.WorkerService; |
||||
|
import cc.hiver.core.vo.WorkerDetailVO; |
||||
|
import cc.hiver.mall.common.constant.WorkerConstant; |
||||
|
import cc.hiver.mall.entity.Recharge; |
||||
|
import cc.hiver.mall.service.RechargeService; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import io.swagger.annotations.ApiParam; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.cache.annotation.CacheConfig; |
||||
|
import org.springframework.data.domain.Page; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpSession; |
||||
|
import javax.validation.Valid; |
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
/** |
||||
|
* 订单工管理接口 |
||||
|
* |
||||
|
* @author houpn |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@Api(tags = "订单工登录接口") |
||||
|
@RequestMapping("/hiver/auth/worker") |
||||
|
@Transactional |
||||
|
public class WorkerAuthController { |
||||
|
|
||||
|
@Autowired |
||||
|
private WorkerService workerService; |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisTemplateHelper redisTemplate; |
||||
|
|
||||
|
@Autowired |
||||
|
private SecurityUtil securityUtil; |
||||
|
|
||||
|
@Autowired |
||||
|
private IpInfoUtil ipInfoUtil; |
||||
|
|
||||
|
@Autowired |
||||
|
private SmsUtil smsUtil; |
||||
|
|
||||
|
@RequestMapping(value = "/app/login/{workerId}", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "app抢单登录接口") |
||||
|
public Result login(@ApiParam("唯一id标识") @PathVariable String workerId, HttpSession httpSession) { |
||||
|
|
||||
|
Worker worker = workerService.get(workerId); |
||||
|
//这儿暂时有bug,启用的时候其实需要判定原状态是启用还是不可接单状态,需要进行逻辑判断
|
||||
|
worker.setWorkerStatus(WorkerConstant.WORKER_STATUS_NORMAL); |
||||
|
workerService.update(worker); |
||||
|
// 手动更新缓存
|
||||
|
//redisTemplate.delete(WORKER + worker.getWorkerId());
|
||||
|
return ResultUtil.success("操作成功"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@RequestMapping(value = "/app/sendLoginSms/{mobile}", method = RequestMethod.GET) |
||||
|
@ApiOperation(value = "发送登录短信验证码") |
||||
|
@RateLimiter(name = "sendLoginSms", rate = 1, ipLimit = true) |
||||
|
public Result sendLoginSmsCode(@PathVariable String mobile, HttpServletRequest request) { |
||||
|
return sendSms(mobile, MessageConstant.SMS_RANGE_REG, SettingConstant.SMS_TYPE.SMS_COMMON.name(), request); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/app/smsLogin", method = RequestMethod.POST) |
||||
|
@SystemLog(description = "短信登录", type = LogType.LOGIN) |
||||
|
@ApiOperation(value = "短信登录") |
||||
|
public Result smsLogin(@RequestParam String mobile,@RequestParam String code) { |
||||
|
boolean saveLogin = true; |
||||
|
Worker worker = workerService.findByMobile(mobile); |
||||
|
if (worker == null) { |
||||
|
throw new HiverException("手机号不存在"); |
||||
|
} |
||||
|
String accessToken = securityUtil.getAppYSToken(worker, saveLogin); |
||||
|
WorkerDetailVO detailVO = new WorkerDetailVO(); |
||||
|
detailVO.setWorker(worker); |
||||
|
detailVO.setWorkerToken(accessToken); |
||||
|
return ResultUtil.data(detailVO); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param mobile 手机号 |
||||
|
* @param range 发送范围 0发送给所有手机号 1只发送给注册手机 2只发送给未注册手机 |
||||
|
* @param templateType 短信模版类型 详见SettingConstant |
||||
|
*/ |
||||
|
public Result sendSms(String mobile, Integer range, String templateType, HttpServletRequest request) { |
||||
|
if (workerService.findByMobile(mobile) == null) { |
||||
|
return ResultUtil.error("手机号未注册"); |
||||
|
} else { |
||||
|
// IP限流 1分钟限1个请求
|
||||
|
String key = "sendSms:" + ipInfoUtil.getIpAddr(request); |
||||
|
String value = redisTemplate.get(key); |
||||
|
if (StrUtil.isNotBlank(value)) { |
||||
|
return ResultUtil.error("您发送的太频繁啦,请稍后再试"); |
||||
|
} |
||||
|
// 生成6位数验证码
|
||||
|
String code = CommonUtil.getRandomNum(); |
||||
|
// 缓存验证码
|
||||
|
redisTemplate.set(CommonConstant.PRE_SMS + mobile, code, 5L, TimeUnit.MINUTES); |
||||
|
// 发送验证码
|
||||
|
smsUtil.sendCode(mobile, code, templateType); |
||||
|
// 请求成功 标记限流
|
||||
|
redisTemplate.set(key, "sended", 1L, TimeUnit.MINUTES); |
||||
|
return ResultUtil.success("发送短信验证码成功"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
package cc.hiver.mall.pojo.vo; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel(value = "下单") |
||||
|
public class OrderVO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 物流方式 |
||||
|
*/ |
||||
|
@ApiModelProperty("物流方式") |
||||
|
private String orderLogistics; |
||||
|
|
||||
|
/** |
||||
|
|
||||
|
/** |
||||
|
* 订单是否超时 |
||||
|
*/ |
||||
|
@ApiModelProperty("订单是否超时") |
||||
|
private Integer timeout; |
||||
|
|
||||
|
/** |
||||
|
* 订单状态 |
||||
|
*/ |
||||
|
@ApiModelProperty("订单状态") |
||||
|
private Integer orderStatus; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 抢单工编号 |
||||
|
*/ |
||||
|
@ApiModelProperty("抢单工编号") |
||||
|
private String orderByWorker; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 订单区域 |
||||
|
*/ |
||||
|
@ApiModelProperty("订单所属区域") |
||||
|
private String region; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 运送公司 |
||||
|
*/ |
||||
|
@ApiModelProperty("运送公司") |
||||
|
private String transCompany; |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue