24 changed files with 796 additions and 32 deletions
@ -0,0 +1,71 @@ |
|||||
|
package cc.hiver.core.common.vo; |
||||
|
|
||||
|
import cc.hiver.core.entity.LogiticsCompany; |
||||
|
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 TokenCompany implements UserDetails, Serializable { |
||||
|
private String id; |
||||
|
|
||||
|
private String companyName; |
||||
|
|
||||
|
private String username; |
||||
|
|
||||
|
private String password; |
||||
|
|
||||
|
private Boolean platform; |
||||
|
|
||||
|
public TokenCompany(LogiticsCompany logiticsCompany, Boolean platform) { |
||||
|
this.id = logiticsCompany.getId(); |
||||
|
this.companyName = logiticsCompany.getCompanyName(); |
||||
|
this.username = logiticsCompany.getUsername(); |
||||
|
this.password = logiticsCompany.getPassword(); |
||||
|
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; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
package cc.hiver.core.vo; |
||||
|
|
||||
|
import cc.hiver.core.entity.LogiticsCompany; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("物流公司登录后明细") |
||||
|
public class LcomDetailVO { |
||||
|
|
||||
|
/** |
||||
|
* 抢单工详细信息 |
||||
|
*/ |
||||
|
@ApiModelProperty("物流公司详情") |
||||
|
private LogiticsCompany logiticsCompany; |
||||
|
|
||||
|
/** |
||||
|
* 当前token |
||||
|
*/ |
||||
|
@ApiModelProperty("登录成功token") |
||||
|
private String lComToken; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,155 @@ |
|||||
|
/* |
||||
|
Copyright [2022] [https://hiver.cc]
|
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
*/ |
||||
|
package cc.hiver.mall.controller; |
||||
|
|
||||
|
import cc.hiver.core.common.annotation.SystemLog; |
||||
|
import cc.hiver.core.common.enums.LogType; |
||||
|
import cc.hiver.core.common.redis.RedisTemplateHelper; |
||||
|
import cc.hiver.core.common.utils.ResultUtil; |
||||
|
import cc.hiver.core.common.utils.SecurityUtil; |
||||
|
import cc.hiver.core.common.vo.Result; |
||||
|
import cc.hiver.core.config.properties.HiverTokenProperties; |
||||
|
import cc.hiver.core.entity.LogiticsCompany; |
||||
|
import cc.hiver.core.service.LogiticsCompanyService; |
||||
|
import cc.hiver.core.vo.LcomDetailVO; |
||||
|
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.security.crypto.bcrypt.BCryptPasswordEncoder; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
/** |
||||
|
* @author houpn |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@Api(tags = "物流公司登录接口") |
||||
|
@RequestMapping(value = "/hiver/app/logitics") |
||||
|
public class LcomAuthController { |
||||
|
|
||||
|
@Autowired |
||||
|
private HiverTokenProperties tokenProperties; |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisTemplateHelper redisTemplate; |
||||
|
|
||||
|
@Autowired |
||||
|
private SecurityUtil securityUtil; |
||||
|
|
||||
|
@Autowired |
||||
|
private LogiticsCompanyService logiticsCompanyService; |
||||
|
|
||||
|
public static final String LOGIN_FAIL_FLAG = "COMPANY_LOGIN_FAIL_FLAG:"; |
||||
|
|
||||
|
public static final String LOGIN_TIME_LIMIT = "COMPANY_LOGIN_TIME_LIMIT:"; |
||||
|
|
||||
|
public static final Integer LOGIN_FAIL_TIP_TIME = 3; |
||||
|
|
||||
|
|
||||
|
public static final String COMPANY = "company::"; |
||||
|
|
||||
|
|
||||
|
@RequestMapping(value = "/login", method = RequestMethod.POST) |
||||
|
@SystemLog(description = "账号登录", type = LogType.LOGIN) |
||||
|
@ApiOperation(value = "账号登录") |
||||
|
public Result login(@RequestParam String username, |
||||
|
@RequestParam String password) { |
||||
|
boolean saveLogin = true; |
||||
|
String loginFailKey = LOGIN_FAIL_FLAG + username; |
||||
|
String loginTimeKey = LOGIN_TIME_LIMIT + username; |
||||
|
|
||||
|
String valueFailFlag = redisTemplate.get(loginFailKey); |
||||
|
Long timeRest = redisTemplate.getExpire(loginFailKey, TimeUnit.MINUTES); |
||||
|
if (StrUtil.isNotBlank(valueFailFlag)) { |
||||
|
// 超过限制次数
|
||||
|
return ResultUtil.error("登录错误次数超过限制,请" + timeRest + "分钟后再试"); |
||||
|
} |
||||
|
LogiticsCompany logiticsCompany = securityUtil.checkCompanyPassword(username, password); |
||||
|
if (logiticsCompany == null) { |
||||
|
// 记录密码错误次数
|
||||
|
String valueTime = redisTemplate.get(loginTimeKey); |
||||
|
if (StrUtil.isBlank(valueTime)) { |
||||
|
valueTime = "0"; |
||||
|
} |
||||
|
// 获取已登录错误次数
|
||||
|
Integer loginFailTime = Integer.parseInt(valueTime) + 1; |
||||
|
redisTemplate.set(loginTimeKey, loginFailTime.toString(), tokenProperties.getLoginAfterTime(), TimeUnit.MINUTES); |
||||
|
if (loginFailTime >= tokenProperties.getLoginTimeLimit()) { |
||||
|
redisTemplate.set(loginFailKey, "FAIL", tokenProperties.getLoginAfterTime(), TimeUnit.MINUTES); |
||||
|
} |
||||
|
int restLoginTime = tokenProperties.getLoginTimeLimit() - loginFailTime; |
||||
|
if (restLoginTime > 0 && restLoginTime <= LOGIN_FAIL_TIP_TIME) { |
||||
|
return ResultUtil.error("账号或密码错误,还有" + restLoginTime + "次尝试机会"); |
||||
|
} else if (restLoginTime <= 0) { |
||||
|
return ResultUtil.error("登录错误次数超过限制,请" + tokenProperties.getLoginAfterTime() + "分钟后再试"); |
||||
|
} |
||||
|
return ResultUtil.error("账号或密码错误"); |
||||
|
} |
||||
|
String accessToken = securityUtil.getAppWLToken(logiticsCompany, saveLogin); |
||||
|
LcomDetailVO detailVO = new LcomDetailVO(); |
||||
|
detailVO.setLogiticsCompany(logiticsCompany); |
||||
|
detailVO.setLComToken(accessToken); |
||||
|
return ResultUtil.data(detailVO); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 线上demo不允许测试账号改密码 |
||||
|
* |
||||
|
* @param password |
||||
|
* @param newPass |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping(value = "/modifyPass", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "修改密码") |
||||
|
public Result modifyPass(@ApiParam("旧密码") @RequestParam String password, |
||||
|
@ApiParam("新密码") @RequestParam String newPass) { |
||||
|
LogiticsCompany logiticsCompany = securityUtil.getCurrCompany(); |
||||
|
if (!new BCryptPasswordEncoder().matches(password, logiticsCompany.getPassword())) { |
||||
|
return ResultUtil.error("旧密码不正确"); |
||||
|
} |
||||
|
String newEncryptPass = new BCryptPasswordEncoder().encode(newPass); |
||||
|
logiticsCompany.setPassword(newEncryptPass); |
||||
|
logiticsCompanyService.update(logiticsCompany); |
||||
|
// 手动更新缓存
|
||||
|
redisTemplate.delete(COMPANY + logiticsCompany.getUsername()); |
||||
|
return ResultUtil.success("修改密码成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/resetPass", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "重置密码") |
||||
|
public Result resetPass(@RequestParam String[] ids) { |
||||
|
for (String id : ids) { |
||||
|
LogiticsCompany logiticsCompany = logiticsCompanyService.get(id); |
||||
|
logiticsCompany.setPassword(new BCryptPasswordEncoder().encode("123456")); |
||||
|
logiticsCompanyService.update(logiticsCompany); |
||||
|
redisTemplate.delete(COMPANY + logiticsCompany.getUsername()); |
||||
|
} |
||||
|
return ResultUtil.success("操作成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/app/info/{id}", method = RequestMethod.GET) |
||||
|
@ApiOperation(value = "小程序端查询物流公司详情页") |
||||
|
public Result disable(@ApiParam("用户唯一id标识") @PathVariable String id) { |
||||
|
LogiticsCompany logiticsCompany = logiticsCompanyService.get(id); |
||||
|
// 手动更新缓存
|
||||
|
return ResultUtil.data(logiticsCompany); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
package cc.hiver.mall.pojo.dto; |
||||
|
|
||||
|
import cc.hiver.core.common.utils.SnowFlakeUtil; |
||||
|
import cc.hiver.mall.entity.SaleDetail; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@ApiModel(value = "销售单明细表") |
||||
|
@Data |
||||
|
public class SaleDetailDTO implements Serializable { |
||||
|
|
||||
|
@ApiModelProperty(value = "销售单ID") |
||||
|
private String saleId; |
||||
|
|
||||
|
@ApiModelProperty(value = "商品ID") |
||||
|
private String productId; |
||||
|
|
||||
|
@ApiModelProperty(value = "商品名称") |
||||
|
private String productName; |
||||
|
|
||||
|
@ApiModelProperty(value = "单位") |
||||
|
private String unit; |
||||
|
|
||||
|
@ApiModelProperty(value = "店铺ID") |
||||
|
private String shopId; |
||||
|
|
||||
|
@ApiModelProperty(value = "商品分类") |
||||
|
private String categoryId; |
||||
|
|
||||
|
@ApiModelProperty(value = "同一件商品购买属性列表") |
||||
|
private List<SaleDetailQueryDTO> saleDetailQueryDTO; |
||||
|
|
||||
|
@ApiModelProperty(value = "属性列表") |
||||
|
private String attributeList; |
||||
|
|
||||
|
@ApiModelProperty(value = "市场价") |
||||
|
private BigDecimal price; |
||||
|
|
||||
|
@ApiModelProperty(value = "采购价") |
||||
|
private BigDecimal purchasePrice; |
||||
|
|
||||
|
@ApiModelProperty(value = "批发价") |
||||
|
private BigDecimal wholesalePrice; |
||||
|
|
||||
|
@ApiModelProperty(value = "销售数量") |
||||
|
private Integer productCount; |
||||
|
|
||||
|
@ApiModelProperty(value = "折扣") |
||||
|
private BigDecimal discount; |
||||
|
|
||||
|
@ApiModelProperty(value = "优惠金额") |
||||
|
private BigDecimal discountAmount; |
||||
|
|
||||
|
@ApiModelProperty(value = "实际价格") |
||||
|
private BigDecimal realPrice; |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
package cc.hiver.mall.pojo.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@ApiModel(value = "销售单规格明细") |
||||
|
@Data |
||||
|
public class SaleDetailQueryDTO implements Serializable { |
||||
|
|
||||
|
@ApiModelProperty(value = "商品具体属性") |
||||
|
private String attributeList; |
||||
|
|
||||
|
@ApiModelProperty(value = "销售数量") |
||||
|
private Integer productCount; |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
package cc.hiver.mall.pojo.dto; |
||||
|
|
||||
|
import cc.hiver.mall.entity.Sale; |
||||
|
import cc.hiver.mall.entity.SaleDetail; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@ApiModel(value = "销售单主表") |
||||
|
@Data |
||||
|
public class SaleQueryDTO implements Serializable { |
||||
|
|
||||
|
@ApiModelProperty(value = "订单") |
||||
|
private Sale sale; |
||||
|
|
||||
|
@ApiModelProperty(value = "订单明细") |
||||
|
private List<SaleDetailDTO> saleDetailList; |
||||
|
|
||||
|
|
||||
|
@ApiModelProperty(value = "扛包工编号") |
||||
|
private String orderByWorker; |
||||
|
|
||||
|
@ApiModelProperty(value = "物流公司编号") |
||||
|
private String transCompany; |
||||
|
|
||||
|
} |
||||
@ -1,9 +1,12 @@ |
|||||
package cc.hiver.mall.service; |
package cc.hiver.mall.service; |
||||
|
|
||||
import cc.hiver.mall.pojo.dto.SaleDTO; |
import cc.hiver.mall.pojo.dto.SaleDTO; |
||||
|
import cc.hiver.mall.pojo.dto.SaleQueryDTO; |
||||
|
|
||||
public interface RushOrderService { |
public interface RushOrderService { |
||||
|
|
||||
void handleRushOrder(SaleDTO saleDTO); |
void handleRushOrder(SaleDTO saleDTO); |
||||
|
|
||||
|
void handleNewRushOrder(SaleQueryDTO saleQueryDTO); |
||||
|
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue