chore[后端服务]: 后端服务代码基于IDEA的reformat code工具格式化代码,但是mybatis generator生成的代码除外。
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>litemall-admin-api</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication(scanBasePackages={"org.linlinjava.litemall.core", "org.linlinjava.litemall.admin","org.linlinjava.litemall.db"})
|
||||
@SpringBootApplication(scanBasePackages = {"org.linlinjava.litemall.core", "org.linlinjava.litemall.admin", "org.linlinjava.litemall.db"})
|
||||
@MapperScan("org.linlinjava.litemall.db.dao")
|
||||
@EnableTransactionManagement
|
||||
@EnableScheduling
|
||||
|
||||
@@ -11,9 +11,10 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
public class LoginAdminHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
public static final String LOGIN_TOKEN_KEY = "Admin-Token";
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.getParameterType().isAssignableFrom(Integer.class)&¶meter.hasParameterAnnotation(LoginAdmin.class);
|
||||
return parameter.getParameterType().isAssignableFrom(Integer.class) && parameter.hasParameterAnnotation(LoginAdmin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,7 +23,7 @@ public class LoginAdminHandlerMethodArgumentResolver implements HandlerMethodArg
|
||||
|
||||
// return new Integer(1);
|
||||
String token = request.getHeader(LOGIN_TOKEN_KEY);
|
||||
if(token == null || token.isEmpty()){
|
||||
if (token == null || token.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.linlinjava.litemall.admin.annotation.support.LoginAdminHandlerMethodA
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -8,35 +8,35 @@ public class AdminToken {
|
||||
private LocalDateTime expireTime;
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public void setExpireTime(LocalDateTime expireTime) {
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public LocalDateTime getExpireTime() {
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime(LocalDateTime expireTime) {
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.linlinjava.litemall.admin.dao;
|
||||
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoods;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsAttribute;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecification;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsProduct;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecification;
|
||||
|
||||
public class GoodsAllinone {
|
||||
LitemallGoods goods;
|
||||
@@ -16,6 +16,10 @@ public class GoodsAllinone {
|
||||
return goods;
|
||||
}
|
||||
|
||||
public void setGoods(LitemallGoods goods) {
|
||||
this.goods = goods;
|
||||
}
|
||||
|
||||
public LitemallGoodsProduct[] getProducts() {
|
||||
return products;
|
||||
}
|
||||
@@ -24,10 +28,6 @@ public class GoodsAllinone {
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
public void setGoods(LitemallGoods goods) {
|
||||
this.goods = goods;
|
||||
}
|
||||
|
||||
public LitemallGoodsSpecification[] getSpecifications() {
|
||||
return specifications;
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ public class AdminTokenManager {
|
||||
public static Integer getUserId(String token) {
|
||||
|
||||
AdminToken userToken = tokenMap.get(token);
|
||||
if(userToken == null){
|
||||
if (userToken == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(userToken.getExpireTime().isBefore(LocalDateTime.now())){
|
||||
if (userToken.getExpireTime().isBefore(LocalDateTime.now())) {
|
||||
tokenMap.remove(token);
|
||||
idMap.remove(userToken.getUserId());
|
||||
return null;
|
||||
@@ -28,7 +28,7 @@ public class AdminTokenManager {
|
||||
}
|
||||
|
||||
|
||||
public static AdminToken generateToken(Integer id){
|
||||
public static AdminToken generateToken(Integer id) {
|
||||
AdminToken userToken = null;
|
||||
|
||||
// userToken = idMap.get(id);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class StatVo {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public void add(Map ... r) {
|
||||
public void add(Map... r) {
|
||||
rows.addAll(Arrays.asList(r));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,17 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallAd;
|
||||
import org.linlinjava.litemall.db.service.LitemallAdService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -34,8 +33,8 @@ public class AdminAdController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -50,23 +49,23 @@ public class AdminAdController {
|
||||
|
||||
private Object validate(LitemallAd ad) {
|
||||
String name = ad.getName();
|
||||
if(StringUtils.isEmpty(name)){
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String content = ad.getName();
|
||||
if(StringUtils.isEmpty(content)){
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallAd ad){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallAd ad) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(ad);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
adService.add(ad);
|
||||
@@ -74,8 +73,8 @@ public class AdminAdController {
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -84,15 +83,15 @@ public class AdminAdController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallAd ad){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallAd ad) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(ad);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if(adService.updateById(ad) == 0){
|
||||
if (adService.updateById(ad) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
@@ -100,12 +99,12 @@ public class AdminAdController {
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallAd ad){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallAd ad) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Integer id = ad.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
adService.deleteById(id);
|
||||
|
||||
@@ -3,19 +3,19 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.RegexUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallAddress;
|
||||
import org.linlinjava.litemall.db.service.LitemallAddressService;
|
||||
import org.linlinjava.litemall.db.service.LitemallRegionService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -32,7 +32,7 @@ public class AdminAddressController {
|
||||
@Autowired
|
||||
private LitemallRegionService regionService;
|
||||
|
||||
private Map<String, Object> toVo (LitemallAddress address){
|
||||
private Map<String, Object> toVo(LitemallAddress address) {
|
||||
Map<String, Object> addressVo = new HashMap<>();
|
||||
addressVo.put("id", address.getId());
|
||||
addressVo.put("userId", address.getUserId());
|
||||
@@ -58,8 +58,8 @@ public class AdminAddressController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class AdminAddressController {
|
||||
int total = addressService.countSelective(userId, name, page, limit, sort, order);
|
||||
|
||||
List<Map<String, Object>> addressVoList = new ArrayList<>(addressList.size());
|
||||
for(LitemallAddress address : addressList){
|
||||
for (LitemallAddress address : addressList) {
|
||||
Map<String, Object> addressVo = toVo(address);
|
||||
addressVoList.add(addressVo);
|
||||
}
|
||||
|
||||
@@ -12,13 +12,11 @@ import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallAdmin;
|
||||
import org.linlinjava.litemall.db.service.LitemallAdminService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -34,13 +32,13 @@ public class AdminAdminController {
|
||||
private LitemallAdminService adminService;
|
||||
|
||||
@GetMapping("/info")
|
||||
public Object info(String token){
|
||||
public Object info(String token) {
|
||||
Integer adminId = AdminTokenManager.getUserId(token);
|
||||
if(adminId == null){
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
LitemallAdmin admin = adminService.findById(adminId);
|
||||
if(admin == null){
|
||||
if (admin == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
@@ -62,8 +60,8 @@ public class AdminAdminController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -78,32 +76,32 @@ public class AdminAdminController {
|
||||
|
||||
private Object validate(LitemallAdmin admin) {
|
||||
String name = admin.getUsername();
|
||||
if(StringUtils.isEmpty(name)){
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if(!RegexUtil.isUsername(name)){
|
||||
if (!RegexUtil.isUsername(name)) {
|
||||
return ResponseUtil.fail(402, "管理员名称不符合规定");
|
||||
}
|
||||
String password = admin.getPassword();
|
||||
if(StringUtils.isEmpty(password) || password.length() < 6){
|
||||
if (StringUtils.isEmpty(password) || password.length() < 6) {
|
||||
return ResponseUtil.fail(402, "管理员密码长度不能小于6");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallAdmin admin){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallAdmin admin) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(admin);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
String username = admin.getUsername();
|
||||
List<LitemallAdmin> adminList = adminService.findAdmin(username);
|
||||
if(adminList.size() > 0){
|
||||
if (adminList.size() > 0) {
|
||||
return ResponseUtil.fail(402, "管理员已经存在");
|
||||
}
|
||||
|
||||
@@ -116,8 +114,8 @@ public class AdminAdminController {
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -126,22 +124,22 @@ public class AdminAdminController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallAdmin admin){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallAdmin admin) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(admin);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
Integer anotherAdminId = admin.getId();
|
||||
if(anotherAdminId == null){
|
||||
if (anotherAdminId == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// TODO 这里开发者需要删除以下检验代码
|
||||
// 目前这里不允许修改超级管理员是防止演示平台上他人修改管理员密码而导致登录失败
|
||||
if(anotherAdminId == 1){
|
||||
if (anotherAdminId == 1) {
|
||||
return ResponseUtil.fail(403, "超级管理员不能修改");
|
||||
}
|
||||
|
||||
@@ -150,7 +148,7 @@ public class AdminAdminController {
|
||||
String encodedPassword = encoder.encode(rawPassword);
|
||||
admin.setPassword(encodedPassword);
|
||||
|
||||
if(adminService.updateById(admin) == 0){
|
||||
if (adminService.updateById(admin) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
@@ -158,18 +156,18 @@ public class AdminAdminController {
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallAdmin admin){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallAdmin admin) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
Integer anotherAdminId = admin.getId();
|
||||
if(anotherAdminId == null){
|
||||
if (anotherAdminId == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// TODO 这里开发者需要删除以下检验代码
|
||||
// 目前这里不允许删除超级管理员是防止演示平台上他人删除管理员账号而导致登录失败
|
||||
if(anotherAdminId == 1){
|
||||
if (anotherAdminId == 1) {
|
||||
return ResponseUtil.fail(403, "超级管理员不能删除");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ package org.linlinjava.litemall.admin.web;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.dao.AdminToken;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.admin.dao.AdminToken;
|
||||
import org.linlinjava.litemall.admin.service.AdminTokenManager;
|
||||
import org.linlinjava.litemall.core.util.JacksonUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.util.bcrypt.BCryptPasswordEncoder;
|
||||
import org.linlinjava.litemall.db.domain.LitemallAdmin;
|
||||
import org.linlinjava.litemall.db.service.LitemallAdminService;
|
||||
import org.linlinjava.litemall.core.util.JacksonUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@@ -33,23 +34,23 @@ public class AdminAuthController {
|
||||
* { username : value, password : value }
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public Object login(@RequestBody String body){
|
||||
public Object login(@RequestBody String body) {
|
||||
String username = JacksonUtil.parseString(body, "username");
|
||||
String password = JacksonUtil.parseString(body, "password");
|
||||
|
||||
if(StringUtils.isEmpty(username) || StringUtils.isEmpty(password)){
|
||||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
List<LitemallAdmin> adminList = adminService.findAdmin(username);
|
||||
Assert.state(adminList.size() < 2, "同一个用户名存在两个账户");
|
||||
if(adminList.size() == 0){
|
||||
if (adminList.size() == 0) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
LitemallAdmin admin = adminList.get(0);
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if(!encoder.matches(password, admin.getPassword())){
|
||||
if (!encoder.matches(password, admin.getPassword())) {
|
||||
return ResponseUtil.fail(403, "账号密码不对");
|
||||
}
|
||||
|
||||
@@ -64,8 +65,8 @@ public class AdminAuthController {
|
||||
*
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public Object login(@LoginAdmin Integer adminId){
|
||||
if(adminId == null){
|
||||
public Object login(@LoginAdmin Integer adminId) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallBrand;
|
||||
import org.linlinjava.litemall.db.service.LitemallBrandService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -35,8 +34,8 @@ public class AdminBrandController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -51,29 +50,29 @@ public class AdminBrandController {
|
||||
|
||||
private Object validate(LitemallBrand brand) {
|
||||
String name = brand.getName();
|
||||
if(StringUtils.isEmpty(name)){
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
String desc = brand.getDesc();
|
||||
if(StringUtils.isEmpty(desc)){
|
||||
if (StringUtils.isEmpty(desc)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
BigDecimal price = brand.getFloorPrice();
|
||||
if(price == null){
|
||||
if (price == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallBrand brand){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallBrand brand) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(brand);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
brandService.add(brand);
|
||||
@@ -81,8 +80,8 @@ public class AdminBrandController {
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -91,27 +90,27 @@ public class AdminBrandController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallBrand brand){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallBrand brand) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(brand);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if(brandService.updateById(brand) == 0){
|
||||
if (brandService.updateById(brand) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(brand);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallBrand brand){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallBrand brand) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Integer id = brand.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
brandService.deleteById(id);
|
||||
|
||||
@@ -3,19 +3,17 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.admin.util.CatVo;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCategory;
|
||||
import org.linlinjava.litemall.db.service.LitemallCategoryService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -36,8 +34,8 @@ public class AdminCategoryController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -52,20 +50,20 @@ public class AdminCategoryController {
|
||||
|
||||
private Object validate(LitemallCategory category) {
|
||||
String name = category.getName();
|
||||
if(StringUtils.isEmpty(name)){
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
String level = category.getLevel();
|
||||
if(StringUtils.isEmpty(level)){
|
||||
if (StringUtils.isEmpty(level)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if(!level.equals("L1") && !level.equals("L2")){
|
||||
if (!level.equals("L1") && !level.equals("L2")) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
Integer pid = category.getPid();
|
||||
if(level.equals("L2") && (pid == null)){
|
||||
if (level.equals("L2") && (pid == null)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
@@ -73,12 +71,12 @@ public class AdminCategoryController {
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallCategory category){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallCategory category) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(category);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
categoryService.add(category);
|
||||
@@ -86,8 +84,8 @@ public class AdminCategoryController {
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -96,28 +94,28 @@ public class AdminCategoryController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallCategory category){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallCategory category) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(category);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if(categoryService.updateById(category) == 0){
|
||||
if (categoryService.updateById(category) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallCategory category){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallCategory category) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Integer id = category.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
categoryService.deleteById(id);
|
||||
@@ -133,7 +131,7 @@ public class AdminCategoryController {
|
||||
// 所有一级分类目录
|
||||
List<LitemallCategory> l1CatList = categoryService.queryL1();
|
||||
List<Map<String, Object>> data = new ArrayList<>(l1CatList.size());
|
||||
for(LitemallCategory category : l1CatList){
|
||||
for (LitemallCategory category : l1CatList) {
|
||||
Map<String, Object> d = new HashMap<>(2);
|
||||
d.put("value", category.getId());
|
||||
d.put("label", category.getName());
|
||||
|
||||
@@ -3,16 +3,18 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCollect;
|
||||
import org.linlinjava.litemall.db.service.LitemallCollectService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,8 +34,8 @@ public class AdminCollectController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,15 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallComment;
|
||||
import org.linlinjava.litemall.db.service.LitemallCommentService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -33,8 +31,8 @@ public class AdminCommentController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -48,12 +46,12 @@ public class AdminCommentController {
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallComment comment){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallComment comment) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Integer id = comment.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
commentService.deleteById(id);
|
||||
|
||||
@@ -3,14 +3,16 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.db.service.LitemallGoodsProductService;
|
||||
import org.linlinjava.litemall.db.service.LitemallGoodsService;
|
||||
import org.linlinjava.litemall.db.service.LitemallOrderService;
|
||||
import org.linlinjava.litemall.db.service.LitemallGoodsProductService;
|
||||
import org.linlinjava.litemall.db.service.LitemallUserService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -31,8 +33,8 @@ public class AdminDashbordController {
|
||||
private LitemallOrderService orderService;
|
||||
|
||||
@GetMapping("")
|
||||
public Object info(@LoginAdmin Integer adminId){
|
||||
if(adminId == null){
|
||||
public Object info(@LoginAdmin Integer adminId) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.RegexUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
@@ -11,10 +10,11 @@ import org.linlinjava.litemall.db.domain.LitemallFeedback;
|
||||
import org.linlinjava.litemall.db.service.LitemallFeedbackService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -39,7 +39,7 @@ public class AdminFeedbackController {
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if(adminId == null){
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
List<LitemallFeedback> feedbackList = feedbackService.querySelective(userId, username, page, limit, sort, order);
|
||||
|
||||
@@ -3,16 +3,18 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallFootprint;
|
||||
import org.linlinjava.litemall.db.service.LitemallFootprintService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,8 +34,8 @@ public class AdminFootprintController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.admin.dao.GoodsAllinone;
|
||||
import org.linlinjava.litemall.admin.util.CatVo;
|
||||
import org.linlinjava.litemall.core.qcode.QCodeService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.*;
|
||||
import org.linlinjava.litemall.db.service.*;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
@@ -22,8 +22,10 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/goods")
|
||||
@@ -73,66 +75,66 @@ public class AdminGoodsController {
|
||||
private Object validate(GoodsAllinone goodsAllinone) {
|
||||
LitemallGoods goods = goodsAllinone.getGoods();
|
||||
String name = goods.getName();
|
||||
if(StringUtils.isEmpty(name)){
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String goodsSn = goods.getGoodsSn();
|
||||
if(StringUtils.isEmpty(goodsSn)){
|
||||
if (StringUtils.isEmpty(goodsSn)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// 品牌商可以不设置,如果设置则需要验证品牌商存在
|
||||
Integer brandId = goods.getBrandId();
|
||||
if(brandId != null && brandId != 0) {
|
||||
if (brandId != null && brandId != 0) {
|
||||
if (brandService.findById(brandId) == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
}
|
||||
// 分类可以不设置,如果设置则需要验证分类存在
|
||||
Integer categoryId = goods.getCategoryId();
|
||||
if(categoryId != null && categoryId != 0) {
|
||||
if (categoryId != null && categoryId != 0) {
|
||||
if (categoryService.findById(categoryId) == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
}
|
||||
|
||||
LitemallGoodsAttribute[] attributes = goodsAllinone.getAttributes();
|
||||
for(LitemallGoodsAttribute attribute : attributes){
|
||||
for (LitemallGoodsAttribute attribute : attributes) {
|
||||
String attr = attribute.getAttribute();
|
||||
if(StringUtils.isEmpty(attr)){
|
||||
if (StringUtils.isEmpty(attr)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String value = attribute.getValue();
|
||||
if(StringUtils.isEmpty(value)){
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
}
|
||||
|
||||
LitemallGoodsSpecification[] specifications = goodsAllinone.getSpecifications();
|
||||
for(LitemallGoodsSpecification specification : specifications){
|
||||
for (LitemallGoodsSpecification specification : specifications) {
|
||||
String spec = specification.getSpecification();
|
||||
if(StringUtils.isEmpty(spec)){
|
||||
if (StringUtils.isEmpty(spec)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String value = specification.getValue();
|
||||
if(StringUtils.isEmpty(value)){
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
}
|
||||
|
||||
LitemallGoodsProduct[] products = goodsAllinone.getProducts();
|
||||
for(LitemallGoodsProduct product : products){
|
||||
for (LitemallGoodsProduct product : products) {
|
||||
Integer number = product.getNumber();
|
||||
if(number == null || number < 0){
|
||||
if (number == null || number < 0) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
BigDecimal price = product.getPrice();
|
||||
if(price == null){
|
||||
if (price == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
String[] productSpecifications = product.getSpecifications();
|
||||
if(productSpecifications.length == 0){
|
||||
if (productSpecifications.length == 0) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
}
|
||||
@@ -158,7 +160,7 @@ public class AdminGoodsController {
|
||||
}
|
||||
|
||||
Object error = validate(goodsAllinone);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -178,7 +180,7 @@ public class AdminGoodsController {
|
||||
goods.setShareUrl(url);
|
||||
|
||||
// 商品基本信息表litemall_goods
|
||||
if(goodsService.updateById(goods) == 0){
|
||||
if (goodsService.updateById(goods) == 0) {
|
||||
throw new Exception("跟新数据失败");
|
||||
}
|
||||
|
||||
@@ -222,7 +224,7 @@ public class AdminGoodsController {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Integer id = goods.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
@@ -253,7 +255,7 @@ public class AdminGoodsController {
|
||||
}
|
||||
|
||||
Object error = validate(goodsAllinone);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -278,7 +280,7 @@ public class AdminGoodsController {
|
||||
|
||||
//将生成的分享图片地址写入数据库
|
||||
String url = qCodeService.createGoodShareImage(goods.getId().toString(), goods.getPicUrl(), goods.getName());
|
||||
if(!StringUtils.isEmpty(url)) {
|
||||
if (!StringUtils.isEmpty(url)) {
|
||||
goods.setShareUrl(url);
|
||||
if (goodsService.updateById(goods) == 0) {
|
||||
throw new Exception("跟新数据失败");
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.JacksonUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
@@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -100,19 +98,19 @@ public class AdminGrouponController {
|
||||
|
||||
private Object validate(LitemallGrouponRules grouponRules) {
|
||||
Integer goodsId = grouponRules.getGoodsId();
|
||||
if(goodsId == null){
|
||||
if (goodsId == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
BigDecimal discount = grouponRules.getDiscount();
|
||||
if(discount == null){
|
||||
if (discount == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
Integer discountMember = grouponRules.getDiscountMember();
|
||||
if(discountMember == null){
|
||||
if (discountMember == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
LocalDateTime expireTime = grouponRules.getExpireTime();
|
||||
if(expireTime == null){
|
||||
if (expireTime == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
@@ -126,7 +124,7 @@ public class AdminGrouponController {
|
||||
}
|
||||
|
||||
Object error = validate(grouponRules);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -139,7 +137,7 @@ public class AdminGrouponController {
|
||||
grouponRules.setGoodsName(goods.getName());
|
||||
grouponRules.setPicUrl(goods.getPicUrl());
|
||||
|
||||
if(rulesService.updateById(grouponRules) == 0){
|
||||
if (rulesService.updateById(grouponRules) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
@@ -154,7 +152,7 @@ public class AdminGrouponController {
|
||||
}
|
||||
|
||||
Object error = validate(grouponRules);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -180,7 +178,7 @@ public class AdminGrouponController {
|
||||
}
|
||||
|
||||
Integer id = grouponRules.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,16 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallSearchHistory;
|
||||
import org.linlinjava.litemall.db.service.LitemallSearchHistoryService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -29,8 +32,8 @@ public class AdminHistoryController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public class AdminIndexController {
|
||||
private final Log logger = LogFactory.getLog(AdminIndexController.class);
|
||||
|
||||
@RequestMapping("/index")
|
||||
public Object index(){
|
||||
public Object index() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
|
||||
@@ -3,18 +3,17 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallIssue;
|
||||
import org.linlinjava.litemall.db.service.LitemallIssueService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -34,8 +33,8 @@ public class AdminIssueController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -50,23 +49,23 @@ public class AdminIssueController {
|
||||
|
||||
private Object validate(LitemallIssue issue) {
|
||||
String question = issue.getQuestion();
|
||||
if(StringUtils.isEmpty(question)){
|
||||
if (StringUtils.isEmpty(question)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String answer = issue.getAnswer();
|
||||
if(StringUtils.isEmpty(answer)){
|
||||
if (StringUtils.isEmpty(answer)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallIssue issue){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallIssue issue) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(issue);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
issueService.add(issue);
|
||||
@@ -74,8 +73,8 @@ public class AdminIssueController {
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -84,15 +83,15 @@ public class AdminIssueController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallIssue issue){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallIssue issue) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(issue);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if(issueService.updateById(issue) == 0){
|
||||
if (issueService.updateById(issue) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
@@ -100,12 +99,12 @@ public class AdminIssueController {
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallIssue issue){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallIssue issue) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Integer id = issue.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
issueService.deleteById(id);
|
||||
|
||||
@@ -3,18 +3,17 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallKeyword;
|
||||
import org.linlinjava.litemall.db.service.LitemallKeywordService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -34,8 +33,8 @@ public class AdminKeywordController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -61,12 +60,12 @@ public class AdminKeywordController {
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallKeyword keywords){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallKeyword keywords) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(keywords);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
keywordService.add(keywords);
|
||||
@@ -74,8 +73,8 @@ public class AdminKeywordController {
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -84,27 +83,27 @@ public class AdminKeywordController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallKeyword keywords){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallKeyword keywords) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(keywords);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if(keywordService.updateById(keywords) == 0){
|
||||
if (keywordService.updateById(keywords) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(keywords);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallKeyword keyword){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallKeyword keyword) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Integer id = keyword.getId();
|
||||
if(id == null){
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
keywordService.deleteById(id);
|
||||
|
||||
@@ -6,12 +6,12 @@ import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.notify.NotifyService;
|
||||
import org.linlinjava.litemall.core.notify.NotifyType;
|
||||
import org.linlinjava.litemall.core.util.JacksonUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.*;
|
||||
import org.linlinjava.litemall.db.service.*;
|
||||
import org.linlinjava.litemall.db.util.OrderUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -60,7 +59,7 @@ public class AdminOrderController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
@@ -135,7 +134,7 @@ public class AdminOrderController {
|
||||
try {
|
||||
// 设置订单取消状态
|
||||
order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM);
|
||||
if(orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
throw new Exception("跟新数据已失效");
|
||||
}
|
||||
|
||||
@@ -146,7 +145,7 @@ public class AdminOrderController {
|
||||
LitemallGoodsProduct product = productService.findById(productId);
|
||||
Integer number = product.getNumber() + orderGoods.getNumber();
|
||||
product.setNumber(number);
|
||||
if(productService.updateById(product) == 0){
|
||||
if (productService.updateById(product) == 0) {
|
||||
throw new Exception("跟新数据失败");
|
||||
}
|
||||
}
|
||||
@@ -209,7 +208,7 @@ public class AdminOrderController {
|
||||
order.setShipSn(shipSn);
|
||||
order.setShipChannel(shipChannel);
|
||||
order.setShipTime(LocalDateTime.now());
|
||||
if(orderService.updateWithOptimisticLocker(order) == 0){
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
return ResponseUtil.updatedDateExpired();
|
||||
}
|
||||
|
||||
@@ -226,7 +225,7 @@ public class AdminOrderController {
|
||||
* 回复订单商品
|
||||
*
|
||||
* @param adminId 管理员ID
|
||||
* @param body 订单信息,{ orderId:xxx }
|
||||
* @param body 订单信息,{ orderId:xxx }
|
||||
* @return 订单操作结果
|
||||
* 成功则 { errno: 0, errmsg: '成功' }
|
||||
* 失败则 { errno: XXX, errmsg: XXX }
|
||||
@@ -238,24 +237,24 @@ public class AdminOrderController {
|
||||
}
|
||||
|
||||
Integer commentId = JacksonUtil.parseInteger(body, "commentId");
|
||||
if(commentId == null || commentId == 0){
|
||||
if (commentId == null || commentId == 0) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// 目前只支持回复一次
|
||||
if(commentService.findById(commentId) != null){
|
||||
if (commentService.findById(commentId) != null) {
|
||||
return ResponseUtil.fail(404, "订单商品已回复!");
|
||||
}
|
||||
String content = JacksonUtil.parseString(body, "content");
|
||||
if(StringUtils.isEmpty(content)){
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// 创建评价回复
|
||||
LitemallComment comment = new LitemallComment();
|
||||
comment.setType((byte)2);
|
||||
comment.setType((byte) 2);
|
||||
comment.setValueId(commentId);
|
||||
comment.setContent(content);
|
||||
comment.setUserId(0); // 评价回复没有用
|
||||
comment.setStar((short)0); // 评价回复没有用
|
||||
comment.setStar((short) 0); // 评价回复没有用
|
||||
comment.setHasPicture(false); // 评价回复没有用
|
||||
comment.setPicUrls(new String[]{}); // 评价回复没有用
|
||||
commentService.save(comment);
|
||||
@@ -294,7 +293,7 @@ public class AdminOrderController {
|
||||
// 设置订单已取消状态
|
||||
order.setOrderStatus(OrderUtil.STATUS_AUTO_CANCEL);
|
||||
order.setEndTime(LocalDateTime.now());
|
||||
if(orderService.updateWithOptimisticLocker(order) == 0){
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
throw new Exception("跟新数据已失效");
|
||||
}
|
||||
|
||||
@@ -306,7 +305,7 @@ public class AdminOrderController {
|
||||
LitemallGoodsProduct product = productService.findById(productId);
|
||||
Integer number = product.getNumber() + orderGoods.getNumber();
|
||||
product.setNumber(number);
|
||||
if(productService.updateById(product) == 0){
|
||||
if (productService.updateById(product) == 0) {
|
||||
throw new Exception("跟新数据失败");
|
||||
}
|
||||
}
|
||||
@@ -353,10 +352,9 @@ public class AdminOrderController {
|
||||
// 设置订单已取消状态
|
||||
order.setOrderStatus(OrderUtil.STATUS_AUTO_CONFIRM);
|
||||
order.setConfirmTime(now);
|
||||
if(orderService.updateWithOptimisticLocker(order) == 0){
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
logger.info("订单 ID=" + order.getId() + " 数据已经更新,放弃自动确认收货");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
logger.info("订单 ID=" + order.getId() + " 已经超期自动确认收货");
|
||||
}
|
||||
}
|
||||
@@ -375,17 +373,17 @@ public class AdminOrderController {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<LitemallOrder> orderList = orderService.queryComment();
|
||||
for (LitemallOrder order : orderList) {
|
||||
LocalDateTime confirm = order.getConfirmTime();
|
||||
LocalDateTime confirm = order.getConfirmTime();
|
||||
LocalDateTime expired = confirm.plusDays(7);
|
||||
if (expired.isAfter(now)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
order.setComments((short)0);
|
||||
order.setComments((short) 0);
|
||||
orderService.updateWithOptimisticLocker(order);
|
||||
|
||||
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
|
||||
for(LitemallOrderGoods orderGoods : orderGoodsList){
|
||||
for (LitemallOrderGoods orderGoods : orderGoodsList) {
|
||||
orderGoods.setComment(-1);
|
||||
orderGoodsService.updateById(orderGoods);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ import org.linlinjava.litemall.db.service.LitemallAdminService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/profile")
|
||||
@@ -23,24 +26,24 @@ public class AdminProfileController {
|
||||
private LitemallAdminService adminService;
|
||||
|
||||
@PostMapping("/password")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody String body){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody String body) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
String oldPassword = JacksonUtil.parseString(body, "oldPassword");
|
||||
String newPassword = JacksonUtil.parseString(body, "newPassword");
|
||||
if(StringUtils.isEmpty(oldPassword)){
|
||||
if (StringUtils.isEmpty(oldPassword)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if(StringUtils.isEmpty(newPassword)){
|
||||
if (StringUtils.isEmpty(newPassword)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
LitemallAdmin admin = adminService.findAdmin(adminId);
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if(!encoder.matches(oldPassword, admin.getPassword())){
|
||||
if (!encoder.matches(oldPassword, admin.getPassword())) {
|
||||
return ResponseUtil.fail(405, "账号密码不对");
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallRegion;
|
||||
import org.linlinjava.litemall.db.service.LitemallRegionService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -31,7 +31,7 @@ public class AdminRegionController {
|
||||
|
||||
@GetMapping("/clist")
|
||||
public Object clist(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if(adminId == null){
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ public class AdminRegionController {
|
||||
String name, Integer code,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort (accepts={"id"}) @RequestParam(defaultValue = "id") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Sort(accepts = {"id"}) @RequestParam(defaultValue = "id") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,13 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.admin.util.StatVo;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.db.dao.StatMapper;
|
||||
import org.linlinjava.litemall.db.service.LitemallOrderService;
|
||||
import org.linlinjava.litemall.db.service.StatService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,8 +25,8 @@ public class AdminStatController {
|
||||
private StatService statService;
|
||||
|
||||
@GetMapping("/user")
|
||||
public Object statUser(@LoginAdmin Integer adminId){
|
||||
if(adminId == null){
|
||||
public Object statUser(@LoginAdmin Integer adminId) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -41,8 +40,8 @@ public class AdminStatController {
|
||||
}
|
||||
|
||||
@GetMapping("/order")
|
||||
public Object statOrder(@LoginAdmin Integer adminId){
|
||||
if(adminId == null){
|
||||
public Object statOrder(@LoginAdmin Integer adminId) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -56,8 +55,8 @@ public class AdminStatController {
|
||||
}
|
||||
|
||||
@GetMapping("/goods")
|
||||
public Object statGoods(@LoginAdmin Integer adminId){
|
||||
if(adminId == null){
|
||||
public Object statGoods(@LoginAdmin Integer adminId) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class AdminStorageController {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
if(litemallStorageService.update(litemallStorage) == 0){
|
||||
if (litemallStorageService.update(litemallStorage) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(litemallStorage);
|
||||
@@ -89,7 +89,7 @@ public class AdminStorageController {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
String key = litemallStorage.getKey();
|
||||
if(StringUtils.isEmpty(key)){
|
||||
if (StringUtils.isEmpty(key)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
litemallStorageService.deleteByKey(key);
|
||||
|
||||
@@ -3,11 +3,11 @@ package org.linlinjava.litemall.admin.web;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallTopic;
|
||||
import org.linlinjava.litemall.db.service.LitemallTopicService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -35,8 +34,8 @@ public class AdminTopicController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -66,12 +65,12 @@ public class AdminTopicController {
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallTopic topic){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallTopic topic) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(topic);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
topicService.add(topic);
|
||||
@@ -79,8 +78,8 @@ public class AdminTopicController {
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@@ -89,23 +88,23 @@ public class AdminTopicController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallTopic topic){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallTopic topic) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(topic);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if(topicService.updateById(topic) == 0){
|
||||
if (topicService.updateById(topic) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(topic);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallTopic topic){
|
||||
if(adminId == null){
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallTopic topic) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
topicService.deleteById(topic.getId());
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package org.linlinjava.litemall.admin.web;
|
||||
|
||||
import com.github.pagehelper.util.StringUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.RegexUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.util.bcrypt.BCryptPasswordEncoder;
|
||||
import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallUser;
|
||||
import org.linlinjava.litemall.db.service.LitemallUserService;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -37,8 +35,8 @@ public class AdminUserController {
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order){
|
||||
if(adminId == null){
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
List<LitemallUser> userList = userService.querySelective(username, mobile, page, limit, sort, order);
|
||||
@@ -51,13 +49,13 @@ public class AdminUserController {
|
||||
}
|
||||
|
||||
@GetMapping("/username")
|
||||
public Object username(@LoginAdmin Integer adminId, @NotEmpty String username){
|
||||
if(adminId == null){
|
||||
public Object username(@LoginAdmin Integer adminId, @NotEmpty String username) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
int total = userService.countSeletive(username, null, null, null, null, null);
|
||||
if(total == 0){
|
||||
if (total == 0) {
|
||||
return ResponseUtil.ok("不存在");
|
||||
}
|
||||
return ResponseUtil.ok("已存在");
|
||||
@@ -65,46 +63,46 @@ public class AdminUserController {
|
||||
|
||||
private Object validate(LitemallUser user) {
|
||||
String username = user.getUsername();
|
||||
if(StringUtils.isEmpty(user)){
|
||||
if (StringUtils.isEmpty(user)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if(!RegexUtil.isUsername(username)){
|
||||
if (!RegexUtil.isUsername(username)) {
|
||||
return ResponseUtil.fail(402, "用户名不符合规定");
|
||||
}
|
||||
String password = user.getPassword();
|
||||
if(StringUtils.isEmpty(password) || password.length() < 6){
|
||||
if (StringUtils.isEmpty(password) || password.length() < 6) {
|
||||
return ResponseUtil.fail(402, "用户密码长度不能小于6");
|
||||
}
|
||||
String mobile = user.getMobile();
|
||||
if(StringUtils.isEmpty(mobile)){
|
||||
if (StringUtils.isEmpty(mobile)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if(!RegexUtil.isMobileExact(mobile)){
|
||||
if (!RegexUtil.isMobileExact(mobile)) {
|
||||
return ResponseUtil.fail(402, "用户手机号码格式不正确");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallUser user){
|
||||
if(adminId == null){
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallUser user) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(user);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
String username = user.getUsername();
|
||||
String mobile = user.getMobile();
|
||||
List<LitemallUser> userList = userService.queryByUsername(username);
|
||||
if(userList.size() > 0){
|
||||
if (userList.size() > 0) {
|
||||
return ResponseUtil.fail(403, "用户名已注册");
|
||||
}
|
||||
userList = userService.queryByMobile(mobile);
|
||||
if(userList.size() > 0){
|
||||
if (userList.size() > 0) {
|
||||
return ResponseUtil.fail(403, "手机号已注册");
|
||||
}
|
||||
if(!RegexUtil.isMobileExact(mobile)){
|
||||
if (!RegexUtil.isMobileExact(mobile)) {
|
||||
return ResponseUtil.fail(403, "手机号格式不正确");
|
||||
}
|
||||
|
||||
@@ -118,12 +116,12 @@ public class AdminUserController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallUser user){
|
||||
if(adminId == null){
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallUser user) {
|
||||
if (adminId == null) {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
Object error = validate(user);
|
||||
if(error != null){
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
// 用户密码加密存储
|
||||
@@ -132,7 +130,7 @@ public class AdminUserController {
|
||||
String encodedPassword = encoder.encode(password);
|
||||
user.setPassword(encodedPassword);
|
||||
|
||||
if(userService.updateById(user) == 0){
|
||||
if (userService.updateById(user) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(user);
|
||||
|
||||
@@ -14,8 +14,8 @@ public class BcryptTest {
|
||||
@Test
|
||||
public void test() {
|
||||
String rawPassword = "aaaaaa";
|
||||
String encodedPassword ="";
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
String encodedPassword = "";
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
encodedPassword = bCryptPasswordEncoder.encode(rawPassword);
|
||||
|
||||
System.out.println("rawPassword=" + rawPassword + " encodedPassword=" + encodedPassword);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>litemall-all</artifactId>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>litemall-core</artifactId>
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
@@ -20,28 +19,28 @@ public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
@ResponseBody
|
||||
public Object badArgumentHandler(IllegalArgumentException e){
|
||||
public Object badArgumentHandler(IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||
@ResponseBody
|
||||
public Object badArgumentHandler(MethodArgumentTypeMismatchException e){
|
||||
public Object badArgumentHandler(MethodArgumentTypeMismatchException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||
@ResponseBody
|
||||
public Object badArgumentHandler(MissingServletRequestParameterException e){
|
||||
public Object badArgumentHandler(MissingServletRequestParameterException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpMessageNotReadableException.class)
|
||||
@ResponseBody
|
||||
public Object badArgumentHandler(HttpMessageNotReadableException e){
|
||||
public Object badArgumentHandler(HttpMessageNotReadableException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
@@ -50,11 +49,11 @@ public class GlobalExceptionHandler {
|
||||
@ResponseBody
|
||||
public Object badArgumentHandler(ValidationException e) {
|
||||
e.printStackTrace();
|
||||
if(e instanceof ConstraintViolationException){
|
||||
if (e instanceof ConstraintViolationException) {
|
||||
ConstraintViolationException exs = (ConstraintViolationException) e;
|
||||
Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
|
||||
for (ConstraintViolation<?> item : violations) {
|
||||
String message = ((PathImpl)item.getPropertyPath()).getLeafNode().getName() +item.getMessage();
|
||||
String message = ((PathImpl) item.getPropertyPath()).getLeafNode().getName() + item.getMessage();
|
||||
return ResponseUtil.fail(402, message);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +62,7 @@ public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Object seriousHandler(Exception e){
|
||||
public Object seriousHandler(Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.serious();
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ import javax.validation.ValidatorFactory;
|
||||
@Configuration
|
||||
public class ValidatorConfiguration {
|
||||
@Bean
|
||||
public Validator validator(){
|
||||
ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class )
|
||||
public Validator validator() {
|
||||
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
|
||||
.configure()
|
||||
.addProperty( "hibernate.validator.fail_fast", "true" )
|
||||
.addProperty("hibernate.validator.fail_fast", "true")
|
||||
.buildValidatorFactory();
|
||||
Validator validator = validatorFactory.getValidator();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ExpressAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ExpressService expressService(){
|
||||
public ExpressService expressService() {
|
||||
ExpressService expressService = new ExpressService();
|
||||
expressService.setProperties(properties);
|
||||
return expressService;
|
||||
|
||||
@@ -9,6 +9,9 @@ import java.util.Map;
|
||||
@ConfigurationProperties(prefix = "litemall.express")
|
||||
public class ExpressProperties {
|
||||
private boolean enable;
|
||||
private String appId;
|
||||
private String appKey;
|
||||
private List<Map<String, String>> vendors = new ArrayList<>();
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
@@ -18,11 +21,6 @@ public class ExpressProperties {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
private String appId;
|
||||
private String appKey;
|
||||
|
||||
private List<Map<String, String>> vendors = new ArrayList<>();
|
||||
|
||||
public List<Map<String, String>> getVendors() {
|
||||
return vendors;
|
||||
}
|
||||
|
||||
@@ -32,62 +32,62 @@ public class ExpressInfo {
|
||||
|
||||
private String ShipperName;
|
||||
|
||||
public void setLogisticCode(String LogisticCode) {
|
||||
this.LogisticCode = LogisticCode;
|
||||
}
|
||||
|
||||
public String getLogisticCode() {
|
||||
return LogisticCode;
|
||||
}
|
||||
|
||||
public void setShipperCode(String ShipperCode) {
|
||||
this.ShipperCode = ShipperCode;
|
||||
public void setLogisticCode(String LogisticCode) {
|
||||
this.LogisticCode = LogisticCode;
|
||||
}
|
||||
|
||||
public String getShipperCode() {
|
||||
return ShipperCode;
|
||||
}
|
||||
|
||||
public void setTraces(List<Traces> Traces) {
|
||||
this.Traces = Traces;
|
||||
public void setShipperCode(String ShipperCode) {
|
||||
this.ShipperCode = ShipperCode;
|
||||
}
|
||||
|
||||
public List<Traces> getTraces() {
|
||||
return Traces;
|
||||
}
|
||||
|
||||
public void setState(String State) {
|
||||
this.State = State;
|
||||
public void setTraces(List<Traces> Traces) {
|
||||
this.Traces = Traces;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return State;
|
||||
}
|
||||
|
||||
public void setEBusinessID(String EBusinessID) {
|
||||
this.EBusinessID = EBusinessID;
|
||||
public void setState(String State) {
|
||||
this.State = State;
|
||||
}
|
||||
|
||||
public String getEBusinessID() {
|
||||
return EBusinessID;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean Success) {
|
||||
this.Success = Success;
|
||||
public void setEBusinessID(String EBusinessID) {
|
||||
this.EBusinessID = EBusinessID;
|
||||
}
|
||||
|
||||
public boolean getSuccess() {
|
||||
return Success;
|
||||
}
|
||||
|
||||
public void setReason(String Reason) {
|
||||
this.Reason = Reason;
|
||||
public void setSuccess(boolean Success) {
|
||||
this.Success = Success;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return Reason;
|
||||
}
|
||||
|
||||
public void setReason(String Reason) {
|
||||
this.Reason = Reason;
|
||||
}
|
||||
|
||||
public String getShipperName() {
|
||||
return ShipperName;
|
||||
}
|
||||
|
||||
@@ -18,20 +18,20 @@ public class Traces {
|
||||
@JsonProperty("AcceptTime")
|
||||
private String AcceptTime;
|
||||
|
||||
public void setAcceptStation(String AcceptStation) {
|
||||
this.AcceptStation = AcceptStation;
|
||||
}
|
||||
|
||||
public String getAcceptStation() {
|
||||
return AcceptStation;
|
||||
}
|
||||
|
||||
public void setAcceptTime(String AcceptTime) {
|
||||
this.AcceptTime = AcceptTime;
|
||||
public void setAcceptStation(String AcceptStation) {
|
||||
this.AcceptStation = AcceptStation;
|
||||
}
|
||||
|
||||
public String getAcceptTime() {
|
||||
return AcceptTime;
|
||||
}
|
||||
|
||||
public void setAcceptTime(String AcceptTime) {
|
||||
this.AcceptTime = AcceptTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,15 +22,15 @@ public class NotifyService {
|
||||
private WxTemplateSender wxTemplateSender;
|
||||
private List<Map<String, String>> wxTemplate = new ArrayList<>();
|
||||
|
||||
public boolean isMailEnable (){
|
||||
public boolean isMailEnable() {
|
||||
return mailSender != null;
|
||||
}
|
||||
|
||||
public boolean isSmsEnable (){
|
||||
public boolean isSmsEnable() {
|
||||
return smsSender != null;
|
||||
}
|
||||
|
||||
public boolean isWxEnable (){
|
||||
public boolean isWxEnable() {
|
||||
return wxTemplateSender != null;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class NotifyService {
|
||||
}
|
||||
|
||||
String templateIdStr = getTemplateId(notifyType, smsTemplate);
|
||||
if (templateIdStr == null){
|
||||
if (templateIdStr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ public enum NotifyType {
|
||||
REFUND("refund"),
|
||||
CAPTCHA("captcha");
|
||||
|
||||
private String type;
|
||||
|
||||
NotifyType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private String type;
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.github.qcloudsms.SmsSingleSenderResult;
|
||||
import com.github.qcloudsms.httpclient.HTTPException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class WxTemplateSender {
|
||||
|
||||
try {
|
||||
wxMaService.getMsgService().sendTemplateMsg(msg);
|
||||
if(formIdService.updateUserFormId(userFormid) == 0){
|
||||
if (formIdService.updateUserFormId(userFormid) == 0) {
|
||||
logger.warn("更新数据已失效");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -21,24 +21,24 @@ public class NotifyAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NotifyService notifyService(){
|
||||
public NotifyService notifyService() {
|
||||
NotifyService notifyService = new NotifyService();
|
||||
|
||||
NotifyProperties.Mail mailConfig = properties.getMail();
|
||||
if(mailConfig.isEnable()) {
|
||||
if (mailConfig.isEnable()) {
|
||||
notifyService.setMailSender(mailSender());
|
||||
notifyService.setSendFrom(mailConfig.getSendfrom());
|
||||
notifyService.setSendTo(mailConfig.getSendto());
|
||||
}
|
||||
|
||||
NotifyProperties.Sms smsConfig = properties.getSms();
|
||||
if(smsConfig.isEnable()){
|
||||
if (smsConfig.isEnable()) {
|
||||
notifyService.setSmsSender(tencentSmsSender());
|
||||
notifyService.setSmsTemplate(smsConfig.getTemplate());
|
||||
}
|
||||
|
||||
NotifyProperties.Wx wxConfig = properties.getWx();
|
||||
if(wxConfig.isEnable()){
|
||||
if (wxConfig.isEnable()) {
|
||||
notifyService.setWxTemplateSender(wxTemplateSender());
|
||||
notifyService.setWxTemplate(wxConfig.getTemplate());
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class NotifyAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JavaMailSender mailSender(){
|
||||
public JavaMailSender mailSender() {
|
||||
NotifyProperties.Mail mailConfig = properties.getMail();
|
||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setHost(mailConfig.getHost());
|
||||
@@ -56,13 +56,13 @@ public class NotifyAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WxTemplateSender wxTemplateSender(){
|
||||
public WxTemplateSender wxTemplateSender() {
|
||||
WxTemplateSender wxTemplateSender = new WxTemplateSender();
|
||||
return wxTemplateSender;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TencentSmsSender tencentSmsSender(){
|
||||
public TencentSmsSender tencentSmsSender() {
|
||||
NotifyProperties.Sms smsConfig = properties.getSms();
|
||||
TencentSmsSender smsSender = new TencentSmsSender();
|
||||
smsSender.setSender(new SmsSingleSender(smsConfig.getAppid(), smsConfig.getAppkey()));
|
||||
|
||||
@@ -97,7 +97,7 @@ public class NotifyProperties {
|
||||
private boolean enable;
|
||||
private int appid;
|
||||
private String appkey;
|
||||
private List<Map<String,String>> template = new ArrayList<>();
|
||||
private List<Map<String, String>> template = new ArrayList<>();
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
@@ -134,7 +134,7 @@ public class NotifyProperties {
|
||||
|
||||
public static class Wx {
|
||||
private boolean enable;
|
||||
private List<Map<String,String>> template = new ArrayList<>();
|
||||
private List<Map<String, String>> template = new ArrayList<>();
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
|
||||
@@ -6,7 +6,8 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class QCodeGoodShare extends QCodeBase {
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class AliyunStorage implements Storage {
|
||||
|
||||
private String endpoint;
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String bucketName;
|
||||
private String endpoint;
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String bucketName;
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
@@ -62,12 +62,12 @@ public class AliyunStorage implements Storage {
|
||||
*
|
||||
* @return ossClient
|
||||
*/
|
||||
private OSSClient getOSSClient(){
|
||||
return new OSSClient(endpoint,accessKeyId, accessKeySecret);
|
||||
private OSSClient getOSSClient() {
|
||||
return new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
}
|
||||
|
||||
private String getBaseUrl() {
|
||||
return "https://" + bucketName + "." + endpoint + "/" ;
|
||||
return "https://" + bucketName + "." + endpoint + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ public class AliyunStorage implements Storage {
|
||||
public void delete(String keyName) {
|
||||
try {
|
||||
getOSSClient().deleteObject(bucketName, keyName);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class QiniuStorage implements Storage {
|
||||
|
||||
private String endpoint;
|
||||
private String endpoint;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
private String bucketName;
|
||||
@@ -62,8 +62,8 @@ public class QiniuStorage implements Storage {
|
||||
*/
|
||||
@Override
|
||||
public void store(InputStream inputStream, long contentLength, String contentType, String keyName) {
|
||||
if(uploadManager == null){
|
||||
if(auth == null) {
|
||||
if (uploadManager == null) {
|
||||
if (auth == null) {
|
||||
auth = Auth.create(accessKey, secretKey);
|
||||
}
|
||||
uploadManager = new UploadManager(new Configuration());
|
||||
@@ -105,16 +105,16 @@ public class QiniuStorage implements Storage {
|
||||
|
||||
@Override
|
||||
public void delete(String keyName) {
|
||||
if(bucketManager == null){
|
||||
if(auth == null) {
|
||||
if (bucketManager == null) {
|
||||
if (auth == null) {
|
||||
auth = Auth.create(accessKey, secretKey);
|
||||
}
|
||||
bucketManager = new BucketManager(auth, new Configuration() );
|
||||
bucketManager = new BucketManager(auth, new Configuration());
|
||||
}
|
||||
|
||||
try {
|
||||
bucketManager.delete(bucketName, keyName);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ public interface Storage {
|
||||
|
||||
/**
|
||||
* 存储一个文件对象
|
||||
* @param inputStream 文件输入流
|
||||
*
|
||||
* @param inputStream 文件输入流
|
||||
* @param contentLength 文件长度
|
||||
* @param contentType 文件类型
|
||||
* @param keyName 文件名
|
||||
* @param contentType 文件类型
|
||||
* @param keyName 文件名
|
||||
*/
|
||||
void store(InputStream inputStream, long contentLength, String contentType, String keyName);
|
||||
|
||||
|
||||
@@ -5,11 +5,9 @@ import org.linlinjava.litemall.db.domain.LitemallStorage;
|
||||
import org.linlinjava.litemall.db.service.LitemallStorageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,7 +122,7 @@ public class TencentStorage implements Storage {
|
||||
public void delete(String keyName) {
|
||||
try {
|
||||
getCOSClient().deleteObject(bucketName, keyName);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(StorageProperties.class)
|
||||
public class StorageAutoConfiguration {
|
||||
@@ -23,20 +20,16 @@ public class StorageAutoConfiguration {
|
||||
StorageService storageService = new StorageService();
|
||||
String active = this.properties.getActive();
|
||||
storageService.setActive(active);
|
||||
if(active.equals("local")){
|
||||
if (active.equals("local")) {
|
||||
storageService.setStorage(localStorage());
|
||||
}
|
||||
else if(active.equals("aliyun")){
|
||||
} else if (active.equals("aliyun")) {
|
||||
storageService.setStorage(aliyunStorage());
|
||||
}
|
||||
else if(active.equals("tencent")){
|
||||
} else if (active.equals("tencent")) {
|
||||
storageService.setStorage(tencentStorage());
|
||||
}
|
||||
else if(active.equals("qiniu")){
|
||||
} else if (active.equals("qiniu")) {
|
||||
storageService.setStorage(qiniuStorage());
|
||||
}
|
||||
else{
|
||||
throw new RuntimeException("当前存储模式 " + active + " 不支持");
|
||||
} else {
|
||||
throw new RuntimeException("当前存储模式 " + active + " 不支持");
|
||||
}
|
||||
|
||||
return storageService;
|
||||
@@ -53,7 +46,7 @@ public class StorageAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public AliyunStorage aliyunStorage() {
|
||||
AliyunStorage aliyunStorage = new AliyunStorage();
|
||||
AliyunStorage aliyunStorage = new AliyunStorage();
|
||||
StorageProperties.Aliyun aliyun = this.properties.getAliyun();
|
||||
aliyunStorage.setAccessKeyId(aliyun.getAccessKeyId());
|
||||
aliyunStorage.setAccessKeySecret(aliyun.getAccessKeySecret());
|
||||
@@ -75,7 +68,7 @@ public class StorageAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public QiniuStorage qiniuStorage() {
|
||||
QiniuStorage qiniuStorage = new QiniuStorage();
|
||||
QiniuStorage qiniuStorage = new QiniuStorage();
|
||||
StorageProperties.Qiniu qiniu = this.properties.getQiniu();
|
||||
qiniuStorage.setAccessKey(qiniu.getAccessKey());
|
||||
qiniuStorage.setSecretKey(qiniu.getSecretKey());
|
||||
|
||||
@@ -111,10 +111,10 @@ public class StorageProperties {
|
||||
}
|
||||
|
||||
public static class Aliyun {
|
||||
private String endpoint;
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String bucketName;
|
||||
private String endpoint;
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String bucketName;
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
|
||||
@@ -13,13 +13,6 @@ abstract class BaseConfig {
|
||||
//所有的配置均保存在该 HashMap 中
|
||||
protected static Map<String, String> configs = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 子类实现该方法,并告知父类配置前缀,该前缀用来索引配置组用于简化访问和按组重读配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
abstract String getPrefix();
|
||||
|
||||
/**
|
||||
* 添加配置到公共Map中
|
||||
*
|
||||
@@ -73,4 +66,11 @@ abstract class BaseConfig {
|
||||
protected static BigDecimal getConfigBigDec(String keyName) {
|
||||
return new BigDecimal(configs.get(keyName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 子类实现该方法,并告知父类配置前缀,该前缀用来索引配置组用于简化访问和按组重读配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
abstract String getPrefix();
|
||||
}
|
||||
|
||||
@@ -14,11 +14,6 @@ import java.util.List;
|
||||
@Component
|
||||
class ConfigService {
|
||||
private static ConfigService systemConfigService;
|
||||
|
||||
static ConfigService getSystemConfigService() {
|
||||
return systemConfigService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private LitemallSystemConfigService litemallSystemConfigService;
|
||||
|
||||
@@ -27,6 +22,10 @@ class ConfigService {
|
||||
|
||||
}
|
||||
|
||||
static ConfigService getSystemConfigService() {
|
||||
return systemConfigService;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void inist() {
|
||||
systemConfigService = this;
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.linlinjava.litemall.core.util;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -16,7 +14,7 @@ public class JacksonUtil {
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if(leaf != null)
|
||||
if (leaf != null)
|
||||
return leaf.asText();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -32,8 +30,9 @@ public class JacksonUtil {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
|
||||
if(leaf != null)
|
||||
return mapper.convertValue(leaf, new TypeReference<List<String>>(){});
|
||||
if (leaf != null)
|
||||
return mapper.convertValue(leaf, new TypeReference<List<String>>() {
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -46,7 +45,7 @@ public class JacksonUtil {
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if(leaf != null)
|
||||
if (leaf != null)
|
||||
return leaf.asInt();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -61,8 +60,9 @@ public class JacksonUtil {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
|
||||
if(leaf != null)
|
||||
return mapper.convertValue(leaf, new TypeReference<List<Integer>>(){});
|
||||
if (leaf != null)
|
||||
return mapper.convertValue(leaf, new TypeReference<List<Integer>>() {
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -70,14 +70,13 @@ public class JacksonUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Boolean parseBoolean(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = null;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if(leaf != null)
|
||||
if (leaf != null)
|
||||
return leaf.asBoolean();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -91,7 +90,7 @@ public class JacksonUtil {
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if(leaf != null) {
|
||||
if (leaf != null) {
|
||||
Integer value = leaf.asInt();
|
||||
return value.shortValue();
|
||||
}
|
||||
@@ -107,7 +106,7 @@ public class JacksonUtil {
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if(leaf != null) {
|
||||
if (leaf != null) {
|
||||
Integer value = leaf.asInt();
|
||||
return value.byteValue();
|
||||
}
|
||||
@@ -131,7 +130,7 @@ public class JacksonUtil {
|
||||
}
|
||||
|
||||
public static Object toNode(String json) {
|
||||
if(json == null){
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@@ -25,46 +25,46 @@ public class RegexUtil {
|
||||
* <p>global star: 1349</p>
|
||||
* <p>virtual operator: 170</p>
|
||||
*/
|
||||
public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|(18[0-9])|(19[8,9]))\\d{8}$";
|
||||
public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|(18[0-9])|(19[8,9]))\\d{8}$";
|
||||
/**
|
||||
* Regex of telephone number.
|
||||
*/
|
||||
public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
|
||||
public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
|
||||
/**
|
||||
* Regex of id card number which length is 15.
|
||||
*/
|
||||
public static final String REGEX_ID_CARD15 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$";
|
||||
public static final String REGEX_ID_CARD15 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$";
|
||||
/**
|
||||
* Regex of id card number which length is 18.
|
||||
*/
|
||||
public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$";
|
||||
public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$";
|
||||
/**
|
||||
* Regex of email.
|
||||
*/
|
||||
public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
||||
public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
||||
/**
|
||||
* Regex of url.
|
||||
*/
|
||||
public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*";
|
||||
public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*";
|
||||
/**
|
||||
* Regex of Chinese character.
|
||||
*/
|
||||
public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$";
|
||||
public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$";
|
||||
/**
|
||||
* Regex of username.
|
||||
* <p>scope for "a-z", "A-Z", "0-9", "_", "Chinese character"</p>
|
||||
* <p>can't end with "_"</p>
|
||||
* <p>length is between 6 to 20</p>
|
||||
*/
|
||||
public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$";
|
||||
public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$";
|
||||
/**
|
||||
* Regex of date which pattern is "yyyy-MM-dd".
|
||||
*/
|
||||
public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
|
||||
public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
|
||||
/**
|
||||
* Regex of ip address.
|
||||
*/
|
||||
public static final String REGEX_IP = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
|
||||
public static final String REGEX_IP = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// The following come from http://tool.oschina.net/regex
|
||||
@@ -73,31 +73,31 @@ public class RegexUtil {
|
||||
/**
|
||||
* Regex of double-byte characters.
|
||||
*/
|
||||
public static final String REGEX_DOUBLE_BYTE_CHAR = "[^\\x00-\\xff]";
|
||||
public static final String REGEX_DOUBLE_BYTE_CHAR = "[^\\x00-\\xff]";
|
||||
/**
|
||||
* Regex of blank line.
|
||||
*/
|
||||
public static final String REGEX_BLANK_LINE = "\\n\\s*\\r";
|
||||
public static final String REGEX_BLANK_LINE = "\\n\\s*\\r";
|
||||
/**
|
||||
* Regex of QQ number.
|
||||
*/
|
||||
public static final String REGEX_QQ_NUM = "[1-9][0-9]{4,}";
|
||||
public static final String REGEX_QQ_NUM = "[1-9][0-9]{4,}";
|
||||
/**
|
||||
* Regex of postal code in China.
|
||||
*/
|
||||
public static final String REGEX_CHINA_POSTAL_CODE = "[1-9]\\d{5}(?!\\d)";
|
||||
public static final String REGEX_CHINA_POSTAL_CODE = "[1-9]\\d{5}(?!\\d)";
|
||||
/**
|
||||
* Regex of positive integer.
|
||||
*/
|
||||
public static final String REGEX_POSITIVE_INTEGER = "^[1-9]\\d*$";
|
||||
public static final String REGEX_POSITIVE_INTEGER = "^[1-9]\\d*$";
|
||||
/**
|
||||
* Regex of negative integer.
|
||||
*/
|
||||
public static final String REGEX_NEGATIVE_INTEGER = "^-[1-9]\\d*$";
|
||||
public static final String REGEX_NEGATIVE_INTEGER = "^-[1-9]\\d*$";
|
||||
/**
|
||||
* Regex of integer.
|
||||
*/
|
||||
public static final String REGEX_INTEGER = "^-?[1-9]\\d*$";
|
||||
public static final String REGEX_INTEGER = "^-?[1-9]\\d*$";
|
||||
/**
|
||||
* Regex of non-negative integer.
|
||||
*/
|
||||
@@ -109,12 +109,12 @@ public class RegexUtil {
|
||||
/**
|
||||
* Regex of positive float.
|
||||
*/
|
||||
public static final String REGEX_POSITIVE_FLOAT = "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$";
|
||||
public static final String REGEX_POSITIVE_FLOAT = "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$";
|
||||
/**
|
||||
* Regex of negative float.
|
||||
*/
|
||||
public static final String REGEX_NEGATIVE_FLOAT = "^-[1-9]\\d*\\.\\d*|-0\\.\\d*[1-9]\\d*$";
|
||||
|
||||
public static final String REGEX_NEGATIVE_FLOAT = "^-[1-9]\\d*\\.\\d*|-0\\.\\d*[1-9]\\d*$";
|
||||
|
||||
private RegexUtil() {
|
||||
throw new UnsupportedOperationException("u can't instantiate me...");
|
||||
}
|
||||
|
||||
@@ -41,31 +41,31 @@ public class ResponseUtil {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static Object badArgument(){
|
||||
public static Object badArgument() {
|
||||
return fail(401, "参数不对");
|
||||
}
|
||||
|
||||
public static Object badArgumentValue(){
|
||||
public static Object badArgumentValue() {
|
||||
return fail(402, "参数值不对");
|
||||
}
|
||||
|
||||
public static Object updatedDateExpired(){
|
||||
public static Object updatedDateExpired() {
|
||||
return fail(403, "更新数据已经失效");
|
||||
}
|
||||
|
||||
public static Object updatedDataFailed(){
|
||||
public static Object updatedDataFailed() {
|
||||
return fail(404, "更新数据失败");
|
||||
}
|
||||
|
||||
public static Object unlogin(){
|
||||
public static Object unlogin() {
|
||||
return fail(501, "请登录");
|
||||
}
|
||||
|
||||
public static Object serious(){
|
||||
public static Object serious() {
|
||||
return fail(502, "系统内部错误");
|
||||
}
|
||||
|
||||
public static Object unsupport(){
|
||||
public static Object unsupport() {
|
||||
return fail(503, "业务不支持");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,16 +59,18 @@ import java.security.SecureRandom;
|
||||
public class BCrypt {
|
||||
// BCrypt parameters
|
||||
|
||||
static final int MIN_LOG_ROUNDS = 4;
|
||||
static final int MAX_LOG_ROUNDS = 31;
|
||||
private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;
|
||||
private static final int BCRYPT_SALT_LEN = 16;
|
||||
// Blowfish parameters
|
||||
private static final int BLOWFISH_NUM_ROUNDS = 16;
|
||||
// Initial contents of key schedule
|
||||
private static final int P_orig[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
|
||||
private static final int P_orig[] = {0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
|
||||
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377,
|
||||
0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
|
||||
0x9216d5d9, 0x8979fb1b };
|
||||
private static final int S_orig[] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
|
||||
0x9216d5d9, 0x8979fb1b};
|
||||
private static final int S_orig[] = {0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
|
||||
0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7,
|
||||
0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
||||
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5,
|
||||
@@ -238,26 +240,24 @@ public class BCrypt {
|
||||
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76,
|
||||
0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
|
||||
0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0,
|
||||
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 };
|
||||
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6};
|
||||
// bcrypt IV: "OrpheanBeholderScryDoubt"
|
||||
static private final int bf_crypt_ciphertext[] = { 0x4f727068, 0x65616e42,
|
||||
0x65686f6c, 0x64657253, 0x63727944, 0x6f756274 };
|
||||
static private final int bf_crypt_ciphertext[] = {0x4f727068, 0x65616e42,
|
||||
0x65686f6c, 0x64657253, 0x63727944, 0x6f756274};
|
||||
// Table for Base64 encoding
|
||||
static private final char base64_code[] = { '.', '/', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||
static private final char base64_code[] = {'.', '/', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
|
||||
'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
|
||||
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
|
||||
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
|
||||
// Table for Base64 decoding
|
||||
static private final byte index_64[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
static private final byte index_64[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55,
|
||||
56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7,
|
||||
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||
-1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1 };
|
||||
static final int MIN_LOG_ROUNDS = 4;
|
||||
static final int MAX_LOG_ROUNDS = 31;
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1};
|
||||
// Expanded Blowfish key
|
||||
private int P[];
|
||||
private int S[];
|
||||
@@ -267,10 +267,10 @@ public class BCrypt {
|
||||
* that this is <strong>not</strong> compatible with the standard MIME-base64
|
||||
* encoding.
|
||||
*
|
||||
* @param d the byte array to encode
|
||||
* @param d the byte array to encode
|
||||
* @param len the number of bytes to encode
|
||||
* @param rs the destination buffer for the base64-encoded string
|
||||
* @exception IllegalArgumentException if the length is invalid
|
||||
* @param rs the destination buffer for the base64-encoded string
|
||||
* @throws IllegalArgumentException if the length is invalid
|
||||
*/
|
||||
static void encode_base64(byte d[], int len, StringBuilder rs)
|
||||
throws IllegalArgumentException {
|
||||
@@ -307,6 +307,7 @@ public class BCrypt {
|
||||
/**
|
||||
* Look up the 3 bits base64-encoded by the specified character, range-checking
|
||||
* against conversion table
|
||||
*
|
||||
* @param x the base64-encoded value
|
||||
* @return the decoded value of x
|
||||
*/
|
||||
@@ -320,7 +321,8 @@ public class BCrypt {
|
||||
/**
|
||||
* Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that
|
||||
* this is *not* compatible with the standard MIME-base64 encoding.
|
||||
* @param s the string to decode
|
||||
*
|
||||
* @param s the string to decode
|
||||
* @param maxolen the maximum number of bytes to decode
|
||||
* @return an array containing the decoded bytes
|
||||
* @throws IllegalArgumentException if maxolen is invalid
|
||||
@@ -366,16 +368,195 @@ public class BCrypt {
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycically extract a word of key material
|
||||
*
|
||||
* @param data the string to extract the data from
|
||||
* @param offp a "pointer" (as a one-entry array) to the current offset into data
|
||||
* @return the next word of material from data
|
||||
*/
|
||||
private static int streamtoword(byte data[], int offp[]) {
|
||||
int i;
|
||||
int word = 0;
|
||||
int off = offp[0];
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
word = (word << 8) | (data[off] & 0xff);
|
||||
off = (off + 1) % data.length;
|
||||
}
|
||||
|
||||
offp[0] = off;
|
||||
return word;
|
||||
}
|
||||
|
||||
static long roundsForLogRounds(int log_rounds) {
|
||||
if (log_rounds < 4 || log_rounds > 31) {
|
||||
throw new IllegalArgumentException("Bad number of rounds");
|
||||
}
|
||||
return 1L << log_rounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash a password using the OpenBSD bcrypt scheme
|
||||
*
|
||||
* @param password the password to hash
|
||||
* @param salt the salt to hash with (perhaps generated using BCrypt.gensalt)
|
||||
* @return the hashed password
|
||||
* @throws IllegalArgumentException if invalid salt is passed
|
||||
*/
|
||||
public static String hashpw(String password, String salt) throws IllegalArgumentException {
|
||||
BCrypt B;
|
||||
String real_salt;
|
||||
byte passwordb[], saltb[], hashed[];
|
||||
char minor = (char) 0;
|
||||
int rounds, off = 0;
|
||||
StringBuilder rs = new StringBuilder();
|
||||
|
||||
if (salt == null) {
|
||||
throw new IllegalArgumentException("salt cannot be null");
|
||||
}
|
||||
|
||||
int saltLength = salt.length();
|
||||
|
||||
if (saltLength < 28) {
|
||||
throw new IllegalArgumentException("Invalid salt");
|
||||
}
|
||||
|
||||
if (salt.charAt(0) != '$' || salt.charAt(1) != '2') {
|
||||
throw new IllegalArgumentException("Invalid salt version");
|
||||
}
|
||||
if (salt.charAt(2) == '$') {
|
||||
off = 3;
|
||||
} else {
|
||||
minor = salt.charAt(2);
|
||||
if (minor != 'a' || salt.charAt(3) != '$') {
|
||||
throw new IllegalArgumentException("Invalid salt revision");
|
||||
}
|
||||
off = 4;
|
||||
}
|
||||
|
||||
if (saltLength - off < 25) {
|
||||
throw new IllegalArgumentException("Invalid salt");
|
||||
}
|
||||
|
||||
// Extract number of rounds
|
||||
if (salt.charAt(off + 2) > '$') {
|
||||
throw new IllegalArgumentException("Missing salt rounds");
|
||||
}
|
||||
rounds = Integer.parseInt(salt.substring(off, off + 2));
|
||||
|
||||
real_salt = salt.substring(off + 3, off + 25);
|
||||
try {
|
||||
passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
throw new AssertionError("UTF-8 is not supported");
|
||||
}
|
||||
|
||||
saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
|
||||
|
||||
B = new BCrypt();
|
||||
hashed = B.crypt_raw(passwordb, saltb, rounds);
|
||||
|
||||
rs.append("$2");
|
||||
if (minor >= 'a') {
|
||||
rs.append(minor);
|
||||
}
|
||||
rs.append("$");
|
||||
if (rounds < 10) {
|
||||
rs.append("0");
|
||||
}
|
||||
rs.append(rounds);
|
||||
rs.append("$");
|
||||
encode_base64(saltb, saltb.length, rs);
|
||||
encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1, rs);
|
||||
return rs.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a salt for use with the BCrypt.hashpw() method
|
||||
*
|
||||
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work
|
||||
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
|
||||
* @param random an instance of SecureRandom to use
|
||||
* @return an encoded salt value
|
||||
*/
|
||||
public static String gensalt(int log_rounds, SecureRandom random) {
|
||||
if (log_rounds < MIN_LOG_ROUNDS || log_rounds > MAX_LOG_ROUNDS) {
|
||||
throw new IllegalArgumentException("Bad number of rounds");
|
||||
}
|
||||
StringBuilder rs = new StringBuilder();
|
||||
byte rnd[] = new byte[BCRYPT_SALT_LEN];
|
||||
|
||||
random.nextBytes(rnd);
|
||||
|
||||
rs.append("$2a$");
|
||||
if (log_rounds < 10) {
|
||||
rs.append("0");
|
||||
}
|
||||
rs.append(log_rounds);
|
||||
rs.append("$");
|
||||
encode_base64(rnd, rnd.length, rs);
|
||||
return rs.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a salt for use with the BCrypt.hashpw() method
|
||||
*
|
||||
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work
|
||||
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
|
||||
* @return an encoded salt value
|
||||
*/
|
||||
public static String gensalt(int log_rounds) {
|
||||
return gensalt(log_rounds, new SecureRandom());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable
|
||||
* default for the number of hashing rounds to apply
|
||||
*
|
||||
* @return an encoded salt value
|
||||
*/
|
||||
public static String gensalt() {
|
||||
return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a plaintext password matches a previously hashed one
|
||||
*
|
||||
* @param plaintext the plaintext password to verify
|
||||
* @param hashed the previously-hashed password
|
||||
* @return true if the passwords match, false otherwise
|
||||
*/
|
||||
public static boolean checkpw(String plaintext, String hashed) {
|
||||
return equalsNoEarlyReturn(hashed, hashpw(plaintext, hashed));
|
||||
}
|
||||
|
||||
static boolean equalsNoEarlyReturn(String a, String b) {
|
||||
char[] caa = a.toCharArray();
|
||||
char[] cab = b.toCharArray();
|
||||
|
||||
if (caa.length != cab.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byte ret = 0;
|
||||
for (int i = 0; i < caa.length; i++) {
|
||||
ret |= caa[i] ^ cab[i];
|
||||
}
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blowfish encipher a single 64-bit block encoded as two 32-bit halves
|
||||
* @param lr an array containing the two 32-bit half blocks
|
||||
*
|
||||
* @param lr an array containing the two 32-bit half blocks
|
||||
* @param off the position in the array of the blocks
|
||||
*/
|
||||
private final void encipher(int lr[], int off) {
|
||||
int i, n, l = lr[off], r = lr[off + 1];
|
||||
|
||||
l ^= P[0];
|
||||
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) {
|
||||
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) {
|
||||
// Feistel substitution on left word
|
||||
n = S[(l >> 24) & 0xff];
|
||||
n += S[0x100 | ((l >> 16) & 0xff)];
|
||||
@@ -394,26 +575,6 @@ public class BCrypt {
|
||||
lr[off + 1] = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycically extract a word of key material
|
||||
* @param data the string to extract the data from
|
||||
* @param offp a "pointer" (as a one-entry array) to the current offset into data
|
||||
* @return the next word of material from data
|
||||
*/
|
||||
private static int streamtoword(byte data[], int offp[]) {
|
||||
int i;
|
||||
int word = 0;
|
||||
int off = offp[0];
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
word = (word << 8) | (data[off] & 0xff);
|
||||
off = (off + 1) % data.length;
|
||||
}
|
||||
|
||||
offp[0] = off;
|
||||
return word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the Blowfish key schedule
|
||||
*/
|
||||
@@ -424,12 +585,13 @@ public class BCrypt {
|
||||
|
||||
/**
|
||||
* Key the Blowfish cipher
|
||||
*
|
||||
* @param key an array containing the key
|
||||
*/
|
||||
private void key(byte key[]) {
|
||||
int i;
|
||||
int koffp[] = { 0 };
|
||||
int lr[] = { 0, 0 };
|
||||
int koffp[] = {0};
|
||||
int lr[] = {0, 0};
|
||||
int plen = P.length, slen = S.length;
|
||||
|
||||
for (i = 0; i < plen; i++) {
|
||||
@@ -452,13 +614,14 @@ public class BCrypt {
|
||||
/**
|
||||
* Perform the "enhanced key schedule" step described by Provos and Mazieres in
|
||||
* "A Future-Adaptable Password Scheme" http://www.openbsd.org/papers/bcrypt-paper.ps
|
||||
*
|
||||
* @param data salt information
|
||||
* @param key password information
|
||||
* @param key password information
|
||||
*/
|
||||
private void ekskey(byte data[], byte key[]) {
|
||||
int i;
|
||||
int koffp[] = { 0 }, doffp[] = { 0 };
|
||||
int lr[] = { 0, 0 };
|
||||
int koffp[] = {0}, doffp[] = {0};
|
||||
int lr[] = {0, 0};
|
||||
int plen = P.length, slen = S.length;
|
||||
|
||||
for (i = 0; i < plen; i++) {
|
||||
@@ -482,17 +645,11 @@ public class BCrypt {
|
||||
}
|
||||
}
|
||||
|
||||
static long roundsForLogRounds(int log_rounds) {
|
||||
if (log_rounds < 4 || log_rounds > 31) {
|
||||
throw new IllegalArgumentException("Bad number of rounds");
|
||||
}
|
||||
return 1L << log_rounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the central password hashing step in the bcrypt scheme
|
||||
* @param password the password to hash
|
||||
* @param salt the binary salt to hash with the password
|
||||
*
|
||||
* @param password the password to hash
|
||||
* @param salt the binary salt to hash with the password
|
||||
* @param log_rounds the binary logarithm of the number of rounds of hashing to apply
|
||||
* @return an array containing the binary hashed password
|
||||
*/
|
||||
@@ -525,151 +682,4 @@ public class BCrypt {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash a password using the OpenBSD bcrypt scheme
|
||||
* @param password the password to hash
|
||||
* @param salt the salt to hash with (perhaps generated using BCrypt.gensalt)
|
||||
* @return the hashed password
|
||||
* @throws IllegalArgumentException if invalid salt is passed
|
||||
*/
|
||||
public static String hashpw(String password, String salt) throws IllegalArgumentException {
|
||||
BCrypt B;
|
||||
String real_salt;
|
||||
byte passwordb[], saltb[], hashed[];
|
||||
char minor = (char) 0;
|
||||
int rounds, off = 0;
|
||||
StringBuilder rs = new StringBuilder();
|
||||
|
||||
if (salt == null) {
|
||||
throw new IllegalArgumentException("salt cannot be null");
|
||||
}
|
||||
|
||||
int saltLength = salt.length();
|
||||
|
||||
if (saltLength < 28) {
|
||||
throw new IllegalArgumentException("Invalid salt");
|
||||
}
|
||||
|
||||
if (salt.charAt(0) != '$' || salt.charAt(1) != '2') {
|
||||
throw new IllegalArgumentException("Invalid salt version");
|
||||
}
|
||||
if (salt.charAt(2) == '$') {
|
||||
off = 3;
|
||||
}
|
||||
else {
|
||||
minor = salt.charAt(2);
|
||||
if (minor != 'a' || salt.charAt(3) != '$') {
|
||||
throw new IllegalArgumentException("Invalid salt revision");
|
||||
}
|
||||
off = 4;
|
||||
}
|
||||
|
||||
if (saltLength - off < 25) {
|
||||
throw new IllegalArgumentException("Invalid salt");
|
||||
}
|
||||
|
||||
// Extract number of rounds
|
||||
if (salt.charAt(off + 2) > '$') {
|
||||
throw new IllegalArgumentException("Missing salt rounds");
|
||||
}
|
||||
rounds = Integer.parseInt(salt.substring(off, off + 2));
|
||||
|
||||
real_salt = salt.substring(off + 3, off + 25);
|
||||
try {
|
||||
passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException uee) {
|
||||
throw new AssertionError("UTF-8 is not supported");
|
||||
}
|
||||
|
||||
saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
|
||||
|
||||
B = new BCrypt();
|
||||
hashed = B.crypt_raw(passwordb, saltb, rounds);
|
||||
|
||||
rs.append("$2");
|
||||
if (minor >= 'a') {
|
||||
rs.append(minor);
|
||||
}
|
||||
rs.append("$");
|
||||
if (rounds < 10) {
|
||||
rs.append("0");
|
||||
}
|
||||
rs.append(rounds);
|
||||
rs.append("$");
|
||||
encode_base64(saltb, saltb.length, rs);
|
||||
encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1, rs);
|
||||
return rs.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a salt for use with the BCrypt.hashpw() method
|
||||
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work
|
||||
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
|
||||
* @param random an instance of SecureRandom to use
|
||||
* @return an encoded salt value
|
||||
*/
|
||||
public static String gensalt(int log_rounds, SecureRandom random) {
|
||||
if (log_rounds < MIN_LOG_ROUNDS || log_rounds > MAX_LOG_ROUNDS) {
|
||||
throw new IllegalArgumentException("Bad number of rounds");
|
||||
}
|
||||
StringBuilder rs = new StringBuilder();
|
||||
byte rnd[] = new byte[BCRYPT_SALT_LEN];
|
||||
|
||||
random.nextBytes(rnd);
|
||||
|
||||
rs.append("$2a$");
|
||||
if (log_rounds < 10) {
|
||||
rs.append("0");
|
||||
}
|
||||
rs.append(log_rounds);
|
||||
rs.append("$");
|
||||
encode_base64(rnd, rnd.length, rs);
|
||||
return rs.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a salt for use with the BCrypt.hashpw() method
|
||||
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work
|
||||
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
|
||||
* @return an encoded salt value
|
||||
*/
|
||||
public static String gensalt(int log_rounds) {
|
||||
return gensalt(log_rounds, new SecureRandom());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable
|
||||
* default for the number of hashing rounds to apply
|
||||
* @return an encoded salt value
|
||||
*/
|
||||
public static String gensalt() {
|
||||
return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a plaintext password matches a previously hashed one
|
||||
* @param plaintext the plaintext password to verify
|
||||
* @param hashed the previously-hashed password
|
||||
* @return true if the passwords match, false otherwise
|
||||
*/
|
||||
public static boolean checkpw(String plaintext, String hashed) {
|
||||
return equalsNoEarlyReturn(hashed, hashpw(plaintext, hashed));
|
||||
}
|
||||
|
||||
static boolean equalsNoEarlyReturn(String a, String b) {
|
||||
char[] caa = a.toCharArray();
|
||||
char[] cab = b.toCharArray();
|
||||
|
||||
if (caa.length != cab.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byte ret = 0;
|
||||
for (int i = 0; i < caa.length; i++) {
|
||||
ret |= caa[i] ^ cab[i];
|
||||
}
|
||||
return ret == 0;
|
||||
}
|
||||
}
|
||||
@@ -28,16 +28,13 @@ import java.util.regex.Pattern;
|
||||
* (exponentially) to hash the passwords. The default value is 10.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class BCryptPasswordEncoder {
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
private final int strength;
|
||||
private final SecureRandom random;
|
||||
private Pattern BCRYPT_PATTERN = Pattern
|
||||
.compile("\\A\\$2a?\\$\\d\\d\\$[./0-9A-Za-z]{53}");
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final int strength;
|
||||
|
||||
private final SecureRandom random;
|
||||
|
||||
public BCryptPasswordEncoder() {
|
||||
this(-1);
|
||||
@@ -52,8 +49,7 @@ public class BCryptPasswordEncoder {
|
||||
|
||||
/**
|
||||
* @param strength the log rounds to use, between 4 and 31
|
||||
* @param random the secure random instance to use
|
||||
*
|
||||
* @param random the secure random instance to use
|
||||
*/
|
||||
public BCryptPasswordEncoder(int strength, SecureRandom random) {
|
||||
if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) {
|
||||
@@ -68,12 +64,10 @@ public class BCryptPasswordEncoder {
|
||||
if (strength > 0) {
|
||||
if (random != null) {
|
||||
salt = BCrypt.gensalt(strength, random);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
salt = BCrypt.gensalt(strength);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
salt = BCrypt.gensalt();
|
||||
}
|
||||
return BCrypt.hashpw(rawPassword.toString(), salt);
|
||||
|
||||
@@ -9,12 +9,13 @@ import java.lang.annotation.Target;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Target({ METHOD, FIELD, PARAMETER })
|
||||
@Target({METHOD, FIELD, PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = OrderValidator.class)
|
||||
public @interface Order {
|
||||
String message() default "排序类型不支持";
|
||||
|
||||
String[] accepts() default {"desc", "asc"};
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OrderValidator implements ConstraintValidator<Order, String>{
|
||||
public class OrderValidator implements ConstraintValidator<Order, String> {
|
||||
private List<String> valueList;
|
||||
|
||||
@Override
|
||||
public void initialize(Order order) {
|
||||
valueList = new ArrayList<String>();
|
||||
for(String val : order.accepts()) {
|
||||
for (String val : order.accepts()) {
|
||||
valueList.add(val.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
|
||||
if(!valueList.contains(s.toUpperCase())) {
|
||||
if (!valueList.contains(s.toUpperCase())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -9,12 +9,13 @@ import java.lang.annotation.Target;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Target({ METHOD, FIELD, PARAMETER })
|
||||
@Target({METHOD, FIELD, PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = SortValidator.class)
|
||||
public @interface Sort {
|
||||
String message() default "排序字段不支持";
|
||||
|
||||
String[] accepts() default {"add_time", "id"};
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SortValidator implements ConstraintValidator<Sort, String>{
|
||||
public class SortValidator implements ConstraintValidator<Sort, String> {
|
||||
private List<String> valueList;
|
||||
|
||||
@Override
|
||||
public void initialize(Sort sort) {
|
||||
valueList = new ArrayList<String>();
|
||||
for(String val : sort.accepts()) {
|
||||
for (String val : sort.accepts()) {
|
||||
valueList.add(val.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
|
||||
if(!valueList.contains(s.toUpperCase())) {
|
||||
if (!valueList.contains(s.toUpperCase())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -6,10 +6,8 @@ import org.linlinjava.litemall.core.storage.AliyunStorage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
@@ -9,14 +9,14 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
/**
|
||||
* 异步测试
|
||||
*
|
||||
*/
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
public class AsyncTest {
|
||||
|
||||
@Autowired AsyncTask task;
|
||||
@Autowired
|
||||
AsyncTask task;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -17,19 +17,27 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* 测试邮件发送服务
|
||||
*
|
||||
* <p>
|
||||
* 注意LitemallNotifyService采用异步线程操作
|
||||
* 因此测试的时候需要睡眠一会儿,保证任务执行
|
||||
*
|
||||
* 开发者需要确保:
|
||||
* 1. 在相应的邮件服务器设置正确notify.properties已经设置正确
|
||||
* 2. 在相应的邮件服务器设置正确
|
||||
* <p>
|
||||
* 开发者需要确保:
|
||||
* 1. 在相应的邮件服务器设置正确notify.properties已经设置正确
|
||||
* 2. 在相应的邮件服务器设置正确
|
||||
*/
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
public class MailTest {
|
||||
|
||||
@Autowired
|
||||
private NotifyService notifyService;
|
||||
|
||||
@Test
|
||||
public void testMail() {
|
||||
notifyService.notifyMail("订单信息", "订单1111111已付款,请发货");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(Application.class)
|
||||
static class ContextConfiguration {
|
||||
@@ -40,13 +48,5 @@ public class MailTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private NotifyService notifyService;
|
||||
|
||||
@Test
|
||||
public void testMail() {
|
||||
notifyService.notifyMail("订单信息", "订单1111111已付款,请发货");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* 测试短信发送服务
|
||||
*
|
||||
* <p>
|
||||
* 注意LitemallNotifyService采用异步线程操作
|
||||
* 因此测试的时候需要睡眠一会儿,保证任务执行
|
||||
*
|
||||
* <p>
|
||||
* 开发者需要确保:
|
||||
* 1. 在腾讯云短信平台设置短信签名和短信模板notify.properties已经设置正确
|
||||
* 2. 在腾讯云短信平台设置短信签名和短信模板
|
||||
@@ -32,6 +32,41 @@ import java.util.concurrent.Executor;
|
||||
@SpringBootTest
|
||||
public class SmsTest {
|
||||
|
||||
@Autowired
|
||||
private NotifyService notifyService;
|
||||
|
||||
@Test
|
||||
public void testCaptcha() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[]{"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.CAPTCHA, params);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPaySucceed() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[]{"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.PAY_SUCCEED, params);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShip() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[]{"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.SHIP, params);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefund() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[]{"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.REFUND, params);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(Application.class)
|
||||
static class ContextConfiguration {
|
||||
@@ -41,39 +76,4 @@ public class SmsTest {
|
||||
return new SyncTaskExecutor();
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private NotifyService notifyService;
|
||||
|
||||
@Test
|
||||
public void testCaptcha() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[] {"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.CAPTCHA, params);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPaySucceed() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[] {"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.PAY_SUCCEED, params);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShip() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[] {"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.SHIP, params);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefund() {
|
||||
String phone = "xxxxxxxxxxx";
|
||||
String[] params = new String[] {"123456"};
|
||||
|
||||
notifyService.notifySmsTemplate(phone, NotifyType.REFUND, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>litemall-db</artifactId>
|
||||
|
||||
@@ -4,8 +4,6 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.linlinjava.litemall.db.domain.LitemallOrder;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface OrderMapper {
|
||||
int updateWithOptimisticLocker(@Param("lastUpdateTime") LocalDateTime lastUpdateTime, @Param("order") LitemallOrder order);
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.util.Map;
|
||||
|
||||
public interface StatMapper {
|
||||
List<Map> statUser();
|
||||
|
||||
List<Map> statOrder();
|
||||
|
||||
List<Map> statGoods();
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class JsonIntegerArrayTypeHandler extends BaseTypeHandler<Integer[]> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, Integer[] parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setString(i,toJson(parameter));
|
||||
ps.setString(i, toJson(parameter));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package org.linlinjava.litemall.db.mybatis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/*
|
||||
<columnOverride column="json_string" javaType="com.fasterxml.jackson.databind.JsonNode" typeHandler="JsonNodeTypeHandler"/>
|
||||
*/
|
||||
@@ -19,62 +19,62 @@ public class JsonNodeTypeHandler extends BaseTypeHandler<com.fasterxml.jackson.d
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JsonNode parameter, JdbcType jdbcType) throws SQLException {
|
||||
String str = null;
|
||||
try {
|
||||
str = mapper.writeValueAsString(parameter);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
str = "{}";
|
||||
}
|
||||
ps.setString(i, str);
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JsonNode parameter, JdbcType jdbcType) throws SQLException {
|
||||
String str = null;
|
||||
try {
|
||||
str = mapper.writeValueAsString(parameter);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
str = "{}";
|
||||
}
|
||||
ps.setString(i, str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String jsonSource = rs.getString(columnName);
|
||||
if(jsonSource == null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JsonNode jsonNode = mapper.readTree(jsonSource);
|
||||
return jsonNode;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@Override
|
||||
public JsonNode getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String jsonSource = rs.getString(columnName);
|
||||
if (jsonSource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String jsonSource = rs.getString(columnIndex);
|
||||
if(jsonSource == null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JsonNode jsonNode = mapper.readTree(jsonSource);
|
||||
return jsonNode;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
try {
|
||||
JsonNode jsonNode = mapper.readTree(jsonSource);
|
||||
return jsonNode;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String jsonSource = cs.getString(columnIndex);
|
||||
if(jsonSource == null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JsonNode jsonNode = mapper.readTree(jsonSource);
|
||||
return jsonNode;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@Override
|
||||
public JsonNode getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String jsonSource = rs.getString(columnIndex);
|
||||
if (jsonSource == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JsonNode jsonNode = mapper.readTree(jsonSource);
|
||||
return jsonNode;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String jsonSource = cs.getString(columnIndex);
|
||||
if (jsonSource == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JsonNode jsonNode = mapper.readTree(jsonSource);
|
||||
return jsonNode;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package org.linlinjava.litemall.db.mybatis;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -20,13 +17,13 @@ public class JsonStringArrayTypeHandler extends BaseTypeHandler<String[]> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, String[] parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setString(i,toJson(parameter));
|
||||
ps.setString(i, toJson(parameter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return this.toObject(rs.getString(columnName));
|
||||
}
|
||||
@Override
|
||||
public String[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return this.toObject(rs.getString(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.dao.LitemallAdMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallAd;
|
||||
import org.linlinjava.litemall.db.domain.LitemallAdExample;
|
||||
import org.linlinjava.litemall.db.dao.LitemallAdMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
@@ -60,10 +60,10 @@ public class LitemallAddressService {
|
||||
LitemallAddressExample example = new LitemallAddressExample();
|
||||
LitemallAddressExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(userId != null){
|
||||
if (userId != null) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -80,14 +80,14 @@ public class LitemallAddressService {
|
||||
LitemallAddressExample example = new LitemallAddressExample();
|
||||
LitemallAddressExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(userId != null){
|
||||
if (userId != null) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)addressMapper.countByExample(example);
|
||||
return (int) addressMapper.countByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LitemallAdminService {
|
||||
private final Column[] result = new Column[]{Column.id, Column.username, Column.avatar};
|
||||
@Resource
|
||||
private LitemallAdminMapper adminMapper;
|
||||
|
||||
@@ -27,12 +28,11 @@ public class LitemallAdminService {
|
||||
return adminMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
private final Column[] result = new Column[]{Column.id, Column.username, Column.avatar};
|
||||
public List<LitemallAdmin> querySelective(String username, Integer page, Integer limit, String sort, String order) {
|
||||
LitemallAdminExample example = new LitemallAdminExample();
|
||||
LitemallAdminExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(username)){
|
||||
if (!StringUtils.isEmpty(username)) {
|
||||
criteria.andUsernameLike("%" + username + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -40,7 +40,7 @@ public class LitemallAdminService {
|
||||
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
|
||||
example.setOrderByClause(sort + " " + order);
|
||||
}
|
||||
|
||||
|
||||
PageHelper.startPage(page, limit);
|
||||
return adminMapper.selectByExampleSelective(example, result);
|
||||
}
|
||||
@@ -49,12 +49,12 @@ public class LitemallAdminService {
|
||||
LitemallAdminExample example = new LitemallAdminExample();
|
||||
LitemallAdminExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(username)){
|
||||
if (!StringUtils.isEmpty(username)) {
|
||||
criteria.andUsernameLike("%" + username + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)adminMapper.countByExample(example);
|
||||
return (int) adminMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public int updateById(LitemallAdmin admin) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallBrandExample;
|
||||
import org.linlinjava.litemall.db.dao.LitemallBrandMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallBrand.Column;
|
||||
import org.linlinjava.litemall.db.domain.LitemallBrand;
|
||||
import org.linlinjava.litemall.db.domain.LitemallBrand.Column;
|
||||
import org.linlinjava.litemall.db.domain.LitemallBrandExample;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
@@ -77,10 +77,10 @@ public class LitemallCartService {
|
||||
LitemallCartExample example = new LitemallCartExample();
|
||||
LitemallCartExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(!StringUtils.isEmpty(goodsId)){
|
||||
if (!StringUtils.isEmpty(goodsId)) {
|
||||
criteria.andGoodsIdEqualTo(goodsId);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -97,15 +97,15 @@ public class LitemallCartService {
|
||||
LitemallCartExample example = new LitemallCartExample();
|
||||
LitemallCartExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(userId != null){
|
||||
if (userId != null) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(goodsId != null){
|
||||
if (goodsId != null) {
|
||||
criteria.andGoodsIdEqualTo(goodsId);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)cartMapper.countByExample(example);
|
||||
return (int) cartMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
public class LitemallCategoryService {
|
||||
@Resource
|
||||
private LitemallCategoryMapper categoryMapper;
|
||||
private LitemallCategory.Column[] CHANNEL = {LitemallCategory.Column.id, LitemallCategory.Column.name, LitemallCategory.Column.iconUrl};
|
||||
|
||||
public List<LitemallCategory> queryL1WithoutRecommend(int offset, int limit) {
|
||||
LitemallCategoryExample example = new LitemallCategoryExample();
|
||||
@@ -56,10 +57,10 @@ public class LitemallCategoryService {
|
||||
LitemallCategoryExample example = new LitemallCategoryExample();
|
||||
LitemallCategoryExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(id)){
|
||||
if (!StringUtils.isEmpty(id)) {
|
||||
criteria.andIdEqualTo(Integer.valueOf(id));
|
||||
}
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -76,15 +77,15 @@ public class LitemallCategoryService {
|
||||
LitemallCategoryExample example = new LitemallCategoryExample();
|
||||
LitemallCategoryExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(id)){
|
||||
if (!StringUtils.isEmpty(id)) {
|
||||
criteria.andIdEqualTo(Integer.valueOf(id));
|
||||
}
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)categoryMapper.countByExample(example);
|
||||
return (int) categoryMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public int updateById(LitemallCategory category) {
|
||||
@@ -102,7 +103,6 @@ public class LitemallCategoryService {
|
||||
categoryMapper.insertSelective(category);
|
||||
}
|
||||
|
||||
private LitemallCategory.Column[] CHANNEL = {LitemallCategory.Column.id, LitemallCategory.Column.name, LitemallCategory.Column.iconUrl};
|
||||
public List<LitemallCategory> queryChannel() {
|
||||
LitemallCategoryExample example = new LitemallCategoryExample();
|
||||
example.or().andLevelEqualTo("L1").andDeletedEqualTo(false);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCollect;
|
||||
import org.linlinjava.litemall.db.dao.LitemallCollectMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCollect;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCollectExample;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -19,7 +19,7 @@ public class LitemallCollectService {
|
||||
public int count(int uid, Integer gid) {
|
||||
LitemallCollectExample example = new LitemallCollectExample();
|
||||
example.or().andUserIdEqualTo(uid).andValueIdEqualTo(gid).andDeletedEqualTo(false);
|
||||
return (int)collectMapper.countByExample(example);
|
||||
return (int) collectMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public List<LitemallCollect> queryByType(Integer userId, Byte type, Integer page, Integer size) {
|
||||
@@ -33,7 +33,7 @@ public class LitemallCollectService {
|
||||
public int countByType(Integer userId, Byte type) {
|
||||
LitemallCollectExample example = new LitemallCollectExample();
|
||||
example.or().andUserIdEqualTo(userId).andTypeEqualTo(type).andDeletedEqualTo(false);
|
||||
return (int)collectMapper.countByExample(example);
|
||||
return (int) collectMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public LitemallCollect queryByTypeAndValue(Integer userId, Byte type, Integer valueId) {
|
||||
@@ -56,10 +56,10 @@ public class LitemallCollectService {
|
||||
LitemallCollectExample example = new LitemallCollectExample();
|
||||
LitemallCollectExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(valueId)){
|
||||
if (!StringUtils.isEmpty(valueId)) {
|
||||
criteria.andValueIdEqualTo(Integer.valueOf(valueId));
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -76,14 +76,14 @@ public class LitemallCollectService {
|
||||
LitemallCollectExample example = new LitemallCollectExample();
|
||||
LitemallCollectExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(valueId)){
|
||||
if (!StringUtils.isEmpty(valueId)) {
|
||||
criteria.andValueIdEqualTo(Integer.valueOf(valueId));
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)collectMapper.countByExample(example);
|
||||
return (int) collectMapper.countByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.linlinjava.litemall.db.dao.LitemallCommentMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallComment;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCommentExample;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -20,45 +19,41 @@ public class LitemallCommentService {
|
||||
public List<LitemallComment> queryGoodsByGid(Integer id, int offset, int limit) {
|
||||
LitemallCommentExample example = new LitemallCommentExample();
|
||||
example.setOrderByClause(LitemallComment.Column.addTime.desc());
|
||||
example.or().andValueIdEqualTo(id).andTypeEqualTo((byte)0).andDeletedEqualTo(false);
|
||||
example.or().andValueIdEqualTo(id).andTypeEqualTo((byte) 0).andDeletedEqualTo(false);
|
||||
PageHelper.startPage(offset, limit);
|
||||
return commentMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public int countGoodsByGid(Integer id, int offset, int limit) {
|
||||
LitemallCommentExample example = new LitemallCommentExample();
|
||||
example.or().andValueIdEqualTo(id).andTypeEqualTo((byte)0).andDeletedEqualTo(false);
|
||||
return (int)commentMapper.countByExample(example);
|
||||
example.or().andValueIdEqualTo(id).andTypeEqualTo((byte) 0).andDeletedEqualTo(false);
|
||||
return (int) commentMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public List<LitemallComment> query(Byte type, Integer valueId, Integer showType, Integer offset, Integer limit) {
|
||||
LitemallCommentExample example = new LitemallCommentExample();
|
||||
example.setOrderByClause(LitemallComment.Column.addTime.desc());
|
||||
if(showType == 0) {
|
||||
if (showType == 0) {
|
||||
example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andDeletedEqualTo(false);
|
||||
}
|
||||
else if(showType == 1){
|
||||
} else if (showType == 1) {
|
||||
example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw new RuntimeException("showType不支持");
|
||||
}
|
||||
PageHelper.startPage(offset, limit);
|
||||
return commentMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public int count(Byte type, Integer valueId, Integer showType, Integer offset, Integer size){
|
||||
public int count(Byte type, Integer valueId, Integer showType, Integer offset, Integer size) {
|
||||
LitemallCommentExample example = new LitemallCommentExample();
|
||||
if(showType == 0) {
|
||||
if (showType == 0) {
|
||||
example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andDeletedEqualTo(false);
|
||||
}
|
||||
else if(showType == 1){
|
||||
} else if (showType == 1) {
|
||||
example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw new RuntimeException("showType不支持");
|
||||
}
|
||||
return (int)commentMapper.countByExample(example);
|
||||
return (int) commentMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public int save(LitemallComment comment) {
|
||||
@@ -72,13 +67,13 @@ public class LitemallCommentService {
|
||||
LitemallCommentExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
// type=2 是订单商品回复,这里过滤
|
||||
criteria.andTypeNotEqualTo((byte)2);
|
||||
criteria.andTypeNotEqualTo((byte) 2);
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(valueId)){
|
||||
criteria.andValueIdEqualTo(Integer.valueOf(valueId)).andTypeEqualTo((byte)0);
|
||||
if (!StringUtils.isEmpty(valueId)) {
|
||||
criteria.andValueIdEqualTo(Integer.valueOf(valueId)).andTypeEqualTo((byte) 0);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
@@ -94,15 +89,15 @@ public class LitemallCommentService {
|
||||
LitemallCommentExample example = new LitemallCommentExample();
|
||||
LitemallCommentExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(valueId)){
|
||||
criteria.andValueIdEqualTo(Integer.valueOf(valueId)).andTypeEqualTo((byte)0);
|
||||
if (!StringUtils.isEmpty(valueId)) {
|
||||
criteria.andValueIdEqualTo(Integer.valueOf(valueId)).andTypeEqualTo((byte) 0);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)commentMapper.countByExample(example);
|
||||
return (int) commentMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
@@ -111,10 +106,10 @@ public class LitemallCommentService {
|
||||
|
||||
public String queryReply(Integer id) {
|
||||
LitemallCommentExample example = new LitemallCommentExample();
|
||||
example.or().andTypeEqualTo((byte)2).andValueIdEqualTo(id);
|
||||
example.or().andTypeEqualTo((byte) 2).andValueIdEqualTo(id);
|
||||
List<LitemallComment> commentReply = commentMapper.selectByExampleSelective(example, LitemallComment.Column.content);
|
||||
// 目前业务只支持回复一次
|
||||
if(commentReply.size() == 1){
|
||||
if (commentReply.size() == 1) {
|
||||
return commentReply.get(0).getContent();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -30,10 +30,10 @@ public class LitemallFeedbackService {
|
||||
LitemallFeedbackExample example = new LitemallFeedbackExample();
|
||||
LitemallFeedbackExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(userId != null){
|
||||
if (userId != null) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(!StringUtils.isEmpty(username)){
|
||||
if (!StringUtils.isEmpty(username)) {
|
||||
criteria.andUsernameLike("%" + username + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -50,13 +50,13 @@ public class LitemallFeedbackService {
|
||||
LitemallFeedbackExample example = new LitemallFeedbackExample();
|
||||
LitemallFeedbackExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(userId != null){
|
||||
if (userId != null) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(!StringUtils.isEmpty(username)){
|
||||
if (!StringUtils.isEmpty(username)) {
|
||||
criteria.andUsernameLike("%" + username + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
return (int)feedbackMapper.countByExample(example);
|
||||
return (int) feedbackMapper.countByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,17 @@ public class LitemallFootprintService {
|
||||
return footprintMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public int countByAddTime(Integer userId,Integer page, Integer size) {
|
||||
public int countByAddTime(Integer userId, Integer page, Integer size) {
|
||||
LitemallFootprintExample example = new LitemallFootprintExample();
|
||||
example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
|
||||
return (int)footprintMapper.countByExample(example);
|
||||
return (int) footprintMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public LitemallFootprint findById(Integer id) {
|
||||
return footprintMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id){
|
||||
public void deleteById(Integer id) {
|
||||
footprintMapper.logicalDeleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ public class LitemallFootprintService {
|
||||
LitemallFootprintExample example = new LitemallFootprintExample();
|
||||
LitemallFootprintExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(goodsId)){
|
||||
if (!StringUtils.isEmpty(goodsId)) {
|
||||
criteria.andGoodsIdEqualTo(Integer.valueOf(goodsId));
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -68,14 +68,14 @@ public class LitemallFootprintService {
|
||||
LitemallFootprintExample example = new LitemallFootprintExample();
|
||||
LitemallFootprintExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(goodsId)){
|
||||
if (!StringUtils.isEmpty(goodsId)) {
|
||||
criteria.andGoodsIdEqualTo(Integer.valueOf(goodsId));
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)footprintMapper.countByExample(example);
|
||||
return (int) footprintMapper.countByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.dao.LitemallGoodsAttributeMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsAttribute;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsAttributeExample;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class LitemallGoodsProductService {
|
||||
public int count() {
|
||||
LitemallGoodsProductExample example = new LitemallGoodsProductExample();
|
||||
example.or().andDeletedEqualTo(false);
|
||||
return (int)goodsProductMapper.countByExample(example);
|
||||
return (int) goodsProductMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public void deleteByGid(Integer gid) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.dao.LitemallGoodsMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoods;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoods.Column;
|
||||
import org.linlinjava.litemall.db.dao.LitemallGoodsMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsExample;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -15,11 +15,10 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LitemallGoodsService {
|
||||
Column[] columns = new Column[]{Column.id, Column.name, Column.brief, Column.picUrl, Column.isHot, Column.isNew, Column.counterPrice, Column.retailPrice};
|
||||
@Resource
|
||||
private LitemallGoodsMapper goodsMapper;
|
||||
|
||||
Column[] columns = new Column[]{Column.id, Column.name, Column.brief, Column.picUrl, Column.isHot, Column.isNew, Column.counterPrice, Column.retailPrice};
|
||||
|
||||
/**
|
||||
* 获取热卖商品
|
||||
*
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.dao.LitemallGoodsSpecificationMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecification;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecificationExample;
|
||||
@@ -40,18 +39,59 @@ public class LitemallGoodsSpecificationService {
|
||||
goodsSpecificationMapper.insertSelective(goodsSpecification);
|
||||
}
|
||||
|
||||
/**
|
||||
* [
|
||||
* {
|
||||
* name: '',
|
||||
* valueList: [ {}, {}]
|
||||
* },
|
||||
* {
|
||||
* name: '',
|
||||
* valueList: [ {}, {}]
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Object getSpecificationVoList(Integer id) {
|
||||
List<LitemallGoodsSpecification> goodsSpecificationList = queryByGid(id);
|
||||
|
||||
Map<String, VO> map = new HashMap<>();
|
||||
List<VO> specificationVoList = new ArrayList<>();
|
||||
|
||||
for (LitemallGoodsSpecification goodsSpecification : goodsSpecificationList) {
|
||||
String specification = goodsSpecification.getSpecification();
|
||||
VO goodsSpecificationVo = map.get(specification);
|
||||
if (goodsSpecificationVo == null) {
|
||||
goodsSpecificationVo = new VO();
|
||||
goodsSpecificationVo.setName(specification);
|
||||
List<LitemallGoodsSpecification> valueList = new ArrayList<>();
|
||||
valueList.add(goodsSpecification);
|
||||
goodsSpecificationVo.setValueList(valueList);
|
||||
map.put(specification, goodsSpecificationVo);
|
||||
specificationVoList.add(goodsSpecificationVo);
|
||||
} else {
|
||||
List<LitemallGoodsSpecification> valueList = goodsSpecificationVo.getValueList();
|
||||
valueList.add(goodsSpecification);
|
||||
}
|
||||
}
|
||||
|
||||
return specificationVoList;
|
||||
}
|
||||
|
||||
private class VO {
|
||||
private String name;
|
||||
private List<LitemallGoodsSpecification> valueList;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<LitemallGoodsSpecification> getValueList() {
|
||||
return valueList;
|
||||
}
|
||||
@@ -61,46 +101,4 @@ public class LitemallGoodsSpecificationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [
|
||||
* {
|
||||
* name: '',
|
||||
* valueList: [ {}, {}]
|
||||
* },
|
||||
* {
|
||||
* name: '',
|
||||
* valueList: [ {}, {}]
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Object getSpecificationVoList(Integer id) {
|
||||
List<LitemallGoodsSpecification> goodsSpecificationList = queryByGid(id);
|
||||
|
||||
Map<String, VO> map = new HashMap<>();
|
||||
List<VO> specificationVoList = new ArrayList<>();
|
||||
|
||||
for(LitemallGoodsSpecification goodsSpecification : goodsSpecificationList){
|
||||
String specification = goodsSpecification.getSpecification();
|
||||
VO goodsSpecificationVo = map.get(specification);
|
||||
if(goodsSpecificationVo == null){
|
||||
goodsSpecificationVo = new VO();
|
||||
goodsSpecificationVo.setName(specification);
|
||||
List<LitemallGoodsSpecification> valueList = new ArrayList<>();
|
||||
valueList.add(goodsSpecification);
|
||||
goodsSpecificationVo.setValueList(valueList);
|
||||
map.put(specification, goodsSpecificationVo);
|
||||
specificationVoList.add(goodsSpecificationVo);
|
||||
}
|
||||
else{
|
||||
List<LitemallGoodsSpecification> valueList = goodsSpecificationVo.getValueList();
|
||||
valueList.add(goodsSpecification);
|
||||
}
|
||||
}
|
||||
|
||||
return specificationVoList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class LitemallGrouponRulesService {
|
||||
private LitemallGrouponRulesMapper mapper;
|
||||
@Resource
|
||||
private LitemallGoodsMapper goodsMapper;
|
||||
private LitemallGoods.Column[] goodsColumns = new LitemallGoods.Column[]{LitemallGoods.Column.id, LitemallGoods.Column.name, LitemallGoods.Column.brief, LitemallGoods.Column.picUrl, LitemallGoods.Column.counterPrice, LitemallGoods.Column.retailPrice};
|
||||
|
||||
public int createRules(LitemallGrouponRules rules) {
|
||||
rules.setAddTime(LocalDateTime.now());
|
||||
@@ -64,7 +65,6 @@ public class LitemallGrouponRulesService {
|
||||
return queryList(offset, limit, "add_time", "desc");
|
||||
}
|
||||
|
||||
private LitemallGoods.Column[] goodsColumns = new LitemallGoods.Column[]{LitemallGoods.Column.id, LitemallGoods.Column.name, LitemallGoods.Column.brief, LitemallGoods.Column.picUrl, LitemallGoods.Column.counterPrice, LitemallGoods.Column.retailPrice};
|
||||
public List<Map<String, Object>> queryList(int offset, int limit, String sort, String order) {
|
||||
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
|
||||
example.or().andDeletedEqualTo(false);
|
||||
@@ -72,7 +72,7 @@ public class LitemallGrouponRulesService {
|
||||
PageHelper.startPage(offset, limit);
|
||||
List<LitemallGrouponRules> grouponRules = mapper.selectByExample(example);
|
||||
|
||||
List<Map<String, Object>> grouponList = new ArrayList<>(grouponRules.size());
|
||||
List<Map<String, Object>> grouponList = new ArrayList<>(grouponRules.size());
|
||||
for (LitemallGrouponRules rule : grouponRules) {
|
||||
Integer goodsId = rule.getGoodsId();
|
||||
LitemallGoods goods = goodsMapper.selectByPrimaryKeySelective(goodsId, goodsColumns);
|
||||
@@ -92,7 +92,7 @@ public class LitemallGrouponRulesService {
|
||||
public int countList(int offset, int limit, String sort, String order) {
|
||||
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
|
||||
example.or().andDeletedEqualTo(false);
|
||||
return (int)mapper.countByExample(example);
|
||||
return (int) mapper.countByExample(example);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,15 +3,13 @@ package org.linlinjava.litemall.db.service;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.dao.LitemallGrouponMapper;
|
||||
import org.linlinjava.litemall.db.domain.*;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGroupon;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGrouponExample;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class LitemallGrouponService {
|
||||
|
||||
@@ -36,8 +36,8 @@ public class LitemallIssueService {
|
||||
LitemallIssueExample example = new LitemallIssueExample();
|
||||
LitemallIssueExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(question)){
|
||||
criteria.andQuestionLike("%" + question + "%" );
|
||||
if (!StringUtils.isEmpty(question)) {
|
||||
criteria.andQuestionLike("%" + question + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
@@ -53,12 +53,12 @@ public class LitemallIssueService {
|
||||
LitemallIssueExample example = new LitemallIssueExample();
|
||||
LitemallIssueExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(question)){
|
||||
criteria.andQuestionLike("%" + question + "%" );
|
||||
if (!StringUtils.isEmpty(question)) {
|
||||
criteria.andQuestionLike("%" + question + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)issueMapper.countByExample(example);
|
||||
return (int) issueMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public int updateById(LitemallIssue issue) {
|
||||
|
||||
@@ -69,7 +69,7 @@ public class LitemallKeywordService {
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
PageHelper.startPage(page, limit);
|
||||
return (int)keywordsMapper.countByExample(example);
|
||||
return (int) keywordsMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public void add(LitemallKeyword keywords) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import org.linlinjava.litemall.db.dao.LitemallOrderGoodsMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallOrder;
|
||||
import org.linlinjava.litemall.db.domain.LitemallOrderGoods;
|
||||
import org.linlinjava.litemall.db.domain.LitemallOrderGoodsExample;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -26,6 +25,7 @@ public class LitemallOrderGoodsService {
|
||||
example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
|
||||
return orderGoodsMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public List<LitemallOrderGoods> findByOidAndGid(Integer orderId, Integer goodsId) {
|
||||
LitemallOrderGoodsExample example = new LitemallOrderGoodsExample();
|
||||
example.or().andOrderIdEqualTo(orderId).andGoodsIdEqualTo(goodsId).andDeletedEqualTo(false);
|
||||
@@ -45,6 +45,6 @@ public class LitemallOrderGoodsService {
|
||||
LitemallOrderGoodsExample example = new LitemallOrderGoodsExample();
|
||||
example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
|
||||
long count = orderGoodsMapper.countByExample(example);
|
||||
return (short)count;
|
||||
return (short) count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class LitemallOrderService {
|
||||
public int count(Integer userId) {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
|
||||
return (int)litemallOrderMapper.countByExample(example);
|
||||
return (int) litemallOrderMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public LitemallOrder findById(Integer orderId) {
|
||||
@@ -52,10 +52,10 @@ public class LitemallOrderService {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public int countByOrderSn(Integer userId, String orderSn){
|
||||
public int countByOrderSn(Integer userId, String orderSn) {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false);
|
||||
return (int)litemallOrderMapper.countByExample(example);
|
||||
return (int) litemallOrderMapper.countByExample(example);
|
||||
}
|
||||
|
||||
// TODO 这里应该产生一个唯一的订单,但是实际上这里仍然存在两个订单相同的可能性
|
||||
@@ -63,7 +63,7 @@ public class LitemallOrderService {
|
||||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
String now = df.format(LocalDate.now());
|
||||
String orderSn = now + getRandomNum(6);
|
||||
while(countByOrderSn(userId, orderSn) != 0){
|
||||
while (countByOrderSn(userId, orderSn) != 0) {
|
||||
orderSn = getRandomNum(6);
|
||||
}
|
||||
return orderSn;
|
||||
@@ -74,7 +74,7 @@ public class LitemallOrderService {
|
||||
example.setOrderByClause(LitemallOrder.Column.addTime.desc());
|
||||
LitemallOrderExample.Criteria criteria = example.or();
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
if(orderStatus != null) {
|
||||
if (orderStatus != null) {
|
||||
criteria.andOrderStatusIn(orderStatus);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -85,24 +85,24 @@ public class LitemallOrderService {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
LitemallOrderExample.Criteria criteria = example.or();
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
if(orderStatus != null) {
|
||||
if (orderStatus != null) {
|
||||
criteria.andOrderStatusIn(orderStatus);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
return (int)litemallOrderMapper.countByExample(example);
|
||||
return (int) litemallOrderMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public List<LitemallOrder> querySelective(Integer userId, String orderSn, List<Short> orderStatusArray, Integer page, Integer size, String sort, String order) {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
LitemallOrderExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(userId != null){
|
||||
if (userId != null) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(!StringUtils.isEmpty(orderSn)){
|
||||
if (!StringUtils.isEmpty(orderSn)) {
|
||||
criteria.andOrderSnEqualTo(orderSn);
|
||||
}
|
||||
if(orderStatusArray != null && orderStatusArray.size() != 0){
|
||||
if (orderStatusArray != null && orderStatusArray.size() != 0) {
|
||||
criteria.andOrderStatusIn(orderStatusArray);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -119,15 +119,15 @@ public class LitemallOrderService {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
LitemallOrderExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(userId != null){
|
||||
if (userId != null) {
|
||||
criteria.andUserIdEqualTo(userId);
|
||||
}
|
||||
if(!StringUtils.isEmpty(orderSn)){
|
||||
if (!StringUtils.isEmpty(orderSn)) {
|
||||
criteria.andOrderSnEqualTo(orderSn);
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)litemallOrderMapper.countByExample(example);
|
||||
return (int) litemallOrderMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public int updateWithOptimisticLocker(LitemallOrder order) {
|
||||
@@ -143,7 +143,7 @@ public class LitemallOrderService {
|
||||
public int count() {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
example.or().andDeletedEqualTo(false);
|
||||
return (int)litemallOrderMapper.countByExample(example);
|
||||
return (int) litemallOrderMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public List<LitemallOrder> queryUnpaid() {
|
||||
@@ -164,7 +164,7 @@ public class LitemallOrderService {
|
||||
return litemallOrderMapper.selectOneByExample(example);
|
||||
}
|
||||
|
||||
public Map<Object, Object> orderInfo(Integer userId){
|
||||
public Map<Object, Object> orderInfo(Integer userId) {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
|
||||
List<LitemallOrder> orders = litemallOrderMapper.selectByExampleSelective(example, LitemallOrder.Column.orderStatus, LitemallOrder.Column.comments);
|
||||
@@ -173,20 +173,16 @@ public class LitemallOrderService {
|
||||
int unship = 0;
|
||||
int unrecv = 0;
|
||||
int uncomment = 0;
|
||||
for(LitemallOrder order : orders){
|
||||
if(OrderUtil.isCreateStatus(order)){
|
||||
for (LitemallOrder order : orders) {
|
||||
if (OrderUtil.isCreateStatus(order)) {
|
||||
unpaid++;
|
||||
}
|
||||
else if(OrderUtil.isPayStatus(order)){
|
||||
} else if (OrderUtil.isPayStatus(order)) {
|
||||
unship++;
|
||||
}
|
||||
else if(OrderUtil.isShipStatus(order)){
|
||||
} else if (OrderUtil.isShipStatus(order)) {
|
||||
unrecv++;
|
||||
}
|
||||
else if(OrderUtil.isConfirmStatus(order) || OrderUtil.isAutoConfirmStatus(order)){
|
||||
} else if (OrderUtil.isConfirmStatus(order) || OrderUtil.isAutoConfirmStatus(order)) {
|
||||
uncomment += order.getComments();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -202,7 +198,7 @@ public class LitemallOrderService {
|
||||
|
||||
public List<LitemallOrder> queryComment() {
|
||||
LitemallOrderExample example = new LitemallOrderExample();
|
||||
example.or().andCommentsGreaterThan((short)0).andDeletedEqualTo(false);
|
||||
example.or().andCommentsGreaterThan((short) 0).andDeletedEqualTo(false);
|
||||
return litemallOrderMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.linlinjava.litemall.db.service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.linlinjava.litemall.db.dao.*;
|
||||
import org.linlinjava.litemall.db.dao.LitemallRegionMapper;
|
||||
import org.linlinjava.litemall.db.domain.LitemallRegion;
|
||||
import org.linlinjava.litemall.db.domain.LitemallRegionExample;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -29,10 +29,10 @@ public class LitemallRegionService {
|
||||
LitemallRegionExample example = new LitemallRegionExample();
|
||||
LitemallRegionExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
if(!StringUtils.isEmpty(code)){
|
||||
if (!StringUtils.isEmpty(code)) {
|
||||
criteria.andCodeEqualTo(code);
|
||||
}
|
||||
|
||||
@@ -48,12 +48,12 @@ public class LitemallRegionService {
|
||||
LitemallRegionExample example = new LitemallRegionExample();
|
||||
LitemallRegionExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
if(code != null){
|
||||
if (code != null) {
|
||||
criteria.andCodeEqualTo(code);
|
||||
}
|
||||
return (int)regionMapper.countByExample(example);
|
||||
return (int) regionMapper.countByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,11 @@ public class LitemallSearchHistoryService {
|
||||
LitemallSearchHistoryExample example = new LitemallSearchHistoryExample();
|
||||
LitemallSearchHistoryExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(keyword)){
|
||||
criteria.andKeywordLike("%" + keyword + "%" );
|
||||
if (!StringUtils.isEmpty(keyword)) {
|
||||
criteria.andKeywordLike("%" + keyword + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
@@ -59,14 +59,14 @@ public class LitemallSearchHistoryService {
|
||||
LitemallSearchHistoryExample example = new LitemallSearchHistoryExample();
|
||||
LitemallSearchHistoryExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(userId)){
|
||||
if (!StringUtils.isEmpty(userId)) {
|
||||
criteria.andUserIdEqualTo(Integer.valueOf(userId));
|
||||
}
|
||||
if(!StringUtils.isEmpty(keyword)){
|
||||
criteria.andKeywordLike("%" + keyword + "%" );
|
||||
if (!StringUtils.isEmpty(keyword)) {
|
||||
criteria.andKeywordLike("%" + keyword + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)searchHistoryMapper.countByExample(example);
|
||||
return (int) searchHistoryMapper.countByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ public class LitemallStorageService {
|
||||
LitemallStorageExample example = new LitemallStorageExample();
|
||||
LitemallStorageExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(key)){
|
||||
if (!StringUtils.isEmpty(key)) {
|
||||
criteria.andKeyEqualTo(key);
|
||||
}
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
@@ -67,14 +67,14 @@ public class LitemallStorageService {
|
||||
LitemallStorageExample example = new LitemallStorageExample();
|
||||
LitemallStorageExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if(!StringUtils.isEmpty(key)){
|
||||
if (!StringUtils.isEmpty(key)) {
|
||||
criteria.andKeyEqualTo(key);
|
||||
}
|
||||
if(!StringUtils.isEmpty(name)){
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andNameLike("%" + name + "%");
|
||||
}
|
||||
criteria.andDeletedEqualTo(false);
|
||||
|
||||
return (int)storageMapper.countByExample(example);
|
||||
return (int) storageMapper.countByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user