feat:退款退库存

This commit is contained in:
dzc committed 2025-01-14 09:33:09 +08:00
1 parent 1327fac21e
commit 7d038b41ef
13 files changed
+140 -94

No files matched your search

@@ -37,51 +37,54 @@ import java.util.Objects;
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/canteenOnlineSpu" )
@Tag(description = "canteenOnlineSpu" , name = "在线点餐spu管理" )
@RequestMapping("/canteenOnlineSpu")
@Tag(description = "canteenOnlineSpu", name = "在线点餐spu管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CanteenOnlineSpuController {
private final CanteenOnlineSpuService canteenOnlineSpuService;
private final CanteenOnlineSpuService canteenOnlineSpuService;
/**
* 分页查询
* @param page 分页对象
*
* @param page 分页对象
* @param canteenOnlineSpu 在线点餐spu
* @return
*/
@Operation(summary = "分页查询" , description = "分页查询" )
@GetMapping("/page" )
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_view')" )
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_view')")
public R getCanteenOnlineSpuPage(@ParameterObject Page page, @ParameterObject CanteenOnlineSpuEntity canteenOnlineSpu) {
LambdaQueryWrapper<CanteenOnlineSpuEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StrUtil.isNotBlank(canteenOnlineSpu.getName()),CanteenOnlineSpuEntity::getName,canteenOnlineSpu.getName());
wrapper.eq(Objects.nonNull(canteenOnlineSpu.getCategoryId()),CanteenOnlineSpuEntity::getCategoryId,canteenOnlineSpu.getCategoryId());
wrapper.like(StrUtil.isNotBlank(canteenOnlineSpu.getName()), CanteenOnlineSpuEntity::getName, canteenOnlineSpu.getName());
wrapper.eq(Objects.nonNull(canteenOnlineSpu.getCategoryId()), CanteenOnlineSpuEntity::getCategoryId, canteenOnlineSpu.getCategoryId());
return R.ok(canteenOnlineSpuService.page(page, wrapper));
}
/**
* 通过id查询在线点餐spu
*
* @param id id
* @return R
*/
@Operation(summary = "通过id查询" , description = "通过id查询" )
@GetMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_view')" )
public R getById(@PathVariable("id" ) Long id) {
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(canteenOnlineSpuService.getById(id));
}
/**
* 新增在线点餐spu
*
* @param canteenOnlineSpu 在线点餐spu
* @return R
*/
@Operation(summary = "新增在线点餐spu" , description = "新增在线点餐spu" )
@SysLog("新增在线点餐spu" )
@Operation(summary = "新增在线点餐spu", description = "新增在线点餐spu")
@SysLog("新增在线点餐spu")
@PostMapping
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_add')" )
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_add')")
public R save(@RequestBody CanteenOnlineSpuEntity canteenOnlineSpu) {
canteenOnlineSpu.setDeptId(SecurityUtils.getUser().getDeptId());
return R.ok(canteenOnlineSpuService.save(canteenOnlineSpu));
@@ -89,26 +92,28 @@ public class CanteenOnlineSpuController {
/**
* 修改在线点餐spu
*
* @param canteenOnlineSpu 在线点餐spu
* @return R
*/
@Operation(summary = "修改在线点餐spu" , description = "修改在线点餐spu" )
@SysLog("修改在线点餐spu" )
@Operation(summary = "修改在线点餐spu", description = "修改在线点餐spu")
@SysLog("修改在线点餐spu")
@PutMapping
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_edit')" )
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_edit')")
public R updateById(@RequestBody CanteenOnlineSpuEntity canteenOnlineSpu) {
return R.ok(canteenOnlineSpuService.updateById(canteenOnlineSpu));
}
/**
* 通过id删除在线点餐spu
*
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除在线点餐spu" , description = "通过id删除在线点餐spu" )
@SysLog("通过id删除在线点餐spu" )
@Operation(summary = "通过id删除在线点餐spu", description = "通过id删除在线点餐spu")
@SysLog("通过id删除在线点餐spu")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_del')" )
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(canteenOnlineSpuService.removeBatchByIds(CollUtil.toList(ids)));
}
@@ -116,14 +121,15 @@ public class CanteenOnlineSpuController {
/**
* 导出excel 表格
*
* @param canteenOnlineSpu 查询条件
* @param ids 导出指定ID
* @param ids 导出指定ID
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_export')" )
public List<CanteenOnlineSpuEntity> export(CanteenOnlineSpuEntity canteenOnlineSpu,Long[] ids) {
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_export')")
public List<CanteenOnlineSpuEntity> export(CanteenOnlineSpuEntity canteenOnlineSpu, Long[] ids) {
return canteenOnlineSpuService.list(Wrappers.lambdaQuery(canteenOnlineSpu).in(ArrayUtil.isNotEmpty(ids), CanteenOnlineSpuEntity::getId, ids));
}
@@ -138,16 +144,16 @@ public class CanteenOnlineSpuController {
* @return
*/
@GetMapping("/app/getCanteenSpuList")
@Operation(summary = "获取在线点餐的菜品列表" , description = "1.通过分类id,可以不填,默认查全部,2.商户id,必传" )
@Operation(summary = "获取在线点餐的菜品列表", description = "1.通过分类id,可以不填,默认查全部,2.商户id,必传")
public R<List<APPOnlineSpuVO>> getCanteenSpuList(@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "merchantId") String merchantId ) {
return canteenOnlineSpuService.getCanteenOnlineSpuList(categoryId,merchantId);
@RequestParam(value = "merchantId") String merchantId) {
return canteenOnlineSpuService.getCanteenOnlineSpuList(categoryId, merchantId);
}
@GetMapping("/app/getCanteenSpuDetails")
@Operation(summary = "获取详情接口" , description = "通过spu的id" )
public R<APPOnlineSpuVO> getCanteenSpuDetails(@RequestParam(value = "id") Long id ) {
@Operation(summary = "获取详情接口", description = "通过spu的id")
public R<APPOnlineSpuVO> getCanteenSpuDetails(@RequestParam(value = "id") Long id) {
CanteenOnlineSpuEntity canteenOnlineSpuEntity = canteenOnlineSpuService.getById(id);
APPOnlineSpuVO bean = BeanUtils.toBean(canteenOnlineSpuEntity, APPOnlineSpuVO.class);
return R.ok(bean);
@@ -157,12 +163,12 @@ public class CanteenOnlineSpuController {
@GetMapping("/app/checkSpuStock")
@SysLog("购物车效验库存")
@Transactional
public R checkSpuStock(@RequestParam(value ="spuId")Long spuId,@RequestParam("incrCount")Integer incrCount) {
public R checkSpuStock(@RequestParam(value = "spuId") Long spuId, @RequestParam("incrCount") Integer incrCount) {
CanteenOnlineSpuEntity canteenOnlineSpuEntity = canteenOnlineSpuService.getById(spuId);
if (canteenOnlineSpuEntity == null) {
R.failed("商品不存在");
return R.failed("商品不存在");
}
if (canteenOnlineSpuEntity.getStock()<Math.abs(incrCount)){
if (canteenOnlineSpuEntity.getStock() < Math.abs(incrCount)) {
return R.failed("库存不足");
}
return R.ok();
@@ -179,12 +185,13 @@ public class CanteenOnlineSpuController {
/**
* 通过ids查询菜品spu
*
* @param ids ids
* @return R
*/
@Operation(summary = "通过ids查询" , description = "通过ids查询" )
@PostMapping("/app/getSpuListByIds" )
@PreAuthorize("@pms.hasPermission('canteen_canteenSpu_view')" )
@Operation(summary = "通过ids查询", description = "通过ids查询")
@PostMapping("/app/getSpuListByIds")
@PreAuthorize("@pms.hasPermission('canteen_canteenSpu_view')")
public R<List<CanteenOnlineSpuAppVO>> getByIds(@RequestBody List<Long> ids) {
List<CanteenOnlineSpuEntity> list = canteenOnlineSpuService.list(new LambdaQueryWrapper<CanteenOnlineSpuEntity>().in(CanteenOnlineSpuEntity::getId, ids));
List<CanteenOnlineSpuAppVO> canteenOnlineSpuAppVOS = BeanUtils.toBean(list, CanteenOnlineSpuAppVO.class);
@@ -36,24 +36,18 @@ public class CanteenOnlineSpuServiceImpl extends ServiceImpl<CanteenOnlineSpuMap
@Override
public R updateOnlineSpuSkuStock(CanteenOnlineSpuUpdateStockReqDTO canteenOnlineSpuUpdateStockReqDTO) {
// 更新 SKU 库存
canteenOnlineSpuUpdateStockReqDTO.getItems().forEach(item -> {
for (CanteenOnlineSpuUpdateStockReqDTO.Item v : canteenOnlineSpuUpdateStockReqDTO.getItems()) {
// 查询当前库存
CanteenOnlineSpuEntity spu = baseMapper.selectById(item.getId());
CanteenOnlineSpuEntity spu = baseMapper.selectById(v.getId());
if (spu == null) {
R.failed(spu.getName()+"商品不存在");
return R.failed(spu.getName() + "商品不存在");
}
// 检查库存是否足够
if (item.getIncrCount() < 0 && Math.abs(item.getIncrCount()) > spu.getStock()) {
R.failed(spu.getName()+"库存不足,无法完成操作");
if (v.getIncrCount() < 0 && Math.abs(v.getIncrCount()) > spu.getStock()) {
return R.failed(spu.getName() + "库存不足,无法完成操作");
}
int i = baseMapper.updateStock(item.getId(), item.getIncrCount());
// if (item.getIncrCount() <= 0) {
// if (i == 0) {
// R.failed("商品库存不足");
// }
// }
});
baseMapper.updateStock(v.getId(), v.getIncrCount());
}
return R.ok();
}
}
@@ -13,6 +13,11 @@
<artifactId>pjcloud-hardware-biz</artifactId>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>lock4j-redis-template-spring-boot-starter</artifactId>
<version>2.2.7</version>
</dependency>
<!--引入分布式事务-->
<dependency>
<groupId>com.bsd</groupId>
@@ -145,7 +150,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<executions>
<execution>
<goals>
<goal>repackage</goal>
@@ -155,7 +160,7 @@
</configuration>
</execution>
</executions>
</plugin>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto;
import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
@@ -55,8 +56,10 @@ public interface HardOrderService extends IService<HardOrderEntity> {
/**
* 扣减库存
*
* @param isReduce true 扣件库存 false增加库存
*/
void fastenerInventory(HardOrderEntity order);
void fastenerInventory(HardOrderEntity order, YesNoEnum isReduce);
/**
* 核销硬件二维码
@@ -12,6 +12,7 @@ import com.bsd.pjcloud.admin.api.entity.SysUser;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
@@ -126,14 +127,6 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
DataUtil.convertDeptList(list.getRecords(), deptList.getData());
}
}
// 订单
List<Long> orderIds = list.getRecords().stream().map(HardAfterSaleVo::getOrderId).filter(ObjectUtil::isNotEmpty).distinct().toList();
if (ObjectUtil.isNotEmpty(orderIds)) {
HardOrderDto hardOrderDto = new HardOrderDto();
hardOrderDto.setOrderIds(orderIds);
List<HardOrderEntity> orderList = hardOrderMapper.list(hardOrderDto);
HardUtil.convertOrderList(list.getRecords(), CollectionUtils.convertMap(orderList, HardOrderEntity::getId));
}
}
return list;
}
@@ -212,7 +205,6 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
}
@Override
@GlobalTransactional
@Transactional(rollbackFor = Exception.class)
public void refund(Long afterSaleId) {
HardAfterSaleEntity afterSale = baseMapper.selectById(afterSaleId);
@@ -263,6 +255,8 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
hardAfterSaleLogMapper.insert(saveLogObj);
// 执行退款
getSelf().refund(updateRefundObj.getId());
// 退库存
hardOrderService.fastenerInventory(order, YesNoEnum.NO);
return true;
}
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service.impl.order;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -111,6 +112,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
@Override
@Transactional(rollbackFor = Exception.class)
@Lock4j(keys = {"#dto.userId"})
public void saveOrUpload(HardCarSaveOrUpdateDto dto) {
List<HardCreateCarDto> carList = dto.getList().stream().filter(v -> v.getProductCount() > 0).toList();
HardParentCarEntity parentCar = getParentCar(dto.getMerchantId(), dto.getUserId(), dto.getHardType());
@@ -287,6 +287,8 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
baseMapper.insert(orderObj);
// 钱包扣款
if (isPay) getSelf().fastReduceBalance(orderObj);
// 扣减库存
getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
return orderObj.getId();
}
@@ -344,7 +346,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
// 是否需要创建二维码
getSelf().generateCode(orderObj);
// 扣减库存
getSelf().fastenerInventory(orderObj);
getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
return orderObj.getId();
}
@@ -449,31 +451,33 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
@Override
@Transactional(rollbackFor = Exception.class)
public void fastenerInventory(HardOrderEntity order) {
public void fastenerInventory(HardOrderEntity order, YesNoEnum isReduce) {
HardTypeEnum hardTypeEnum = HardTypeEnum.valueOfByType(order.getSysType());
HardOrderTypeEnum orderTypeEnum = HardOrderTypeEnum.valueOfByType(order.getOrderType());
if (!ObjectUtil.isAllNotEmpty(hardTypeEnum, orderTypeEnum)) return;
String CarErrorMsg = ObjectUtil.equals(isReduce, YesNoEnum.YES.getCode()) ? "扣减库存错误" : "恢复库存错误";
int base = ObjectUtil.equals(isReduce, YesNoEnum.YES.getCode()) ? -1 : 1;
// 食堂扣件库存
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.CANTEEN) && ObjectUtil.equals(orderTypeEnum, HardOrderTypeEnum.RESERVE)) {
// 查询购物车
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException(CarErrorMsg + ",购物车不存在");
CanteenSpuUpdateStockReqDTO dto = new CanteenSpuUpdateStockReqDTO();
List<CanteenSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
CanteenSpuUpdateStockReqDTO.Item item = new CanteenSpuUpdateStockReqDTO.Item();
item.setId(v.getProductId());
item.setIncrCount(v.getProductCount());
item.setIncrCount(v.getProductCount() * base);
return item;
}).toList();
dto.setItems(list);
R updateSkuStockRes = onlineCanteenSpuService.updateSkuStock(dto);
if (updateSkuStockRes.getCode() != 0) {
throw new RuntimeException("库存不足");
throw new RuntimeException(CarErrorMsg);
}
return;
}
// 超市扣家库存
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.SUPERMARKET) && ObjectUtil.equals(orderTypeEnum, HardOrderTypeEnum.RESERVE)) {
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.SUPERMARKET)) {
// 查询购物车
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
@@ -481,13 +485,13 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
List<SupermarketSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
SupermarketSpuUpdateStockReqDTO.Item item = new SupermarketSpuUpdateStockReqDTO.Item();
item.setId(v.getProductId());
item.setIncrCount(v.getProductCount());
item.setIncrCount(v.getProductCount() * base);
return item;
}).toList();
dto.setItems(list);
R updateSkuStockRes = supermarketSpuService.updateSpuStock(dto);
if (updateSkuStockRes.getCode() != 0) {
throw new RuntimeException("扣件库存错误");
throw new RuntimeException(CarErrorMsg);
}
return;
}
@@ -53,7 +53,7 @@
a.update_by,
a.update_time,
a.del_flag,
a.tenant_id
a.tenant_id,
</sql>
<sql id="whereA">
@@ -64,14 +64,32 @@
<if test="dto.orderId != null">
and a.order_id = #{dto.orderId}
</if>
<if test="dto.status != null and dto.status != '' ">
and a.status = #{dto.status}
</if>
<if test="dto.userIds != null and dto.userIds.size() != 0">
and a.user_id IN
<foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{pa.createTimeList[1]}
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
</sql>
<select id="scopePageJoinList" resultType="com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo">
<include refid="selectA"/>
o.dept_id,
o.dept_id as orderDeptId,
o.hard_id as orderHardId,
o.parent_car_id as orderParentCarId,
o.total_price as orderTotalPrice,
o.extra_price as orderExtraPrice,
o.pay_price as orderPayPrice,
o.pay_time as orderPayTime
from hard_after_sale a
left join hard_order o on o.id = a.order_id
<where>
<include refid="whereA"/>
</where>
@@ -122,25 +122,18 @@ public class SupermarketSpuServiceImpl extends ServiceImpl<SupermarketSpuMapper,
@Override
@Transactional
public R updateSpuStock(SupermarketSpuUpdateStockReqDTO updateStockReqDTO) {
// 更新 SKU 库存
updateStockReqDTO.getItems().forEach(item -> {
for (SupermarketSpuUpdateStockReqDTO.Item v : updateStockReqDTO.getItems()) {
// 查询当前库存
SupermarketSpuEntity spu = baseMapper.selectById(item.getId());
SupermarketSpuEntity spu = baseMapper.selectById(v.getId());
if (spu == null) {
R.failed(spu.getProductName()+"商品不存在");
return R.failed(spu.getProductName() + "商品不存在");
}
// 检查库存是否足够
if (item.getIncrCount() < 0 && Math.abs(item.getIncrCount()) > spu.getStock()) {
R.failed(spu.getProductName()+"库存不足,无法完成操作");
if (v.getIncrCount() < 0 && Math.abs(v.getIncrCount()) > spu.getStock()) {
return R.failed(spu.getProductName() + "库存不足,无法完成操作");
}
int i = baseMapper.updateStock(item.getId(), item.getIncrCount());
// if (item.getIncrCount() <= 0) {
// if (i == 0) {
// R.failed("商品库存不足");
// }
// }
});
int i = baseMapper.updateStock(v.getId(), v.getIncrCount());
}
return R.ok();
}
@@ -109,7 +109,7 @@ public class MchManageController {
@GetMapping("/page-join")
@PreAuthorize("@pms.hasPermission('wallet_mchManage_view')")
public R getMchManagePageJoin(@ParameterObject Page page, @ParameterObject MchManageDto dto) {
return R.ok(mchManageService.pageJoin(page, dto));
return R.ok(mchManageService.scopePageList(page, dto));
}
@Operation(summary = "分页不要权限下拉", description = "分页不要权限下拉")
@@ -19,6 +19,8 @@ public interface MchManageService extends IService<MchManageEntity> {
Page<MchManageVo> pageJoin(Page page, MchManageDto dto);
Page<MchManageVo> scopePageList(Page page, MchManageDto dto);
MchManageVo join(Long id);
List<MchManageVo> list(MchManageDto dto);
@@ -1,6 +1,7 @@
package com.bsd.pjcloud.wallet.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -22,6 +23,7 @@ import com.bsd.pjcloud.wallet.mapper.MchManageMapper;
import com.bsd.pjcloud.wallet.service.MchManageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
@@ -92,15 +94,15 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
}
@Override
@CachePut(value = CacheConstants.WALLET_MCH, key = "dto.getId()", condition = "dto.getId() != null", unless = "#result == null ")
@CacheEvict(value = CacheConstants.WALLET_MCH, key = "#dto.getId()", condition = "#dto.getId() != null")
public void edit(MchManageEntity dto) {
if (existName(dto.getName(), null)) {
if (existName(dto.getName(), dto.getId())) {
throw new CheckedException("商户名不能重复");
}
if (existDeptId(dto.getDeptId(), null)) {
if (existDeptId(dto.getDeptId(), dto.getId())) {
throw new CheckedException("改部门已经绑定过商户");
}
MchManageEntity mchManage = getById(dto.getId());
MchManageEntity mchManage = getSelf().getById(dto.getId());
if (ObjectUtil.isEmpty(mchManage)) {
throw new CheckedException("商户不存在");
}
@@ -117,13 +119,31 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
@Override
public Page<MchManageVo> pageJoin(Page page, MchManageDto dto) {
Page<MchManageVo> list = baseMapper.pageJoin(page, dto);
if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 部门
List<Long> deptIds = list.getRecords().stream().map(MchManageVo::getDeptId).distinct().toList();
if (ObjectUtil.isNotEmpty(deptIds)) {
R<Map<Long, SysDept>> deptList = remoteDeptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(page.getRecords(), deptList.getData());
}
}
}
return list;
}
@Override
public Page<MchManageVo> scopePageList(Page page, MchManageDto dto) {
Page<MchManageVo> list = baseMapper.scopePageList(page, dto);
if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 部门
List<Long> deptIds = list.getRecords().stream().map(MchManageVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = remoteDeptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(page.getRecords(), deptList.getData());
if (ObjectUtil.isNotEmpty(deptIds)) {
R<Map<Long, SysDept>> deptList = remoteDeptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(page.getRecords(), deptList.getData());
}
}
}
return list;
@@ -190,4 +210,8 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
}
return count > 0;
}
private MchManageServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}
@@ -38,7 +38,7 @@
<sql id="whereA">
a.del_flag = 0
<if test="dto.userIds">
<if test="dto.userIds != null and dto.userIds.size() != 0">
and a.user_id in
<foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">
#{v}