pull/1121/head
梁宇奇 2025-07-03 17:32:25 +08:00
parent c781fa177c
commit ee2339f048
8 changed files with 100 additions and 104 deletions

View File

@ -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<UserListItem> 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<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
List<SysUser> userList = util.importExcel(file.getInputStream());

View File

@ -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;
}
/**
*
*

View File

@ -52,4 +52,12 @@ public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
*/
List<Long> listRelUserId(@Param("menuId") Long menuId);
/**
* ID
*
* @param roleId
* @return
*/
List<Long> listRelMenuId(@Param("roleId") Long roleId);
}

View File

@ -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<Long> storeUsableMenuIds() {
//TODO USER
return roleMenuMapper.selectList(Wrappers.emptyWrapper()).stream().map(SysRoleMenu::getMenuId).collect(Collectors.toSet());
return new HashSet<>(roleMenuMapper.listRelMenuId(ESystemRole.SUPPLIER.getId()));
}

View File

@ -375,7 +375,6 @@ public class SysUserServiceImpl implements ISysUserService {
successNum++;
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
} else if (isUpdateSupport) {
//TODO USER
BeanValidators.validateWithException(validator, user);
checkUserAllowed(u);
// checkUserDataScope(u.getUserId());

View File

@ -22,7 +22,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
srm.menu_id = #{menuId}
</select>
<delete id="deleteRoleMenuByRoleId" parameterType="Long">
<select id="listRelMenuId" resultType="java.lang.Long">
SELECT
srm.menu_id
FROM
sys_role_menu srm
WHERE
srm.role_id = #{roleId};
</select>
<delete id="deleteRoleMenuByRoleId" parameterType="Long">
delete from sys_role_menu where role_id=#{roleId}
</delete>

View File

@ -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<FinanceBillDetail> 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<FinanceBillDetail> 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<FinanceBillDetail> 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 extends SimpleEntity> T prepareInsert(T obj) {
String username = SecurityUtils.getUsernameSafe();
obj.setCreateBy(username);
obj.setUpdateBy(username);
return obj;
}
private <T extends SimpleEntity> T prepareUpdate(T obj) {
obj.setUpdateBy(SecurityUtils.getUsernameSafe());
obj.setUpdateTime(new Date());
return obj;
}
}

View File

@ -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<Long> 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<Long> 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<Long> 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 extends SimpleEntity> T prepareInsert(T obj) {
String username = SecurityUtils.getUsernameSafe();
obj.setCreateBy(username);
obj.setUpdateBy(username);
return obj;
}
private <T extends SimpleEntity> T prepareUpdate(T obj) {
obj.setUpdateBy(SecurityUtils.getUsernameSafe());
obj.setUpdateTime(new Date());
return obj;
}
@Data
@AllArgsConstructor
@NoArgsConstructor