|
@@ -0,0 +1,76 @@
|
|
|
+package com.sd.business.service.inventory.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.inventory.dto.InventorySelectDto;
|
|
|
+import com.sd.business.entity.inventory.po.Inventory;
|
|
|
+import com.sd.business.entity.inventory.po.InventoryBackup;
|
|
|
+import com.sd.business.entity.inventory.vo.InventoryBackupVo;
|
|
|
+import com.sd.business.mapper.inventory.InventoryBackupMapper;
|
|
|
+import com.sd.business.service.inventory.InventoryBackupService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 库存快照 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-07-03
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class InventoryBackupServiceImpl extends ServiceImpl<InventoryBackupMapper, InventoryBackup> implements InventoryBackupService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sync() {
|
|
|
+ List<Inventory> list = inventoryService.list();
|
|
|
+ Date date = new Date();
|
|
|
+ Date backupDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -1));
|
|
|
+
|
|
|
+ List<InventoryBackup> inventoryBackupList = list.stream().map(item -> {
|
|
|
+ InventoryBackup inventoryBackup = BeanUtil.toBean(item, InventoryBackup.class);
|
|
|
+ inventoryBackup.setInventoryId(inventoryBackup.getId());
|
|
|
+ inventoryBackup.setBackupDate(backupDate);
|
|
|
+ inventoryBackup.setId(IdWorker.getId());
|
|
|
+ return inventoryBackup;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ saveBatch(inventoryBackupList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<InventoryBackupVo> getPage(InventorySelectDto dto) {
|
|
|
+
|
|
|
+ IWrapper<InventoryBackup> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("ib", InventoryBackup::getId);
|
|
|
+ wrapper.le("ib", InventoryBackup::getBackupDate, dto.getBeginTime());
|
|
|
+ wrapper.ge("ib", InventoryBackup::getBackupDate, dto.getEndTime());
|
|
|
+
|
|
|
+ Page<InventoryBackupVo> page = baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<InventoryBackupVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (InventoryBackupVo record : records) {
|
|
|
+ record.setBackupDate(DateUtil.offsetDay(record.getBackupDate(), 1));
|
|
|
+ record.setBackupDateStr(DateUtil.format(record.getBackupDate(), "yyyy-MM-dd"));
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|