diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByCanteenDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByCanteenDto.java index 8e228b3eb..483819972 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByCanteenDto.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByCanteenDto.java @@ -1,11 +1,9 @@ package com.bsd.pjcloud.hard.api.dto.order.app; -import com.bsd.pjcloud.hard.api.constant.total.DateRangeTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.List; /** @@ -14,8 +12,11 @@ import java.util.List; @Data public class HardAppProductByCanteenDto { + @Schema(description = "用户Id") + private Long userId; + @Schema(description = "食堂id") - private List canteenIdList; + private List canteenIdList; @Schema(description = "用餐时间段") private String hourType; diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByClassifyDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByClassifyDto.java index 3f7bdf37f..fa9a7ddf7 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByClassifyDto.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductByClassifyDto.java @@ -13,6 +13,9 @@ import java.util.List; @Data public class HardAppProductByClassifyDto { + @Schema(description = "用户Id") + private Long userId; + @Schema(description = "食堂id") private List canteenIdList; diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCanteenTotalController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCanteenTotalController.java index 1f686ef7d..5a2c7bd46 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCanteenTotalController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCanteenTotalController.java @@ -49,6 +49,10 @@ public class HardCanteenTotalController { @Operation(summary = "菜品销量按照分类查询", description = "菜品销量按照分类查询") @PostMapping("/app/product-by-classify") public R> productByClassify(@RequestBody HardAppProductByClassifyDto dto) { + PjcloudUser user = SecurityUtils.getUser(); + if (ObjectUtil.isNotEmpty(user)) { + dto.setUserId(user.getId()); + } return R.ok(canteenTotalService.productByClassify(dto)); } @@ -59,6 +63,10 @@ public class HardCanteenTotalController { @Operation(summary = "近一周各个食堂菜品购买统计", description = "近一周各个食堂菜品购买统计") @PostMapping("/app/product-by-canteen") public R>>> productByCanteen(@RequestBody HardAppProductByCanteenDto dto) { + PjcloudUser user = SecurityUtils.getUser(); + if (ObjectUtil.isNotEmpty(user)) { + dto.setUserId(user.getId()); + } return R.ok(canteenTotalService.productByCanteen(dto)); } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/sync/HardSyncController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/sync/HardSyncController.java new file mode 100644 index 000000000..cdc932000 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/sync/HardSyncController.java @@ -0,0 +1,40 @@ +package com.bsd.pjcloud.hard.controller.sync; + +import com.bsd.pjcloud.common.core.util.R; +import com.bsd.pjcloud.common.idempotent.annotation.Idempotent; +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.service.HardSyncService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 设备同步 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/hard-sync") +@Tag(description = "hard-sync", name = "设备同步") +@SecurityRequirement(name = HttpHeaders.AUTHORIZATION) +public class HardSyncController { + + private final HardSyncService hardSyncService; + + @Operation(summary = "同步超市分类商品和同步", description = "同步超市分类商品和同步") + @SysLog("同步超市分类商品和同步") + @Idempotent(expireTime = 3, info = "正在同步中,请勿重复操作") + @GetMapping("/sync-supermarket") + public R syncSupermarket() { + PjcloudUser user = SecurityUtils.getUser(); + hardSyncService.syncSupermarket(user); + return R.ok(); + } + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardSyncService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardSyncService.java new file mode 100644 index 000000000..dd2ede6d6 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardSyncService.java @@ -0,0 +1,12 @@ +package com.bsd.pjcloud.hard.service; + +import com.bsd.pjcloud.common.security.service.PjcloudUser; + +public interface HardSyncService { + + /** + * 同步超市分类商品和同步 + */ + void syncSupermarket(PjcloudUser user); + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCanteenTotalServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCanteenTotalServiceImpl.java index b54ac130b..6d6492112 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCanteenTotalServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCanteenTotalServiceImpl.java @@ -9,6 +9,7 @@ import com.bsd.pjcloud.admin.api.feign.RemoteDeptService; import com.bsd.pjcloud.canteen.api.feign.RemoteCanteenCategoryService; import com.bsd.pjcloud.canteen.entity.CanteenCategoryEntity; import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum; +import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum; import com.bsd.pjcloud.common.data.datascope.DataScope; import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; import com.bsd.pjcloud.hard.api.constant.total.DateRangeTypeEnum; @@ -86,6 +87,14 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService { */ @Override public List>> productByCanteen(HardAppProductByCanteenDto dto) { + // 查询自营食堂并且在移动端显示的 + List canteenList = remoteMchService.getByTypes(List.of(MerchantTypeEnum.CANTEEN.getType())).getData(); + if (ObjectUtil.isEmpty(canteenList)) return null; + canteenList = canteenList.stream().filter(v -> ObjectUtil.equals(v.getVisibleMobile(), YesNoEnum.YES.getCode())).toList(); + if (ObjectUtil.isNotEmpty(canteenList)) { + List canteenIdList = canteenList.stream().map(MchManageVo::getId).toList(); + dto.setCanteenIdList(canteenIdList); + } dto.setPayTimeList(new LocalDate[]{LocalDate.now().minusWeeks(1), LocalDate.now()}); // 查询近一周的时间 List dateList = new LinkedList<>(); @@ -99,10 +108,8 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService { } // 查询自营食堂 - List mchList = remoteMchService.getByTypes(List.of(MerchantTypeEnum.CANTEEN.getType())).getData(); - if (ObjectUtil.isEmpty(mchList)) return null; List>> result = new ArrayList<>(); - for (MchManageVo vo : mchList) { + for (MchManageVo vo : canteenList) { result.add(Map.of(vo.getName(), dateList)); } @@ -112,8 +119,8 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService { for (Map> map : result) { for (Map.Entry> entry : map.entrySet()) { String canteenName = entry.getKey(); - List canteenList = entry.getValue(); - for (HardAppProductByCanteenVo vo : canteenList) { + List currentCanteenList = entry.getValue(); + for (HardAppProductByCanteenVo vo : currentCanteenList) { dateList.stream().filter(item -> ObjectUtil.equals(item.getCanteenName(), canteenName) && ObjectUtil.equals(item.getTime(), vo.getTime())).findFirst().ifPresent(target -> { target.setCanteenId(vo.getCanteenId()); target.setCanteenName(canteenName); diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/sync/HardSyncServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/sync/HardSyncServiceImpl.java new file mode 100644 index 000000000..8c0eae4e1 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/sync/HardSyncServiceImpl.java @@ -0,0 +1,41 @@ +package com.bsd.pjcloud.hard.service.impl.sync; + +import cn.hutool.core.util.ObjectUtil; +import com.bsd.pjcloud.admin.api.feign.RemoteUserService; +import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum; +import com.bsd.pjcloud.common.security.service.PjcloudUser; +import com.bsd.pjcloud.hard.service.HardSyncService; +import com.bsd.pjcloud.mqtt.api.feign.RemoteMqttEventService; +import com.bsd.pjcloud.wallet.api.feign.RemoteMchService; +import com.bsd.pjcloud.wallet.api.vo.MchManageVo; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +@Validated +@Slf4j +@RequiredArgsConstructor +@Service +public class HardSyncServiceImpl implements HardSyncService { + + private final RemoteMchService remoteMchService; + private final RemoteMqttEventService mqttEventService; + + /** + * 同步超市分类商品和同步 + */ + @Override + public void syncSupermarket(PjcloudUser user) { + if (ObjectUtil.isEmpty(user)) throw new RuntimeException("当前登录用户错误"); + Long deptId = user.getDeptId(); + // 查询该用户属于的超市 + MchManageVo targetMch = remoteMchService.getFirstMchByDeptId(deptId, MerchantTypeEnum.CANTEEN).getData(); + if (ObjectUtil.isEmpty(targetMch) || ObjectUtil.notEqual(targetMch.getTypes(), MerchantTypeEnum.CANTEEN.getType())) { + throw new RuntimeException("您不是超市用户,无法操作"); + } + mqttEventService.sendSupermarketClassifyChangeMsg(deptId); + mqttEventService.sendSupermarketProductChangeMsg(deptId); + } + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml index 896850e49..0fac99a77 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml @@ -300,6 +300,9 @@ left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id a.del_flag = '0' + + and o.user_id = #{dto.userId} + and o.hour_type = #{dto.hourType} @@ -332,6 +335,9 @@ a.del_flag = '0' and o.pay_time is not null + + and o.user_id = #{dto.userId} + and o.merchant_id in