From 3a90299b6429bb0695fa5fabea621db33fc2cda4 Mon Sep 17 00:00:00 2001 From: 19991905653 Date: Wed, 10 Apr 2024 18:16:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8+=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 15 +- .../controller/UserContoller.java | 7 + .../cashierservice/dao/TbOrderInfoMapper.java | 3 +- .../dao/TbReleaseFlowMapper.java | 5 + .../dao/TbSystemCouponsMapper.java | 3 +- .../dao/TbWiningParamsMapper.java | 21 + .../cashierservice/dao/TbYhqParamsMapper.java | 21 + .../cashierservice/entity/TbShopInfo.java | 367 +----------------- .../entity/TbSystemCoupons.java | 1 + .../cashierservice/entity/TbWiningParams.java | 22 ++ .../cashierservice/entity/TbWiningUser.java | 31 +- .../cashierservice/entity/TbYhqParams.java | 58 +++ .../entity/vo/IntegralFlowVo.java | 17 + .../exception/DefaultError.java | 108 ++++++ .../exception/DefaultExceptionAdvice.java | 155 ++++++++ .../cashierservice/exception/IError.java | 32 ++ .../cashierservice/rabbit/CartConsumer.java | 3 +- .../cashierservice/rabbit/RabbitConfig.java | 9 +- .../rabbit/RabbitConstants.java | 6 +- .../cashierservice/rabbit/RabbitProducer.java | 8 +- .../cashierservice/service/CartService.java | 166 ++++---- .../cashierservice/service/LoginService.java | 11 +- .../cashierservice/service/OrderService.java | 93 ++++- .../cashierservice/service/PayService.java | 6 +- .../cashierservice/service/UserService.java | 51 ++- .../system/cashierservice/sign/Result.java | 9 + .../socket/AppWebSocketServer.java | 12 - .../cashierservice/task/TaskScheduler.java | 101 ++++- .../util/NicknameGenerator.java | 40 ++ .../cashierservice/util/RandomUtil.java | 31 ++ .../cashierservice/util/WiningUtil.java | 50 --- src/main/resources/application-dev.yml | 4 +- src/main/resources/application-dev2.yml | 63 +++ src/main/resources/application-prod.yml | 2 + src/main/resources/application-prod2.yml | 2 + .../generator-mapper/generatorConfig.xml | 2 +- .../resources/mapper/TbOrderInfoMapper.xml | 4 + .../resources/mapper/TbReleaseFlowMapper.xml | 121 ++++++ .../resources/mapper/TbShopInfoMapper.xml | 3 +- .../mapper/TbSystemCouponsMapper.xml | 9 +- .../resources/mapper/TbWiningParamsMapper.xml | 97 +++++ .../resources/mapper/TbWiningUserMapper.xml | 88 ++++- .../resources/mapper/TbYhqParamsMapper.xml | 96 +++++ 43 files changed, 1374 insertions(+), 579 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java create mode 100644 src/main/resources/application-dev2.yml create mode 100644 src/main/resources/mapper/TbReleaseFlowMapper.xml create mode 100644 src/main/resources/mapper/TbWiningParamsMapper.xml create mode 100644 src/main/resources/mapper/TbYhqParamsMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index ef269c5..eb1aa5c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.IOException; +import java.text.ParseException; @CrossOrigin(origins = "*") @RestController @@ -51,7 +52,7 @@ public class OrderController { orderService.testMessage(tableId,message); } @GetMapping("/tradeIntegral") - private Result tradeIntegral(@RequestParam("userId") String userId, @RequestParam("id") String id) throws IOException { + private Result tradeIntegral(@RequestParam("userId") String userId, @RequestParam("id") String id) throws IOException, ParseException { return orderService.tradeIntegral(userId,id); } // @GetMapping("/我的积分") @@ -65,13 +66,21 @@ public class OrderController { return orderService.mineCoupons(userId,status,page,size); } @GetMapping("/findCoupons") - private Result findCoupons(@RequestHeader String token, + private Result findCoupons(@RequestHeader String token,@RequestParam String type, @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @RequestParam(value = "size", required = false, defaultValue = "1") Integer size) throws IOException { - return orderService.findCoupons(page,size); + return orderService.findCoupons(type,page,size); } @GetMapping("/findWiningUser") private Result findWiningUser(){ return orderService.findWiningUser(); } + @GetMapping("/getYhqPara") + private Result getYhqPara(){ + return orderService.getYhqPara(); + } + @GetMapping("/testPay") + private Result testPay(@RequestParam Integer orderId){ + return orderService.testPay(orderId); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index d5668b6..c1d21e6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -11,6 +11,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount; import com.chaozhanggui.system.cashierservice.entity.TbShopUser; import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto; import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto; +import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo; import com.chaozhanggui.system.cashierservice.service.LoginService; @@ -76,4 +77,10 @@ public class UserContoller { String userSign = jsonObject.getString("userSign"); return userService.modityIntegral(integralVo,userSign); } + @GetMapping("/userIntegral") + public JSONObject userIntegral(@RequestHeader String token,@RequestBody IntegralFlowVo integralFlowVo ) throws Exception { + JSONObject jsonObject = TokenUtil.parseParamFromToken(token); + String userSign = jsonObject.getString("userSign"); + return userService.userIntegral(integralFlowVo,userSign); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java index bea67e1..bf851e8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java @@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; +import java.math.BigDecimal; import java.util.List; @Component @@ -32,5 +33,5 @@ public interface TbOrderInfoMapper { @Param("size")Integer size, @Param("status") String status); - + List selectByTradeDay(@Param("day") String day,@Param("minPrice") BigDecimal minPrice,@Param("maxPrice") BigDecimal maxPrice); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java index 8002f56..b2f02b5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java @@ -1,6 +1,9 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow; +import org.apache.ibatis.annotations.Param; + +import java.util.List; public interface TbReleaseFlowMapper { int deleteByPrimaryKey(Integer id); @@ -14,4 +17,6 @@ public interface TbReleaseFlowMapper { int updateByPrimaryKeySelective(TbReleaseFlow record); int updateByPrimaryKey(TbReleaseFlow record); + + List selectByUserId(@Param("userId") String userId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java index 2f70da0..f4bfecf 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbSystemCoupons; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -17,5 +18,5 @@ public interface TbSystemCouponsMapper { int updateByPrimaryKey(TbSystemCoupons record); - List selectAll(); + List selectAll(@Param("type") String type); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java new file mode 100644 index 0000000..803fc9f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java @@ -0,0 +1,21 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbWiningParams; + +import java.util.List; + +public interface TbWiningParamsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbWiningParams record); + + int insertSelective(TbWiningParams record); + + TbWiningParams selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbWiningParams record); + + int updateByPrimaryKey(TbWiningParams record); + + List selectAll(); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java new file mode 100644 index 0000000..0693c83 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java @@ -0,0 +1,21 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbYhqParams; + +import java.util.List; + +public interface TbYhqParamsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbYhqParams record); + + int insertSelective(TbYhqParams record); + + TbYhqParams selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbYhqParams record); + + int updateByPrimaryKey(TbYhqParams record); + + List selectAll(); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java index 54863e8..2073721 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java @@ -1,8 +1,12 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.math.BigDecimal; + +@Data public class TbShopInfo implements Serializable { private Integer id; @@ -95,366 +99,5 @@ public class TbShopInfo implements Serializable { * 商家二维码 */ private String shopQrcode; - - public String getShopQrcode() { - return shopQrcode; - } - - public void setShopQrcode(String shopQrcode) { - this.shopQrcode = shopQrcode; - } - - private static final long serialVersionUID = 1L; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getAccount() { - return account; - } - - public void setAccount(String account) { - this.account = account == null ? null : account.trim(); - } - - public String getShopCode() { - return shopCode; - } - - public void setShopCode(String shopCode) { - this.shopCode = shopCode == null ? null : shopCode.trim(); - } - - public String getSubTitle() { - return subTitle; - } - - public void setSubTitle(String subTitle) { - this.subTitle = subTitle == null ? null : subTitle.trim(); - } - - public String getMerchantId() { - return merchantId; - } - - public void setMerchantId(String merchantId) { - this.merchantId = merchantId == null ? null : merchantId.trim(); - } - - public String getShopName() { - return shopName; - } - - public void setShopName(String shopName) { - this.shopName = shopName == null ? null : shopName.trim(); - } - - public String getChainName() { - return chainName; - } - - public void setChainName(String chainName) { - this.chainName = chainName == null ? null : chainName.trim(); - } - - public String getBackImg() { - return backImg; - } - - public void setBackImg(String backImg) { - this.backImg = backImg == null ? null : backImg.trim(); - } - - public String getFrontImg() { - return frontImg; - } - - public void setFrontImg(String frontImg) { - this.frontImg = frontImg == null ? null : frontImg.trim(); - } - - public String getContactName() { - return contactName; - } - - public void setContactName(String contactName) { - this.contactName = contactName == null ? null : contactName.trim(); - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone == null ? null : phone.trim(); - } - - public String getLogo() { - return logo; - } - - public void setLogo(String logo) { - this.logo = logo == null ? null : logo.trim(); - } - - public Byte getIsDeposit() { - return isDeposit; - } - - public void setIsDeposit(Byte isDeposit) { - this.isDeposit = isDeposit; - } - - public Byte getIsSupply() { - return isSupply; - } - - public void setIsSupply(Byte isSupply) { - this.isSupply = isSupply; - } - - public String getCoverImg() { - return coverImg; - } - - public void setCoverImg(String coverImg) { - this.coverImg = coverImg == null ? null : coverImg.trim(); - } - - public String getShareImg() { - return shareImg; - } - - public void setShareImg(String shareImg) { - this.shareImg = shareImg == null ? null : shareImg.trim(); - } - - public String getDetail() { - return detail; - } - - public void setDetail(String detail) { - this.detail = detail == null ? null : detail.trim(); - } - - public String getLat() { - return lat; - } - - public void setLat(String lat) { - this.lat = lat == null ? null : lat.trim(); - } - - public String getLng() { - return lng; - } - - public void setLng(String lng) { - this.lng = lng == null ? null : lng.trim(); - } - - public String getMchId() { - return mchId; - } - - public void setMchId(String mchId) { - this.mchId = mchId == null ? null : mchId.trim(); - } - - public String getRegisterType() { - return registerType; - } - - public void setRegisterType(String registerType) { - this.registerType = registerType == null ? null : registerType.trim(); - } - - public Byte getIsWxMaIndependent() { - return isWxMaIndependent; - } - - public void setIsWxMaIndependent(Byte isWxMaIndependent) { - this.isWxMaIndependent = isWxMaIndependent; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address == null ? null : address.trim(); - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city == null ? null : city.trim(); - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type == null ? null : type.trim(); - } - - public String getIndustry() { - return industry; - } - - public void setIndustry(String industry) { - this.industry = industry == null ? null : industry.trim(); - } - - public String getIndustryName() { - return industryName; - } - - public void setIndustryName(String industryName) { - this.industryName = industryName == null ? null : industryName.trim(); - } - - public String getBusinessTime() { - return businessTime; - } - - public void setBusinessTime(String businessTime) { - this.businessTime = businessTime == null ? null : businessTime.trim(); - } - - public String getPostTime() { - return postTime; - } - - public void setPostTime(String postTime) { - this.postTime = postTime == null ? null : postTime.trim(); - } - - public BigDecimal getPostAmountLine() { - return postAmountLine; - } - - public void setPostAmountLine(BigDecimal postAmountLine) { - this.postAmountLine = postAmountLine; - } - - public Byte getOnSale() { - return onSale; - } - - public void setOnSale(Byte onSale) { - this.onSale = onSale; - } - - public Byte getSettleType() { - return settleType; - } - - public void setSettleType(Byte settleType) { - this.settleType = settleType; - } - - public String getSettleTime() { - return settleTime; - } - - public void setSettleTime(String settleTime) { - this.settleTime = settleTime == null ? null : settleTime.trim(); - } - - public Integer getEnterAt() { - return enterAt; - } - - public void setEnterAt(Integer enterAt) { - this.enterAt = enterAt; - } - - public Long getExpireAt() { - return expireAt; - } - - public void setExpireAt(Long expireAt) { - this.expireAt = expireAt; - } - - public Byte getStatus() { - return status; - } - - public void setStatus(Byte status) { - this.status = status; - } - - public Float getAverage() { - return average; - } - - public void setAverage(Float average) { - this.average = average; - } - - public Integer getOrderWaitPayMinute() { - return orderWaitPayMinute; - } - - public void setOrderWaitPayMinute(Integer orderWaitPayMinute) { - this.orderWaitPayMinute = orderWaitPayMinute; - } - - public Integer getSupportDeviceNumber() { - return supportDeviceNumber; - } - - public void setSupportDeviceNumber(Integer supportDeviceNumber) { - this.supportDeviceNumber = supportDeviceNumber; - } - - public Byte getDistributeLevel() { - return distributeLevel; - } - - public void setDistributeLevel(Byte distributeLevel) { - this.distributeLevel = distributeLevel; - } - - public Long getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Long createdAt) { - this.createdAt = createdAt; - } - - public Long getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Long updatedAt) { - this.updatedAt = updatedAt; - } - - public String getProxyId() { - return proxyId; - } - - public void setProxyId(String proxyId) { - this.proxyId = proxyId == null ? null : proxyId.trim(); - } - - public String getView() { - return view; - } - - public void setView(String view) { - this.view = view == null ? null : view.trim(); - } + private String isOpenYhq; } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java index 01cdae9..6f03d88 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java @@ -17,6 +17,7 @@ public class TbSystemCoupons implements Serializable { private BigDecimal couponsAmount; private String status; + private String typeName; private Date createTime; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java new file mode 100644 index 0000000..6c513c1 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; + +@Data +public class TbWiningParams implements Serializable { + private Integer id; + + private BigDecimal minPrice; + + private BigDecimal maxPrice; + + private Integer winingNum; + + private Integer winingUserNum; + private String status; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java index f2b6862..6fdc83b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java @@ -17,9 +17,38 @@ public class TbWiningUser implements Serializable { private BigDecimal orderAmount; private String isUser; - private String tradeDay; private Date createTime; + private String isRefund; + + private BigDecimal refundAmount; + + private String refundNo; + + private String refundPayType; + + private String tradeDay; + + private Date refundTime; + + private static final long serialVersionUID = 1L; + public TbWiningUser(){ + super(); + } + public TbWiningUser(String userName,String orderNo,BigDecimal orderAmount, + String isUser,String tradeDay){ + this.createTime = new Date(); + this.userName = userName; + this.orderNo = orderNo; + this.orderAmount = orderAmount; + this.isUser = isUser; + this.tradeDay = tradeDay; + this.isRefund = "false"; + this.refundAmount = BigDecimal.ZERO; + this.refundPayType = "WX"; + + + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java new file mode 100644 index 0000000..0c6bd92 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java @@ -0,0 +1,58 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; + +public class TbYhqParams implements Serializable { + private Integer id; + + private String name; + + private BigDecimal minPrice; + + private BigDecimal maxPrice; + + private String status; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public BigDecimal getMinPrice() { + return minPrice; + } + + public void setMinPrice(BigDecimal minPrice) { + this.minPrice = minPrice; + } + + public BigDecimal getMaxPrice() { + return maxPrice; + } + + public void setMaxPrice(BigDecimal maxPrice) { + this.maxPrice = maxPrice; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java new file mode 100644 index 0000000..12cfe06 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author lyf + */ +@Data +public class IntegralFlowVo { + private String openId; + private Integer page; + private Integer pageSize; + private String sign; + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java new file mode 100644 index 0000000..da542b9 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java @@ -0,0 +1,108 @@ +package com.chaozhanggui.system.cashierservice.exception; + + +public enum DefaultError implements IError { + /** + * 系统内部错误 + */ + SYSTEM_INTERNAL_ERROR("0000", "系统错误"), + /** + * 无效参数 + */ + INVALID_PARAMETER("0001", "参数验证失败"), + /** + * 服务不存在 + */ + SERVICE_NOT_FOUND("0002", "服务不存在"), + /** + * 参数不全 + */ + PARAMETER_REQUIRED("0003", "参数不全"), + /** + * 参数过长 + */ + PARAMETER_MAX_LENGTH("0004", "参数过长"), + /** + * 参数过短 + */ + PARAMETER_MIN_LENGTH("0005", "参数过短"), + /** + * 认证失败 + */ + AUTHENTICATION_ERROR("0006", "认证失败"), + /** + * 认证动作失败 + */ + AUTHENTICATION_OPTION_ERROR("0007", "认证失败"), + /** + * 请求方法出错 + */ + METHOD_NOT_SUPPORTED("0008", "请求方法出错"), + /** + * 不支持的content类型 + */ + CONTENT_TYPE_NOT_SUPPORT("0009", "不支持的content类型"), + /** + * json格式化出错 + */ + JSON_FORMAT_ERROR("0010", "json格式化出错"), + /** + * 远程调用出错 + */ + CALL_REMOTE_ERROR("0011", "远程调用出错"), + /** + * 服务运行SQLException异常 + */ + SQL_EXCEPTION("0012", "服务运行SQL异常"), + /** + * 客户端异常 给调用者 app,移动端调用 + */ + CLIENT_EXCEPTION("0013", "客户端异常"), + /** + * 服务端异常, 微服务服务端产生的异常 + */ + SERVER_EXCEPTION("0014", "服务端异常"), + /** + * 授权失败 禁止访问 + */ + ACCESS_DENIED("0015", "没有访问权限"), + /** + * 演示环境 没有权限访问 + */ + SHOW_AUTH_CONTROL("0016", "演示环境,没有权限访问"), + /** + * 业务异常 + */ + BUSINESS_ERROR("0017", "业务异常"), + + NO_USER("0018","用户不存在"); + + String errorCode; + String errorMessage; + private static final String NS = "SYS"; + + DefaultError(String errorCode, String errorMessage) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + } + + @Override + public String getNameSpace() { + return NS; + } + + @Override + public String getErrorCode() { + return NS + "." + this.errorCode; + } + + @Override + public String getErrorMessage() { + return this.errorMessage; + } + + @Override + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java new file mode 100644 index 0000000..083db51 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -0,0 +1,155 @@ +package com.chaozhanggui.system.cashierservice.exception; + +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.validation.BindException; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.validation.ObjectError; +import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +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.servlet.NoHandlerFoundException; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.UnexpectedTypeException; +import java.sql.SQLException; +import java.util.List; +import java.util.Set; + +@ControllerAdvice +@ResponseBody +public class DefaultExceptionAdvice { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionAdvice.class); + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler({HttpMessageNotReadableException.class, }) + public ResponseEntity handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { + LOGGER.error("参数解析失败", e); + Result response = Result.failure(DefaultError.INVALID_PARAMETER); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @ExceptionHandler({HttpRequestMethodNotSupportedException.class}) + public ResponseEntity handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { + LOGGER.error("不支持当前请求方法", e); + Result response = Result.failure(DefaultError.METHOD_NOT_SUPPORTED); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.METHOD_NOT_ALLOWED); + } + + @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) + @ExceptionHandler({HttpMediaTypeNotSupportedException.class}) + public ResponseEntity handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) { + LOGGER.error("不支持当前媒体类型", e); + Result response = Result.failure(DefaultError.CONTENT_TYPE_NOT_SUPPORT); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.UNSUPPORTED_MEDIA_TYPE); + } + + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler({SQLException.class}) + public ResponseEntity handleSQLException(SQLException e) { + LOGGER.error("服务运行SQLException异常", e); + Result response = Result.failure(DefaultError.SQL_EXCEPTION); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); + } + + /** + * 所有异常统一处理 + * + * @return ResponseEntity + */ + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(Exception.class) + public ResponseEntity handleException(Exception ex) { + LOGGER.error("未知异常", ex); + IError error; + String extMessage = null; + if (ex instanceof BindException) { + error = DefaultError.INVALID_PARAMETER; + List errors = ((BindException) ex).getAllErrors(); + if (errors.size() != 0) { + StringBuilder msg = new StringBuilder(); + for (ObjectError objectError : errors) { + msg.append("Field error in object '").append(objectError.getObjectName()).append(" "); + if (objectError instanceof FieldError) { + msg.append("on field ").append(((FieldError) objectError).getField()).append(" "); + } + msg.append(objectError.getDefaultMessage()).append(" "); + } + extMessage = msg.toString(); + } + } else if (ex instanceof MissingServletRequestParameterException) { + error = DefaultError.INVALID_PARAMETER; + extMessage = ex.getMessage(); + } else if (ex instanceof ConstraintViolationException) { + error = DefaultError.INVALID_PARAMETER; + Set> violations = ((ConstraintViolationException) ex).getConstraintViolations(); + final StringBuilder msg = new StringBuilder(); + for (ConstraintViolation constraintViolation : violations) { + msg.append(constraintViolation.getPropertyPath()).append(":").append(constraintViolation.getMessage()).append("\n"); + } + extMessage = msg.toString(); + } else if (ex instanceof HttpMediaTypeNotSupportedException) { + error = DefaultError.CONTENT_TYPE_NOT_SUPPORT; + extMessage = ex.getMessage(); + } else if (ex instanceof HttpMessageNotReadableException) { + error = DefaultError.INVALID_PARAMETER; + extMessage = ex.getMessage(); + } else if (ex instanceof MethodArgumentNotValidException) { + error = DefaultError.INVALID_PARAMETER; + final BindingResult result = ((MethodArgumentNotValidException) ex).getBindingResult(); + if (result.hasErrors()) { + extMessage = result.getAllErrors().get(0).getDefaultMessage(); + } else { + extMessage = ex.getMessage(); + } + } else if (ex instanceof HttpRequestMethodNotSupportedException) { + error = DefaultError.METHOD_NOT_SUPPORTED; + extMessage = ex.getMessage(); + } else if (ex instanceof UnexpectedTypeException) { + error = DefaultError.INVALID_PARAMETER; + extMessage = ex.getMessage(); + } else if (ex instanceof NoHandlerFoundException) { + error = DefaultError.SERVICE_NOT_FOUND; + extMessage = ex.getMessage(); + } else { + error = DefaultError.SYSTEM_INTERNAL_ERROR; + extMessage = ex.getMessage(); + } + + + Result response = Result.failure(error); + response.setMsg(extMessage); + return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); + } + + /** + * BusinessException 业务异常处理 + * + * @return ResponseEntity + */ + @ResponseStatus(HttpStatus.OK) + @ExceptionHandler(MsgException.class) + public ResponseEntity handleException(MsgException e) { + LOGGER.error("业务异常", e); + Result response = Result.failure(DefaultError.BUSINESS_ERROR); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.OK); + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java new file mode 100644 index 0000000..56d1d1b --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java @@ -0,0 +1,32 @@ +package com.chaozhanggui.system.cashierservice.exception; + +public interface IError { + + /** + * 获取nameSpace + * + * @return nameSpace + */ + String getNameSpace(); + + /** + * 获取错误码 + + * @return 错误码 + */ + String getErrorCode(); + + /** + * 获取错误信息 + + * @return 错误信息 + */ + String getErrorMessage(); + + /** + * 设置错误信息 + * + * @param errorMessage 错误信息 + */ + void setErrorMessage(String errorMessage); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index a1edf56..97be65c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -29,7 +29,7 @@ import java.util.*; @Slf4j @Component -@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) +//@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) @Service public class CartConsumer { @@ -39,6 +39,7 @@ public class CartConsumer { @Autowired private CartService cartService; @RabbitHandler + @RabbitListener(queues = {"${queue}"}) public void listener(String message) { try { JSONObject jsonObject = JSON.parseObject(message); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java index 2fcbea8..2e1f20c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java @@ -27,7 +27,8 @@ public class RabbitConfig { @Value("${spring.rabbitmq.password}") private String password; - + @Value("${prod}") + private String prod; @Bean @@ -49,17 +50,17 @@ public class RabbitConfig { } @Bean public DirectExchange defaultExchange_Register() { - return new DirectExchange(RabbitConstants.CART_PUT); + return new DirectExchange(RabbitConstants.CART_PUT+prod); } @Bean public Queue queuePut_Register() { - return new Queue(RabbitConstants.CART_QUEUE_PUT, true); //队列持久 + return new Queue(RabbitConstants.CART_QUEUE_PUT+prod, true); //队列持久 } @Bean public Binding bindingPut_Register() { - return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT); + return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT+prod); } @Bean public DirectExchange defaultIntegral() { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java index 89c24fe..1e44c86 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java @@ -32,10 +32,10 @@ public interface RabbitConstants { - public static final String INTEGRAL_PUT="integral_put"; + public static final String INTEGRAL_PUT="integral_put1"; - public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put"; + public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put1"; - public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put"; + public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put1"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java index 8d6eba4..5498148 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -16,7 +17,8 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { private final Logger logger = LoggerFactory.getLogger(this.getClass()); private RabbitTemplate rabbitTemplate; - + @Value("${prod}") + private String prod; @Autowired public RabbitProducer(RabbitTemplate rabbitTemplate) { this.rabbitTemplate = rabbitTemplate; @@ -25,7 +27,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { public void putCart(String content) { CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); - rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT, RabbitConstants.CART_ROUTINGKEY_PUT, content, correlationId); + rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT+prod, RabbitConstants.CART_ROUTINGKEY_PUT+prod, content, correlationId); } public void putOrderCollect(String content) { CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); @@ -38,7 +40,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { } public void printCoupons(String content){ CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); - rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_QUEUE_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId); + rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId); } @Override public void confirm(CorrelationData correlationData, boolean ack, String cause) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index c649946..b8640f5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -213,7 +213,7 @@ public class CartService { BigDecimal packAMount = BigDecimal.ZERO; BigDecimal originAmount = BigDecimal.ZERO; BigDecimal saleAmount = BigDecimal.ZERO; - String couponId = ""; + String couponId = jsonObject.getString("couponsId"); BigDecimal couponAmount = BigDecimal.ZERO; Map skuMap = new HashMap<>(); List orderDetails = new ArrayList<>(); @@ -270,12 +270,12 @@ public class CartService { //生成订单 TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); String isBuyYhq = "false"; - if (jsonObject.containsKey("isYhq")){ + if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { //1:购买优惠券,0:自己持有优惠券 Integer couponsId = jsonObject.getInteger("couponsId"); - if (jsonObject.getString("isBuyYhq").equals("1")){ + if (jsonObject.getString("isBuyYhq").equals("1")) { TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")){ + if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -286,7 +286,7 @@ public class CartService { log.info("消息推送"); return; } - if (N.gt(systemCoupons.getCouponsAmount(),totalAmount)){ + if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -299,21 +299,22 @@ public class CartService { } totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount()); originAmount = originAmount.add(systemCoupons.getCouponsPrice()); + couponAmount = systemCoupons.getCouponsAmount(); systemCoupons.setStatus("1"); systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons); TbUserCoupons userCoupons = new TbUserCoupons(); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,systemCoupons.getDayNum())); + userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 3, systemCoupons.getDayNum())); userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount()); userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice()); userCoupons.setStatus("1"); userCoupons.setUserId(userId); userCoupons.setCreateTime(new Date()); userCouponsMapper.insert(userCoupons); - couponId = userCoupons.getId()+""; + couponId = userCoupons.getId() + ""; couponAmount = userCoupons.getCouponsAmount(); - }else { + } else { TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")){ + if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -324,7 +325,7 @@ public class CartService { log.info("消息推送"); return; } - if (N.gt(userCoupons.getCouponsAmount(),totalAmount)){ + if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -337,93 +338,94 @@ public class CartService { } totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount()); userCoupons.setStatus("1"); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(),5,30)); + userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30)); userCouponsMapper.updateByPrimaryKeySelective(userCoupons); + couponAmount = userCoupons.getCouponsAmount(); } - }else { - if (Objects.nonNull(orderInfo)) { - log.info("订单状态:" + orderInfo.getStatus()); - if (!"unpaid".equals(orderInfo.getStatus())) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单正在支付中,请稍后再试"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - orderDetailMapper.deleteByOUrderId(orderId); - orderInfo.setUpdatedAt(System.currentTimeMillis()); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setUserCouponAmount(couponAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOriginAmount(originAmount); - orderInfo.setOrderAmount(totalAmount.add(packAMount)); - orderInfo.setFreightAmount(BigDecimal.ZERO); - orderInfo.setProductAmount(saleAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setUserCouponAmount(couponAmount); - orderInfoMapper.updateByPrimaryKeySelective(orderInfo); - } else { - orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); - orderInfo = getOrder(totalAmount,packAMount,shopTable,tbMerchantAccount.getId().toString(),jsonObject,originAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setOriginAmount(originAmount); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setUserCouponAmount(couponAmount); - orderInfoMapper.insert(orderInfo); - orderId = orderInfo.getId(); - } - for (TbOrderDetail orderDetail : orderDetails) { - orderDetail.setOrderId(orderId); - orderDetailMapper.insert(orderDetail); - } - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - cashierCart.setUpdatedAt(System.currentTimeMillis()); - cashierCart.setOrderId(orderId + ""); - cashierCart.setStatus("closed"); - cashierCartMapper.updateByPrimaryKeySelective(cashierCart); - object.put("updatedAt", System.currentTimeMillis()); - object.put("orderId", orderId + ""); - } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); - orderInfo.setDetailList(orderDetails); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", orderInfo); - redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); - JSONObject jsonObject12 = new JSONObject(); - jsonObject12.put("status", "success"); - jsonObject12.put("msg", "成功"); - jsonObject12.put("type", "order"); - jsonObject12.put("amount", BigDecimal.ZERO); - jsonObject12.put("data", new JSONArray()); - AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); } + if (Objects.nonNull(orderInfo)) { + log.info("订单状态:" + orderInfo.getStatus()); + if (!"unpaid".equals(orderInfo.getStatus())) { + log.info("开始处理订单"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "订单正在支付中,请稍后再试"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", ""); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + log.info("消息推送"); + return; + } + + orderDetailMapper.deleteByOUrderId(orderId); + orderInfo.setUpdatedAt(System.currentTimeMillis()); + orderInfo.setSettlementAmount(totalAmount); + orderInfo.setUserCouponId(couponId); + orderInfo.setUserCouponAmount(couponAmount); + orderInfo.setAmount(totalAmount); + orderInfo.setOriginAmount(originAmount); + orderInfo.setOrderAmount(totalAmount.add(packAMount)); + orderInfo.setFreightAmount(BigDecimal.ZERO); + orderInfo.setProductAmount(saleAmount); + orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfoMapper.updateByPrimaryKeySelective(orderInfo); + } else { + orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount); + orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); + orderInfo.setUserCouponId(couponId); + orderInfo.setOriginAmount(originAmount); + orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfo.setUserCouponAmount(couponAmount); + orderInfoMapper.insert(orderInfo); + orderId = orderInfo.getId(); + } + for (TbOrderDetail orderDetail : orderDetails) { + orderDetail.setOrderId(orderId); + orderDetailMapper.insert(orderDetail); + } + for (int i = 0; i < array.size(); i++) { + JSONObject object = array.getJSONObject(i); + TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + cashierCart.setUpdatedAt(System.currentTimeMillis()); + cashierCart.setOrderId(orderId + ""); + cashierCart.setStatus("closed"); + cashierCartMapper.updateByPrimaryKeySelective(cashierCart); + object.put("updatedAt", System.currentTimeMillis()); + object.put("orderId", orderId + ""); + } + redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); + orderInfo.setDetailList(orderDetails); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", orderInfo); + redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + JSONObject jsonObject12 = new JSONObject(); + jsonObject12.put("status", "success"); + jsonObject12.put("msg", "成功"); + jsonObject12.put("type", "order"); + jsonObject12.put("amount", BigDecimal.ZERO); + + jsonObject12.put("data", new JSONArray()); + AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); } catch (Exception e) { e.getMessage(); } } + private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount, - TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount){ + TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount) { TbOrderInfo orderInfo = new TbOrderInfo(); String orderNo = generateOrderNumber(); orderInfo.setOrderNo(orderNo); orderInfo.setSettlementAmount(totalAmount); orderInfo.setPackFee(packAMount); orderInfo.setOriginAmount(originAmount); - orderInfo.setProductAmount(totalAmount); + orderInfo.setProductAmount(originAmount); orderInfo.setAmount(totalAmount); orderInfo.setOrderAmount(totalAmount.add(packAMount)); orderInfo.setPayAmount(BigDecimal.ZERO); @@ -445,12 +447,14 @@ public class CartService { orderInfo.setMerchantId(merchantId); return orderInfo; } + public String generateOrderNumber() { String date = DateUtils.getSdfTimes(); Random random = new Random(); int randomNum = random.nextInt(900) + 100; return "WX" + date + randomNum; } + public void clearCart(JSONObject jsonObject) throws IOException { String shopId = jsonObject.getString("shopId"); if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 0e9532c..21ffb9a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -156,6 +156,11 @@ public class LoginService { } return Result.fail("登录失败"); } + public static void main(String[] args) throws Exception { + String token = TokenUtil.generateToken(19, "or1l8654IFK6GIBQjK1ZKaPH3x0M", + "19191703856", "微信用户"); + System.out.println(token); + } public TbUserInfo register(String phone, String password, String nickName) { @@ -304,9 +309,5 @@ public class LoginService { return Result.success(CodeEnum.ENCRYPT, map); } - public static void main(String[] args) { - for (int i = 0; i < 10; i++) { - System.out.println(RandomUtil.randomNumbers(10)); - } - } + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index e158128..c6352fd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -3,17 +3,20 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo; import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.N; import com.chaozhanggui.system.cashierservice.util.RedisUtils; import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import com.github.pagehelper.PageHelper; @@ -27,6 +30,7 @@ import javax.annotation.Resource; import java.awt.print.Pageable; import java.io.IOException; import java.math.BigDecimal; +import java.text.ParseException; import java.time.Instant; import java.util.ArrayList; import java.util.Date; @@ -41,7 +45,7 @@ import java.util.concurrent.TimeUnit; public class OrderService { @Resource - private TbShopUserMapper shopUserMapper; + private RabbitProducer producer; @Resource private TbOrderInfoMapper orderInfoMapper; @@ -62,7 +66,7 @@ public class OrderService { @Resource private TbOrderDetailMapper tbOrderDetailMapper; @Autowired - private TbIntegralMapper tbIntegralMapper; + private TbReleaseFlowMapper releaseFlowMapper; @Resource private TbParamsMapper paramsMapper; @Resource @@ -73,6 +77,8 @@ public class OrderService { private TbUserCouponsMapper userCouponsMapper; @Resource private TbSystemCouponsMapper systemCouponsMapper; + @Autowired + private TbYhqParamsMapper yhqParamsMapper; /** * 创建订单 * @@ -253,37 +259,62 @@ public class OrderService { } @Transactional(rollbackFor = Exception.class) - public Result tradeIntegral(String userId, String id) { + public Result tradeIntegral(String userId, String id) throws ParseException { updateIntegral(userId, id); return Result.success(CodeEnum.ENCRYPT); } - private void updateIntegral(String userId, String id) { + private void updateIntegral(String userId, String id) throws ParseException { boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS); if (lock_coin) { - TbIntegral integral = tbIntegralMapper.selectByPrimaryKey(Integer.valueOf(id)); - if (Objects.isNull(integral) || !integral.getStatus().equals("1")) { + TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(Integer.valueOf(id)); + if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { throw new MsgException("该优惠券已被使用"); } TbParams params = paramsMapper.selectByPrimaryKey(1); - BigDecimal jfAmount = params.getTradeRatio().multiply(integral.getNum()); - TbShopUser tbShopUser = shopUserMapper.selectByUserId(userId); - tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(jfAmount)); - shopUserMapper.updateByPrimaryKeySelective(tbShopUser); - integral.setStatus("TRADE"); - integral.setUpdateTime(new Date()); - tbIntegralMapper.updateByPrimaryKeySelective(integral); + BigDecimal jfAmount = params.getTradeRatio().multiply(userCoupons.getCouponsAmount()); + TbUserInfo tbShopUser = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + tbShopUser.setTotalScore(tbShopUser.getTotalScore()+jfAmount.intValue()); + userInfoMapper.updateByPrimaryKeySelective(tbShopUser); + userCoupons.setStatus("2"); + userCoupons.setUpdateTime(new Date()); + userCouponsMapper.updateByPrimaryKeySelective(userCoupons); + TbSystemCoupons systemCoupons = new TbSystemCoupons(); + systemCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30)); + systemCoupons.setCouponsAmount(userCoupons.getCouponsAmount()); + systemCoupons.setCouponsPrice(userCoupons.getCouponsPrice()); + systemCoupons.setStatus("0"); + systemCoupons.setName(userCoupons.getCouponsAmount()+"无门槛优惠券"); + systemCoupons.setCreateTime(new Date()); + String typeName = findName(userCoupons.getCouponsAmount()); + systemCoupons.setTypeName(typeName); + systemCouponsMapper.insert(systemCoupons); + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + releaseFlow.setNum(jfAmount); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setUserId(userId); + releaseFlow.setType("EXCHANGEADD"); + releaseFlowMapper.insert(releaseFlow); redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); } else { updateIntegral(userId, id); } } -// public Result mineYhq(String userId) { -// List list = tbIntegralMapper.selectAllByUserId(userId); -// return Result.success(CodeEnum.ENCRYPT, list); -// } + private String findName(BigDecimal amount) { + List list = yhqParamsMapper.selectAll(); + String typeName = ""; + for (TbYhqParams yhqParams:list){ + if (N.egt(amount,yhqParams.getMinPrice()) && N.gt(yhqParams.getMaxPrice(),amount)){ + typeName = yhqParams.getName(); + break; + } + } + return typeName; + } + public Result mineCoupons(String userId, String status, Integer page, Integer size) { PageHelper.startPage(page, size); @@ -292,9 +323,9 @@ public class OrderService { return Result.success(CodeEnum.SUCCESS, pageInfo); } - public Result findCoupons(Integer page, Integer size) { + public Result findCoupons(String type, Integer page, Integer size) { PageHelper.startPage(page, size); - List list = systemCouponsMapper.selectAll(); + List list = systemCouponsMapper.selectAll(type); PageInfo pageInfo = new PageInfo(list); return Result.success(CodeEnum.SUCCESS, pageInfo); } @@ -304,4 +335,28 @@ public class OrderService { List list = tbWiningUserMapper.selectAllByTrade(day); return Result.success(CodeEnum.SUCCESS, list); } + + public Result getYhqPara() { + List list = yhqParamsMapper.selectAll(); + return Result.success(CodeEnum.SUCCESS, list); + } + + public Result testPay(Integer orderId) { + TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + orderInfo.setStatus("closed"); + orderInfo.setPayType("wx_lite"); + orderInfo.setPayOrderNo("test"); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + orderInfoMapper.updateByPrimaryKeySelective(orderInfo); + JSONObject jsonObject=new JSONObject(); + jsonObject.put("token",0); + jsonObject.put("type","wxcreate"); + jsonObject.put("orderId",orderId.toString()); + producer.putOrderCollect(jsonObject.toJSONString()); + JSONObject coupons = new JSONObject(); + coupons.put("type","buy"); + coupons.put("orderId",orderId); + producer.printCoupons(coupons.toJSONString()); + return Result.success(CodeEnum.SUCCESS); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 1dcefcb..0162190 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -246,7 +246,11 @@ public class PayService { log.info("发送打印数据"); producer.printMechine(orderInfo.getId() + ""); - + log.info("发送赠送购物券"); + JSONObject coupons = new JSONObject(); + coupons.put("type","buy"); + coupons.put("orderId",orderId); + producer.printCoupons(coupons.toJSONString()); return Result.success(CodeEnum.SUCCESS,orderId); case "2": //退款成功 cartStatus="refund"; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index a29904b..42c957b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; @@ -13,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; +import com.github.pagehelper.PageHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -106,23 +108,17 @@ public class UserService { tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(num)); } if (flag) { + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + releaseFlow.setNum(num); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setUserId(userId); if (type.equals("sub")) { - TbReleaseFlow releaseFlow = new TbReleaseFlow(); - releaseFlow.setNum(num); - releaseFlow.setCreateTime(new Date()); - releaseFlow.setFromSource("OWER"); releaseFlow.setType("BUYSUB"); - releaseFlow.setUserId(userId); - releaseFlowMapper.insert(releaseFlow); }else if (type.equals("sub")){ - TbReleaseFlow releaseFlow = new TbReleaseFlow(); - releaseFlow.setNum(num); - releaseFlow.setCreateTime(new Date()); - releaseFlow.setFromSource("OWER"); releaseFlow.setType("THREEADD"); - releaseFlow.setUserId(userId); - releaseFlowMapper.insert(releaseFlow); } + releaseFlowMapper.insert(releaseFlow); shopUserMapper.updateByPrimaryKeySelective(tbShopUser); } redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); @@ -131,4 +127,35 @@ public class UserService { return updateIntegral(userId, num, type); } } + + public JSONObject userIntegral(IntegralFlowVo integralFlowVo, String userSign) { + JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo); + object.put("userSign", userSign); + JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map); + System.out.println(jsonObject.toJSONString()); + String sign = MD5Util.encrypt(jsonObject.toJSONString()); + if (!sign.equals(integralFlowVo.getSign())) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "签名验证失败"); + result.put("data", ""); + return result; + } + TbShopUser shopUser = shopUserMapper.selectByOpenId(integralFlowVo.getOpenId()); + if (Objects.isNull(shopUser)) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "用户不存在"); + result.put("data", ""); + return result; + } + PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize()); + PageHelper.orderBy("id DESC"); + List list = releaseFlowMapper.selectByUserId(shopUser.getId()); + JSONObject result = new JSONObject(); + result.put("status", "success"); + result.put("msg", "成功"); + result.put("data",list); + return result; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java index 114d58a..a47ee5a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.sign; import cn.hutool.json.JSONUtil; +import com.chaozhanggui.system.cashierservice.exception.IError; import com.chaozhanggui.system.cashierservice.util.DESUtil; import java.util.List; @@ -143,4 +144,12 @@ public class Result { dto.setIcon(CodeEnum.FAIL.getIcon()); return dto; } + public static Result failure(IError error) { + Result dto = new Result(); + dto.setMsg(error.getErrorMessage()); + dto.setEncrypt(false); + dto.setCode(error.getErrorCode()); + dto.setIcon(CodeEnum.FAIL.getIcon()); + return dto; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index c53181b..eac5be3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -111,18 +111,6 @@ public class AppWebSocketServer { serverList.add(this); webSocketMap.put(tableId + "-" + shopId, serverList); } - SocketSession socketSession = new SocketSession(); - socketSession.setSession(session); - socketSession.setShopId(shopId); - socketSession.setTableId(tableId); - socketSession.setUserId(userId); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(session); - byte[] sessionData = bos.toByteArray(); - - // 将序列化后的会话数据存储到Redis中 - redisUtils.saveHashAll(session.getId().getBytes(), sessionData); if (userMap.containsKey(tableId + "-" + shopId)) { Set userSet = userMap.get(tableId + "-" + shopId); userSet.add(userId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java index 771b43d..88eead9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java @@ -1,17 +1,38 @@ package com.chaozhanggui.system.cashierservice.task; +import com.chaozhanggui.system.cashierservice.dao.TbOrderInfoMapper; +import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper; +import com.chaozhanggui.system.cashierservice.dao.TbWiningParamsMapper; import com.chaozhanggui.system.cashierservice.dao.TbWiningUserMapper; +import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo; +import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; +import com.chaozhanggui.system.cashierservice.entity.TbWiningParams; +import com.chaozhanggui.system.cashierservice.entity.TbWiningUser; import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.NicknameGenerator; +import com.chaozhanggui.system.cashierservice.util.RandomUtil; +import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.ParseException; +import java.util.*; +import java.util.concurrent.*; + @Component public class TaskScheduler { @Autowired private TbWiningUserMapper tbWiningUserMapper; - + @Autowired + private TbOrderInfoMapper orderInfoMapper; + @Autowired + private TbWiningParamsMapper winingParamsMapper; + @Autowired + private TbUserInfoMapper userInfoMapper; //更新订单状态 // @Scheduled(fixedRate = 1000, initialDelay = 5000) public void orderStatus() throws InterruptedException { @@ -20,9 +41,81 @@ public class TaskScheduler { } - // @Scheduled(fixedRate = 1000) - public void winningUser(){ - System.out.println("恭喜您中奖了"+DateUtils.getTime()); + public void winningUser() { + String day = DateUtils.getDay(); + List list = winingParamsMapper.selectAll(); + ThreadPoolExecutor es = new ThreadPoolExecutor(5, 10, 60L, TimeUnit.SECONDS, + new LinkedBlockingQueue(), new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + }); + for (TbWiningParams winingParams : list) { + es.submit(new winingUser(winingParams, day)); + } + es.shutdown(); + + } + + class winingUser implements Runnable { + private TbWiningParams winingParams; + private String day; + + public winingUser(TbWiningParams winingParams, String day) { + this.winingParams = winingParams; + this.day = day; + } + + @Override + public void run() { + try { + List list = orderInfoMapper.selectByTradeDay(day, winingParams.getMinPrice(), winingParams.getMaxPrice()); + int num = winingParams.getWiningUserNum(); + List newList = new ArrayList<>(); + Map map = new HashMap<>(); + int noUserNum = winingParams.getWiningNum() - num; + if (list.size() < num) { + noUserNum = winingParams.getWiningNum(); + } else { + for (int i = 0; i < num; i++) { + TbOrderInfo orderInfo = RandomUtil.selectWinner(list, map); + newList.add(orderInfo); + map.put(orderInfo.getId(), 1); + } + } + for (int i = 0; i < noUserNum; i++) { + long endDate = DateUtils.convertDate1(day + " 00:00:00").getTime(); + long startDate = DateUtils.convertDate1(DateUtils.getTimes(DateUtils.getNewDate(new Date(), 3, -1)) + " 00:00:00").getTime(); + String orderNo = generateOrderNumber(startDate, endDate); + String userName = NicknameGenerator.generateRandomWeChatNickname(); + BigDecimal orderAmount = RandomUtil.getRandomBigDecimal(winingParams.getMinPrice(), winingParams.getMaxPrice()); + TbWiningUser winingUser = new TbWiningUser(userName, orderNo, orderAmount, "false", day); + tbWiningUserMapper.insert(winingUser); + } + for (TbOrderInfo orderInfo:newList){ + TbUserInfo userInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getUserId())); + TbWiningUser winingUser = new TbWiningUser(userInfo.getNickName(), orderInfo.getOrderNo(), orderInfo.getPayAmount(), "true", day); + tbWiningUserMapper.insert(winingUser); + } + } catch (ParseException e) { + e.printStackTrace(); + } + } + } + + public String generateOrderNumber(long startTimestamp, long endTimestamp) { + long date = getRandomTimestamp(startTimestamp, endTimestamp); + Random random = new Random(); + int randomNum = random.nextInt(900) + 100; + return "WX" + date + randomNum; + } + + public static long getRandomTimestamp(long startTimestamp, long endTimestamp) { + long randomMilliseconds = ThreadLocalRandom.current().nextLong(startTimestamp, endTimestamp); + return randomMilliseconds; } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java new file mode 100644 index 0000000..f50d390 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java @@ -0,0 +1,40 @@ +package com.chaozhanggui.system.cashierservice.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; + +public class NicknameGenerator { + private static final String[] FIRST_NAMES = { + "晓", "小", "云", "飞", "宝", "琳", "静", "翔", "晨", "昊", "若", "萌", "悦", "舒", "婷", "紫", "凡", "佳", "雨", "阳" + }; + + private static final String[] LAST_NAMES = { + "天", "星", "月", "琪", "雪", "梦", "婷", "晨", "宇", "瑞", "颖", "欣", "莹", "妍", "娜", "辰", "楠", "妮", "欢", "瑶" + }; + + private static final String[] WORDS = { + "烟火", "夜景", "小巷", "阳光", "雨滴", "星空", "花海", "梦境", "魔法", "飞翔", "童话", "温柔", "快乐", "微笑", "甜蜜", "浪漫", "幸福" + }; + + private static final String[] EMOJIS = { + "(^-^)", "( ̄▽ ̄)~■干杯□~( ̄▽ ̄)", "(*^▽^*)", "≧◡≦", "ヾ(≧▽≦*)o", + "(*^3^)/~☆", "(*^▽^*)", "╰( ̄▽ ̄)╮", "(o^^)o", "(づ ̄ 3 ̄)づ" + }; + + public static String generateRandomWeChatNickname() { + Random random = new Random(); + String firstName = FIRST_NAMES[random.nextInt(FIRST_NAMES.length)]; + String lastName = LAST_NAMES[random.nextInt(LAST_NAMES.length)]; + String word = WORDS[random.nextInt(WORDS.length)]; + String emoji = EMOJIS[random.nextInt(EMOJIS.length)]; + return firstName + lastName + word + emoji; + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java new file mode 100644 index 0000000..c89b72e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java @@ -0,0 +1,31 @@ +package com.chaozhanggui.system.cashierservice.util; + +import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; +import java.util.Map; +import java.util.Random; + +public class RandomUtil { + //获取BigDeciaml随机数 + public static BigDecimal getRandomBigDecimal(BigDecimal minAmount, BigDecimal maxAmount) { + BigDecimal randomBigDecimal = maxAmount.subtract(minAmount).multiply(new BigDecimal(Math.random())).add(minAmount); + return randomBigDecimal.setScale(2, RoundingMode.HALF_UP); // 设置保留两位小数并四舍五入 + } + //获取中奖随机数 + public static TbOrderInfo selectWinner(List list, Map map) { + if (list == null || list.isEmpty()) { + return null; // 如果用户列表为空,则返回null + } + + Random random = new Random(); + int randomIndex = random.nextInt(list.size()); // 生成一个随机的索引值 + TbOrderInfo orderInfo = list.get(randomIndex); + if (map.containsKey(orderInfo.getId())){ + return selectWinner(list,map); + } + return list.get(randomIndex); // 返回对应索引的用户 + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java deleted file mode 100644 index 6268b23..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.chaozhanggui.system.cashierservice.util; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Random; - -public class WiningUtil { - private List participants; - private Random random; - - public WiningUtil(List participants) { - this.participants = participants; - this.random = new Random(); - } - - public String drawWinner() { - if (participants.isEmpty()) { - return "No participants to draw from"; - } - - int index = random.nextInt(participants.size()); - return participants.get(index); - } - - public static void main(String[] args) { - // 参与抽奖的人员名单 - List participants = new ArrayList<>(); - participants.add("Alice"); - participants.add("Bob"); - participants.add("Charlie"); - participants.add("David"); - participants.add("Eve"); - - // 创建抽奖对象 - WiningUtil winingUtil = new WiningUtil(participants); - - // 进行抽奖 - String winner = winingUtil.drawWinner(); - System.out.println("Winner: " + winner); - } - public static boolean winingresult(){ - - return false; - } -} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 393e40e..f0a4eef 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -55,7 +55,9 @@ ysk: callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 server: - port: 9889 + port: 9888 +prod: dev1 +queue: cart_queue_putdev1 diff --git a/src/main/resources/application-dev2.yml b/src/main/resources/application-dev2.yml new file mode 100644 index 0000000..022ca33 --- /dev/null +++ b/src/main/resources/application-dev2.yml @@ -0,0 +1,63 @@ +spring: + datasource: + url: jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false + username: root + password: mysqlroot@123 + driver-class-name: com.mysql.cj.jdbc.Driver + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + logging: + level: + com.chaozhanggui.system.openness: info + redis: + # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 + database: 5 + # redis服务器地址(默认为localhost) + host: 101.37.12.135 + # redis端口(默认为6379) + port: 6379 + # redis访问密码(默认为空) + password: 111111 + # redis连接超时时间(单位为毫秒) + timeout: 1000 + block-when-exhausted: true + # redis连接池配置 + jedis: + pool: + max-active: 8 + max-idle: 1024 + min-idle: 0 + max-wait: -1 + main: + allow-circular-references: true + rabbitmq: + host: 101.37.12.135 + port: 5672 + username: admin + password: Czg666888 +#分页配置 +pagehelper: + supportMethodsArguments: true + reasonable: true + helperDialect: mysql + params: count=countSql + +mybatis: + configuration: + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath:mapper/*.xml +ysk: + url: https://gatewaytestapi.sxczgkj.cn/gate-service/ + callBackurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBack + callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack + default: 18710449883 +server: + port: 9889 +prod: devyhq +queue: cart_queue_putdevyhq + + + diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index f8e8e1d..767ea64 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -56,6 +56,8 @@ ysk: callBackurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBack callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 +prod: prod1 +queue: cart_queue_putprod1 diff --git a/src/main/resources/application-prod2.yml b/src/main/resources/application-prod2.yml index e8c808b..22f552f 100644 --- a/src/main/resources/application-prod2.yml +++ b/src/main/resources/application-prod2.yml @@ -56,6 +56,8 @@ ysk: callBackurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBack callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 +prod: prod2 +queue: cart_queue_putprod2 diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index a31c3b8..c908550 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -52,7 +52,7 @@ -
diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index 0bef918..8b61660 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -552,4 +552,8 @@ + \ No newline at end of file diff --git a/src/main/resources/mapper/TbReleaseFlowMapper.xml b/src/main/resources/mapper/TbReleaseFlowMapper.xml new file mode 100644 index 0000000..597c801 --- /dev/null +++ b/src/main/resources/mapper/TbReleaseFlowMapper.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + id, user_id, num, type, remark, from_source, create_time + + + + + delete from tb_release_flow + where id = #{id,jdbcType=INTEGER} + + + insert into tb_release_flow (id, user_id, num, + type, remark, from_source, + create_time) + values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{num,jdbcType=DECIMAL}, + #{type,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{fromSource,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}) + + + insert into tb_release_flow + + + id, + + + user_id, + + + num, + + + type, + + + remark, + + + from_source, + + + create_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{userId,jdbcType=VARCHAR}, + + + #{num,jdbcType=DECIMAL}, + + + #{type,jdbcType=VARCHAR}, + + + #{remark,jdbcType=VARCHAR}, + + + #{fromSource,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + update tb_release_flow + + + user_id = #{userId,jdbcType=VARCHAR}, + + + num = #{num,jdbcType=DECIMAL}, + + + type = #{type,jdbcType=VARCHAR}, + + + remark = #{remark,jdbcType=VARCHAR}, + + + from_source = #{fromSource,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_release_flow + set user_id = #{userId,jdbcType=VARCHAR}, + num = #{num,jdbcType=DECIMAL}, + type = #{type,jdbcType=VARCHAR}, + remark = #{remark,jdbcType=VARCHAR}, + from_source = #{fromSource,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbShopInfoMapper.xml b/src/main/resources/mapper/TbShopInfoMapper.xml index a16fbc7..42dbfa5 100644 --- a/src/main/resources/mapper/TbShopInfoMapper.xml +++ b/src/main/resources/mapper/TbShopInfoMapper.xml @@ -45,6 +45,7 @@ + @@ -55,7 +56,7 @@ detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type, industry, industry_name, business_time, post_time, post_amount_line, on_sale, settle_type, settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number, - distribute_level, created_at, updated_at, proxy_id + distribute_level, created_at, updated_at, proxy_id,is_open_yhq view diff --git a/src/main/resources/mapper/TbSystemCouponsMapper.xml b/src/main/resources/mapper/TbSystemCouponsMapper.xml index 54ad7f7..2185fbf 100644 --- a/src/main/resources/mapper/TbSystemCouponsMapper.xml +++ b/src/main/resources/mapper/TbSystemCouponsMapper.xml @@ -7,12 +7,13 @@ + - id, name, coupons_price, coupons_amount, status, create_time, update_time, end_time + id, name, coupons_price, coupons_amount, status, create_time, update_time, end_time,type_name delete from tb_system_coupons @@ -30,10 +31,10 @@ insert into tb_system_coupons (id, name, coupons_price, coupons_amount, status, create_time, - update_time, end_time) + update_time, end_time,type_name) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{couponsPrice,jdbcType=DECIMAL}, #{couponsAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, - #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}) + #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{typeName,jdbcType=VARCHAR}) insert into tb_system_coupons diff --git a/src/main/resources/mapper/TbWiningParamsMapper.xml b/src/main/resources/mapper/TbWiningParamsMapper.xml new file mode 100644 index 0000000..00f9f38 --- /dev/null +++ b/src/main/resources/mapper/TbWiningParamsMapper.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + id, min_price, max_price, wining_num, wining_user_num,status + + + + + delete from tb_wining_params + where id = #{id,jdbcType=INTEGER} + + + insert into tb_wining_params (id, min_price, max_price, + wining_num, wining_user_num) + values (#{id,jdbcType=INTEGER}, #{minPrice,jdbcType=DECIMAL}, #{maxPrice,jdbcType=DECIMAL}, + #{winingNum,jdbcType=INTEGER}, #{winingUserNum,jdbcType=INTEGER}) + + + insert into tb_wining_params + + + id, + + + min_price, + + + max_price, + + + wining_num, + + + wining_user_num, + + + + + #{id,jdbcType=INTEGER}, + + + #{minPrice,jdbcType=DECIMAL}, + + + #{maxPrice,jdbcType=DECIMAL}, + + + #{winingNum,jdbcType=INTEGER}, + + + #{winingUserNum,jdbcType=INTEGER}, + + + + + update tb_wining_params + + + min_price = #{minPrice,jdbcType=DECIMAL}, + + + max_price = #{maxPrice,jdbcType=DECIMAL}, + + + wining_num = #{winingNum,jdbcType=INTEGER}, + + + wining_user_num = #{winingUserNum,jdbcType=INTEGER}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_wining_params + set min_price = #{minPrice,jdbcType=DECIMAL}, + max_price = #{maxPrice,jdbcType=DECIMAL}, + wining_num = #{winingNum,jdbcType=INTEGER}, + wining_user_num = #{winingUserNum,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbWiningUserMapper.xml b/src/main/resources/mapper/TbWiningUserMapper.xml index ab1b7a7..99bc24d 100644 --- a/src/main/resources/mapper/TbWiningUserMapper.xml +++ b/src/main/resources/mapper/TbWiningUserMapper.xml @@ -7,11 +7,17 @@ - + + + + + + - id, user_name, order_no, order_amount, is_user, create_time,trade_day + id, user_name, order_no, order_amount, is_user, create_time, is_refund, refund_amount, + refund_no, refund_pay_type, trade_day, refund_time - - + delete from tb_wining_user where id = #{id,jdbcType=INTEGER} insert into tb_wining_user (id, user_name, order_no, - order_amount, is_user, create_time + order_amount, is_user, create_time, + is_refund, refund_amount, refund_no, + refund_pay_type, trade_day, refund_time ) values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{orderNo,jdbcType=VARCHAR}, - #{orderAmount,jdbcType=DECIMAL}, #{isUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP} + #{orderAmount,jdbcType=DECIMAL}, #{isUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{isRefund,jdbcType=VARCHAR}, #{refundAmount,jdbcType=DECIMAL}, #{refundNo,jdbcType=VARCHAR}, + #{refundPayType,jdbcType=VARCHAR}, #{tradeDay,jdbcType=VARCHAR}, #{refundTime,jdbcType=TIMESTAMP} ) @@ -55,6 +62,24 @@ create_time, + + is_refund, + + + refund_amount, + + + refund_no, + + + refund_pay_type, + + + trade_day, + + + refund_time, + @@ -75,6 +100,24 @@ #{createTime,jdbcType=TIMESTAMP}, + + #{isRefund,jdbcType=VARCHAR}, + + + #{refundAmount,jdbcType=DECIMAL}, + + + #{refundNo,jdbcType=VARCHAR}, + + + #{refundPayType,jdbcType=VARCHAR}, + + + #{tradeDay,jdbcType=VARCHAR}, + + + #{refundTime,jdbcType=TIMESTAMP}, + @@ -95,6 +138,24 @@ create_time = #{createTime,jdbcType=TIMESTAMP}, + + is_refund = #{isRefund,jdbcType=VARCHAR}, + + + refund_amount = #{refundAmount,jdbcType=DECIMAL}, + + + refund_no = #{refundNo,jdbcType=VARCHAR}, + + + refund_pay_type = #{refundPayType,jdbcType=VARCHAR}, + + + trade_day = #{tradeDay,jdbcType=VARCHAR}, + + + refund_time = #{refundTime,jdbcType=TIMESTAMP}, + where id = #{id,jdbcType=INTEGER} @@ -104,7 +165,16 @@ order_no = #{orderNo,jdbcType=VARCHAR}, order_amount = #{orderAmount,jdbcType=DECIMAL}, is_user = #{isUser,jdbcType=VARCHAR}, - create_time = #{createTime,jdbcType=TIMESTAMP} + create_time = #{createTime,jdbcType=TIMESTAMP}, + is_refund = #{isRefund,jdbcType=VARCHAR}, + refund_amount = #{refundAmount,jdbcType=DECIMAL}, + refund_no = #{refundNo,jdbcType=VARCHAR}, + refund_pay_type = #{refundPayType,jdbcType=VARCHAR}, + trade_day = #{tradeDay,jdbcType=VARCHAR}, + refund_time = #{refundTime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=INTEGER} + \ No newline at end of file diff --git a/src/main/resources/mapper/TbYhqParamsMapper.xml b/src/main/resources/mapper/TbYhqParamsMapper.xml new file mode 100644 index 0000000..6636929 --- /dev/null +++ b/src/main/resources/mapper/TbYhqParamsMapper.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + id, name, min_price, max_price, status + + + + + delete from tb_yhq_params + where id = #{id,jdbcType=INTEGER} + + + insert into tb_yhq_params (id, name, min_price, + max_price, status) + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{minPrice,jdbcType=DECIMAL}, + #{maxPrice,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}) + + + insert into tb_yhq_params + + + id, + + + name, + + + min_price, + + + max_price, + + + status, + + + + + #{id,jdbcType=INTEGER}, + + + #{name,jdbcType=VARCHAR}, + + + #{minPrice,jdbcType=DECIMAL}, + + + #{maxPrice,jdbcType=DECIMAL}, + + + #{status,jdbcType=VARCHAR}, + + + + + update tb_yhq_params + + + name = #{name,jdbcType=VARCHAR}, + + + min_price = #{minPrice,jdbcType=DECIMAL}, + + + max_price = #{maxPrice,jdbcType=DECIMAL}, + + + status = #{status,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_yhq_params + set name = #{name,jdbcType=VARCHAR}, + min_price = #{minPrice,jdbcType=DECIMAL}, + max_price = #{maxPrice,jdbcType=DECIMAL}, + status = #{status,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file