diff --git a/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java b/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java index 253c5af..5725652 100644 --- a/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java +++ b/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java @@ -53,7 +53,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/api/wx-login/loginByMpWxPhone", "/api/wxWorkQrConnect", "/api/sys/user-plan-log/wx-pay/**", - "/api/wx-official/**" + "/api/wx-official/**", + "/lvQ4EoivKJ.txt" ) .permitAll() .anyRequest() diff --git a/src/main/java/com/gxwebsoft/common/core/socketio/config/SocketIOConfig.java b/src/main/java/com/gxwebsoft/common/core/socketio/config/SocketIOConfig.java index 3fe7fd0..d79884f 100644 --- a/src/main/java/com/gxwebsoft/common/core/socketio/config/SocketIOConfig.java +++ b/src/main/java/com/gxwebsoft/common/core/socketio/config/SocketIOConfig.java @@ -73,10 +73,10 @@ public class SocketIOConfig implements InitializingBean { config.setKeyStorePassword("123456"); // 设置证书密码 // 启动socket服务 - SocketIOServer server = new SocketIOServer(config); - server.addListeners(socketIOHandler); - server.start(); - ClientCache.setSocketIOServer(server); - logger.debug("Netty SocketIO启动:{}:{}",host,port); +// SocketIOServer server = new SocketIOServer(config); +// server.addListeners(socketIOHandler); +// server.start(); +// ClientCache.setSocketIOServer(server); +// logger.debug("Netty SocketIO启动:{}:{}",host,port); } } diff --git a/src/main/java/com/gxwebsoft/common/system/controller/OrderController.java b/src/main/java/com/gxwebsoft/common/system/controller/OrderController.java index 1c2f570..04fa874 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/OrderController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/OrderController.java @@ -1,10 +1,12 @@ package com.gxwebsoft.common.system.controller; +import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.system.entity.Company; import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.service.CompanyService; +import com.gxwebsoft.common.system.service.OrderInfoService; import com.gxwebsoft.common.system.service.OrderService; import com.gxwebsoft.common.system.entity.Order; import com.gxwebsoft.common.system.param.OrderParam; @@ -36,6 +38,8 @@ public class OrderController extends BaseController { private OrderService orderService; @Resource private CompanyService companyService; + @Resource + private OrderInfoService orderInfoService; @PreAuthorize("hasAuthority('sys:order:list')") @OperationLog @@ -69,21 +73,34 @@ public class OrderController extends BaseController { @ApiOperation("添加订单") @PostMapping() public ApiResult save(@RequestBody Order order) { - // 记录当前登录用户id - User loginUser = getLoginUser(); - if (loginUser != null) { - order.setUserId(loginUser.getUserId()); + // 记录当前登录用户id + User loginUser = getLoginUser(); + long timeMillis = System.currentTimeMillis(); + long orderNo = IdUtil.getSnowflakeNextId(); + if (loginUser != null) { + order.setUserId(loginUser.getUserId()); + order.setOpenid(loginUser.getOpenid()); + } + order.setOrderNo(Long.toString(orderNo)); + order.setRealName(loginUser.getRealName()); + order.setStartTime(timeMillis / 1000); + order.setAddTime(timeMillis / 1000); + order.setPhone(loginUser.getPhone()); + order.setVersion(10); + if (orderService.save(order)) { + order.getOrderInfoList().forEach(d -> { + d.setOid(order.getOrderId()); + d.setTimeFlag(timeMillis); + d.setVersion(10); + d.setOrderTime(timeMillis / 1000); + }); + orderInfoService.saveBatch(order.getOrderInfoList()); + // 创建微信订单 + if (order.getPayType().equals(1)) { + return success("下单成功",orderService.createWxOrder(order)); } - if (orderService.save(order)) { - System.out.println("order = " + order); - // 延长到期时间 - final Company company = companyService.getByTenantIdRel(order.getTenantId()); - company.setStatus(1); -// company.setExpirationTime(new Date()); - companyService.updateById(company); - return success("添加成功"); - } - return fail("添加失败"); + } + return fail("下单失败"); } @PreAuthorize("hasAuthority('sys:order:update')") diff --git a/src/main/java/com/gxwebsoft/common/system/controller/OrderInfoController.java b/src/main/java/com/gxwebsoft/common/system/controller/OrderInfoController.java new file mode 100644 index 0000000..9880593 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/controller/OrderInfoController.java @@ -0,0 +1,138 @@ +package com.gxwebsoft.common.system.controller; + +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.common.system.service.OrderInfoService; +import com.gxwebsoft.common.system.entity.OrderInfo; +import com.gxwebsoft.common.system.param.OrderInfoParam; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.annotation.OperationLog; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 控制器 + * + * @author 科技小王子 + * @since 2024-05-10 18:02:54 + */ +@Api(tags = "管理") +@RestController +@RequestMapping("/api/system/order-info") +public class OrderInfoController extends BaseController { + @Resource + private OrderInfoService orderInfoService; + + @PreAuthorize("hasAuthority('sys:orderInfo:list')") + @OperationLog + @ApiOperation("分页查询") + @GetMapping("/page") + public ApiResult> page(OrderInfoParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return success(orderInfoService.page(page, page.getWrapper())); + // 使用关联查询 + //return success(orderInfoService.pageRel(param)); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:list')") + @OperationLog + @ApiOperation("查询全部") + @GetMapping() + public ApiResult> list(OrderInfoParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return success(orderInfoService.list(page.getOrderWrapper())); + // 使用关联查询 + //return success(orderInfoService.listRel(param)); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:list')") + @OperationLog + @ApiOperation("根据id查询") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(orderInfoService.getById(id)); + // 使用关联查询 + //return success(orderInfoService.getByIdRel(id)); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:save')") + @OperationLog + @ApiOperation("添加") + @PostMapping() + public ApiResult save(@RequestBody OrderInfo orderInfo) { + // 记录当前登录用户id + User loginUser = getLoginUser(); + if (loginUser != null) { + } + if (orderInfoService.save(orderInfo)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:update')") + @OperationLog + @ApiOperation("修改") + @PutMapping() + public ApiResult update(@RequestBody OrderInfo orderInfo) { + if (orderInfoService.updateById(orderInfo)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:remove')") + @OperationLog + @ApiOperation("删除") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (orderInfoService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:save')") + @OperationLog + @ApiOperation("批量添加") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (orderInfoService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:update')") + @OperationLog + @ApiOperation("批量修改") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(orderInfoService, "id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:orderInfo:remove')") + @OperationLog + @ApiOperation("批量删除") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (orderInfoService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/common/system/controller/PaymentController.java b/src/main/java/com/gxwebsoft/common/system/controller/PaymentController.java new file mode 100644 index 0000000..3bdd488 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/controller/PaymentController.java @@ -0,0 +1,150 @@ +package com.gxwebsoft.common.system.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.gxwebsoft.common.core.utils.RedisUtil; +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.common.system.entity.Merchant; +import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.common.system.service.PaymentService; +import com.gxwebsoft.common.system.entity.Payment; +import com.gxwebsoft.common.system.param.PaymentParam; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.annotation.OperationLog; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 支付方式控制器 + * + * @author 科技小王子 + * @since 2024-05-11 12:39:11 + */ +@Api(tags = "支付方式管理") +@RestController +@RequestMapping("/api/system/payment") +public class PaymentController extends BaseController { + @Resource + private PaymentService paymentService; + @Resource + private RedisUtil redisUtil; + + @PreAuthorize("hasAuthority('sys:payment:list')") + @OperationLog + @ApiOperation("分页查询支付方式") + @GetMapping("/page") + public ApiResult> page(PaymentParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number asc, create_time asc"); + return success(paymentService.page(page, page.getWrapper())); + // 使用关联查询 +// return success(paymentService.pageRel(param)); + } + + @PreAuthorize("hasAuthority('sys:payment:list')") + @OperationLog + @ApiOperation("查询全部支付方式") + @GetMapping() + public ApiResult> list(PaymentParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number asc, create_time asc"); + return success(paymentService.list(page.getOrderWrapper())); + // 使用关联查询 + //return success(paymentService.listRel(param)); + } + + @PreAuthorize("hasAuthority('sys:payment:list')") + @OperationLog + @ApiOperation("根据id查询支付方式") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(paymentService.getById(id)); + // 使用关联查询 + //return success(paymentService.getByIdRel(id)); + } + + @PreAuthorize("hasAuthority('sys:payment:save')") + @OperationLog + @ApiOperation("添加支付方式") + @PostMapping() + public ApiResult save(@RequestBody Payment payment) { + if (paymentService.count(new LambdaQueryWrapper().eq(Payment::getCode,payment.getCode())) > 0) { + return fail(payment.getName() + "已存在"); + } + if (paymentService.save(payment)) { + String key = "Payment:" + payment.getCode() + ":" + getTenantId(); + redisUtil.set(key,payment); + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:payment:update')") + @OperationLog + @ApiOperation("修改支付方式") + @PutMapping() + public ApiResult update(@RequestBody Payment payment) { + if (paymentService.updateById(payment)) { + String key = "Payment:" + payment.getCode() + ":" + getTenantId(); + redisUtil.set(key,payment); + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:payment:remove')") + @OperationLog + @ApiOperation("删除支付方式") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + final Payment payment = paymentService.getById(id); + System.out.println("payment = " + payment); + String key = "Payment:" + payment.getCode() + ":" + getTenantId(); + redisUtil.delete(key); + if (paymentService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:payment:save')") + @OperationLog + @ApiOperation("批量添加支付方式") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (paymentService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:payment:update')") + @OperationLog + @ApiOperation("批量修改支付方式") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(paymentService, "id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:payment:remove')") + @OperationLog + @ApiOperation("批量删除支付方式") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (paymentService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/common/system/controller/VerifyTxt.java b/src/main/java/com/gxwebsoft/common/system/controller/VerifyTxt.java new file mode 100644 index 0000000..0199ea0 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/controller/VerifyTxt.java @@ -0,0 +1,19 @@ +package com.gxwebsoft.common.system.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "域名所有权验证") +@RestController +@RequestMapping("/lvQ4EoivKJ.txt") +public class VerifyTxt { + + @ApiOperation("域名所有权验证") + @GetMapping() + public String verify(){ + return "cbfbfe827744f1ebfaf03bfe2a0def6a"; + } +} diff --git a/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java b/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java index 2a0c5cb..a3e1f84 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java @@ -268,7 +268,12 @@ public class WxLoginController extends BaseController { final String response = HttpUtil.get(apiUrl,map); System.out.println("response = " + response); final JSONObject jsonObject = JSONObject.parseObject(response); - return fail("更新失败",null); + final String openid = jsonObject.getString("openid"); + jsonObject.getString("session_key"); + jsonObject.getString("unionid"); + System.out.println("openid = " + openid); + System.out.println("loginUser = " + loginUser); + return success("获取成功",jsonObject); } @ApiOperation("获取微信小程序码") diff --git a/src/main/java/com/gxwebsoft/common/system/controller/WxPayNotifyController.java b/src/main/java/com/gxwebsoft/common/system/controller/WxPayNotifyController.java new file mode 100644 index 0000000..539f4c5 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/controller/WxPayNotifyController.java @@ -0,0 +1,148 @@ +package com.gxwebsoft.common.system.controller; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayApiException; +import com.alipay.api.DefaultAlipayClient; +import com.alipay.api.request.AlipayTradeAppPayRequest; +import com.alipay.api.response.AlipayTradeAppPayResponse; +import com.gxwebsoft.common.core.config.ConfigProperties; +import com.gxwebsoft.common.core.utils.AlipayConfigUtil; +import com.gxwebsoft.common.core.utils.CommonUtil; +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.common.system.entity.Order; +import com.gxwebsoft.common.system.entity.Setting; +import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.common.system.mapper.SettingMapper; +import com.gxwebsoft.common.system.param.SettingParam; +import com.gxwebsoft.common.system.service.OrderInfoService; +import com.gxwebsoft.common.system.service.OrderService; +import com.gxwebsoft.common.system.service.SettingService; +import com.gxwebsoft.common.system.service.UserService; +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAConfig; +import com.wechat.pay.java.core.notification.NotificationConfig; +import com.wechat.pay.java.core.notification.NotificationParser; +import com.wechat.pay.java.core.notification.RSANotificationConfig; +import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction; +import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; +import com.wechat.pay.java.service.payments.jsapi.model.Amount; +import com.wechat.pay.java.service.payments.jsapi.model.Payer; +import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest; +import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModelProperty; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.util.HashMap; +import java.util.Map; + +import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_NO_PAY; +import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_SUCCESS; + +/** + * 会员特权购买记录表控制器 + * + * @author 科技小王子 + * @since 2023-06-20 18:07:50 + */ +@Api(tags = "会员特权购买记录表管理") +@RestController +@RequestMapping("/api/love/user-plan-log") +public class WxPayNotifyController extends BaseController { + @Resource + private OrderService orderService; + @Resource + private ConfigProperties config; + @Resource + private SettingMapper settingMapper; + + @ApiModelProperty("异步通知") + @PostMapping("/wx-pay/notify/{tenantId}") + public String wxNotify(@RequestHeader Map header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) { + System.out.println("异步通知*************** = "); + System.out.println("request header = " + header); + System.out.println("request body = " + body); + System.out.println("tenantId = " + tenantId); + + // 获取支付配置信息用于解密 + final SettingParam param = new SettingParam(); + param.setSettingKey("payment"); + param.setTenantId(tenantId); + final String uploadPath = config.getUploadPath(); // 服务器本地路径 + final Setting payment = settingMapper.getBySettingKeyIgnore(param); + final JSONObject jsonObject = JSONObject.parseObject(payment.getContent()); + final String apiV3key = jsonObject.getString("wechatApiKey"); + final String apiclientCert = uploadPath.concat("file").concat(jsonObject.getString("apiclientCert")); + +// System.out.println("apiV3key ====== " + apiV3key); +// System.out.println("payment ===== " + payment); + + com.wechat.pay.java.core.notification.RequestParam requestParam = new com.wechat.pay.java.core.notification.RequestParam.Builder() + .serialNumber(header.get("wechatpay-serial")) + .nonce(header.get("wechatpay-nonce")) + .signature(header.get("wechatpay-signature")) + .timestamp(header.get("wechatpay-timestamp")) + .body(body) + .build(); + + // 如果已经初始化了 RSAAutoCertificateConfig,可直接使用 + // 没有的话,则构造一个 + NotificationConfig config = new RSANotificationConfig.Builder() + .apiV3Key(apiV3key) + .certificatesFromPath(apiclientCert) + .build(); + + // 初始化 NotificationParser + NotificationParser parser = new NotificationParser(config); + + // 以支付通知回调为例,验签、解密并转换成 Transaction + try { + Transaction transaction = parser.parse(requestParam, Transaction.class); + final String outTradeNo = transaction.getOutTradeNo(); + final String transactionId = transaction.getTransactionId(); + final Integer total = transaction.getAmount().getTotal(); + final String tradeStateDesc = transaction.getTradeStateDesc(); +// final Transaction.TradeStateEnum tradeState = transaction.getTradeState(); +// final Transaction.TradeTypeEnum tradeType = transaction.getTradeType(); +// System.out.println("transaction = " + transaction); +// System.out.println("tradeStateDesc = " + tradeStateDesc); +// System.out.println("tradeType = " + tradeType); +// System.out.println("tradeState = " + tradeState); +// System.out.println("outTradeNo = " + outTradeNo); +// System.out.println("amount = " + total); + + if (StrUtil.equals("支付成功", tradeStateDesc)) { + // 1. 查询要处理的订单 + Order order = orderService.getByOutTradeNo(outTradeNo); + // 2. 已支付则跳过 + if (order.getPayStatus().equals(PAY_STATUS_SUCCESS)) { + return "SUCCESS"; + } + // 2. 未支付则处理更新订单状态 + if (order.getPayStatus().equals(PAY_STATUS_NO_PAY)) { + // 5. TODO 处理订单状态 + order.setPayStatus(PAY_STATUS_SUCCESS); + order.setPayTime(DateUtil.date()); + order.setTransactionId(transactionId); + // 实际付款金额:Integer除以100后转BigDecimal + DecimalFormat df = new DecimalFormat("0.00"); + final String format = df.format(total / 100); + order.setPayPrice(new BigDecimal(format)); + orderService.updateByOutTradeNo(order); + return "SUCCESS"; + } + } + } catch (Exception $e) { + System.out.println($e.getMessage()); + } + + return "fail"; + } + + +} diff --git a/src/main/java/com/gxwebsoft/common/system/entity/Merchant.java b/src/main/java/com/gxwebsoft/common/system/entity/Merchant.java index 6496bb7..2da89fc 100644 --- a/src/main/java/com/gxwebsoft/common/system/entity/Merchant.java +++ b/src/main/java/com/gxwebsoft/common/system/entity/Merchant.java @@ -72,9 +72,18 @@ public class Merchant implements Serializable { @ApiModelProperty(value = "资质图片") private String files; + @ApiModelProperty(value = "营业时间") + private String businessTime; + + @ApiModelProperty(value = "商户简介") + private String content; + @ApiModelProperty(value = "是否自营") private Integer ownStore; + @ApiModelProperty(value = "每小时价格") + private BigDecimal price; + @ApiModelProperty(value = "是否推荐") private Integer recommend; diff --git a/src/main/java/com/gxwebsoft/common/system/entity/Order.java b/src/main/java/com/gxwebsoft/common/system/entity/Order.java index 61d681d..717ffb5 100644 --- a/src/main/java/com/gxwebsoft/common/system/entity/Order.java +++ b/src/main/java/com/gxwebsoft/common/system/entity/Order.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.*; import java.time.LocalDateTime; import java.io.Serializable; import java.util.Date; +import java.util.List; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -66,9 +67,15 @@ public class Order implements Serializable { @ApiModelProperty(value = "联系电话") private String phone; + @ApiModelProperty(value = "订单总额") + private BigDecimal totalPrice; + @ApiModelProperty(value = "付款时间") private Date payTime; + @ApiModelProperty(value = "1微信支付,2积分,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡") + private Integer payType; + @ApiModelProperty(value = "支付流水号") private String transactionId; @@ -130,6 +137,19 @@ public class Order implements Serializable { @ApiModelProperty(value = "修改时间") private Date updateTime; + @ApiModelProperty(value = "用于微信支付") + @TableField(exist = false) + private String openid; + + @ApiModelProperty(value = "预约详情开始时间数组") + private Long startTime; + + @ApiModelProperty(value = "下单时间") + private Long addTime; + + @ApiModelProperty(value = "系统版本") + private Integer version; + @ApiModelProperty(value = "租户名称") @TableField(exist = false) private String tenantName; @@ -138,4 +158,8 @@ public class Order implements Serializable { @TableField(exist = false) private Integer companyId; + @ApiModelProperty(value = "订单详情") + @TableField(exist = false) + private List orderInfoList; + } diff --git a/src/main/java/com/gxwebsoft/common/system/entity/OrderInfo.java b/src/main/java/com/gxwebsoft/common/system/entity/OrderInfo.java new file mode 100644 index 0000000..8bd4217 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/entity/OrderInfo.java @@ -0,0 +1,94 @@ +package com.gxwebsoft.common.system.entity; + +import java.math.BigDecimal; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * + * + * @author 科技小王子 + * @since 2024-05-10 18:02:54 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "OrderInfo对象", description = "") +@TableName("sys_order_info") +public class OrderInfo implements Serializable { + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "关联订单表id") + private Integer oid; + + @ApiModelProperty(value = "关联场馆id") + private Integer sid; + + @ApiModelProperty(value = "关联场地id") + private Integer fid; + + @ApiModelProperty(value = "场馆") + private String siteName; + + @ApiModelProperty(value = "场地") + private String fieldName; + + @ApiModelProperty(value = "预约时间段") + private String dateTime; + + @ApiModelProperty(value = "单价") + private BigDecimal price; + + @ApiModelProperty(value = "儿童价") + private BigDecimal childrenPrice; + + @ApiModelProperty(value = "成人人数") + private Integer adultNum; + + @ApiModelProperty(value = "儿童人数") + private Integer childrenNum; + + @ApiModelProperty(value = "1已付款,2未付款,3无需付款或占用状态") + private Integer payStatus; + + @ApiModelProperty(value = "是否免费:1免费、2收费") + private Integer isFree; + + @ApiModelProperty(value = "是否支持儿童票:1支持,2不支持") + private Integer isChildren; + + @ApiModelProperty(value = "预订类型:1全场,2半场") + private Integer type; + + @ApiModelProperty(value = "组合数据:日期+时间段+场馆id+场地id") + private String mergeData; + + @ApiModelProperty(value = "开场时间") + private Integer startTime; + + @ApiModelProperty(value = "下单时间") + private Long orderTime; + + @ApiModelProperty(value = "毫秒时间戳") + private Long timeFlag; + + @ApiModelProperty(value = "系统版本") + private Integer version; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + +} diff --git a/src/main/java/com/gxwebsoft/common/system/entity/Payment.java b/src/main/java/com/gxwebsoft/common/system/entity/Payment.java new file mode 100644 index 0000000..5dcda1d --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/entity/Payment.java @@ -0,0 +1,85 @@ +package com.gxwebsoft.common.system.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.TableLogic; +import java.io.Serializable; +import java.util.Date; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 支付方式 + * + * @author 科技小王子 + * @since 2024-05-11 12:39:11 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "Payment对象", description = "支付方式") +@TableName("sys_payment") +public class Payment implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "支付方式") + private String name; + + @ApiModelProperty(value = "标识") + private String code; + + @ApiModelProperty(value = "支付图标") + private String image; + + @ApiModelProperty(value = "微信商户号类型 1普通商户2子商户") + private Integer wechatType; + + @ApiModelProperty(value = "应用ID") + private String appId; + + @ApiModelProperty(value = "商户号") + private String mchId; + + @ApiModelProperty(value = "设置APIv3密钥") + private String apiKey; + + @ApiModelProperty(value = "证书文件 (CERT)") + private String apiclientCert; + + @ApiModelProperty(value = "证书文件 (KEY)") + private String apiclientKey; + + @ApiModelProperty(value = "商户证书序列号") + private String merchantSerialNumber; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "文章排序(数字越小越靠前)") + private Integer sortNumber; + + @ApiModelProperty(value = "状态, 0未启用, 1启用") + private Boolean status; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "注册时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + +} diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/OrderInfoMapper.java b/src/main/java/com/gxwebsoft/common/system/mapper/OrderInfoMapper.java new file mode 100644 index 0000000..a5ecc43 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/mapper/OrderInfoMapper.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.gxwebsoft.common.system.entity.OrderInfo; +import com.gxwebsoft.common.system.param.OrderInfoParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * Mapper + * + * @author 科技小王子 + * @since 2024-05-10 18:02:54 + */ +public interface OrderInfoMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") OrderInfoParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") OrderInfoParam param); + +} diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/OrderMapper.java b/src/main/java/com/gxwebsoft/common/system/mapper/OrderMapper.java index cef0bf2..646f84a 100644 --- a/src/main/java/com/gxwebsoft/common/system/mapper/OrderMapper.java +++ b/src/main/java/com/gxwebsoft/common/system/mapper/OrderMapper.java @@ -1,5 +1,6 @@ package com.gxwebsoft.common.system.mapper; +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.gxwebsoft.common.system.entity.Order; @@ -34,4 +35,10 @@ public interface OrderMapper extends BaseMapper { */ List selectListRel(@Param("param") OrderParam param); + @InterceptorIgnore(tenantLine = "true") + List getByOutTradeNo(OrderParam param); + + @InterceptorIgnore(tenantLine = "true") + void updateByOutTradeNo(@Param("param") Order outTradeNo); + } diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/PaymentMapper.java b/src/main/java/com/gxwebsoft/common/system/mapper/PaymentMapper.java new file mode 100644 index 0000000..53213e9 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/mapper/PaymentMapper.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.gxwebsoft.common.system.entity.Payment; +import com.gxwebsoft.common.system.param.PaymentParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 支付方式Mapper + * + * @author 科技小王子 + * @since 2024-05-11 12:39:11 + */ +public interface PaymentMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") PaymentParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") PaymentParam param); + +} diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrderInfoMapper.xml b/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrderInfoMapper.xml new file mode 100644 index 0000000..64da232 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrderInfoMapper.xml @@ -0,0 +1,86 @@ + + + + + + + SELECT a.* + FROM sys_order_info a + + + AND a.id = #{param.id} + + + AND a.oid = #{param.oid} + + + AND a.sid = #{param.sid} + + + AND a.fid = #{param.fid} + + + AND a.site_name LIKE CONCAT('%', #{param.siteName}, '%') + + + AND a.field_name LIKE CONCAT('%', #{param.fieldName}, '%') + + + AND a.date_time LIKE CONCAT('%', #{param.dateTime}, '%') + + + AND a.price = #{param.price} + + + AND a.children_price = #{param.childrenPrice} + + + AND a.adult_num = #{param.adultNum} + + + AND a.children_num = #{param.childrenNum} + + + AND a.pay_status = #{param.payStatus} + + + AND a.is_free = #{param.isFree} + + + AND a.is_children = #{param.isChildren} + + + AND a.type = #{param.type} + + + AND a.merge_data LIKE CONCAT('%', #{param.mergeData}, '%') + + + AND a.start_time = #{param.startTime} + + + AND a.order_time = #{param.orderTime} + + + AND a.time_flag LIKE CONCAT('%', #{param.timeFlag}, '%') + + + AND a.deleted = #{param.deleted} + + + AND a.deleted = 0 + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrderMapper.xml b/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrderMapper.xml index daa951f..c1f7aec 100644 --- a/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrderMapper.xml +++ b/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrderMapper.xml @@ -123,4 +123,14 @@ + + + + + + diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/xml/PaymentMapper.xml b/src/main/java/com/gxwebsoft/common/system/mapper/xml/PaymentMapper.xml new file mode 100644 index 0000000..b215ece --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/mapper/xml/PaymentMapper.xml @@ -0,0 +1,74 @@ + + + + + + + SELECT a.* + FROM sys_payment a + + + AND a.id = #{param.id} + + + AND a.name LIKE CONCAT('%', #{param.name}, '%') + + + AND a.code = #{param.code} + + + AND a.wechat_type = #{param.wechatType} + + + AND a.app_id LIKE CONCAT('%', #{param.appId}, '%') + + + AND a.mch_id LIKE CONCAT('%', #{param.mchId}, '%') + + + AND a.api_key LIKE CONCAT('%', #{param.apiKey}, '%') + + + AND a.apiclient_cert LIKE CONCAT('%', #{param.apiclientCert}, '%') + + + AND a.apiclient_key LIKE CONCAT('%', #{param.apiclientKey}, '%') + + + AND a.merchant_serial_number LIKE CONCAT('%', #{param.merchantSerialNumber}, '%') + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.sort_number = #{param.sortNumber} + + + AND a.status = #{param.status} + + + AND a.deleted = #{param.deleted} + + + AND a.deleted = 0 + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/common/system/param/OrderInfoParam.java b/src/main/java/com/gxwebsoft/common/system/param/OrderInfoParam.java new file mode 100644 index 0000000..9e77331 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/param/OrderInfoParam.java @@ -0,0 +1,101 @@ +package com.gxwebsoft.common.system.param; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; + +/** + * 查询参数 + * + * @author 科技小王子 + * @since 2024-05-10 18:02:54 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "OrderInfoParam对象", description = "查询参数") +public class OrderInfoParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @QueryField(type = QueryType.EQ) + private Integer id; + + @ApiModelProperty(value = "关联订单表id") + @QueryField(type = QueryType.EQ) + private Integer oid; + + @ApiModelProperty(value = "关联场馆id") + @QueryField(type = QueryType.EQ) + private Integer sid; + + @ApiModelProperty(value = "关联场地id") + @QueryField(type = QueryType.EQ) + private Integer fid; + + @ApiModelProperty(value = "场馆") + private String siteName; + + @ApiModelProperty(value = "场地") + private String fieldName; + + @ApiModelProperty(value = "预约时间段") + private String dateTime; + + @ApiModelProperty(value = "单价") + @QueryField(type = QueryType.EQ) + private BigDecimal price; + + @ApiModelProperty(value = "儿童价") + @QueryField(type = QueryType.EQ) + private BigDecimal childrenPrice; + + @ApiModelProperty(value = "成人人数") + @QueryField(type = QueryType.EQ) + private Boolean adultNum; + + @ApiModelProperty(value = "儿童人数") + @QueryField(type = QueryType.EQ) + private Boolean childrenNum; + + @ApiModelProperty(value = "1已付款,2未付款,3无需付款或占用状态") + @QueryField(type = QueryType.EQ) + private Boolean payStatus; + + @ApiModelProperty(value = "是否免费:1免费、2收费") + @QueryField(type = QueryType.EQ) + private Boolean isFree; + + @ApiModelProperty(value = "是否支持儿童票:1支持,2不支持") + @QueryField(type = QueryType.EQ) + private Boolean isChildren; + + @ApiModelProperty(value = "预订类型:1全场,2半场") + @QueryField(type = QueryType.EQ) + private Boolean type; + + @ApiModelProperty(value = "组合数据:日期+时间段+场馆id+场地id") + private String mergeData; + + @ApiModelProperty(value = "开场时间") + @QueryField(type = QueryType.EQ) + private Integer startTime; + + @ApiModelProperty(value = "下单时间") + @QueryField(type = QueryType.EQ) + private Integer orderTime; + + @ApiModelProperty(value = "毫秒时间戳") + private Long timeFlag; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @QueryField(type = QueryType.EQ) + private Integer deleted; + +} diff --git a/src/main/java/com/gxwebsoft/common/system/param/PaymentParam.java b/src/main/java/com/gxwebsoft/common/system/param/PaymentParam.java new file mode 100644 index 0000000..8e29f09 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/param/PaymentParam.java @@ -0,0 +1,73 @@ +package com.gxwebsoft.common.system.param; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 支付方式查询参数 + * + * @author 科技小王子 + * @since 2024-05-11 12:39:11 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "PaymentParam对象", description = "支付方式查询参数") +public class PaymentParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "ID") + @QueryField(type = QueryType.EQ) + private Integer id; + + @ApiModelProperty(value = "支付方式") + private String name; + + @ApiModelProperty(value = "标识") + @QueryField(type = QueryType.EQ) + private Integer code; + + @ApiModelProperty(value = "微信商户号类型 1普通商户2子商户") + @QueryField(type = QueryType.EQ) + private Integer wechatType; + + @ApiModelProperty(value = "应用ID") + private String appId; + + @ApiModelProperty(value = "商户号") + private String mchId; + + @ApiModelProperty(value = "设置APIv3密钥") + private String apiKey; + + @ApiModelProperty(value = "证书文件 (CERT)") + private String apiclientCert; + + @ApiModelProperty(value = "证书文件 (KEY)") + private String apiclientKey; + + @ApiModelProperty(value = "商户证书序列号") + private String merchantSerialNumber; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "文章排序(数字越小越靠前)") + @QueryField(type = QueryType.EQ) + private Integer sortNumber; + + @ApiModelProperty(value = "状态, 0启用, 1禁用") + @QueryField(type = QueryType.EQ) + private Boolean status; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @QueryField(type = QueryType.EQ) + private Integer deleted; + +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/OrderInfoService.java b/src/main/java/com/gxwebsoft/common/system/service/OrderInfoService.java new file mode 100644 index 0000000..d43f1d7 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/OrderInfoService.java @@ -0,0 +1,42 @@ +package com.gxwebsoft.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.system.entity.OrderInfo; +import com.gxwebsoft.common.system.param.OrderInfoParam; + +import java.util.List; + +/** + * Service + * + * @author 科技小王子 + * @since 2024-05-10 18:02:54 + */ +public interface OrderInfoService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(OrderInfoParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(OrderInfoParam param); + + /** + * 根据id查询 + * + * @param id + * @return OrderInfo + */ + OrderInfo getByIdRel(Integer id); + +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/OrderService.java b/src/main/java/com/gxwebsoft/common/system/service/OrderService.java index 6d2c5b5..9e99448 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/OrderService.java +++ b/src/main/java/com/gxwebsoft/common/system/service/OrderService.java @@ -5,6 +5,7 @@ import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.system.entity.Order; import com.gxwebsoft.common.system.param.OrderParam; +import java.util.HashMap; import java.util.List; /** @@ -39,4 +40,9 @@ public interface OrderService extends IService { */ Order getByIdRel(Integer orderId); + HashMap createWxOrder(Order order); + + Order getByOutTradeNo(String outTradeNo); + + void updateByOutTradeNo(Order order); } diff --git a/src/main/java/com/gxwebsoft/common/system/service/PaymentService.java b/src/main/java/com/gxwebsoft/common/system/service/PaymentService.java new file mode 100644 index 0000000..918bd12 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/PaymentService.java @@ -0,0 +1,42 @@ +package com.gxwebsoft.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.system.entity.Payment; +import com.gxwebsoft.common.system.param.PaymentParam; + +import java.util.List; + +/** + * 支付方式Service + * + * @author 科技小王子 + * @since 2024-05-11 12:39:11 + */ +public interface PaymentService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(PaymentParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(PaymentParam param); + + /** + * 根据id查询 + * + * @param id ID + * @return Payment + */ + Payment getByIdRel(Integer id); + +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/OrderInfoServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/OrderInfoServiceImpl.java new file mode 100644 index 0000000..fd065f9 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/OrderInfoServiceImpl.java @@ -0,0 +1,47 @@ +package com.gxwebsoft.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.common.system.mapper.OrderInfoMapper; +import com.gxwebsoft.common.system.service.OrderInfoService; +import com.gxwebsoft.common.system.entity.OrderInfo; +import com.gxwebsoft.common.system.param.OrderInfoParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Service实现 + * + * @author 科技小王子 + * @since 2024-05-10 18:02:54 + */ +@Service +public class OrderInfoServiceImpl extends ServiceImpl implements OrderInfoService { + + @Override + public PageResult pageRel(OrderInfoParam param) { + PageParam page = new PageParam<>(param); + //page.setDefaultOrder("create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(OrderInfoParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + //page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } + + @Override + public OrderInfo getByIdRel(Integer id) { + OrderInfoParam param = new OrderInfoParam(); + param.setId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/OrderServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/OrderServiceImpl.java index 75625f5..c1d94e5 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/OrderServiceImpl.java @@ -1,14 +1,31 @@ package com.gxwebsoft.common.system.service.impl; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.common.core.config.ConfigProperties; +import com.gxwebsoft.common.core.utils.RedisUtil; +import com.gxwebsoft.common.system.entity.OrderInfo; +import com.gxwebsoft.common.system.entity.Payment; import com.gxwebsoft.common.system.mapper.OrderMapper; import com.gxwebsoft.common.system.service.OrderService; import com.gxwebsoft.common.system.entity.Order; import com.gxwebsoft.common.system.param.OrderParam; import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.system.service.PaymentService; +import com.gxwebsoft.common.system.service.SettingService; +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAConfig; +import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; +import com.wechat.pay.java.service.payments.jsapi.model.Amount; +import com.wechat.pay.java.service.payments.jsapi.model.Payer; +import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest; +import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.HashMap; import java.util.List; /** @@ -19,29 +36,127 @@ import java.util.List; */ @Service public class OrderServiceImpl extends ServiceImpl implements OrderService { + @Resource + private ConfigProperties config; + @Resource + private SettingService settingService; + @Resource + private RedisUtil redisUtil; + @Resource + private PaymentService paymentService; + @Override + public PageResult pageRel(OrderParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } - @Override - public PageResult pageRel(OrderParam param) { - PageParam page = new PageParam<>(param); - page.setDefaultOrder("create_time desc"); - List list = baseMapper.selectPageRel(page, param); - return new PageResult<>(list, page.getTotal()); - } + @Override + public List listRel(OrderParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + //page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } - @Override - public List listRel(OrderParam param) { - List list = baseMapper.selectListRel(param); - // 排序 - PageParam page = new PageParam<>(); - //page.setDefaultOrder("create_time desc"); - return page.sortRecords(list); - } + @Override + public Order getByIdRel(Integer orderId) { + OrderParam param = new OrderParam(); + param.setOrderId(orderId); + return param.getOne(baseMapper.selectListRel(param)); + } - @Override - public Order getByIdRel(Integer orderId) { - OrderParam param = new OrderParam(); - param.setOrderId(orderId); - return param.getOne(baseMapper.selectListRel(param)); - } + /** + * 创建微信支付 + * + * @param order + * @return + */ + @Override + public HashMap createWxOrder(Order order) { + final String uploadPath = config.getUploadPath(); // 服务器本地路径 + final HashMap orderInfo = new HashMap<>(); + // 微信小程序(微信支付) + String key = "Payment:wxPay:".concat(order.getTenantId().toString()); + final Payment payment = redisUtil.get(key, Payment.class); + System.out.println("payment1 = " + payment); + final JSONObject mpWx = settingService.getBySettingKey("mp-weixin"); +// final JSONObject payment = settingService.getBySettingKey("payment"); + + + // 计算金额 + BigDecimal decimal = order.getTotalPrice(); + final BigDecimal multiply = decimal.multiply(new BigDecimal(100)); + // 将 BigDecimal 转换为 Integer + Integer money = multiply.intValue(); + + final String appId = mpWx.getString("appId"); + final String mchId = payment.getMchId(); + final String openid = order.getOpenid(); // openid + final String notifyUrl = config.getServerUrl() + "/love/user-plan-log/wx-pay/notify/" + order.getTenantId(); // 异步通知地址 + final String privateKey = uploadPath.concat("file").concat(payment.getApiclientKey()); // 秘钥证书 + final String apiclientCert = uploadPath.concat("file").concat(payment.getApiclientCert()); + final String merchantSerialNumber = payment.getMerchantSerialNumber(); // 证书序列号 + final String apiV3key = payment.getApiKey(); + + System.out.println("privateKey = " + privateKey); + System.out.println("apiclientCert = " + apiclientCert); + System.out.println("merchantSerialNumber = " + merchantSerialNumber); + System.out.println("apiV3key = " + apiV3key); + System.out.println("mchId = " + mchId); + System.out.println("appId = " + appId); + + Config config = + new RSAConfig.Builder() + .merchantId(mchId) + .privateKeyFromPath(privateKey) + .merchantSerialNumber(merchantSerialNumber) + .wechatPayCertificatesFromPath(apiclientCert) + .build(); + + // 构建service + JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build(); + // 跟之前下单示例一样,填充预下单参数 + PrepayRequest request = new PrepayRequest(); + Amount amount = new Amount(); + amount.setTotal(money); + amount.setCurrency("CNY"); + request.setAmount(amount); + request.setAppid(appId); + request.setMchid(mchId); + OrderInfo desc = order.getOrderInfoList().get(0); + + request.setDescription(desc.getSiteName().concat(desc.getFieldName()).concat(desc.getDateTime())); + request.setNotifyUrl(notifyUrl); + request.setOutTradeNo(order.getOrderNo()); + request.setAttach(order.getTenantId().toString()); + final Payer payer = new Payer(); + payer.setOpenid(openid); + request.setPayer(payer); + System.out.println("request2 = " + request); + PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request); + System.out.println("response = " + response); + orderInfo.put("provider", "wxpay"); + orderInfo.put("timeStamp", response.getTimeStamp()); + orderInfo.put("nonceStr", response.getNonceStr()); + orderInfo.put("package", response.getPackageVal()); + orderInfo.put("signType", "RSA"); + orderInfo.put("paySign", response.getPaySign()); + return orderInfo; + } + + @Override + public Order getByOutTradeNo(String outTradeNo) { + OrderParam param = new OrderParam(); + param.setOrderNo(outTradeNo); + return param.getOne(baseMapper.getByOutTradeNo(param)); + } + + @Override + public void updateByOutTradeNo(Order order) { + baseMapper.updateByOutTradeNo(order); + } } diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/PaymentServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/PaymentServiceImpl.java new file mode 100644 index 0000000..2ab34b2 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/PaymentServiceImpl.java @@ -0,0 +1,47 @@ +package com.gxwebsoft.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.common.system.mapper.PaymentMapper; +import com.gxwebsoft.common.system.service.PaymentService; +import com.gxwebsoft.common.system.entity.Payment; +import com.gxwebsoft.common.system.param.PaymentParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 支付方式Service实现 + * + * @author 科技小王子 + * @since 2024-05-11 12:39:11 + */ +@Service +public class PaymentServiceImpl extends ServiceImpl implements PaymentService { + + @Override + public PageResult pageRel(PaymentParam param) { + PageParam page = new PageParam<>(param); + //page.setDefaultOrder("create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(PaymentParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + //page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } + + @Override + public Payment getByIdRel(Integer id) { + PaymentParam param = new PaymentParam(); + param.setId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/test/java/com/gxwebsoft/generator/Sys2Generator.java b/src/test/java/com/gxwebsoft/generator/Sys2Generator.java new file mode 100644 index 0000000..5ba7c11 --- /dev/null +++ b/src/test/java/com/gxwebsoft/generator/Sys2Generator.java @@ -0,0 +1,227 @@ +package com.gxwebsoft.generator; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 代码生成工具 + * + * @author WebSoft + * @since 2021-09-05 00:31:14 + */ +public class Sys2Generator { + // 输出位置 + private static final String OUTPUT_LOCATION = System.getProperty("user.dir"); + //private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径 + // 输出目录 + private static final String OUTPUT_DIR = "/src/main/java"; + // Vue文件输出位置 + private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/com.gxwebsoft.core-web"; + // Vue文件输出目录 + private static final String OUTPUT_DIR_VUE = "/src"; + // 作者名称 + private static final String AUTHOR = "科技小王子"; + // 是否在xml中添加二级缓存配置 + private static final boolean ENABLE_CACHE = false; + // 数据库连接配置 + private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/gxwebsoft_core?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"; + private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver"; + private static final String DB_USERNAME = "gxwebsoft_core"; + private static final String DB_PASSWORD = "jdj7HYEdYHnYEFBy"; + // 包名 + private static final String PACKAGE_NAME = "com.gxwebsoft"; + // 模块名 + private static final String MODULE_NAME = "common.system"; + // 需要生成的表 + private static final String[] TABLE_NAMES = new String[]{ + "sys_payment" + }; + // 需要去除的表前缀 + private static final String[] TABLE_PREFIX = new String[]{ + "sys_", + "tb_" + }; + // 不需要作为查询参数的字段 + private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{ + "tenant_id", + "create_time", + "update_time" + }; + // 查询参数使用String的类型 + private static final String[] PARAM_TO_STRING_TYPE = new String[]{ + "Date", + "LocalDate", + "LocalTime", + "LocalDateTime" + }; + // 查询参数使用EQ的类型 + private static final String[] PARAM_EQ_TYPE = new String[]{ + "Integer", + "Boolean", + "BigDecimal" + }; + // 是否添加权限注解 + private static final boolean AUTH_ANNOTATION = true; + // 是否添加日志注解 + private static final boolean LOG_ANNOTATION = true; + // controller的mapping前缀 + private static final String CONTROLLER_MAPPING_PREFIX = "/api"; + // 模板所在位置 + private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates"; + + public static void main(String[] args) { + // 代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 全局配置 + GlobalConfig gc = new GlobalConfig(); + gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR); + gc.setAuthor(AUTHOR); + gc.setOpen(false); + gc.setFileOverride(true); + gc.setEnableCache(ENABLE_CACHE); + gc.setSwagger2(true); + gc.setIdType(IdType.AUTO); + gc.setServiceName("%sService"); + mpg.setGlobalConfig(gc); + + // 数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + dsc.setUrl(DB_URL); + // dsc.setSchemaName("public"); + dsc.setDriverName(DB_DRIVER); + dsc.setUsername(DB_USERNAME); + dsc.setPassword(DB_PASSWORD); + mpg.setDataSource(dsc); + + // 包配置 + PackageConfig pc = new PackageConfig(); + pc.setModuleName(MODULE_NAME); + pc.setParent(PACKAGE_NAME); + mpg.setPackageInfo(pc); + + // 策略配置 + StrategyConfig strategy = new StrategyConfig(); + strategy.setNaming(NamingStrategy.underline_to_camel); + strategy.setColumnNaming(NamingStrategy.underline_to_camel); + strategy.setInclude(TABLE_NAMES); + strategy.setTablePrefix(TABLE_PREFIX); + strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController"); + strategy.setEntityLombokModel(true); + strategy.setRestControllerStyle(true); + strategy.setControllerMappingHyphenStyle(true); + strategy.setLogicDeleteFieldName("deleted"); + mpg.setStrategy(strategy); + + // 模板配置 + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setController(TEMPLATES_DIR + "/controller.java"); + templateConfig.setEntity(TEMPLATES_DIR + "/entity.java"); + templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java"); + templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml"); + templateConfig.setService(TEMPLATES_DIR + "/service.java"); + templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java"); + mpg.setTemplate(templateConfig); + mpg.setTemplateEngine(new BeetlTemplateEnginePlus()); + + // 自定义模板配置 + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + Map map = new HashMap<>(); + map.put("packageName", PACKAGE_NAME); + map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS); + map.put("paramToStringType", PARAM_TO_STRING_TYPE); + map.put("paramEqType", PARAM_EQ_TYPE); + map.put("authAnnotation", AUTH_ANNOTATION); + map.put("logAnnotation", LOG_ANNOTATION); + map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX); + this.setMap(map); + } + }; + String templatePath = TEMPLATES_DIR + "/param.java.btl"; + List focList = new ArrayList<>(); + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION + OUTPUT_DIR + "/" + + PACKAGE_NAME.replace(".", "/") + + "/" + pc.getModuleName() + "/param/" + + tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA; + } + }); + /** + * 以下是生成VUE项目代码 + * 生成文件的路径 /api/shop/goods/index.ts + */ + templatePath = TEMPLATES_DIR + "/index.ts.btl"; + + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/api/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/" + "index.ts"; + } + }); + // 生成TS文件 (/api/shop/goods/model/index.ts) + templatePath = TEMPLATES_DIR + "/model.ts.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/api/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/model/" + "index.ts"; + } + }); + // 生成Vue文件(/views/shop/goods/index.vue) + templatePath = TEMPLATES_DIR + "/index.vue.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/views/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/" + "index.vue"; + } + }); + + // 生成components文件(/views/shop/goods/components/edit.vue) + templatePath = TEMPLATES_DIR + "/components.edit.vue.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/views/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue"; + } + }); + + // 生成components文件(/views/shop/goods/components/search.vue) + templatePath = TEMPLATES_DIR + "/components.search.vue.btl"; + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE + + "/views/" + pc.getModuleName() + "/" + + tableInfo.getEntityPath() + "/components/" + "search.vue"; + } + }); + + cfg.setFileOutConfigList(focList); + mpg.setCfg(cfg); + + mpg.execute(); + } + +} diff --git a/src/test/java/com/gxwebsoft/generator/SysGenerator.java b/src/test/java/com/gxwebsoft/generator/SysGenerator.java index 58bc355..fab5f50 100644 --- a/src/test/java/com/gxwebsoft/generator/SysGenerator.java +++ b/src/test/java/com/gxwebsoft/generator/SysGenerator.java @@ -21,26 +21,26 @@ import java.util.Map; * @since 2021-09-05 00:31:14 */ public class SysGenerator { - // 输出位置 - private static final String OUTPUT_LOCATION = System.getProperty("user.dir"); - //private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径 - // 输出目录 - private static final String OUTPUT_DIR = "/src/main/java"; - // 作者名称 - private static final String AUTHOR = "科技小王子"; - // 是否在xml中添加二级缓存配置 - private static final boolean ENABLE_CACHE = false; - // 数据库连接配置 - private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/gxwebsoft_core?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"; - private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver"; - private static final String DB_USERNAME = "gxwebsoft_core"; - private static final String DB_PASSWORD = "jdj7HYEdYHnYEFBy"; - // 包名 - private static final String PACKAGE_NAME = "com.gxwebsoft"; - // 模块名 - private static final String MODULE_NAME = "common.system"; - // 需要生成的表 - private static final String[] TABLE_NAMES = new String[]{ + // 输出位置 + private static final String OUTPUT_LOCATION = System.getProperty("user.dir"); + //private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径 + // 输出目录 + private static final String OUTPUT_DIR = "/src/main/java"; + // 作者名称 + private static final String AUTHOR = "科技小王子"; + // 是否在xml中添加二级缓存配置 + private static final boolean ENABLE_CACHE = false; + // 数据库连接配置 + private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/gxwebsoft_core?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"; + private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver"; + private static final String DB_USERNAME = "gxwebsoft_core"; + private static final String DB_PASSWORD = "jdj7HYEdYHnYEFBy"; + // 包名 + private static final String PACKAGE_NAME = "com.gxwebsoft"; + // 模块名 + private static final String MODULE_NAME = "common.system"; + // 需要生成的表 + private static final String[] TABLE_NAMES = new String[]{ // "sys_user", // "sys_tenant", @@ -69,127 +69,129 @@ public class SysGenerator { // "sys_website_field", // "sys_white_domain" // "sys_order", +// "sys_order_info", // "sys_user_collection", - "sys_user" +// "sys_user", + "sys_payment" + }; + // 需要去除的表前缀 + private static final String[] TABLE_PREFIX = new String[]{ + "sys_", + "tb_" + }; + // 不需要作为查询参数的字段 + private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{ + "tenant_id", + "create_time", + "update_time" + }; + // 查询参数使用String的类型 + private static final String[] PARAM_TO_STRING_TYPE = new String[]{ + "Date", + "LocalDate", + "LocalTime", + "LocalDateTime" + }; + // 查询参数使用EQ的类型 + private static final String[] PARAM_EQ_TYPE = new String[]{ + "Integer", + "Boolean", + "BigDecimal" + }; + // 是否添加权限注解 + private static final boolean AUTH_ANNOTATION = true; + // 是否添加日志注解 + private static final boolean LOG_ANNOTATION = true; + // controller的mapping前缀 + private static final String CONTROLLER_MAPPING_PREFIX = "/api"; + // 模板所在位置 + private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates"; + + public static void main(String[] args) { + // 代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 全局配置 + GlobalConfig gc = new GlobalConfig(); + gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR); + gc.setAuthor(AUTHOR); + gc.setOpen(false); + gc.setFileOverride(true); + gc.setEnableCache(ENABLE_CACHE); + gc.setSwagger2(true); + gc.setIdType(IdType.AUTO); + gc.setServiceName("%sService"); + mpg.setGlobalConfig(gc); + + // 数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + dsc.setUrl(DB_URL); + // dsc.setSchemaName("public"); + dsc.setDriverName(DB_DRIVER); + dsc.setUsername(DB_USERNAME); + dsc.setPassword(DB_PASSWORD); + mpg.setDataSource(dsc); + + // 包配置 + PackageConfig pc = new PackageConfig(); + pc.setModuleName(MODULE_NAME); + pc.setParent(PACKAGE_NAME); + mpg.setPackageInfo(pc); + + // 策略配置 + StrategyConfig strategy = new StrategyConfig(); + strategy.setNaming(NamingStrategy.underline_to_camel); + strategy.setColumnNaming(NamingStrategy.underline_to_camel); + strategy.setInclude(TABLE_NAMES); + strategy.setTablePrefix(TABLE_PREFIX); + strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController"); + strategy.setEntityLombokModel(true); + strategy.setRestControllerStyle(true); + strategy.setControllerMappingHyphenStyle(true); + strategy.setLogicDeleteFieldName("deleted"); + mpg.setStrategy(strategy); + + // 模板配置 + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setController(TEMPLATES_DIR + "/controller.java"); + templateConfig.setEntity(TEMPLATES_DIR + "/entity.java"); + templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java"); + templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml"); + templateConfig.setService(TEMPLATES_DIR + "/service.java"); + templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java"); + mpg.setTemplate(templateConfig); + mpg.setTemplateEngine(new BeetlTemplateEnginePlus()); + + // 自定义模板配置 + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + Map map = new HashMap<>(); + map.put("packageName", PACKAGE_NAME); + map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS); + map.put("paramToStringType", PARAM_TO_STRING_TYPE); + map.put("paramEqType", PARAM_EQ_TYPE); + map.put("authAnnotation", AUTH_ANNOTATION); + map.put("logAnnotation", LOG_ANNOTATION); + map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX); + this.setMap(map); + } }; - // 需要去除的表前缀 - private static final String[] TABLE_PREFIX = new String[]{ - "sys_", - "tb_" - }; - // 不需要作为查询参数的字段 - private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{ - "tenant_id", - "create_time", - "update_time" - }; - // 查询参数使用String的类型 - private static final String[] PARAM_TO_STRING_TYPE = new String[]{ - "Date", - "LocalDate", - "LocalTime", - "LocalDateTime" - }; - // 查询参数使用EQ的类型 - private static final String[] PARAM_EQ_TYPE = new String[]{ - "Integer", - "Boolean", - "BigDecimal" - }; - // 是否添加权限注解 - private static final boolean AUTH_ANNOTATION = true; - // 是否添加日志注解 - private static final boolean LOG_ANNOTATION = true; - // controller的mapping前缀 - private static final String CONTROLLER_MAPPING_PREFIX = "/api"; - // 模板所在位置 - private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates"; + String templatePath = TEMPLATES_DIR + "/param.java.btl"; + List focList = new ArrayList<>(); + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION + OUTPUT_DIR + "/" + + PACKAGE_NAME.replace(".", "/") + + "/" + pc.getModuleName() + "/param/" + + tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA; + } + }); + cfg.setFileOutConfigList(focList); + mpg.setCfg(cfg); - public static void main(String[] args) { - // 代码生成器 - AutoGenerator mpg = new AutoGenerator(); - - // 全局配置 - GlobalConfig gc = new GlobalConfig(); - gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR); - gc.setAuthor(AUTHOR); - gc.setOpen(false); - gc.setFileOverride(true); - gc.setEnableCache(ENABLE_CACHE); - gc.setSwagger2(true); - gc.setIdType(IdType.AUTO); - gc.setServiceName("%sService"); - mpg.setGlobalConfig(gc); - - // 数据源配置 - DataSourceConfig dsc = new DataSourceConfig(); - dsc.setUrl(DB_URL); - // dsc.setSchemaName("public"); - dsc.setDriverName(DB_DRIVER); - dsc.setUsername(DB_USERNAME); - dsc.setPassword(DB_PASSWORD); - mpg.setDataSource(dsc); - - // 包配置 - PackageConfig pc = new PackageConfig(); - pc.setModuleName(MODULE_NAME); - pc.setParent(PACKAGE_NAME); - mpg.setPackageInfo(pc); - - // 策略配置 - StrategyConfig strategy = new StrategyConfig(); - strategy.setNaming(NamingStrategy.underline_to_camel); - strategy.setColumnNaming(NamingStrategy.underline_to_camel); - strategy.setInclude(TABLE_NAMES); - strategy.setTablePrefix(TABLE_PREFIX); - strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController"); - strategy.setEntityLombokModel(true); - strategy.setRestControllerStyle(true); - strategy.setControllerMappingHyphenStyle(true); - strategy.setLogicDeleteFieldName("deleted"); - mpg.setStrategy(strategy); - - // 模板配置 - TemplateConfig templateConfig = new TemplateConfig(); - templateConfig.setController(TEMPLATES_DIR + "/controller.java"); - templateConfig.setEntity(TEMPLATES_DIR + "/entity.java"); - templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java"); - templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml"); - templateConfig.setService(TEMPLATES_DIR + "/service.java"); - templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java"); - mpg.setTemplate(templateConfig); - mpg.setTemplateEngine(new BeetlTemplateEnginePlus()); - - // 自定义模板配置 - InjectionConfig cfg = new InjectionConfig() { - @Override - public void initMap() { - Map map = new HashMap<>(); - map.put("packageName", PACKAGE_NAME); - map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS); - map.put("paramToStringType", PARAM_TO_STRING_TYPE); - map.put("paramEqType", PARAM_EQ_TYPE); - map.put("authAnnotation", AUTH_ANNOTATION); - map.put("logAnnotation", LOG_ANNOTATION); - map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX); - this.setMap(map); - } - }; - String templatePath = TEMPLATES_DIR + "/param.java.btl"; - List focList = new ArrayList<>(); - focList.add(new FileOutConfig(templatePath) { - @Override - public String outputFile(TableInfo tableInfo) { - return OUTPUT_LOCATION + OUTPUT_DIR + "/" - + PACKAGE_NAME.replace(".", "/") - + "/" + pc.getModuleName() + "/param/" - + tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA; - } - }); - cfg.setFileOutConfigList(focList); - mpg.setCfg(cfg); - - mpg.execute(); - } + mpg.execute(); + } } diff --git a/src/test/java/com/gxwebsoft/generator/templates/components.edit.vue.btl b/src/test/java/com/gxwebsoft/generator/templates/components.edit.vue.btl new file mode 100644 index 0000000..1e0c8a2 --- /dev/null +++ b/src/test/java/com/gxwebsoft/generator/templates/components.edit.vue.btl @@ -0,0 +1,221 @@ + + + + diff --git a/src/test/java/com/gxwebsoft/generator/templates/components.search.vue.btl b/src/test/java/com/gxwebsoft/generator/templates/components.search.vue.btl new file mode 100644 index 0000000..82fea9d --- /dev/null +++ b/src/test/java/com/gxwebsoft/generator/templates/components.search.vue.btl @@ -0,0 +1,42 @@ + + + + diff --git a/src/test/java/com/gxwebsoft/generator/templates/index.ts.btl b/src/test/java/com/gxwebsoft/generator/templates/index.ts.btl new file mode 100644 index 0000000..9cd968d --- /dev/null +++ b/src/test/java/com/gxwebsoft/generator/templates/index.ts.btl @@ -0,0 +1,106 @@ +import request from '@/utils/request'; +import type { ApiResult, PageResult } from '@/api'; +import type { ${entity}, ${entity}Param } from './model'; +import { MODULES_API_URL } from '@/config/setting'; + +/** + * 分页查询${table.comment!} + */ +export async function page${entity}(params: ${entity}Param) { + const res = await request.get>>( + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/page', + { + params + } + ); + if (res.data.code === 0) { + return res.data.data; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 查询${table.comment!}列表 + */ +export async function list${entity}(params?: ${entity}Param) { + const res = await request.get>( + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}', + { + params + } + ); + if (res.data.code === 0 && res.data.data) { + return res.data.data; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 添加${table.comment!} + */ +export async function add${entity}(data: ${entity}) { + const res = await request.post>( + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}', + data + ); + if (res.data.code === 0) { + return res.data.message; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 修改${table.comment!} + */ +export async function update${entity}(data: ${entity}) { + const res = await request.put>( + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}', + data + ); + if (res.data.code === 0) { + return res.data.message; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 删除${table.comment!} + */ +export async function remove${entity}(id?: number) { + const res = await request.delete>( + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/' + id + ); + if (res.data.code === 0) { + return res.data.message; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 批量删除${table.comment!} + */ +export async function removeBatch${entity}(data: (number | undefined)[]) { + const res = await request.delete>( + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/batch', + { + data + } + ); + if (res.data.code === 0) { + return res.data.message; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 根据id查询${table.comment!} + */ +export async function get${entity}(id: number) { + const res = await request.get>( + MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/' + id + ); + if (res.data.code === 0 && res.data.data) { + return res.data.data; + } + return Promise.reject(new Error(res.data.message)); +} diff --git a/src/test/java/com/gxwebsoft/generator/templates/index.vue.btl b/src/test/java/com/gxwebsoft/generator/templates/index.vue.btl new file mode 100644 index 0000000..3a52886 --- /dev/null +++ b/src/test/java/com/gxwebsoft/generator/templates/index.vue.btl @@ -0,0 +1,217 @@ + + + + + + + diff --git a/src/test/java/com/gxwebsoft/generator/templates/model.ts.btl b/src/test/java/com/gxwebsoft/generator/templates/model.ts.btl new file mode 100644 index 0000000..b0b99db --- /dev/null +++ b/src/test/java/com/gxwebsoft/generator/templates/model.ts.btl @@ -0,0 +1,43 @@ +import type { PageParam } from '@/api'; + +/** + * ${table.comment!} + */ +export interface ${entity} { +<% /** -----------BEGIN 字段循环遍历----------- **/ %> +<% for(field in table.fields) { %> + <% + var keyPropertyName; + if(field.keyFlag) { + keyPropertyName = field.propertyName; + } + %> + <% /* 主键 */ %> + <% if(field.keyFlag) { %> + <% /* 普通字段 */ %> + <% } else if(isNotEmpty(field.fill)) { %> + <% if(field.convert){ %> + @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}) + <% }else{ %> + @TableField(fill = FieldFill.${field.fill}) + <% } %> + <% } else if(field.convert) { %> + @TableField("${field.annotationColumnName}") + <% } %> + // ${field.comment} + ${field.propertyName}?: <% if(field.propertyType == 'Integer') { %>number<% }else{ %>string<% } %>; +<% } %> +<% /** -----------END 字段循环遍历----------- **/ %> +} + +/** + * ${table.comment!}搜索条件 + */ +export interface ${entity}Param extends PageParam { +<% for(field in table.fields) { %> +<% if(field.keyFlag) { %> + ${field.propertyName}?: number; + <% } %> +<% } %> + keywords?: string; +}