Merge remote-tracking branch 'origin/master'

This commit is contained in:
zjf committed 2025-01-07 16:48:33 +08:00
commit 9c99f6ef42
8 files changed
+175 -11

No files matched your search

@@ -0,0 +1,37 @@
package com.bsd.pjcloud.hard.api.dto.app;
import com.bsd.pjcloud.hard.api.dto.order.HardCarDto;
import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class HardCarSaveOrUpdateDto {
@Schema(description = "商户id")
@NotNull(message = "商户id不能为空")
private Long merchantId;
@Schema(description = "购物车")
@NotEmpty(message = "购物车不能为空")
private List<HardCreateCarDto> list;
@Schema(description = "用户id")
private Long userId;
@Schema(description = "订单类型")
private String orderType;
@Schema(description = "订单类型渠道id")
private Long orderSourceTypeId;
}
@@ -110,6 +110,18 @@
<version>5.7.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.bsd</groupId>
<artifactId>pjcloud-supermarket-api</artifactId>
<version>5.7.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.bsd</groupId>
<artifactId>pjcloud-supermarket-biz</artifactId>
<version>5.7.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<profiles>
<profile>
@@ -7,8 +7,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
import com.bsd.pjcloud.hard.api.dto.app.HardCarSaveOrUpdateDto;
import com.bsd.pjcloud.hard.api.dto.order.HardCarDto;
import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity;
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
import com.bsd.pjcloud.hard.service.HardCarService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
@@ -21,7 +26,6 @@ import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
* 购物车表
@@ -38,6 +42,31 @@ public class HardCarController {
private final HardCarService hardCarService;
/* ************************************* start app start ************************************* */
@GetMapping("/app/mch-detail")
@Operation(summary = "根据商户id查询当前用户购物车")
public R<List<HardCarEntity>> appMchDetail(@RequestParam Long merchantId) {
PjcloudUser user = SecurityUtils.getUser();
return R.ok(hardCarService.mchDetail(merchantId, user.getId()));
}
@GetMapping("/app/order-id")
@Operation(summary = "根据订单id查询当前用户购物车")
public R<List<HardCarVo>> appOrderId(@RequestParam Long orderId) {
return R.ok(hardCarService.getByOrderId(orderId));
}
@PostMapping("/app/save-or-upload")
@Operation(summary = "新增或者更新购物车")
public R saveOrUpload(@RequestBody HardCarSaveOrUpdateDto dto) {
PjcloudUser user = SecurityUtils.getUser();
dto.setUserId(user.getId());
dto.setOrderType(HardOrderTypeEnum.RESERVE.getType());
hardCarService.saveOrUpload(dto);
return R.ok(true);
}
/* ************************************* end app end ************************************* */
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('hard_hardCar_view')")
@@ -3,6 +3,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.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.hard.api.dto.app.HardCarSaveOrUpdateDto;
import com.bsd.pjcloud.hard.api.dto.order.HardCarDto;
import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity;
@@ -18,8 +19,16 @@ public interface HardCarService extends IService<HardCarEntity> {
List<HardCarVo> getByOrderId(Long orderId);
List<HardCarEntity> mchDetail(Long merchantId, Long userId);
Integer computerCarTotalPrice(@NotNull HardTypeEnum sysType, @NotEmpty List<HardCreateCarDto> list);
/**
* 新增或者更新购物车
* @param dto
*/
void saveOrUpload(HardCarSaveOrUpdateDto dto);
/**
* @param userId 用户id
* @param merchantId 商户id
@@ -1,13 +1,17 @@
package com.bsd.pjcloud.hard.service.impl.order;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.canteen.api.feign.RemoteCanteenSpuService;
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.dto.app.HardCarSaveOrUpdateDto;
import com.bsd.pjcloud.hard.api.dto.order.HardCarDto;
import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity;
@@ -18,6 +22,8 @@ import com.bsd.pjcloud.hard.mapper.order.HardCarMapper;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.mapper.order.HardParentCarMapper;
import com.bsd.pjcloud.hard.service.HardCarService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketUnitSkuService;
import com.bsd.pjcloud.supermarket.entity.SupermarketUnitEntity;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -45,12 +51,20 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
private final HardParentCarMapper hardParentCarMapper;
private final RemoteCanteenSpuService canteenSpuService;
private final RemoteSupermarketUnitSkuService supermarketUnitSkuService;
@Override
public Page<HardCarVo> pageJoin(Page page, HardCarDto dto) {
return baseMapper.pageJoin(page, dto);
}
@Override
public List<HardCarEntity> mchDetail(Long merchantId, Long userId) {
HardParentCarEntity parentCarDO = getParentCar(merchantId, userId);
if (ObjectUtil.isEmpty(parentCarDO)) return null;
return list(new LambdaQueryWrapper<HardCarEntity>().eq(HardCarEntity::getParentCarId, parentCarDO.getId()));
}
@Override
public List<HardCarVo> getByOrderId(Long orderId) {
HardOrderEntity order = hardCarMapper.selectById(orderId);
@@ -61,6 +75,23 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
return BeanUtils.toBean(list, HardCarVo.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpload(HardCarSaveOrUpdateDto dto) {
HardParentCarEntity parentCar = getParentCar(dto.getMerchantId(), dto.getUserId());
if (ObjectUtil.isNotEmpty(parentCar)) {
baseMapper.delete(new LambdaQueryWrapper<HardCarEntity>().eq(HardCarEntity::getParentCarId, parentCar.getId()));
// 添加购物车
getSelf().appCreateCard(parentCar.getId(), HardTypeEnum.CANTEEN, dto.getList());
return;
}
// 添加父订单
HardParentCarEntity parentCarObj = HardParentCarEntity.builder().userId(dto.getUserId()).merchantId(dto.getMerchantId()).orderStatus(HardOrderStatusEnum.CREATE.getType()).build();
hardParentCarMapper.insert(parentCarObj);
// 添加购物车
getSelf().appCreateCard(parentCar.getId(), HardTypeEnum.CANTEEN, dto.getList());
}
@Override
public Integer computerCarTotalPrice(HardTypeEnum sysType, List<HardCreateCarDto> list) {
List<Long> productIds = list.stream().map(HardCreateCarDto::getProductId).toList();
@@ -91,16 +122,22 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
@Override
@Transactional(rollbackFor = Exception.class)
public Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, List<HardCreateCarDto> list) {
List<Long> productIds = list.stream().map(HardCreateCarDto::getProductId).toList();
// 创建父订单
HardParentCarEntity parentCarObj = HardParentCarEntity.builder().userId(userId).merchantId(merchantId).orderStatus(sysType.getType()).build();
HardParentCarEntity parentCarObj = HardParentCarEntity.builder().userId(userId).merchantId(merchantId).orderStatus(HardOrderStatusEnum.PAY.getType()).build();
hardParentCarMapper.insert(parentCarObj);
List<HardCarEntity> carObjectList = new ArrayList<>();
getSelf().appCreateCard(parentCarObj.getId(), sysType, list);
return parentCarObj.getId();
}
@Transactional(rollbackFor = Exception.class)
public void appCreateCard(Long parentCarId, HardTypeEnum sysType, List<HardCreateCarDto> productList) {
List<Long> productIds = productList.stream().map(HardCreateCarDto::getProductId).toList();
// 食堂
if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) {
List<HardCarEntity> carObjectList = new ArrayList<>();
List<CanteenSpuEntity> supList = (List<CanteenSpuEntity>) canteenSpuService.getSpuListByIds(productIds).getData();
for (HardCreateCarDto v : list) {
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarObj.getId()).build();
for (HardCreateCarDto v : productList) {
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
int totalPrice = v.getProductCount() * spu.getPrice();
item.setProductId(spu.getId());
@@ -110,15 +147,32 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
item.setTotalPrice((long) totalPrice);
item.setProductCount(v.getProductCount());
item.setProductWeight(new BigDecimal(0));
carObjectList.add(item);
});
}
baseMapper.insert(carObjectList);
return;
}
// 超市
if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) {
List<HardCarEntity> carObjectList = new ArrayList<>();
List<SupermarketUnitEntity> supList = (List<SupermarketUnitEntity>) supermarketUnitSkuService.getSupermarketUnits(productIds).getData();
for (HardCreateCarDto v : productList) {
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
int totalPrice = v.getProductCount() * spu.getRetailPrice();
item.setProductId(spu.getId());
item.setProductName("");
item.setProductPrice(spu.getRetailPrice());
item.setProductPic("");
item.setTotalPrice((long) totalPrice);
item.setProductCount(v.getProductCount());
item.setProductWeight(new BigDecimal(0));
carObjectList.add(item);
});
}
return;
}
baseMapper.insert(carObjectList);
return parentCarObj.getId();
}
@Override
@@ -134,8 +188,26 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
}
}
if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) {
List<SupermarketUnitEntity> supList = (List<SupermarketUnitEntity>) supermarketUnitSkuService.getSupermarketUnits(productIds).getData();
for (HardCreateCarDto v : list) {
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
str.append("").append("x").append(v.getProductCount()).append(";");
});
}
}
return str.toString();
}
private HardParentCarEntity getParentCar(Long merchantId, Long userId) {
if (!ObjectUtil.isAllNotEmpty(merchantId, userId)) return null;
return hardParentCarMapper.selectOne(new LambdaQueryWrapper<HardParentCarEntity>()
.eq(HardParentCarEntity::getUserId, userId)
.eq(HardParentCarEntity::getMerchantId, merchantId)
.eq(HardParentCarEntity::getOrderStatus, HardOrderStatusEnum.CREATE.getType())
);
}
private HardCarServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}
@@ -22,6 +22,7 @@ package com.bsd.pjcloud.admin.api.feign;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.feign.annotation.NoToken;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -61,6 +62,7 @@ public interface RemoteDeptService {
* @param deptIds
* @return
*/
@NoToken
@GetMapping("/dept/getDeptListByDeptIds")
R<Map<Long, SysDept>> getDeptByDeptIds(@RequestParam("deptIds") List<Long> deptIds);
@@ -27,6 +27,7 @@ import com.bsd.pjcloud.common.excel.annotation.RequestExcel;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.HasPermission;
import com.bsd.pjcloud.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -186,12 +187,13 @@ public class SysDeptController {
return R.ok(sysDeptService.getOrgTreeUser(username));
}
@Inner
@GetMapping("/getDeptListByDeptIds")
public R<Map<Long, SysDept>> getDeptListByDeptIds(@RequestParam("deptIds") List<Long> deptIds) {
return R.ok(sysDeptService.getDeptListByDeptIds(deptIds));
}
@Inner(value = false)
@GetMapping("/getDeptListByDeptId")
public R<SysDept> getDeptByDeptId(@RequestParam("deptId") Long deptId) {
return R.ok(sysDeptService.getById(deptId));
@@ -86,6 +86,7 @@ public class MchManageController {
/* ************************************* start app start ************************************* */
@Operation(summary = "app查询商铺", description = "app查询商铺")
@GetMapping("/app/page-join")
@Inner(value = false)
public R<Page<MchManageVo>> appPageJoin(@ParameterObject Page page, @ParameterObject MchManageDto dto) {
return R.ok(mchManageService.pageJoin(page, dto));
}