feat(mall): 代码优化

master
waynaqua 10 months ago
parent 12bf4a0109
commit e24976dada

@ -11,7 +11,7 @@ import java.util.List;
public class OrderVO {
/**
* ID
*
*/
private String orderSn;

@ -1,8 +1,11 @@
package com.wayn.common.enums;
import lombok.Getter;
/**
* enum
*/
@Getter
public enum ReturnCodeEnum {
// 200通用操作成功 3xx资源重定向 4xx客户端错误 500通用操作失败
@ -91,14 +94,6 @@ public enum ReturnCodeEnum {
this.msg = msg;
}
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
public ReturnCodeEnum setMsg(String msg) {
this.msg = msg;
return this;

@ -3,6 +3,7 @@ package com.wayn.common.util;
import com.alibaba.fastjson2.JSONObject;
import com.wayn.common.enums.ReturnCodeEnum;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.io.Serial;
@ -10,14 +11,25 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@Setter
@Getter
public class R implements Serializable {
public class R<T> implements Serializable {
@Serial
private static final long serialVersionUID = -5316597326293972581L;
/**
* 200200
*/
private int code;
/**
*
*/
private String msg;
private Map<String, Object> map = new HashMap<>();
/**
*
*/
private Map<String, T> map = new HashMap<>();
public static R success() {
R r = new R();
@ -26,14 +38,7 @@ public class R implements Serializable {
return r;
}
public static R success(ReturnCodeEnum ReturnCodeEnum) {
R r = new R();
r.code = ReturnCodeEnum.getCode();
r.msg = ReturnCodeEnum.getMsg();
return r;
}
public static R success(Object data) {
public static <T> R success(T data) {
R r = new R();
r.code = ReturnCodeEnum.SUCCESS.getCode();
r.msg = ReturnCodeEnum.SUCCESS.getMsg();
@ -71,23 +76,11 @@ public class R implements Serializable {
return r;
}
public R add(String key, Object value) {
public R add(String key, T value) {
map.put(key, value);
return this;
}
public void setCode(int code) {
this.code = code;
}
public void setMsg(String msg) {
this.msg = msg;
}
public void setMap(Map<String, Object> map) {
this.map = map;
}
@Override
public String toString() {
return new ToStringBuilder(this)

@ -11,6 +11,12 @@ import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.Objects;
/**
*
*
* @author wayn
* @since 2020-08-03
*/
@RestController
@AllArgsConstructor
@RequestMapping("address")
@ -18,12 +24,22 @@ public class AddressController {
private IAddressService iAddressService;
/**
*
*
* @return R
*/
@GetMapping("list")
public R list() {
Long memberId = MobileSecurityUtils.getUserId();
return R.success().add("data", iAddressService.list(new QueryWrapper<Address>().eq("member_id", memberId)));
}
/**
*
*
* @return R
*/
@PostMapping
public R add(@RequestBody Address address) {
Long memberId = MobileSecurityUtils.getUserId();
@ -39,6 +55,11 @@ public class AddressController {
return R.result(iAddressService.save(address));
}
/**
*
*
* @return R
*/
@DeleteMapping("{addressId}")
public R delete(@PathVariable Long addressId) {
return R.result(iAddressService.removeById(addressId));

@ -1,7 +1,6 @@
package com.wayn.mobile.api.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.base.controller.BaseController;
@ -18,7 +17,7 @@ import java.math.BigDecimal;
import java.util.List;
/**
*
*
*
* @author wayn
* @since 2020-08-03
@ -31,8 +30,11 @@ public class CartController extends BaseController {
private ICartService iCartService;
private WaynConfig waynConfig;
/**
*
*
* @return
*/
@GetMapping("list")
public R list() {
Long userId = MobileSecurityUtils.getUserId();
@ -41,36 +43,75 @@ public class CartController extends BaseController {
return list;
}
/**
*
*
* @return R
*/
@PostMapping
public R add(@RequestBody Cart cart) {
return iCartService.add(cart);
}
/**
*
*
* @return R
*/
@PostMapping("addDefaultGoodsProduct")
public R addDefaultGoodsProduct(@RequestBody Cart cart) {
return iCartService.addDefaultGoodsProduct(cart);
}
/**
*
*
* @param cart
* @return R
*/
@PutMapping
public R update(@RequestBody Cart cart) {
return R.result(iCartService.updateById(cart));
}
/**
*
*
* @param cartId id
* @param number
* @return R
*/
@PostMapping("changeNum/{cartId}/{number}")
public R changeNum(@PathVariable Long cartId, @PathVariable Integer number) {
return R.result(iCartService.changeNum(cartId, number));
}
/**
*
*
* @param cartId id
* @return R
*/
@DeleteMapping("{cartId}")
public R delete(@PathVariable Long cartId) {
return R.result(iCartService.removeById(cartId));
}
/**
*
*
* @return R
*/
@GetMapping("goodsCount")
public R goodsCount() {
return iCartService.goodsCount();
}
/**
*
*
* @return R
*/
@PostMapping("getCheckedGoods")
public R getCheckedGoods() {
Long userId = MobileSecurityUtils.getUserId();

@ -16,6 +16,12 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author wayn
* @since 2024/1/15
*/
@RestController
@AllArgsConstructor
@RequestMapping("comment")
@ -23,6 +29,13 @@ public class CommentController extends BaseController {
private ICommentService iCommentService;
/**
*
*
* @param tagType , 1 2 3
* @param goodsId id
* @return R
*/
@PostMapping("list")
public R list(Integer tagType, Long goodsId) {
Page<Comment> page = getPage();
@ -30,12 +43,24 @@ public class CommentController extends BaseController {
return R.success().add("page", commentIPage);
}
/**
*
*
* @param commentVO
* @return R
*/
@PostMapping
public R addComment(@Valid @RequestBody CommentVO commentVO) {
commentVO.setUserId(MobileSecurityUtils.getUserId());
return R.success().add("data", iCommentService.saveComment(commentVO));
}
/**
*
*
* @param goodsId id
* @return R
*/
@PostMapping("tagNum")
public R tagNum(Long goodsId) {
CommentTagNumVO commentTagNumVO = iCommentService.selectTagNum(goodsId);

@ -15,6 +15,12 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
*
*
* @author wayn
* @since 2024/1/15
*/
@RestController
@AllArgsConstructor
@RequestMapping("diamond")
@ -24,6 +30,12 @@ public class DiamondController extends BaseController {
private DiamondJumpContext diamondJumpContext;
/**
*
*
* @param diamondId id
* @return R
*/
@GetMapping("getGoodsList")
public R getGoodsList(Long diamondId) {
Page<Goods> page = getPage();

@ -8,6 +8,12 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author wayn
* @since 2024/1/15
*/
@RestController
@AllArgsConstructor
@RequestMapping("goods")
@ -15,6 +21,12 @@ public class GoodsController {
private IGoodsDetailService iGoodsDetailService;
/**
*
*
* @param goodsId id
* @return R
*/
@GetMapping("detail/{goodsId}")
public R detail(@PathVariable Long goodsId) {
return R.success(iGoodsDetailService.getGoodsDetailData(goodsId));

@ -10,6 +10,9 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*/
@RestController
@AllArgsConstructor
@RequestMapping("home")

@ -30,6 +30,12 @@ import java.util.Date;
import static com.wayn.common.enums.ReturnCodeEnum.*;
/**
*
*
* @author wayn
* @since 2024/1/15
*/
@RestController
@AllArgsConstructor
public class LoginController {
@ -40,6 +46,12 @@ public class LoginController {
private IMailConfigService mailConfigService;
private ThreadPoolTaskExecutor commonThreadPoolTaskExecutor;
/**
*
*
* @param loginObj
* @return R
*/
@PostMapping("/login")
public R login(@RequestBody LoginObj loginObj) {
// 生成令牌
@ -47,6 +59,12 @@ public class LoginController {
return R.success().add(SysConstants.TOKEN, token);
}
/**
*
*
* @param registryObj
* @return R
*/
@PostMapping("/registry")
public R registry(@RequestBody RegistryObj registryObj) {
if (!StringUtils.equalsIgnoreCase(registryObj.getPassword(), registryObj.getConfirmPassword())) {
@ -95,6 +113,11 @@ public class LoginController {
return R.result(iMemberService.save(member));
}
/**
*
*
* @return R
*/
@ResponseBody
@RequestMapping("/captcha")
public R captcha() {
@ -110,6 +133,12 @@ public class LoginController {
return R.success().add("captchaKey", key).add("captchaImg", specCaptcha.toBase64());
}
/**
*
*
* @param registryObj
* @return R
*/
@PostMapping("/sendEmailCode")
public R sendEmailCode(@RequestBody RegistryObj registryObj) {
// 判断图形验证码是否正确
@ -140,7 +169,7 @@ public class LoginController {
// 生成邮箱验证码唯一key
String key = RedisKeyEnum.EMAIL_KEY_CACHE.getKey(IdUtil.getUid());
// 存入redis并设置过期时间为20分钟
redisCache.setCacheObject(key, verCode + "_" + mobile, RedisKeyEnum.EMAIL_KEY_CACHE.getExpireSecond());
redisCache.setCacheObject(key, verCode + "_" + mobile, RedisKeyEnum.EMAIL_KEY_CACHE.getExpireSecond());
commonThreadPoolTaskExecutor.execute(() -> {
EmailConfig emailConfig = mailConfigService.getById(1L);
SendMailVO sendMailVO = new SendMailVO();

@ -11,6 +11,13 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
/**
*
*
* @author wayn
* @since 2024/1/15
*/
@Slf4j
@RestController
@AllArgsConstructor
@ -19,47 +26,89 @@ public class OrderController extends BaseController {
private IMobileOrderService iMobileOrderService;
/**
*
*
* @param orderSn
* @return R
*/
@GetMapping("detail/{orderSn}")
public R detail(@PathVariable String orderSn) {
return iMobileOrderService.getOrderDetailByOrderSn(orderSn);
}
/**
*
*
* @param showType 0 1 2 3 4
* @return
*/
@GetMapping("list")
public R list(@RequestParam(defaultValue = "0") Integer showType) {
Page<Order> page = getPage();
return iMobileOrderService.selectListPage(page, showType);
}
@PostMapping("info")
public R info(@RequestBody OrderVO orderVO) {
return R.success().add("data", iMobileOrderService.getById(orderVO.getOrderSn()));
}
/**
*
*
* @return R
*/
@PostMapping("statusCount")
public R statusCount() {
return iMobileOrderService.statusCount();
}
/**
*
*
* @param orderVO
* @return R
*/
@PostMapping("submit")
public R submit(@RequestBody OrderVO orderVO) throws Exception {
return iMobileOrderService.asyncSubmit(orderVO);
}
/**
*
*
* @param orderSn
* @return R
*/
@GetMapping("searchResult/{orderSn}")
public R searchResult(@PathVariable String orderSn) {
return iMobileOrderService.searchResult(orderSn);
}
/**
*
*
* @param orderId id
* @return R
*/
@PostMapping("cancel/{orderId}")
public R cancel(@PathVariable Long orderId) {
return iMobileOrderService.cancel(orderId);
}
/**
*
*
* @param orderId id
* @return R
*/
@PostMapping("confirm/{orderId}")
public R confirm(@PathVariable Long orderId) {
return iMobileOrderService.confirm(orderId);
}
/**
*
*
* @param orderId id
* @return R
*/
@PostMapping("delete/{orderId}")
public R delete(@PathVariable Long orderId) {
return iMobileOrderService.delete(orderId);

@ -1,18 +0,0 @@
package com.wayn.mobile.api.controller;
import com.wayn.common.base.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author wayn
* @since 2020-08-11
*/
@RestController
@RequestMapping("orderGoods")
public class OrderGoodsController extends BaseController {
}

@ -13,6 +13,12 @@ import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
/**
* 退
*
* @author wayn
* @since 2024/1/15
*/
@Slf4j
@RestController
@AllArgsConstructor
@ -21,6 +27,11 @@ public class OrderRefundController extends BaseController {
private IPayService payService;
/**
* 退
* @param orderId id
* @return R
*/
@PostMapping("{orderId}")
public R refund(@PathVariable Long orderId) throws UnsupportedEncodingException, AlipayApiException, WxPayException {
return payService.refund(orderId);

@ -13,6 +13,9 @@ import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
/**
*
*/
@Slf4j
@RestController
@AllArgsConstructor
@ -21,12 +24,24 @@ public class PayCallbackController extends BaseController {
private IPayService payService;
/**
*
* @param request
* @param response
* @return string
*/
@PostMapping("wxPayNotify")
public String wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
log.info("微信paySuccess通知数据记录req{}", JSONObject.toJSONString(request.getParameterMap()));
return payService.wxPayNotify(request, response);
}
/**
*
* @param request
* @param response
* @return string
*/
@PostMapping("aliPayNotify")
public String aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException, UnsupportedEncodingException {
log.info("支付宝paySuccess通知数据记录req: {}", JSONObject.toJSONString(request.getParameterMap()));

@ -14,6 +14,9 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.UnsupportedEncodingException;
/**
*
*/
@Slf4j
@RestController
@AllArgsConstructor

@ -3,7 +3,6 @@ package com.wayn.mobile.api.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.base.controller.BaseController;
import com.wayn.common.core.domain.shop.Goods;
@ -17,7 +16,6 @@ import com.wayn.mobile.api.domain.SearchHistory;
import com.wayn.mobile.api.service.ISearchHistoryService;
import com.wayn.mobile.framework.manager.thread.AsyncManager;
import com.wayn.mobile.framework.security.util.MobileSecurityUtils;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -44,7 +42,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
*
*
*
* @author wayn
* @since 2020-09-23
@ -64,9 +62,9 @@ public class SearchController extends BaseController {
/**
*
* @param searchVO
* @return
* @throws IOException
*
* @param searchVO
* @return R
*/
@GetMapping("sugguest")
public R sugguest(SearchVO searchVO) throws IOException {
@ -85,9 +83,9 @@ public class SearchController extends BaseController {
/**
*
* @param searchVO
* @return
* @throws IOException
*
* @param searchVO
* @return R
*/
@GetMapping("result")
public R result(SearchVO searchVO) throws IOException {
@ -180,6 +178,7 @@ public class SearchController extends BaseController {
/**
*
*
* @return R
*/
@GetMapping("hotKeywords")
@ -192,9 +191,6 @@ public class SearchController extends BaseController {
List<Keyword> defaultKeyword = iKeywordService.list(new QueryWrapper<Keyword>().eq("is_default", true).orderByAsc("sort"));
List<String> defaultStrings = defaultKeyword.stream().map(Keyword::getKeyword).collect(Collectors.toList());
R r = R.success();
if (CollectionUtils.isNotEmpty(hotStrings)) {
r.add("data", hotStrings);
}
r.add("data", hotStrings);
if (CollectionUtils.isNotEmpty(defaultStrings)) {
r.add("default", defaultStrings.get(0));

@ -11,7 +11,7 @@ import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
/**
*
*
*
* @author wayn
* @since 2020-09-23
@ -28,6 +28,12 @@ public class SearchHistoryController extends BaseController {
return R.success().add("data", iSearchHistoryService.selectList());
}
/**
*
*
* @param searchHistory
* @return R
*/
@PostMapping
public R add(@RequestBody SearchHistory searchHistory) {
Long memberId = MobileSecurityUtils.getUserId();
@ -35,11 +41,22 @@ public class SearchHistoryController extends BaseController {
return R.result(iSearchHistoryService.save(searchHistory));
}
/**
*
*
* @param id id
* @return R
*/
@DeleteMapping("{id}")
public R delete(@PathVariable Long id) {
return R.result(iSearchHistoryService.removeById(id));
}
/**
*
*
* @return R
*/
@DeleteMapping("all")
public R delete() {
Long memberId = MobileSecurityUtils.getUserId();

@ -1,16 +0,0 @@
package com.wayn.mobile.api.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("test")
public class TestController {
@GetMapping("shutdown")
public String gracefullyShutdown() throws InterruptedException {
Thread.sleep(15000);
return "gracefully shutdown!";
}
}

@ -28,6 +28,9 @@ import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
*
*/
@RestController
@AllArgsConstructor
@RequestMapping("user")
@ -41,12 +44,24 @@ public class UserController {
private IMailConfigService mailConfigService;
/**
*
* header Authorization
*
* @return
*/
@GetMapping("info")
public R getInfo() {
LoginUserDetail loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
return R.success().add("info", loginUser.getMember());
}
/**
*
*
* @param profileVO
* @return R
*/
@PostMapping("profile")
public R profile(@RequestBody ProfileVO profileVO) {
String nickname = profileVO.getNickname();
@ -76,6 +91,12 @@ public class UserController {
return R.result(iMemberService.updateById(member));
}
/**
*
*
* @param registryObj
* @return R
*/
@PostMapping("/sendEmailCode")
public R sendEmailCode(@RequestBody RegistryObj registryObj) {
SpecCaptcha specCaptcha = new SpecCaptcha(80, 32, 4);
@ -92,6 +113,12 @@ public class UserController {
return R.success().add("key", key);
}
/**
*
*
* @param avatar
* @return R
*/
@PostMapping("uploadAvatar")
public R uploadAvatar(String avatar) {
LoginUserDetail loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
@ -109,6 +136,12 @@ public class UserController {
return R.result(true).add("userInfo", member);
}
/**
*
*
* @param registryObj
* @return R
*/
@PostMapping("updatePassword")
public R updatePassword(@RequestBody RegistryObj registryObj) {
if (!StringUtils.equalsIgnoreCase(registryObj.getPassword(), registryObj.getConfirmPassword())) {

@ -12,6 +12,9 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
*
*/
@RestController
@AllArgsConstructor
@RequestMapping("callback/email")
@ -19,6 +22,13 @@ public class EmailController {
private IMailConfigService mailConfigService;
/**
*
* @param subject
* @param content
* @param tos
* @return R
*/
@PostMapping
public R sendEmail(String subject, String content, String tos) {
EmailConfig emailConfig = mailConfigService.getById(1L);

@ -13,6 +13,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*/
@Slf4j
@RestController
@AllArgsConstructor
@ -22,6 +25,11 @@ public class SubmitOrderController {
private IMobileOrderService iMobileOrderService;
private RedisCache redisCache;
/**
*
* @param order
* @return R
*/
@PostMapping("submit")
public R submit(String order) {
log.info("callback order request is {}", order);

@ -7,6 +7,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*/
@RestController
@AllArgsConstructor
@RequestMapping("callback/order")
@ -14,6 +17,12 @@ public class UnpaidOrderController {
private IOrderUnpaidService orderUnpaidService;
/**
*
*
* @param orderSn
* @return R
*/
@PostMapping("unpaid")
public R unpaid(String orderSn) {
return orderUnpaidService.unpaid(orderSn);

Loading…
Cancel
Save