diff --git a/litemall-admin-api/pom.xml b/litemall-admin-api/pom.xml index 8ee7dc92..28da2b7f 100644 --- a/litemall-admin-api/pom.xml +++ b/litemall-admin-api/pom.xml @@ -1,4 +1,4 @@ - 4.0.0 litemall-admin-api diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/Application.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/Application.java index e3810295..ecc36658 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/Application.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/Application.java @@ -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 diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/annotation/support/LoginAdminHandlerMethodArgumentResolver.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/annotation/support/LoginAdminHandlerMethodArgumentResolver.java index 0f9890b1..831d41ab 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/annotation/support/LoginAdminHandlerMethodArgumentResolver.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/annotation/support/LoginAdminHandlerMethodArgumentResolver.java @@ -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; } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/config/AdminConfig.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/config/AdminConfig.java index 4984bb24..c751c737 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/config/AdminConfig.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/config/AdminConfig.java @@ -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 diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/AdminToken.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/AdminToken.java index 1c2b2816..0a1bc0d3 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/AdminToken.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/AdminToken.java @@ -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; + } } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/GoodsAllinone.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/GoodsAllinone.java index cfea1eaa..84c037fa 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/GoodsAllinone.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/dao/GoodsAllinone.java @@ -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; } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/service/AdminTokenManager.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/service/AdminTokenManager.java index cf4dcf08..c430a87b 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/service/AdminTokenManager.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/service/AdminTokenManager.java @@ -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); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/util/StatVo.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/util/StatVo.java index a19b97f2..04005d25 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/util/StatVo.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/util/StatVo.java @@ -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)); } } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java index a09a87b4..c79786dc 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java @@ -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); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAddressController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAddressController.java index 6f25550d..125e6f76 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAddressController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAddressController.java @@ -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 toVo (LitemallAddress address){ + private Map toVo(LitemallAddress address) { Map 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> addressVoList = new ArrayList<>(addressList.size()); - for(LitemallAddress address : addressList){ + for (LitemallAddress address : addressList) { Map addressVo = toVo(address); addressVoList.add(addressVo); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdminController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdminController.java index 1a2ab299..4f7af49b 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdminController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdminController.java @@ -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 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, "超级管理员不能删除"); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAuthController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAuthController.java index 94ba96c4..c2ee5a0a 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAuthController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAuthController.java @@ -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 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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminBrandController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminBrandController.java index d781e931..7581dc64 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminBrandController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminBrandController.java @@ -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); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCategoryController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCategoryController.java index fe4df940..ee18c09e 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCategoryController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCategoryController.java @@ -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 l1CatList = categoryService.queryL1(); List> data = new ArrayList<>(l1CatList.size()); - for(LitemallCategory category : l1CatList){ + for (LitemallCategory category : l1CatList) { Map d = new HashMap<>(2); d.put("value", category.getId()); d.put("label", category.getName()); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCollectController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCollectController.java index 8e64ef1a..a3ddbab5 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCollectController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCollectController.java @@ -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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCommentController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCommentController.java index 98568529..db371a10 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCommentController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminCommentController.java @@ -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); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminDashbordController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminDashbordController.java index 3e9758c0..2cda9c28 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminDashbordController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminDashbordController.java @@ -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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFeedbackController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFeedbackController.java index c3ea914c..f551afcb 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFeedbackController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFeedbackController.java @@ -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 feedbackList = feedbackService.querySelective(userId, username, page, limit, sort, order); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFootprintController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFootprintController.java index f1172c79..d0eeb295 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFootprintController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminFootprintController.java @@ -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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGoodsController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGoodsController.java index 6c5976cd..6424252f 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGoodsController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGoodsController.java @@ -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("跟新数据失败"); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGrouponController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGrouponController.java index 6199b500..5c371d1f 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGrouponController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminGrouponController.java @@ -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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminHistoryController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminHistoryController.java index c338f366..1b014857 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminHistoryController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminHistoryController.java @@ -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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIndexController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIndexController.java index 0808c115..a9b8e9cb 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIndexController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIndexController.java @@ -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"); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIssueController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIssueController.java index b2e7ac18..9ea5b034 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIssueController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminIssueController.java @@ -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); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminKeywordController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminKeywordController.java index 20fd493e..a368c854 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminKeywordController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminKeywordController.java @@ -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); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java index 99a7ddb2..613ac15b 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java @@ -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 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 orderGoodsList = orderGoodsService.queryByOid(order.getId()); - for(LitemallOrderGoods orderGoods : orderGoodsList){ + for (LitemallOrderGoods orderGoods : orderGoodsList) { orderGoods.setComment(-1); orderGoodsService.updateById(orderGoods); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminProfileController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminProfileController.java index 8cb3c9a7..e0f141af 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminProfileController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminProfileController.java @@ -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, "账号密码不对"); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminRegionController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminRegionController.java index 446a43b9..cd86b363 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminRegionController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminRegionController.java @@ -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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStatController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStatController.java index 11f4603d..38613376 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStatController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStatController.java @@ -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(); } diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java index ab7bffc0..665344d8 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java @@ -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); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminTopicController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminTopicController.java index 3b5e0d9f..69a55d42 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminTopicController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminTopicController.java @@ -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()); diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminUserController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminUserController.java index 27be5230..b35b545a 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminUserController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminUserController.java @@ -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 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 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); diff --git a/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/BcryptTest.java b/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/BcryptTest.java index 7fb0d867..937b7b9b 100644 --- a/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/BcryptTest.java +++ b/litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/BcryptTest.java @@ -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); diff --git a/litemall-all/pom.xml b/litemall-all/pom.xml index a2db2efc..7c4c9139 100644 --- a/litemall-all/pom.xml +++ b/litemall-all/pom.xml @@ -1,4 +1,4 @@ - 4.0.0 litemall-all diff --git a/litemall-core/pom.xml b/litemall-core/pom.xml index 256f1eb8..9efeb1a4 100644 --- a/litemall-core/pom.xml +++ b/litemall-core/pom.xml @@ -1,4 +1,4 @@ - 4.0.0 litemall-core diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java index 037aa1ca..e14e6227 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java @@ -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> 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(); } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/ValidatorConfiguration.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/ValidatorConfiguration.java index 8b7b481a..73cc4743 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/ValidatorConfiguration.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/ValidatorConfiguration.java @@ -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(); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java index 08c68e6c..4e7458ff 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java @@ -16,7 +16,7 @@ public class ExpressAutoConfiguration { } @Bean - public ExpressService expressService(){ + public ExpressService expressService() { ExpressService expressService = new ExpressService(); expressService.setProperties(properties); return expressService; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressProperties.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressProperties.java index 84479440..034cf963 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressProperties.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressProperties.java @@ -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> 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> vendors = new ArrayList<>(); - public List> getVendors() { return vendors; } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/ExpressInfo.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/ExpressInfo.java index ce1e4512..d281385d 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/ExpressInfo.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/ExpressInfo.java @@ -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) { - this.Traces = Traces; + public void setShipperCode(String ShipperCode) { + this.ShipperCode = ShipperCode; } public List getTraces() { return Traces; } - public void setState(String State) { - this.State = State; + public void setTraces(List 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; } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/Traces.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/Traces.java index 6c9510f9..24a070de 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/Traces.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/Traces.java @@ -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; + } + } \ No newline at end of file diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java index 3e7b76fe..233ba4c8 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java @@ -22,15 +22,15 @@ public class NotifyService { private WxTemplateSender wxTemplateSender; private List> 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; } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyType.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyType.java index 2d9e7579..ae599627 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyType.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyType.java @@ -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; } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java index afee89cf..7d15154c 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java @@ -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; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java index ad0c2feb..448e0d2a 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java @@ -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) { diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyAutoConfiguration.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyAutoConfiguration.java index 17b31377..43e22ec5 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyAutoConfiguration.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyAutoConfiguration.java @@ -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())); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyProperties.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyProperties.java index 7e1eba94..878afc48 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyProperties.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyProperties.java @@ -97,7 +97,7 @@ public class NotifyProperties { private boolean enable; private int appid; private String appkey; - private List> template = new ArrayList<>(); + private List> template = new ArrayList<>(); public boolean isEnable() { return enable; @@ -134,7 +134,7 @@ public class NotifyProperties { public static class Wx { private boolean enable; - private List> template = new ArrayList<>(); + private List> template = new ArrayList<>(); public boolean isEnable() { return enable; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeGoodShare.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeGoodShare.java index 21570675..23b3ea64 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeGoodShare.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeGoodShare.java @@ -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 { diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java index 432b7f46..7a3d87ef 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java @@ -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(); } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java index d5301728..cf307cba 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java @@ -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(); } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/Storage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/Storage.java index 1e0e3fe5..6c3ce0c8 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/Storage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/Storage.java @@ -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); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java index c063b110..2b642908 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java @@ -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; /** diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java index 625aa554..b4e3e300 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java @@ -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(); } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java index 0f06f900..20ecae2b 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java @@ -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()); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageProperties.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageProperties.java index b2f7d9b7..a2c8b7b7 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageProperties.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageProperties.java @@ -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; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/system/BaseConfig.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/system/BaseConfig.java index 41710c77..7f6784ca 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/system/BaseConfig.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/system/BaseConfig.java @@ -13,13 +13,6 @@ abstract class BaseConfig { //所有的配置均保存在该 HashMap 中 protected static Map 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(); } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/system/ConfigService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/system/ConfigService.java index 326f0351..d1448272 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/system/ConfigService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/system/ConfigService.java @@ -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; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java index 692570d6..890c1591 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java @@ -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>(){}); + if (leaf != null) + return mapper.convertValue(leaf, new TypeReference>() { + }); } 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>(){}); + if (leaf != null) + return mapper.convertValue(leaf, new TypeReference>() { + }); } 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(); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java index ec8b0030..3fbbf07e 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java @@ -25,46 +25,46 @@ public class RegexUtil { *

global star: 1349

*

virtual operator: 170

*/ - 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. *

scope for "a-z", "A-Z", "0-9", "_", "Chinese character"

*

can't end with "_"

*

length is between 6 to 20

*/ - public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?not 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; - } } \ No newline at end of file diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/bcrypt/BCryptPasswordEncoder.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/bcrypt/BCryptPasswordEncoder.java index 58a4b3f0..8a75e203 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/bcrypt/BCryptPasswordEncoder.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/bcrypt/BCryptPasswordEncoder.java @@ -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); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Order.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Order.java index 7dcafeeb..dfbaa2b3 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Order.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Order.java @@ -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 {}; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java index 2066c3b2..7511c0a2 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java @@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext; import java.util.ArrayList; import java.util.List; -public class OrderValidator implements ConstraintValidator{ +public class OrderValidator implements ConstraintValidator { private List valueList; @Override public void initialize(Order order) { valueList = new ArrayList(); - 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; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Sort.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Sort.java index 572d33ac..2568e709 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Sort.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/Sort.java @@ -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 {}; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java index e2601647..4d8bf7e2 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java @@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext; import java.util.ArrayList; import java.util.List; -public class SortValidator implements ConstraintValidator{ +public class SortValidator implements ConstraintValidator { private List valueList; @Override public void initialize(Sort sort) { valueList = new ArrayList(); - 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; diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java index 51ec0507..6623e039 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java @@ -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; diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTest.java index cb51c0cb..5a6ca9c4 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTest.java @@ -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() { diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java index 8e39629f..3d89bcf6 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java @@ -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; diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java index 37cc54f2..160df655 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java @@ -17,19 +17,27 @@ import java.util.concurrent.Executor; /** * 测试邮件发送服务 - * + *

* 注意LitemallNotifyService采用异步线程操作 * 因此测试的时候需要睡眠一会儿,保证任务执行 - * - * 开发者需要确保: - * 1. 在相应的邮件服务器设置正确notify.properties已经设置正确 - * 2. 在相应的邮件服务器设置正确 + *

+ * 开发者需要确保: + * 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已付款,请发货"); - } - } diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java index 400c295b..331dc866 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java @@ -18,10 +18,10 @@ import java.util.concurrent.Executor; /** * 测试短信发送服务 - * + *

* 注意LitemallNotifyService采用异步线程操作 * 因此测试的时候需要睡眠一会儿,保证任务执行 - * + *

* 开发者需要确保: * 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); - } } diff --git a/litemall-db/pom.xml b/litemall-db/pom.xml index 77d0e7c7..40f00e77 100644 --- a/litemall-db/pom.xml +++ b/litemall-db/pom.xml @@ -1,4 +1,4 @@ - 4.0.0 litemall-db diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/OrderMapper.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/OrderMapper.java index 333fe8c9..bdb8da5c 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/OrderMapper.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/OrderMapper.java @@ -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); diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/StatMapper.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/StatMapper.java index b1f65e92..d42715e7 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/StatMapper.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/dao/StatMapper.java @@ -5,6 +5,8 @@ import java.util.Map; public interface StatMapper { List statUser(); + List statOrder(); + List statGoods(); } \ No newline at end of file diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonIntegerArrayTypeHandler.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonIntegerArrayTypeHandler.java index 6cd9620a..1c1e8188 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonIntegerArrayTypeHandler.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonIntegerArrayTypeHandler.java @@ -17,7 +17,7 @@ public class JsonIntegerArrayTypeHandler extends BaseTypeHandler { @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 diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonNodeTypeHandler.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonNodeTypeHandler.java index 82575bbd..982f7bd7 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonNodeTypeHandler.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/mybatis/JsonNodeTypeHandler.java @@ -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; + /* */ @@ -19,62 +19,62 @@ public class JsonNodeTypeHandler extends BaseTypeHandler { @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 { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java index f23122ca..0dbd202c 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java @@ -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; diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAddressService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAddressService.java index 0c0b5ade..93c7c8da 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAddressService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAddressService.java @@ -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); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java index 16e7c4ac..317c25fb 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java @@ -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 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) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java index 13b3e888..3229f201 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java @@ -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; diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java index 032c769c..15ea6743 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java @@ -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) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java index f2b0e36e..bb24da7d 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java @@ -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 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 queryChannel() { LitemallCategoryExample example = new LitemallCategoryExample(); example.or().andLevelEqualTo("L1").andDeletedEqualTo(false); diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java index 9336a0f4..23ba015e 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java @@ -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 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); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java index 5fc49a03..1c2767d9 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java @@ -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 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 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 commentReply = commentMapper.selectByExampleSelective(example, LitemallComment.Column.content); // 目前业务只支持回复一次 - if(commentReply.size() == 1){ + if (commentReply.size() == 1) { return commentReply.get(0).getContent(); } return null; diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFeedbackService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFeedbackService.java index 16463a31..005496b2 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFeedbackService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFeedbackService.java @@ -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); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFootprintService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFootprintService.java index 63d26340..da27087b 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFootprintService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFootprintService.java @@ -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); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java index 06e86fca..14f9e955 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java @@ -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; diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsProductService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsProductService.java index d4cb06ab..afcd76a2 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsProductService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsProductService.java @@ -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) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java index a7fdf228..1ff3e24c 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java @@ -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}; - /** * 获取热卖商品 * diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java index d1d913ba..501c3730 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java @@ -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 goodsSpecificationList = queryByGid(id); + + Map map = new HashMap<>(); + List 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 valueList = new ArrayList<>(); + valueList.add(goodsSpecification); + goodsSpecificationVo.setValueList(valueList); + map.put(specification, goodsSpecificationVo); + specificationVoList.add(goodsSpecificationVo); + } else { + List valueList = goodsSpecificationVo.getValueList(); + valueList.add(goodsSpecification); + } + } + + return specificationVoList; + } + private class VO { private String name; private List valueList; - public void setName(String name) { - this.name = name; - } - public String getName() { return name; } + public void setName(String name) { + this.name = name; + } + public List getValueList() { return valueList; } @@ -61,46 +101,4 @@ public class LitemallGoodsSpecificationService { } } - /** - * [ - * { - * name: '', - * valueList: [ {}, {}] - * }, - * { - * name: '', - * valueList: [ {}, {}] - * } - * ] - * - * @param id - * @return - */ - public Object getSpecificationVoList(Integer id) { - List goodsSpecificationList = queryByGid(id); - - Map map = new HashMap<>(); - List 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 valueList = new ArrayList<>(); - valueList.add(goodsSpecification); - goodsSpecificationVo.setValueList(valueList); - map.put(specification, goodsSpecificationVo); - specificationVoList.add(goodsSpecificationVo); - } - else{ - List valueList = goodsSpecificationVo.getValueList(); - valueList.add(goodsSpecification); - } - } - - return specificationVoList; - } - } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java index 262033d7..c3472efe 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java @@ -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> 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 grouponRules = mapper.selectByExample(example); - List> grouponList = new ArrayList<>(grouponRules.size()); + List> 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); } /** diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java index 48768573..3ddfd05e 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java @@ -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 { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java index 619a20b7..442e6719 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java @@ -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) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java index 25a43ee2..d770ac3c 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java @@ -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) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderGoodsService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderGoodsService.java index 418510dd..2374f039 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderGoodsService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderGoodsService.java @@ -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 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; } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java index 9964aa81..32836280 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java @@ -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 querySelective(Integer userId, String orderSn, List 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 queryUnpaid() { @@ -164,7 +164,7 @@ public class LitemallOrderService { return litemallOrderMapper.selectOneByExample(example); } - public Map orderInfo(Integer userId){ + public Map orderInfo(Integer userId) { LitemallOrderExample example = new LitemallOrderExample(); example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false); List 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 queryComment() { LitemallOrderExample example = new LitemallOrderExample(); - example.or().andCommentsGreaterThan((short)0).andDeletedEqualTo(false); + example.or().andCommentsGreaterThan((short) 0).andDeletedEqualTo(false); return litemallOrderMapper.selectByExample(example); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallRegionService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallRegionService.java index 99f085ef..74b4431d 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallRegionService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallRegionService.java @@ -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); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSearchHistoryService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSearchHistoryService.java index 3785d300..e6a1277f 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSearchHistoryService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSearchHistoryService.java @@ -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); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java index 39c7706d..2fb244d3 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java @@ -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); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java index c25e7df8..ce053fc3 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java @@ -7,11 +7,10 @@ import org.linlinjava.litemall.db.domain.LitemallUserExample; import org.linlinjava.litemall.db.domain.UserVo; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; + import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.HashMap; import java.util.List; -import java.util.Map; @Service public class LitemallUserService { @@ -51,10 +50,10 @@ public class LitemallUserService { LitemallUserExample example = new LitemallUserExample(); LitemallUserExample.Criteria criteria = example.createCriteria(); - if(!StringUtils.isEmpty(username)){ + if (!StringUtils.isEmpty(username)) { criteria.andUsernameLike("%" + username + "%"); } - if(!StringUtils.isEmpty(mobile)){ + if (!StringUtils.isEmpty(mobile)) { criteria.andMobileEqualTo(mobile); } criteria.andDeletedEqualTo(false); @@ -71,10 +70,10 @@ public class LitemallUserService { LitemallUserExample example = new LitemallUserExample(); LitemallUserExample.Criteria criteria = example.createCriteria(); - if(!StringUtils.isEmpty(username)){ + if (!StringUtils.isEmpty(username)) { criteria.andUsernameLike("%" + username + "%"); } - if(!StringUtils.isEmpty(mobile)){ + if (!StringUtils.isEmpty(mobile)) { criteria.andMobileEqualTo(mobile); } criteria.andDeletedEqualTo(false); @@ -86,7 +85,7 @@ public class LitemallUserService { LitemallUserExample example = new LitemallUserExample(); example.or().andDeletedEqualTo(false); - return (int)userMapper.countByExample(example); + return (int) userMapper.countByExample(example); } public List queryByUsername(String username) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/StatService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/StatService.java index ee2eb098..191278a1 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/StatService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/StatService.java @@ -17,11 +17,11 @@ public class StatService { return statMapper.statUser(); } - public List statOrder(){ + public List statOrder() { return statMapper.statOrder(); } - public List statGoods(){ + public List statGoods() { return statMapper.statGoods(); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderHandleOption.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderHandleOption.java index 3245bba5..af9dd63c 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderHandleOption.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderHandleOption.java @@ -9,60 +9,60 @@ public class OrderHandleOption { private boolean refund = false; // 取消订单并退款操作 private boolean rebuy = false; // 再次购买 - public void setCancel(boolean cancel) { - this.cancel = cancel; - } - - public void setDelete(boolean delete) { - this.delete = delete; - } - - public void setPay(boolean pay) { - this.pay = pay; - } - - public void setComment(boolean comment) { - this.comment = comment; - } - - public void setConfirm(boolean confirm) { - this.confirm = confirm; - } - - public void setRefund(boolean refund) { - this.refund = refund; - } - - public void setRebuy(boolean rebuy) { - this.rebuy = rebuy; - } - public boolean isCancel() { return cancel; } + public void setCancel(boolean cancel) { + this.cancel = cancel; + } + public boolean isDelete() { return delete; } + public void setDelete(boolean delete) { + this.delete = delete; + } + public boolean isPay() { return pay; } + public void setPay(boolean pay) { + this.pay = pay; + } + public boolean isComment() { return comment; } + public void setComment(boolean comment) { + this.comment = comment; + } + public boolean isConfirm() { return confirm; } + public void setConfirm(boolean confirm) { + this.confirm = confirm; + } + public boolean isRefund() { return refund; } + public void setRefund(boolean refund) { + this.refund = refund; + } + public boolean isRebuy() { return rebuy; } + public void setRebuy(boolean rebuy) { + this.rebuy = rebuy; + } + } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderUtil.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderUtil.java index 7f538e93..325bc8a4 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderUtil.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/util/OrderUtil.java @@ -1,7 +1,6 @@ package org.linlinjava.litemall.db.util; import org.linlinjava.litemall.db.domain.LitemallOrder; -import org.springframework.util.Assert; import java.util.ArrayList; import java.util.List; @@ -76,7 +75,7 @@ public class OrderUtil { } - public static OrderHandleOption build(LitemallOrder order){ + public static OrderHandleOption build(LitemallOrder order) { int status = order.getOrderStatus().intValue(); OrderHandleOption handleOption = new OrderHandleOption(); @@ -84,41 +83,34 @@ public class OrderUtil { // 如果订单没有被取消,且没有支付,则可支付,可取消 handleOption.setCancel(true); handleOption.setPay(true); - } - else if (status == 102 || status == 103) { + } else if (status == 102 || status == 103) { // 如果订单已经取消或是已完成,则可删除 handleOption.setDelete(true); - } - else if (status == 201) { + } else if (status == 201) { // 如果订单已付款,没有发货,则可退款 handleOption.setRefund(true); - } - else if (status == 202) { + } else if (status == 202) { // 如果订单申请退款中,没有相关操作 - } - else if (status == 203) { + } else if (status == 203) { // 如果订单已经退款,则可删除 handleOption.setDelete(true); - } - else if (status == 301) { + } else if (status == 301) { // 如果订单已经发货,没有收货,则可收货操作, // 此时不能取消订单 handleOption.setConfirm(true); - } - else if (status == 401 || status == 402) { + } else if (status == 401 || status == 402) { // 如果订单已经支付,且已经收货,则可删除、去评论和再次购买 handleOption.setDelete(true); handleOption.setComment(true); handleOption.setRebuy(true); - } - else { + } else { throw new IllegalStateException("status不支持"); } return handleOption; } - public static List orderStatus(Integer showType){ + public static List orderStatus(Integer showType) { // 全部订单 if (showType == 0) { return null; @@ -128,23 +120,19 @@ public class OrderUtil { if (showType.equals(1)) { // 待付款订单 - status.add((short)101); - } - else if (showType.equals(2)) { + status.add((short) 101); + } else if (showType.equals(2)) { // 待发货订单 - status.add((short)201); - } - else if (showType.equals(3)) { + status.add((short) 201); + } else if (showType.equals(3)) { // 待收货订单 - status.add((short)301); - } - else if (showType.equals(4)) { + status.add((short) 301); + } else if (showType.equals(4)) { // 待评价订单 - status.add((short)401); + status.add((short) 401); // 系统超时自动取消,此时应该不支持评价 // status.add((short)402); - } - else { + } else { return null; } diff --git a/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/OrderMapper.xml b/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/OrderMapper.xml index 3bb2e5e4..80757b7b 100644 --- a/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/OrderMapper.xml +++ b/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/OrderMapper.xml @@ -1,92 +1,92 @@ - - - update litemall_order - - - id = #{order.id,jdbcType=INTEGER}, - - - user_id = #{order.userId,jdbcType=INTEGER}, - - - order_sn = #{order.orderSn,jdbcType=VARCHAR}, - - - order_status = #{order.orderStatus,jdbcType=SMALLINT}, - - - consignee = #{order.consignee,jdbcType=VARCHAR}, - - - mobile = #{order.mobile,jdbcType=VARCHAR}, - - - address = #{order.address,jdbcType=VARCHAR}, - - - message = #{order.message,jdbcType=VARCHAR}, - - - goods_price = #{order.goodsPrice,jdbcType=DECIMAL}, - - - freight_price = #{order.freightPrice,jdbcType=DECIMAL}, - - - coupon_price = #{order.couponPrice,jdbcType=DECIMAL}, - - - integral_price = #{order.integralPrice,jdbcType=DECIMAL}, - - - groupon_price = #{order.grouponPrice,jdbcType=DECIMAL}, - - - order_price = #{order.orderPrice,jdbcType=DECIMAL}, - - - actual_price = #{order.actualPrice,jdbcType=DECIMAL}, - - - pay_id = #{order.payId,jdbcType=VARCHAR}, - - - pay_time = #{order.payTime,jdbcType=TIMESTAMP}, - - - ship_sn = #{order.shipSn,jdbcType=VARCHAR}, - - - ship_channel = #{order.shipChannel,jdbcType=VARCHAR}, - - - ship_time = #{order.shipTime,jdbcType=TIMESTAMP}, - - - confirm_time = #{order.confirmTime,jdbcType=TIMESTAMP}, - - - comments = #{order.comments,jdbcType=SMALLINT}, - - - end_time = #{order.endTime,jdbcType=TIMESTAMP}, - - - add_time = #{order.addTime,jdbcType=TIMESTAMP}, - - - update_time = #{order.updateTime,jdbcType=TIMESTAMP}, - - - deleted = #{order.deleted,jdbcType=BIT}, - - - where id = #{order.id,jdbcType=INTEGER} and update_time = #{lastUpdateTime,jdbcType=INTEGER} - + + + update litemall_order + + + id = #{order.id,jdbcType=INTEGER}, + + + user_id = #{order.userId,jdbcType=INTEGER}, + + + order_sn = #{order.orderSn,jdbcType=VARCHAR}, + + + order_status = #{order.orderStatus,jdbcType=SMALLINT}, + + + consignee = #{order.consignee,jdbcType=VARCHAR}, + + + mobile = #{order.mobile,jdbcType=VARCHAR}, + + + address = #{order.address,jdbcType=VARCHAR}, + + + message = #{order.message,jdbcType=VARCHAR}, + + + goods_price = #{order.goodsPrice,jdbcType=DECIMAL}, + + + freight_price = #{order.freightPrice,jdbcType=DECIMAL}, + + + coupon_price = #{order.couponPrice,jdbcType=DECIMAL}, + + + integral_price = #{order.integralPrice,jdbcType=DECIMAL}, + + + groupon_price = #{order.grouponPrice,jdbcType=DECIMAL}, + + + order_price = #{order.orderPrice,jdbcType=DECIMAL}, + + + actual_price = #{order.actualPrice,jdbcType=DECIMAL}, + + + pay_id = #{order.payId,jdbcType=VARCHAR}, + + + pay_time = #{order.payTime,jdbcType=TIMESTAMP}, + + + ship_sn = #{order.shipSn,jdbcType=VARCHAR}, + + + ship_channel = #{order.shipChannel,jdbcType=VARCHAR}, + + + ship_time = #{order.shipTime,jdbcType=TIMESTAMP}, + + + confirm_time = #{order.confirmTime,jdbcType=TIMESTAMP}, + + + comments = #{order.comments,jdbcType=SMALLINT}, + + + end_time = #{order.endTime,jdbcType=TIMESTAMP}, + + + add_time = #{order.addTime,jdbcType=TIMESTAMP}, + + + update_time = #{order.updateTime,jdbcType=TIMESTAMP}, + + + deleted = #{order.deleted,jdbcType=BIT}, + + + where id = #{order.id,jdbcType=INTEGER} and update_time = #{lastUpdateTime,jdbcType=INTEGER} + \ No newline at end of file diff --git a/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/StatMapper.xml b/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/StatMapper.xml index aa7853ec..75a91964 100644 --- a/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/StatMapper.xml +++ b/litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/StatMapper.xml @@ -1,31 +1,31 @@ - - - + + + \ No newline at end of file diff --git a/litemall-db/src/test/java/org/linlinjava/litemall/db/StatMapperTest.java b/litemall-db/src/test/java/org/linlinjava/litemall/db/StatMapperTest.java index fc3cd751..d4dfee43 100644 --- a/litemall-db/src/test/java/org/linlinjava/litemall/db/StatMapperTest.java +++ b/litemall-db/src/test/java/org/linlinjava/litemall/db/StatMapperTest.java @@ -22,7 +22,7 @@ public class StatMapperTest { @Test public void testUser() { List result = statMapper.statUser(); - for(Map m : result) { + for (Map m : result) { m.forEach((k, v) -> System.out.println("key:value = " + k + ":" + v)); } } @@ -30,7 +30,7 @@ public class StatMapperTest { @Test public void testOrder() { List result = statMapper.statOrder(); - for(Map m : result) { + for (Map m : result) { m.forEach((k, v) -> System.out.println("key:value = " + k + ":" + v)); } } @@ -38,7 +38,7 @@ public class StatMapperTest { @Test public void testGoods() { List result = statMapper.statGoods(); - for(Map m : result) { + for (Map m : result) { m.forEach((k, v) -> System.out.println("key:value = " + k + ":" + v)); } } diff --git a/litemall-wx-api/pom.xml b/litemall-wx-api/pom.xml index 51849a25..84802689 100644 --- a/litemall-wx-api/pom.xml +++ b/litemall-wx-api/pom.xml @@ -1,4 +1,4 @@ - 4.0.0 litemall-wx-api diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/Application.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/Application.java index f079f22f..92367b11 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/Application.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/Application.java @@ -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.wx","org.linlinjava.litemall.db"}) +@SpringBootApplication(scanBasePackages = {"org.linlinjava.litemall.core", "org.linlinjava.litemall.wx", "org.linlinjava.litemall.db"}) @MapperScan("org.linlinjava.litemall.db.dao") @EnableTransactionManagement @EnableScheduling diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/annotation/support/LoginUserHandlerMethodArgumentResolver.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/annotation/support/LoginUserHandlerMethodArgumentResolver.java index ac50aab7..9c244aa6 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/annotation/support/LoginUserHandlerMethodArgumentResolver.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/annotation/support/LoginUserHandlerMethodArgumentResolver.java @@ -11,9 +11,10 @@ import org.springframework.web.method.support.ModelAndViewContainer; public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { public static final String LOGIN_TOKEN_KEY = "X-Litemall-Token"; + @Override public boolean supportsParameter(MethodParameter parameter) { - return parameter.getParameterType().isAssignableFrom(Integer.class)&¶meter.hasParameterAnnotation(LoginUser.class); + return parameter.getParameterType().isAssignableFrom(Integer.class) && parameter.hasParameterAnnotation(LoginUser.class); } @Override @@ -22,7 +23,7 @@ public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgu // return new Integer(1); String token = request.getHeader(LOGIN_TOKEN_KEY); - if(token == null || token.isEmpty()){ + if (token == null || token.isEmpty()) { return null; } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/config/UseConfig.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/config/UseConfig.java index 9a9ba041..f55e8d56 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/config/UseConfig.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/config/UseConfig.java @@ -4,6 +4,7 @@ import org.linlinjava.litemall.wx.annotation.support.LoginUserHandlerMethodArgum 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 diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserInfo.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserInfo.java index 7b00692d..70f168f8 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserInfo.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserInfo.java @@ -9,58 +9,59 @@ public class UserInfo { private String language; private Byte gender; - public void setCountry(String country) { - this.country = country; - } - - public void setProvince(String province) { - this.province = province; - } - - public void setCity(String city) { - this.city = city; - } - - public void setLanguage(String language) { - this.language = language; - } - - public void setGender(Byte gender) { - this.gender = gender; - } - public String getCountry() { return country; } + public void setCountry(String country) { + this.country = country; + } + public String getProvince() { return province; } + public void setProvince(String province) { + this.province = province; + } + public String getCity() { return city; } + public void setCity(String city) { + this.city = city; + } + public String getLanguage() { return language; } + public void setLanguage(String language) { + this.language = language; + } + public Byte getGender() { return gender; } + public void setGender(Byte gender) { + this.gender = gender; + } + + public String getNickName() { + return nickName; + } + public void setNickName(String nickName) { this.nickName = nickName; } - public void setAvatarUrl(String avatarUrl) { - this.avatarUrl = avatarUrl; - } - - public String getNickName() { - return nickName; - } public String getAvatarUrl() { return avatarUrl; } + + public void setAvatarUrl(String avatarUrl) { + this.avatarUrl = avatarUrl; + } } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserToken.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserToken.java index a7dd4ef5..e890a45c 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserToken.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/UserToken.java @@ -17,35 +17,35 @@ public class UserToken { this.sessionKey = sessionKey; } - 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; + } } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java index 6b358a61..6bd8e320 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java @@ -3,10 +3,10 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.linlinjava.litemall.core.util.RegexUtil; +import org.linlinjava.litemall.core.util.ResponseUtil; 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.linlinjava.litemall.wx.annotation.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; @@ -14,7 +14,6 @@ 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,22 +35,22 @@ public class WxAddressController { * * @param userId 用户ID * @return 收货地址列表 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: xxx - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: xxx + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("list") public Object list(@LoginUser Integer userId) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } List addressList = addressService.queryByUid(userId); List> addressVoList = new ArrayList<>(addressList.size()); - for(LitemallAddress address : addressList){ + for (LitemallAddress address : addressList) { Map addressVo = new HashMap<>(); addressVo.put("id", address.getId()); addressVo.put("name", address.getName()); @@ -73,38 +72,38 @@ public class WxAddressController { * 收货地址详情 * * @param userId 用户ID - * @param id 收获地址ID + * @param id 收获地址ID * @return 收货地址详情 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * id: xxx, - * name: xxx, - * provinceId: xxx, - * cityId: xxx, - * areaId: xxx, - * mobile: xxx, - * address: xxx, - * isDefault: xxx, - * version: xxx - * provinceName: xxx, - * cityName: xxx, - * areaName: xxx - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * id: xxx, + * name: xxx, + * provinceId: xxx, + * cityId: xxx, + * areaId: xxx, + * mobile: xxx, + * address: xxx, + * isDefault: xxx, + * version: xxx + * provinceName: xxx, + * cityName: xxx, + * areaName: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("detail") public Object detail(@LoginUser Integer userId, @NotNull Integer id) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } LitemallAddress address = addressService.findById(id); - if(address == null){ + if (address == null) { return ResponseUtil.badArgumentValue(); } @@ -128,50 +127,50 @@ public class WxAddressController { private Object validate(LitemallAddress address) { String name = address.getName(); - if(StringUtils.isEmpty(name)){ + if (StringUtils.isEmpty(name)) { return ResponseUtil.badArgument(); } // 测试收货手机号码是否正确 String mobile = address.getMobile(); - if(StringUtils.isEmpty(mobile)){ + if (StringUtils.isEmpty(mobile)) { return ResponseUtil.badArgument(); } - if(!RegexUtil.isMobileExact(mobile)){ + if (!RegexUtil.isMobileExact(mobile)) { return ResponseUtil.badArgument(); } Integer pid = address.getProvinceId(); - if(pid == null){ + if (pid == null) { return ResponseUtil.badArgument(); } - if(regionService.findById(pid) == null){ + if (regionService.findById(pid) == null) { return ResponseUtil.badArgumentValue(); } Integer cid = address.getCityId(); - if(cid == null){ + if (cid == null) { return ResponseUtil.badArgument(); } - if(regionService.findById(cid) == null){ + if (regionService.findById(cid) == null) { return ResponseUtil.badArgumentValue(); } Integer aid = address.getAreaId(); - if(aid == null){ + if (aid == null) { return ResponseUtil.badArgument(); } - if(regionService.findById(aid) == null){ + if (regionService.findById(aid) == null) { return ResponseUtil.badArgumentValue(); } String detailedAddress = address.getAddress(); - if(StringUtils.isEmpty(detailedAddress)){ + if (StringUtils.isEmpty(detailedAddress)) { return ResponseUtil.badArgument(); } Boolean isDefault = address.getIsDefault(); - if(isDefault == null){ + if (isDefault == null) { return ResponseUtil.badArgument(); } return null; @@ -180,23 +179,23 @@ public class WxAddressController { /** * 添加或更新收货地址 * - * @param userId 用户ID + * @param userId 用户ID * @param address 用户收货地址 * @return 添加或更新操作结果 - * 成功则 { errno: 0, errmsg: '成功' } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 { errno: 0, errmsg: '成功' } + * 失败则 { errno: XXX, errmsg: XXX } */ @PostMapping("save") public Object save(@LoginUser Integer userId, @RequestBody LitemallAddress address) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } Object error = validate(address); - if(error != null){ + if (error != null) { return error; } - if(address.getIsDefault()){ + if (address.getIsDefault()) { // 重置其他收获地址的默认选项 addressService.resetDefault(userId); } @@ -207,7 +206,7 @@ public class WxAddressController { addressService.add(address); } else { address.setUserId(userId); - if(addressService.update(address) == 0){ + if (addressService.update(address) == 0) { return ResponseUtil.updatedDataFailed(); } } @@ -217,19 +216,19 @@ public class WxAddressController { /** * 删除收货地址 * - * @param userId 用户ID + * @param userId 用户ID * @param address 用户收货地址 * @return 删除结果 - * 成功则 { errno: 0, errmsg: '成功' } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 { errno: 0, errmsg: '成功' } + * 失败则 { errno: XXX, errmsg: XXX } */ @PostMapping("delete") public Object delete(@LoginUser Integer userId, @RequestBody LitemallAddress address) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } Integer id = address.getId(); - if(id == null){ + if (id == null) { return ResponseUtil.badArgument(); } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java index 7686f9fb..8de4a880 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java @@ -166,7 +166,7 @@ public class WxAuthController { } else { user.setLastLoginTime(LocalDateTime.now()); user.setLastLoginIp(IpUtil.client(request)); - if(userService.updateById(user) == 0){ + if (userService.updateById(user) == 0) { return ResponseUtil.updatedDataFailed(); } } @@ -192,21 +192,21 @@ public class WxAuthController { @PostMapping("regCaptcha") public Object registerCaptcha(@RequestBody String body) { String phoneNumber = JacksonUtil.parseString(body, "mobile"); - if(StringUtils.isEmpty(phoneNumber)){ + if (StringUtils.isEmpty(phoneNumber)) { return ResponseUtil.badArgument(); } - if(!RegexUtil.isMobileExact(phoneNumber)){ + if (!RegexUtil.isMobileExact(phoneNumber)) { return ResponseUtil.badArgumentValue(); } - if(notifyService.isSmsEnable()){ + if (notifyService.isSmsEnable()) { return ResponseUtil.fail(404, "小程序后台验证码服务不支持"); } String code = CharUtil.getRandomNum(6); notifyService.notifySmsTemplate(phoneNumber, NotifyType.CAPTCHA, new String[]{code}); boolean successful = CaptchaCodeManager.addToCache(phoneNumber, code); - if(!successful){ + if (!successful) { return ResponseUtil.fail(404, "验证码未超时1分钟,不能发送"); } @@ -248,7 +248,7 @@ public class WxAuthController { String wxCode = JacksonUtil.parseString(body, "wxCode"); if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password) || StringUtils.isEmpty(mobile) - || StringUtils.isEmpty(wxCode) || StringUtils.isEmpty(code)) { + || StringUtils.isEmpty(wxCode) || StringUtils.isEmpty(code)) { return ResponseUtil.badArgument(); } @@ -279,16 +279,16 @@ public class WxAuthController { return ResponseUtil.fail(403, "openid 获取失败"); } userList = userService.queryByOpenid(openId); - if(userList.size() > 1){ + if (userList.size() > 1) { return ResponseUtil.fail(403, "openid 存在多个"); } - if(userList.size() == 1){ - LitemallUser checkUser = userList.get(0); - String checkUsername = checkUser.getUsername(); - String checkPassword = checkUser.getPassword(); - if(!checkUsername.equals(openId) || !checkPassword.equals(openId)){ - return ResponseUtil.fail(403, "openid已绑定账号"); - } + if (userList.size() == 1) { + LitemallUser checkUser = userList.get(0); + String checkUsername = checkUser.getUsername(); + String checkPassword = checkUser.getPassword(); + if (!checkUsername.equals(openId) || !checkPassword.equals(openId)) { + return ResponseUtil.fail(403, "openid已绑定账号"); + } } LitemallUser user = null; @@ -367,7 +367,7 @@ public class WxAuthController { String encodedPassword = encoder.encode(password); user.setPassword(encodedPassword); - if(userService.updateById(user) == 0){ + if (userService.updateById(user) == 0) { return ResponseUtil.updatedDataFailed(); } @@ -383,7 +383,7 @@ public class WxAuthController { String phone = phoneNumberInfo.getPhoneNumber(); LitemallUser user = userService.findById(userId); user.setMobile(phone); - if(userService.updateById(user) == 0){ + if (userService.updateById(user) == 0) { return ResponseUtil.updatedDataFailed(); } return ResponseUtil.ok(); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java index 9abc03f9..e861b865 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxBrandController.java @@ -2,9 +2,9 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.core.util.ResponseUtil; 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.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java index 369ab913..1925ee34 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java @@ -3,18 +3,17 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.linlinjava.litemall.db.domain.*; -import org.linlinjava.litemall.db.service.*; +import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.util.JacksonUtil; import org.linlinjava.litemall.core.util.ResponseUtil; +import org.linlinjava.litemall.db.domain.*; +import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.wx.annotation.LoginUser; -import org.linlinjava.litemall.core.system.SystemConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -149,7 +148,7 @@ public class WxCartController { return ResponseUtil.fail(400, "库存不足"); } existCart.setNumber((short) num); - if(cartService.updateById(existCart) == 0){ + if (cartService.updateById(existCart) == 0) { return ResponseUtil.updatedDataFailed(); } } @@ -222,7 +221,7 @@ public class WxCartController { return ResponseUtil.fail(400, "库存不足"); } existCart.setNumber((short) num); - if(cartService.updateById(existCart) == 0){ + if (cartService.updateById(existCart) == 0) { return ResponseUtil.updatedDataFailed(); } } @@ -284,7 +283,7 @@ public class WxCartController { } existCart.setNumber(number.shortValue()); - if(cartService.updateById(existCart) == 0){ + if (cartService.updateById(existCart) == 0) { return ResponseUtil.updatedDataFailed(); } return ResponseUtil.ok(); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java index 9e7d2823..b3b82ec7 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java @@ -3,19 +3,18 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.core.util.JacksonUtil; +import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.LitemallCollect; import org.linlinjava.litemall.db.domain.LitemallGoods; import org.linlinjava.litemall.db.service.LitemallCollectService; import org.linlinjava.litemall.db.service.LitemallGoodsService; -import org.linlinjava.litemall.core.util.JacksonUtil; -import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.wx.annotation.LoginUser; 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.ArrayList; import java.util.HashMap; import java.util.List; @@ -36,29 +35,29 @@ public class WxCollectController { * 用户收藏列表 * * @param userId 用户ID - * @param type 类型,如果是0则是商品收藏,如果是1则是专题收藏 - * 目前没有使用 - * @param page 分页页数 - * @param size 分页大小 + * @param type 类型,如果是0则是商品收藏,如果是1则是专题收藏 + * 目前没有使用 + * @param page 分页页数 + * @param size 分页大小 * @return 用户收藏列表 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * collectList: xxx, - * totalPages: xxx - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * collectList: xxx, + * totalPages: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("list") public Object list(@LoginUser Integer userId, @NotNull Byte type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } @@ -67,7 +66,7 @@ public class WxCollectController { int totalPages = (int) Math.ceil((double) count / size); List collects = new ArrayList<>(collectList.size()); - for(LitemallCollect collect : collectList){ + for (LitemallCollect collect : collectList) { Map c = new HashMap(); c.put("id", collect.getId()); c.put("type", collect.getType()); @@ -92,42 +91,41 @@ public class WxCollectController { * 用户收藏添加或删除 * * @param userId 用户ID - * @param body 请求内容 + * @param body 请求内容 * @return 操作结果 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * type: xxx, - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * type: xxx, + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @PostMapping("addordelete") public Object addordelete(@LoginUser Integer userId, @RequestBody String body) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } - if(body == null){ + if (body == null) { return ResponseUtil.badArgument(); } Byte type = JacksonUtil.parseByte(body, "type"); Integer valueId = JacksonUtil.parseInteger(body, "valueId"); - if(!ObjectUtils.allNotNull(type, valueId)){ + if (!ObjectUtils.allNotNull(type, valueId)) { return ResponseUtil.badArgument(); } LitemallCollect collect = collectService.queryByTypeAndValue(userId, type, valueId); String handleType = null; - if(collect != null){ + if (collect != null) { handleType = "delete"; collectService.deleteById(collect.getId()); - } - else{ + } else { handleType = "add"; collect = new LitemallCollect(); collect.setUserId(userId); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCommentController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCommentController.java index bf6360c1..40b91b75 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCommentController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCommentController.java @@ -1,25 +1,22 @@ package org.linlinjava.litemall.wx.web; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.LitemallComment; -import org.linlinjava.litemall.db.domain.LitemallGoodsSpecification; import org.linlinjava.litemall.db.service.LitemallCommentService; import org.linlinjava.litemall.db.service.LitemallGoodsService; import org.linlinjava.litemall.db.service.LitemallTopicService; import org.linlinjava.litemall.db.service.LitemallUserService; -import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.wx.annotation.LoginUser; -import org.linlinjava.litemall.wx.service.UserInfoService; import org.linlinjava.litemall.wx.dao.UserInfo; +import org.linlinjava.litemall.wx.service.UserInfoService; 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.ArrayList; import java.util.HashMap; import java.util.List; @@ -44,38 +41,36 @@ public class WxCommentController { private Object validate(LitemallComment comment) { String content = comment.getContent(); - if(StringUtils.isEmpty(content)){ + if (StringUtils.isEmpty(content)) { return ResponseUtil.badArgument(); } Short star = comment.getStar(); - if(star == null){ + if (star == null) { return ResponseUtil.badArgument(); } - if(star < 0 || star > 5){ + if (star < 0 || star > 5) { return ResponseUtil.badArgumentValue(); } Byte type = comment.getType(); Integer valueId = comment.getValueId(); - if(type == null || valueId == null){ + if (type == null || valueId == null) { return ResponseUtil.badArgument(); } - if(type == 0){ - if(goodsService.findById(valueId) == null){ - return ResponseUtil.badArgumentValue(); - } - } - else if(type == 1){ - if(topicService.findById(valueId) == null){ + if (type == 0) { + if (goodsService.findById(valueId) == null) { return ResponseUtil.badArgumentValue(); } - } - else{ + } else if (type == 1) { + if (topicService.findById(valueId) == null) { + return ResponseUtil.badArgumentValue(); + } + } else { return ResponseUtil.badArgumentValue(); } Boolean hasPicture = comment.getHasPicture(); - if(hasPicture == null || !hasPicture){ + if (hasPicture == null || !hasPicture) { comment.setPicUrls(new String[0]); } return null; @@ -84,24 +79,24 @@ public class WxCommentController { /** * 发表评论 * - * @param userId 用户ID + * @param userId 用户ID * @param comment 评论内容 * @return 发表评论操作结果 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: xxx - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: xxx + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @PostMapping("post") public Object post(@LoginUser Integer userId, @RequestBody LitemallComment comment) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } Object error = validate(comment); - if(error != null){ + if (error != null) { return error; } @@ -113,20 +108,20 @@ public class WxCommentController { /** * 评论数量 * - * @param type 类型ID。 如果是0,则查询商品评论;如果是1,则查询专题评论。 + * @param type 类型ID。 如果是0,则查询商品评论;如果是1,则查询专题评论。 * @param valueId 商品或专题ID。如果type是0,则是商品ID;如果type是1,则是专题ID。 * @return 评论数量 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * allCount: xxx, - * hasPicCount: xxx - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * allCount: xxx, + * hasPicCount: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("count") public Object count(@NotNull Byte type, @NotNull Integer valueId) { @@ -141,24 +136,24 @@ public class WxCommentController { /** * 评论列表 * - * @param type 类型ID。 如果是0,则查询商品评论;如果是1,则查询专题评论。 - * @param valueId 商品或专题ID。如果type是0,则是商品ID;如果type是1,则是专题ID。 + * @param type 类型ID。 如果是0,则查询商品评论;如果是1,则查询专题评论。 + * @param valueId 商品或专题ID。如果type是0,则是商品ID;如果type是1,则是专题ID。 * @param showType 显示类型。如果是0,则查询全部;如果是1,则查询有图片的评论。 - * @param page 分页页数 - * @param size 分页大小 + * @param page 分页页数 + * @param size 分页大小 * @return 评论列表 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * data: xxx, - * count: xxx, - * currentPage: xxx - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * data: xxx, + * count: xxx, + * currentPage: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("list") public Object list(@NotNull Byte type, @@ -170,10 +165,10 @@ public class WxCommentController { int count = commentService.count(type, valueId, showType, page, size); List> commentVoList = new ArrayList<>(commentList.size()); - for(LitemallComment comment : commentList){ + for (LitemallComment comment : commentList) { Map commentVo = new HashMap<>(); commentVo.put("addTime", comment.getAddTime()); - commentVo.put("content",comment.getContent()); + commentVo.put("content", comment.getContent()); commentVo.put("picList", comment.getPicUrls()); UserInfo userInfo = userInfoService.getInfo(comment.getUserId()); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java index 170ef842..32fcbe67 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java @@ -1,6 +1,8 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.linlinjava.litemall.core.util.RegexUtil; import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.LitemallFeedback; @@ -8,12 +10,12 @@ import org.linlinjava.litemall.db.domain.LitemallUser; import org.linlinjava.litemall.db.service.LitemallFeedbackService; import org.linlinjava.litemall.db.service.LitemallUserService; import org.linlinjava.litemall.wx.annotation.LoginUser; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import java.time.LocalDateTime; +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; /** * @author Yogeek @@ -32,23 +34,23 @@ public class WxFeedbackController { private Object validate(LitemallFeedback feedback) { String content = feedback.getContent(); - if(StringUtils.isEmpty(content)){ + if (StringUtils.isEmpty(content)) { return ResponseUtil.badArgument(); } String type = feedback.getFeedType(); - if(StringUtils.isEmpty(type)){ + if (StringUtils.isEmpty(type)) { return ResponseUtil.badArgument(); } Boolean hasPicture = feedback.getHasPicture(); - if(hasPicture == null || !hasPicture){ + if (hasPicture == null || !hasPicture) { feedback.setPicUrls(new String[0]); } // 测试手机号码是否正确 String mobile = feedback.getMobile(); - if(StringUtils.isEmpty(mobile)){ + if (StringUtils.isEmpty(mobile)) { return ResponseUtil.badArgument(); } if (!RegexUtil.isMobileExact(mobile)) { @@ -58,7 +60,7 @@ public class WxFeedbackController { } /** - * 意见反馈 + * 意见反馈 */ @PostMapping("submit") public Object submit(@LoginUser Integer userId, @RequestBody LitemallFeedback feedback) { @@ -66,7 +68,7 @@ public class WxFeedbackController { return ResponseUtil.unlogin(); } Object error = validate(feedback); - if(error != null){ + if (error != null) { return error; } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFootprintController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFootprintController.java index cecf7379..0465957a 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFootprintController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFootprintController.java @@ -2,12 +2,12 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.core.util.JacksonUtil; +import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.LitemallFootprint; import org.linlinjava.litemall.db.domain.LitemallGoods; import org.linlinjava.litemall.db.service.LitemallFootprintService; import org.linlinjava.litemall.db.service.LitemallGoodsService; -import org.linlinjava.litemall.core.util.JacksonUtil; -import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.wx.annotation.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -33,30 +33,30 @@ public class WxFootprintController { * 删除用户足迹 * * @param userId 用户ID - * @param body 请求内容, { footprintId: xxx } + * @param body 请求内容, { footprintId: xxx } * @return 删除操作结果 - * 成功则 { errno: 0, errmsg: '成功' } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 { errno: 0, errmsg: '成功' } + * 失败则 { errno: XXX, errmsg: XXX } */ @PostMapping("delete") public Object delete(@LoginUser Integer userId, @RequestBody String body) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } - if(body == null){ + if (body == null) { return ResponseUtil.badArgument(); } Integer footprintId = JacksonUtil.parseInteger(body, "footprintId"); - if(footprintId == null){ + if (footprintId == null) { return ResponseUtil.badArgument(); } LitemallFootprint footprint = footprintService.findById(footprintId); - if(footprint == null){ + if (footprint == null) { return ResponseUtil.badArgumentValue(); } - if(!footprint.getUserId().equals(userId)){ + if (!footprint.getUserId().equals(userId)) { return ResponseUtil.badArgumentValue(); } @@ -70,23 +70,23 @@ public class WxFootprintController { * @param page 分页页数 * @param size 分页大小 * @return 用户足迹列表 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: - * { - * footprintList: xxx, - * totalPages: xxx - * } - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * footprintList: xxx, + * totalPages: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("list") public Object list(@LoginUser Integer userId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } @@ -95,7 +95,7 @@ public class WxFootprintController { int totalPages = (int) Math.ceil((double) count / size); List footprintVoList = new ArrayList<>(footprintList.size()); - for(LitemallFootprint footprint : footprintList){ + for (LitemallFootprint footprint : footprintList) { Map c = new HashMap(); c.put("id", footprint.getId()); c.put("goodsId", footprint.getGoodsId()); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java index a9b74b50..7adbface 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java @@ -18,7 +18,6 @@ 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; @@ -106,10 +105,9 @@ public class WxGoodsController { // 商品品牌商 Integer brandId = info.getBrandId(); LitemallBrand brand = null; - if(brandId == 0){ + if (brandId == 0) { brand = new LitemallBrand(); - } - else { + } else { brand = brandService.findById(info.getBrandId()); } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java index 3bb39bd8..d3fd5297 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.wx.web; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.linlinjava.litemall.core.express.ExpressService; import org.linlinjava.litemall.core.express.dao.ExpressInfo; import org.linlinjava.litemall.core.util.ResponseUtil; @@ -15,8 +17,6 @@ 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 org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import javax.validation.constraints.NotNull; import java.util.ArrayList; diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java index d4a83505..75496a55 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java @@ -2,10 +2,10 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.service.*; -import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.wx.service.HomeCacheManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxIndexController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxIndexController.java index 4654c26e..e5bbe8ea 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxIndexController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxIndexController.java @@ -12,7 +12,7 @@ public class WxIndexController { private final Log logger = LogFactory.getLog(WxIndexController.class); @RequestMapping("/index") - public Object index(){ + public Object index() { return ResponseUtil.ok("hello world, this is wx service"); } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java index 29364f2e..50fe1203 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java @@ -15,6 +15,7 @@ import org.linlinjava.litemall.core.express.dao.ExpressInfo; import org.linlinjava.litemall.core.notify.NotifyService; import org.linlinjava.litemall.core.notify.NotifyType; import org.linlinjava.litemall.core.qcode.QCodeService; +import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.util.DateTimeUtil; import org.linlinjava.litemall.core.util.JacksonUtil; import org.linlinjava.litemall.core.util.ResponseUtil; @@ -23,7 +24,6 @@ import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.util.OrderHandleOption; import org.linlinjava.litemall.db.util.OrderUtil; import org.linlinjava.litemall.wx.annotation.LoginUser; -import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.wx.util.IpUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.PlatformTransactionManager; @@ -39,7 +39,6 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import java.io.IOException; import java.math.BigDecimal; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; @@ -300,7 +299,7 @@ public class WxOrderController { // 收货地址 LitemallAddress checkedAddress = addressService.findById(addressId); - if(checkedAddress == null){ + if (checkedAddress == null) { return ResponseUtil.badArgument(); } @@ -416,7 +415,7 @@ public class WxOrderController { throw new RuntimeException("下单的商品货品数量大于库存量"); } product.setNumber(remainNumber); - if(productService.updateById(product) == 0){ + if (productService.updateById(product) == 0) { throw new Exception("更新数据失败"); } } @@ -501,7 +500,7 @@ public class WxOrderController { // 设置订单已取消状态 order.setOrderStatus(OrderUtil.STATUS_CANCEL); order.setEndTime(LocalDateTime.now()); - if(orderService.updateWithOptimisticLocker(order) == 0){ + if (orderService.updateWithOptimisticLocker(order) == 0) { throw new Exception("更新数据已失效"); } @@ -512,7 +511,7 @@ public class WxOrderController { 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("更新数据失败"); } } @@ -599,7 +598,7 @@ public class WxOrderController { return ResponseUtil.fail(403, "订单不能支付"); } - if(orderService.updateWithOptimisticLocker(order) == 0){ + if (orderService.updateWithOptimisticLocker(order) == 0) { return ResponseUtil.updatedDateExpired(); } return ResponseUtil.ok(result); @@ -670,7 +669,7 @@ public class WxOrderController { // 因此,这里会重新读取数据库检查状态是否是订单自动取消,如果是则更新成支付状态。 order = orderService.findBySn(orderSn); int updated = 0; - if(OrderUtil.isAutoCancelStatus(order)){ + if (OrderUtil.isAutoCancelStatus(order)) { order.setPayId(payId); order.setPayTime(LocalDateTime.now()); order.setOrderStatus(OrderUtil.STATUS_PAY); @@ -678,7 +677,7 @@ public class WxOrderController { } // 如果updated是0,那么数据库更新失败 - if(updated == 0) { + if (updated == 0) { return WxPayNotifyResponse.fail("更新数据已失效"); } } @@ -756,7 +755,7 @@ public class WxOrderController { // 设置订单申请退款状态 order.setOrderStatus(OrderUtil.STATUS_REFUND); - if(orderService.updateWithOptimisticLocker(order) == 0){ + if (orderService.updateWithOptimisticLocker(order) == 0) { return ResponseUtil.updatedDateExpired(); } @@ -806,7 +805,7 @@ public class WxOrderController { order.setOrderStatus(OrderUtil.STATUS_CONFIRM); order.setConfirmTime(LocalDateTime.now()); - if(orderService.updateWithOptimisticLocker(order) == 0){ + if (orderService.updateWithOptimisticLocker(order) == 0) { return ResponseUtil.updatedDateExpired(); } return ResponseUtil.ok(); @@ -865,8 +864,8 @@ public class WxOrderController { */ @GetMapping("goods") public Object goods(@LoginUser Integer userId, - @NotNull Integer orderId, - @NotNull Integer goodsId) { + @NotNull Integer orderId, + @NotNull Integer goodsId) { if (userId == null) { return ResponseUtil.unlogin(); } @@ -901,48 +900,48 @@ public class WxOrderController { } Integer orderGoodsId = JacksonUtil.parseInteger(body, "orderGoodsId"); - if(orderGoodsId == null){ + if (orderGoodsId == null) { return ResponseUtil.badArgument(); } LitemallOrderGoods orderGoods = orderGoodsService.findById(orderGoodsId); - if(orderGoods == null){ + if (orderGoods == null) { return ResponseUtil.badArgumentValue(); } - Integer orderId = orderGoods.getOrderId(); + Integer orderId = orderGoods.getOrderId(); LitemallOrder order = orderService.findById(orderId); - if(order == null){ + if (order == null) { return ResponseUtil.badArgumentValue(); } Short orderStatus = order.getOrderStatus(); - if(!OrderUtil.isConfirmStatus(order) && !OrderUtil.isAutoConfirmStatus(order)) { + if (!OrderUtil.isConfirmStatus(order) && !OrderUtil.isAutoConfirmStatus(order)) { return ResponseUtil.fail(404, "当前商品不能评价"); } - if(!order.getUserId().equals(userId)){ + if (!order.getUserId().equals(userId)) { return ResponseUtil.fail(404, "当前商品不属于用户"); } Integer commentId = orderGoods.getComment(); - if(commentId == -1){ + if (commentId == -1) { return ResponseUtil.fail(404, "当前商品评价时间已经过期"); } - if(commentId != 0){ + if (commentId != 0) { return ResponseUtil.fail(404, "订单商品已评价"); } String content = JacksonUtil.parseString(body, "content"); Integer star = JacksonUtil.parseInteger(body, "star"); - if(star == null || star < 0 || star > 5){ + if (star == null || star < 0 || star > 5) { return ResponseUtil.badArgumentValue(); } Boolean hasPicture = JacksonUtil.parseBoolean(body, "hasPicture"); List picUrls = JacksonUtil.parseStringList(body, "picUrls"); - if(hasPicture == null || !hasPicture){ + if (hasPicture == null || !hasPicture) { picUrls = new ArrayList<>(0); } // 1. 创建评价 LitemallComment comment = new LitemallComment(); comment.setUserId(userId); - comment.setType((byte)0); + comment.setType((byte) 0); comment.setValueId(orderGoods.getGoodsId()); comment.setStar(star.shortValue()); comment.setContent(content); @@ -956,7 +955,7 @@ public class WxOrderController { // 3. 更新订单中未评价的订单商品可评价数量 Short commentCount = order.getComments(); - if(commentCount > 0){ + if (commentCount > 0) { commentCount--; } order.setComments(commentCount); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxRegionController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxRegionController.java index f9ea3cc5..9853c026 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxRegionController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxRegionController.java @@ -2,9 +2,9 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.core.util.ResponseUtil; 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; @@ -25,19 +25,19 @@ public class WxRegionController { /** * 区域数据 - * + *

* 根据父区域ID,返回子区域数据。 * 如果父区域ID是0,则返回省级区域数据; * * @param pid 父区域ID * @return 区域数据 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: xxx - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: xxx + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("list") public Object list(@NotNull Integer pid) { diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxSearchController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxSearchController.java index fe1d4fa1..2d812856 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxSearchController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxSearchController.java @@ -2,11 +2,11 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.LitemallKeyword; import org.linlinjava.litemall.db.domain.LitemallSearchHistory; import org.linlinjava.litemall.db.service.LitemallKeywordService; import org.linlinjava.litemall.db.service.LitemallSearchHistoryService; -import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.wx.annotation.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java index 0788d47f..3b8cc8b7 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java @@ -63,7 +63,7 @@ public class WxStorageController { if (key == null) { return ResponseEntity.notFound().build(); } - if(key.contains("../")){ + if (key.contains("../")) { return ResponseEntity.badRequest().build(); } String type = litemallStorage.getType(); @@ -82,7 +82,7 @@ public class WxStorageController { if (key == null) { return ResponseEntity.notFound().build(); } - if(key.contains("../")){ + if (key.contains("../")) { return ResponseEntity.badRequest().build(); } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxTopicController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxTopicController.java index 35cc3969..ac5d1948 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxTopicController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxTopicController.java @@ -2,13 +2,13 @@ package org.linlinjava.litemall.wx.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +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.LitemallGoods; import org.linlinjava.litemall.db.domain.LitemallTopic; import org.linlinjava.litemall.db.service.LitemallGoodsService; import org.linlinjava.litemall.db.service.LitemallTopicService; -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; diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxUserController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxUserController.java index 5319f39a..703fb6be 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxUserController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxUserController.java @@ -7,7 +7,10 @@ import org.linlinjava.litemall.db.service.LitemallOrderService; import org.linlinjava.litemall.wx.annotation.LoginUser; 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; @@ -25,17 +28,17 @@ public class WxUserController { * * @param userId 用户ID * @return 用户信息 - * 成功则 - * { - * errno: 0, - * errmsg: '成功', - * data: xxx - * } - * 失败则 { errno: XXX, errmsg: XXX } + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: xxx + * } + * 失败则 { errno: XXX, errmsg: XXX } */ @GetMapping("index") public Object list(@LoginUser Integer userId) { - if(userId == null){ + if (userId == null) { return ResponseUtil.unlogin(); } diff --git a/litemall-wx-api/src/test/java/org/linlinjava/litemall/wx/WxConfigTest.java b/litemall-wx-api/src/test/java/org/linlinjava/litemall/wx/WxConfigTest.java index ed2c8101..107b4d19 100644 --- a/litemall-wx-api/src/test/java/org/linlinjava/litemall/wx/WxConfigTest.java +++ b/litemall-wx-api/src/test/java/org/linlinjava/litemall/wx/WxConfigTest.java @@ -1,7 +1,5 @@ package org.linlinjava.litemall.wx; -import com.github.binarywang.wxpay.config.WxPayConfig; -import com.github.binarywang.wxpay.service.WxPayService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired;