From ee2339f048f4a56c8bb69a59c7ca436f2ae12cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=AE=87=E5=A5=87?= Date: Thu, 3 Jul 2025 17:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysUserController.java | 8 +- .../web/service/SysRegisterService.java | 51 +----------- .../system/mapper/SysRoleMenuMapper.java | 8 ++ .../service/impl/SysMenuServiceImpl.java | 5 +- .../service/impl/SysUserServiceImpl.java | 1 - .../mapper/system/SysRoleMenuMapper.xml | 11 ++- .../service/impl/FinanceBillServiceImpl.java | 42 ++++++---- .../service/impl/StoreOrderServiceImpl.java | 78 +++++++++++-------- 8 files changed, 100 insertions(+), 104 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java index e07b62f80..126490a50 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java @@ -105,8 +105,8 @@ public class SysUserController extends BaseController { @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") @Log(title = "用户管理", businessType = BusinessType.EXPORT) - @ApiOperation("导出 - 管理员") - @PostMapping("/export") +// @ApiOperation("导出 - 管理员") +// @PostMapping("/export") public void export(@Validated @RequestBody UserQueryVO vo, HttpServletResponse response) { UserQuery query = BeanUtil.toBean(vo, UserQuery.class); List list = userService.listUser(query); @@ -116,8 +116,8 @@ public class SysUserController extends BaseController { @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") @Log(title = "用户管理", businessType = BusinessType.IMPORT) - @ApiOperation("导入 - 管理员") - @PostMapping("/importData") +// @ApiOperation("导入 - 管理员") +// @PostMapping("/importData") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil util = new ExcelUtil(SysUser.class); List userList = util.importExcel(file.getInputStream()); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java index 8b5a94a11..227b58568 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java @@ -41,9 +41,6 @@ public class SysRegisterService { @Autowired private ISysUserService userService; - @Autowired - private ISysConfigService configService; - @Autowired private RedisCache redisCache; @@ -73,6 +70,9 @@ public class SysRegisterService { } //创建账号 Long userId = userService.createUser(userEdit); + //日志 + AsyncManager.me().execute(AsyncFactory.recordLogininfor(phoneNumber, Constants.REGISTER, + MessageUtils.message("user.register.success"))); //登录 UserInfo userInfo = userService.getUserById(userId); LoginUser loginUser = new LoginUser(userInfo); @@ -80,51 +80,6 @@ public class SysRegisterService { return loginService.createToken(loginUser); } - /** - * 注册 - */ - public String register(RegisterBody registerBody) { - String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword(); - UserInfoEdit sysUser = new UserInfoEdit(); - sysUser.setUserName(username); - - // 验证码开关 - boolean captchaEnabled = configService.selectCaptchaEnabled(); - if (captchaEnabled) { - validateCaptcha(registerBody.getCode(), registerBody.getUuid()); - } - - if (StringUtils.isEmpty(username)) { - msg = "用户名不能为空"; - } else if (StringUtils.isEmpty(password)) { - msg = "用户密码不能为空"; - } else if (username.length() < UserConstants.USERNAME_MIN_LENGTH - || username.length() > UserConstants.USERNAME_MAX_LENGTH) { - msg = "账户长度必须在2到20个字符之间"; - } else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH - || password.length() > UserConstants.PASSWORD_MAX_LENGTH) { - msg = "密码长度必须在5到20个字符之间"; - } else if (!userService.checkUserNameUnique(sysUser)) { - msg = "保存用户'" + username + "'失败,注册账号已存在"; - } else { - sysUser.setNickName(username); - sysUser.setPassword(SecurityUtils.encryptPassword(password)); - boolean regFlag = false; - try { - //TODO USER - userService.createUser(sysUser); - } catch (Exception e) { - log.error("用户注册失败", e); - } - if (!regFlag) { - msg = "注册失败,请联系系统管理人员"; - } else { - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success"))); - } - } - return msg; - } - /** * 校验验证码 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java index 8c60127d1..8273f9ff2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java @@ -52,4 +52,12 @@ public interface SysRoleMenuMapper extends BaseMapper { */ List listRelUserId(@Param("menuId") Long menuId); + /** + * 获取角色关联菜单ID + * + * @param roleId + * @return + */ + List listRelMenuId(@Param("roleId") Long roleId); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index e356a798b..7c1d80b68 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysMenu; @@ -13,7 +12,6 @@ import com.ruoyi.common.core.domain.model.*; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.system.domain.SysRoleMenu; import com.ruoyi.system.domain.vo.menu.SysMenuDTO; import com.ruoyi.system.mapper.SysMenuMapper; import com.ruoyi.system.mapper.SysRoleMapper; @@ -275,8 +273,7 @@ public class SysMenuServiceImpl implements ISysMenuService { @Override public Set storeUsableMenuIds() { - //TODO USER - return roleMenuMapper.selectList(Wrappers.emptyWrapper()).stream().map(SysRoleMenu::getMenuId).collect(Collectors.toSet()); + return new HashSet<>(roleMenuMapper.listRelMenuId(ESystemRole.SUPPLIER.getId())); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index d54b3d216..bef22f52d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -375,7 +375,6 @@ public class SysUserServiceImpl implements ISysUserService { successNum++; successMsg.append("
" + successNum + "、账号 " + user.getUserName() + " 导入成功"); } else if (isUpdateSupport) { - //TODO USER BeanValidators.validateWithException(validator, user); checkUserAllowed(u); // checkUserDataScope(u.getUserId()); diff --git a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml index 5332794be..7c9e55ca1 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml @@ -22,7 +22,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" srm.menu_id = #{menuId} - + + + delete from sys_role_menu where role_id=#{roleId} diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java index a82c9b00b..33b7c8bec 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java @@ -13,6 +13,7 @@ import com.github.pagehelper.PageHelper; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.SimpleEntity; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.xkt.domain.FinanceBill; import com.ruoyi.xkt.domain.FinanceBillDetail; @@ -90,7 +91,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { orderExt.getOrder().getRealTotalAmount().toPlainString())); bill.setVersion(0L); bill.setDelFlag(Constants.UNDELETED); - financeBillMapper.insert(bill); + financeBillMapper.insert(prepareInsert(bill)); List billDetails = new ArrayList<>(orderExt.getOrderDetails().size()); for (StoreOrderDetail orderDetail : orderExt.getOrderDetails()) { FinanceBillDetail billDetail = new FinanceBillDetail(); @@ -100,7 +101,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { billDetail.setBusinessAmount(orderDetail.getTotalAmount()); billDetail.setTransAmount(orderDetail.getRealTotalAmount()); billDetail.setDelFlag(Constants.UNDELETED); - financeBillDetailMapper.insert(billDetail); + financeBillDetailMapper.insert(prepareInsert(billDetail)); billDetails.add(billDetail); } TransInfo transInfo = TransInfo.builder() @@ -148,7 +149,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { orderExt.getOrder().getRealTotalAmount().toPlainString())); bill.setVersion(0L); bill.setDelFlag(Constants.UNDELETED); - financeBillMapper.insert(bill); + financeBillMapper.insert(prepareInsert(bill)); List billDetails = new ArrayList<>(orderExt.getOrderDetails().size()); for (StoreOrderDetail orderDetail : orderExt.getOrderDetails()) { FinanceBillDetail billDetail = new FinanceBillDetail(); @@ -158,7 +159,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { billDetail.setBusinessAmount(orderDetail.getTotalAmount()); billDetail.setTransAmount(orderDetail.getRealTotalAmount()); billDetail.setDelFlag(Constants.UNDELETED); - financeBillDetailMapper.insert(billDetail); + financeBillDetailMapper.insert(prepareInsert(billDetail)); billDetails.add(billDetail); } TransInfo transInfo = TransInfo.builder() @@ -269,10 +270,10 @@ public class FinanceBillServiceImpl implements IFinanceBillService { transAmount.toPlainString())); bill.setVersion(0L); bill.setDelFlag(Constants.UNDELETED); - financeBillMapper.insert(bill); + financeBillMapper.insert(prepareInsert(bill)); for (FinanceBillDetail billDetail : billDetails) { billDetail.setFinanceBillId(bill.getId()); - financeBillDetailMapper.insert(billDetail); + financeBillDetailMapper.insert(prepareInsert(billDetail)); } TransInfo transInfo = TransInfo.builder() .srcBillId(bill.getId()) @@ -322,7 +323,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { transferAmount.toPlainString())); bill.setVersion(0L); bill.setDelFlag(Constants.UNDELETED); - financeBillMapper.insert(bill); + financeBillMapper.insert(prepareInsert(bill)); List billDetails = new ArrayList<>(orderExt.getOrderDetails().size()); for (StoreOrderDetail orderDetail : orderExt.getOrderDetails()) { FinanceBillDetail billDetail = new FinanceBillDetail(); @@ -332,7 +333,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { billDetail.setBusinessAmount(orderDetail.getTotalAmount()); billDetail.setTransAmount(orderDetail.getRealTotalAmount()); billDetail.setDelFlag(Constants.UNDELETED); - financeBillDetailMapper.insert(billDetail); + financeBillDetailMapper.insert(prepareInsert(billDetail)); billDetails.add(billDetail); } TransInfo transInfo = TransInfo.builder() @@ -368,7 +369,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { throw new ServiceException(CharSequenceUtil.format("付款单[{}]状态异常", financeBill.getId())); } financeBill.setBillStatus(EFinBillStatus.SUCCESS.getValue()); - int r = financeBillMapper.updateById(financeBill); + int r = financeBillMapper.updateById(prepareUpdate(financeBill)); if (r == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -404,7 +405,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { bill.setRemark(CharSequenceUtil.format("账户提现{}元", amount.toPlainString())); bill.setVersion(0L); bill.setDelFlag(Constants.UNDELETED); - financeBillMapper.insert(bill); + financeBillMapper.insert(prepareInsert(bill)); TransInfo transInfo = TransInfo.builder() .srcBillId(bill.getId()) .srcBillType(bill.getBillType()) @@ -441,7 +442,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { throw new ServiceException(CharSequenceUtil.format("付款单[{}]状态异常", financeBill.getId())); } financeBill.setBillStatus(EFinBillStatus.SUCCESS.getValue()); - int r = financeBillMapper.updateById(financeBill); + int r = financeBillMapper.updateById(prepareUpdate(financeBill)); if (r == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -474,7 +475,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { bill.setRemark(CharSequenceUtil.format("档口充值{}元", amount.toPlainString())); bill.setVersion(0L); bill.setDelFlag(Constants.UNDELETED); - financeBillMapper.insert(bill); + financeBillMapper.insert(prepareInsert(bill)); TransInfo transInfo = TransInfo.builder() .srcBillId(bill.getId()) .srcBillType(bill.getBillType()) @@ -510,7 +511,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { throw new ServiceException(CharSequenceUtil.format("收款单[{}]状态异常", financeBill.getId())); } financeBill.setBillStatus(EFinBillStatus.SUCCESS.getValue()); - int r = financeBillMapper.updateById(financeBill); + int r = financeBillMapper.updateById(prepareUpdate(financeBill)); if (r == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -548,7 +549,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { bill.setRemark(remark); bill.setVersion(0L); bill.setDelFlag(Constants.UNDELETED); - financeBillMapper.insert(bill); + financeBillMapper.insert(prepareInsert(bill)); TransInfo transInfo = TransInfo.builder() .srcBillId(bill.getId()) .srcBillType(bill.getBillType()) @@ -590,4 +591,17 @@ public class FinanceBillServiceImpl implements IFinanceBillService { //未确定规则,暂时用UUID代替 return IdUtil.simpleUUID(); } + + private T prepareInsert(T obj) { + String username = SecurityUtils.getUsernameSafe(); + obj.setCreateBy(username); + obj.setUpdateBy(username); + return obj; + } + + private T prepareUpdate(T obj) { + obj.setUpdateBy(SecurityUtils.getUsernameSafe()); + obj.setUpdateTime(new Date()); + return obj; + } } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreOrderServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreOrderServiceImpl.java index d4eeb20fa..b75f405c8 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreOrderServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreOrderServiceImpl.java @@ -17,6 +17,7 @@ import com.ruoyi.common.core.domain.SimpleEntity; import com.ruoyi.common.core.domain.XktBaseEntity; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.system.mapper.SysUserMapper; import com.ruoyi.xkt.domain.*; @@ -193,12 +194,12 @@ public class StoreOrderServiceImpl implements IStoreOrderService { order.setVersion(0L); order.setDelFlag(Constants.UNDELETED); //落库 - storeOrderMapper.insert(order); + storeOrderMapper.insert(prepareInsert(order)); Long orderId = order.getId(); List orderDetailIdList = new ArrayList<>(orderDetailList.size()); orderDetailList.forEach(storeOrderDetail -> { storeOrderDetail.setStoreOrderId(orderId); - storeOrderDetailMapper.insert(storeOrderDetail); + storeOrderDetailMapper.insert(prepareInsert(storeOrderDetail)); orderDetailIdList.add(storeOrderDetail.getId()); }); //操作记录 @@ -324,7 +325,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { order.setDeliveryType(storeOrderUpdateDTO.getDeliveryType()); order.setDeliveryEndTime(storeOrderUpdateDTO.getDeliveryEndTime()); //落库 - int r = storeOrderMapper.updateById(order); + int r = storeOrderMapper.updateById(prepareUpdate(order)); if (r == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -332,7 +333,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { //删除原明细 for (StoreOrderDetail originDetail : originDetails) { originDetail.setDelFlag(Constants.DELETED); - storeOrderDetailMapper.updateById(originDetail); + storeOrderDetailMapper.updateById(prepareUpdate(originDetail)); } //操作记录 addOperationRecords(orderId, EOrderAction.UPDATE, @@ -342,7 +343,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { List orderDetailIdList = new ArrayList<>(orderDetailList.size()); orderDetailList.forEach(storeOrderDetail -> { storeOrderDetail.setStoreOrderId(orderId); - storeOrderDetailMapper.insert(storeOrderDetail); + storeOrderDetailMapper.insert(prepareInsert(storeOrderDetail)); orderDetailIdList.add(storeOrderDetail.getId()); }); //操作记录 @@ -498,7 +499,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { order.getOrderNo())); } order.setPayStatus(EPayStatus.PAYING.getValue()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -513,7 +514,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { orderDetail.getId())); } orderDetail.setPayStatus(EPayStatus.PAYING.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -543,7 +544,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { order.setPayTradeNo(payTradeNo); //TODO 暂时使用总金额 order.setRealTotalAmount(order.getTotalAmount()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -561,7 +562,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { orderDetail.setDetailStatus(EOrderStatus.PENDING_SHIPMENT.getValue()); orderDetail.setPayStatus(EPayStatus.PAID.getValue()); orderDetail.setRealTotalAmount(orderDetail.getTotalAmount()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -595,7 +596,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } //订单已取消 order.setOrderStatus(EOrderStatus.CANCELLED.getValue()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -607,7 +608,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { for (StoreOrderDetail orderDetail : orderDetails) { //明细已取消 orderDetail.setDetailStatus(EOrderStatus.CANCELLED.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -685,7 +686,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { orderDetail.setExpressStatus(EExpressStatus.PLACED.getValue()); orderDetail.setExpressReqNo(shipReq.getExpressReqNo()); orderDetail.setExpressWaybillNo(expressWaybillNo); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -704,7 +705,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } //订单 -> 代发货/已发货 order.setOrderStatus(currentOrderStatus.getValue()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -766,7 +767,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { orderDetail.setExpressType(EExpressType.STORE.getValue()); orderDetail.setExpressStatus(EExpressStatus.COMPLETED.getValue()); orderDetail.setExpressWaybillNo(expressWaybillNo); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -785,7 +786,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } //订单 -> 代发货/已发货 order.setOrderStatus(currentOrderStatus.getValue()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -835,7 +836,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } //订单->已完成 order.setOrderStatus(EOrderStatus.COMPLETED.getValue()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -852,7 +853,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } //订单明细->已完成 orderDetail.setDetailStatus(EOrderStatus.COMPLETED.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -910,7 +911,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { afterSaleOrder.getOrderNo())); } //售后订单更新一次,触发乐观锁 - int r = storeOrderMapper.updateById(afterSaleOrder); + int r = storeOrderMapper.updateById(prepareUpdate(afterSaleOrder)); if (r == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -918,7 +919,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } //订单->已完成 order.setOrderStatus(EOrderStatus.COMPLETED.getValue()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -935,7 +936,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } //订单明细->已完成 orderDetail.setDetailStatus(EOrderStatus.COMPLETED.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1061,15 +1062,15 @@ public class StoreOrderServiceImpl implements IStoreOrderService { order.setVersion(0L); order.setDelFlag(Constants.UNDELETED); //落库 - storeOrderMapper.insert(order); + storeOrderMapper.insert(prepareInsert(order)); List orderDetailIdList = new ArrayList<>(orderDetails.size()); orderDetails.forEach(orderDetail -> { orderDetail.setStoreOrderId(order.getId()); - storeOrderDetailMapper.insert(orderDetail); + storeOrderDetailMapper.insert(prepareInsert(orderDetail)); orderDetailIdList.add(orderDetail.getId()); }); //原订单更新一次,触发乐观锁,防止退货明细重复创建 - int r = storeOrderMapper.updateById(originOrder); + int r = storeOrderMapper.updateById(prepareUpdate(originOrder)); if (r == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1107,14 +1108,14 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } orderDetail.setDetailStatus(EOrderStatus.AFTER_SALE_REJECTED.getValue()); orderDetail.setRefundRejectReason(refundRejectDTO.getRefundRejectReason()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } } order.setOrderStatus(EOrderStatus.AFTER_SALE_REJECTED.getValue()); order.setRefundRejectReason(refundRejectDTO.getRefundRejectReason()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1154,7 +1155,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } orderDetail.setPayStatus(EPayStatus.PAYING.getValue()); orderDetail.setDetailStatus(EOrderStatus.AFTER_SALE_COMPLETED.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1173,7 +1174,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } } order.setOrderStatus(orderStatus.getValue()); - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1210,12 +1211,12 @@ public class StoreOrderServiceImpl implements IStoreOrderService { throw new ServiceException(CharSequenceUtil.format("订单明细[{}]状态异常", storeOrderDetailId)); } orderDetail.setPayStatus(EPayStatus.PAID.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(orderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } } - int orderSuccess = storeOrderMapper.updateById(order); + int orderSuccess = storeOrderMapper.updateById(prepareUpdate(order)); if (orderSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1249,14 +1250,14 @@ public class StoreOrderServiceImpl implements IStoreOrderService { if (EExpressStatus.PICKED_UP == trackAddDTO.getExpressStatus()) { if (storeOrderDetail.getExpressStatus() == null) { storeOrderDetail.setExpressStatus(EExpressStatus.PICKED_UP.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(storeOrderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(storeOrderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } } else { if (storeOrderDetail.getExpressStatus() < EExpressStatus.PICKED_UP.getValue()) { storeOrderDetail.setExpressStatus(EExpressStatus.PICKED_UP.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(storeOrderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(storeOrderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1265,7 +1266,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService { } if (EExpressStatus.COMPLETED == trackAddDTO.getExpressStatus()) { storeOrderDetail.setExpressStatus(EExpressStatus.COMPLETED.getValue()); - int orderDetailSuccess = storeOrderDetailMapper.updateById(storeOrderDetail); + int orderDetailSuccess = storeOrderDetailMapper.updateById(prepareUpdate(storeOrderDetail)); if (orderDetailSuccess == 0) { throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); } @@ -1552,6 +1553,19 @@ public class StoreOrderServiceImpl implements IStoreOrderService { return reqDTO; } + private T prepareInsert(T obj) { + String username = SecurityUtils.getUsernameSafe(); + obj.setCreateBy(username); + obj.setUpdateBy(username); + return obj; + } + + private T prepareUpdate(T obj) { + obj.setUpdateBy(SecurityUtils.getUsernameSafe()); + obj.setUpdateTime(new Date()); + return obj; + } + @Data @AllArgsConstructor @NoArgsConstructor