24282 1 سال پیش
والد
کامیت
424e8088f2
17فایلهای تغییر یافته به همراه356 افزوده شده و 6 حذف شده
  1. 60 0
      sd-business/src/main/java/com/sd/business/controller/inventory/InventoryBackupController.java
  2. 2 1
      sd-business/src/main/java/com/sd/business/controller/inventory/InventoryController.java
  3. 17 0
      sd-business/src/main/java/com/sd/business/entity/inventory/dto/InventoryBackupDto.java
  4. 17 0
      sd-business/src/main/java/com/sd/business/entity/inventory/dto/InventoryBackupSelectDto.java
  5. 6 0
      sd-business/src/main/java/com/sd/business/entity/inventory/dto/InventorySelectDto.java
  6. 59 0
      sd-business/src/main/java/com/sd/business/entity/inventory/po/InventoryBackup.java
  7. 28 0
      sd-business/src/main/java/com/sd/business/entity/inventory/vo/InventoryBackupVo.java
  8. 23 0
      sd-business/src/main/java/com/sd/business/mapper/inventory/InventoryBackupMapper.java
  9. 3 1
      sd-business/src/main/java/com/sd/business/mapper/inventory/InventoryMapper.java
  10. 23 0
      sd-business/src/main/java/com/sd/business/scheduled/InventoryBackupTask.java
  11. 24 0
      sd-business/src/main/java/com/sd/business/service/inventory/InventoryBackupService.java
  12. 1 1
      sd-business/src/main/java/com/sd/business/service/inventory/InventoryService.java
  13. 76 0
      sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryBackupServiceImpl.java
  14. 4 2
      sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java
  15. 10 0
      sd-business/src/main/resources/mapper/inventory/InventoryBackupMapper.xml
  16. 1 1
      sd-business/src/main/resources/mapper/inventory/InventoryMapper.xml
  17. 2 0
      sd-starter/src/main/java/com/sd/SdApplication.java

+ 60 - 0
sd-business/src/main/java/com/sd/business/controller/inventory/InventoryBackupController.java

@@ -0,0 +1,60 @@
+package com.sd.business.controller.inventory;
+
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.exception.ServiceException;
+import com.sd.business.entity.inventory.dto.InventorySelectDto;
+import com.sd.business.entity.inventory.vo.InventoryBackupVo;
+import com.sd.business.entity.inventory.vo.InventoryVo;
+import com.sd.business.service.inventory.InventoryBackupService;
+import com.sd.business.service.inventory.InventoryService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
+
+
+/**
+ * <p>
+ * 库存快照 前端控制器
+ * </p>
+ *
+ * @author
+ * @since 2023-07-03
+ */
+@RestController
+@RequestMapping("/inventoryBackup")
+public class InventoryBackupController {
+
+    @Autowired
+    private InventoryBackupService inventoryBackupService;
+
+    @Autowired
+    private InventoryService inventoryService;
+
+    /**
+     * 库存分页
+     */
+    @PostMapping("/page")
+    public Page<InventoryBackupVo> page(@RequestBody InventorySelectDto dto) {
+        return inventoryBackupService.getPage(dto);
+    }
+
+    /**
+     * 库存分页
+     */
+    @PostMapping("/detailPage")
+    public Page<InventoryVo> detailPage(@RequestBody InventorySelectDto dto) {
+        Date backupDate = dto.getBackupDate();
+        if (backupDate == null) {
+            throw new ServiceException("备份日期不能为空");
+        }
+
+        dto.setBackupDate(DateUtil.offsetDay(backupDate, -1));
+        return inventoryService.getPage(dto, "inventory_backup");
+    }
+
+}

+ 2 - 1
sd-business/src/main/java/com/sd/business/controller/inventory/InventoryController.java

@@ -35,7 +35,8 @@ public class InventoryController {
      */
     @PostMapping("/page")
     public Page<InventoryVo> page(@RequestBody InventorySelectDto dto) {
-        return inventoryService.getPage(dto);
+        dto.setBackupDate(null);
+        return inventoryService.getPage(dto, "inventory");
     }
 
     /**

+ 17 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/dto/InventoryBackupDto.java

@@ -0,0 +1,17 @@
+package com.sd.business.entity.inventory.dto;
+
+import com.sd.business.entity.inventory.po.InventoryBackup;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 库存快照新增编辑入参实体
+ *
+ * @author
+ * @since 2023-07-03
+ */
+@Getter
+@Setter
+public class InventoryBackupDto extends InventoryBackup {
+
+}

+ 17 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/dto/InventoryBackupSelectDto.java

@@ -0,0 +1,17 @@
+package com.sd.business.entity.inventory.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 库存快照列表查询入参实体
+ *
+ * @author
+ * @since 2023-07-03
+ */
+@Getter
+@Setter
+public class InventoryBackupSelectDto extends BaseSelectDto {
+
+}

+ 6 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/dto/InventorySelectDto.java

@@ -5,6 +5,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * 库存列表查询入参实体
@@ -81,4 +82,9 @@ public class InventorySelectDto extends BaseSelectDto {
      */
     private Long departmentId;
 
+    /**
+     * 备份日期
+     */
+    private Date backupDate;
+
 }

+ 59 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/po/InventoryBackup.java

@@ -0,0 +1,59 @@
+package com.sd.business.entity.inventory.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.core.domain.BasePo;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * <p>
+ * 库存快照
+ * </p>
+ *
+ * @author
+ * @since 2023-07-03
+ */
+@Getter
+@Setter
+@TableName("inventory_backup")
+public class InventoryBackup extends BasePo {
+
+    /**
+     * 库存id
+     */
+    private Long inventoryId;
+
+    /**
+     * 仓库id
+     */
+    private Long warehouseId;
+
+    /**
+     * bom规格id
+     */
+    private Long bomSpecId;
+
+    /**
+     * 结存单价
+     */
+    private BigDecimal balanceUnitPrice;
+
+    /**
+     * 数量
+     */
+    private BigDecimal quantity;
+
+    /**
+     * 事业部id
+     */
+    private Long departmentId;
+
+    /**
+     * 备份日期
+     */
+    private Date backupDate;
+
+}

+ 28 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/vo/InventoryBackupVo.java

@@ -0,0 +1,28 @@
+package com.sd.business.entity.inventory.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * 库存快照列表查询返回值实体
+ *
+ * @author
+ * @since 2023-07-03
+ */
+@Getter
+@Setter
+public class InventoryBackupVo {
+
+    /**
+     * 备份日期
+     */
+    private Date backupDate;
+
+    /**
+     * 备份日期
+     */
+    private String backupDateStr;
+
+}

+ 23 - 0
sd-business/src/main/java/com/sd/business/mapper/inventory/InventoryBackupMapper.java

@@ -0,0 +1,23 @@
+package com.sd.business.mapper.inventory;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.sd.business.entity.inventory.po.InventoryBackup;
+import com.sd.business.entity.inventory.vo.InventoryBackupVo;
+import org.apache.ibatis.annotations.Param;
+
+
+/**
+ * <p>
+ * 库存快照 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2023-07-03
+ */
+public interface InventoryBackupMapper extends BaseMapper<InventoryBackup> {
+
+    Page<InventoryBackupVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<InventoryBackup> wrapper);
+
+}

+ 3 - 1
sd-business/src/main/java/com/sd/business/mapper/inventory/InventoryMapper.java

@@ -25,7 +25,9 @@ public interface InventoryMapper extends BaseMapper<Inventory> {
     /**
      * 库存分页
      */
-    Page<InventoryVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<Inventory> wrapper);
+    Page<InventoryVo> getPage(@Param("page") Page<Object> page,
+                              @Param("ew") IWrapper<Inventory> wrapper,
+                              @Param("tableName") String tableName);
 
     /**
      * 根据仓库获取库存数量

+ 23 - 0
sd-business/src/main/java/com/sd/business/scheduled/InventoryBackupTask.java

@@ -0,0 +1,23 @@
+package com.sd.business.scheduled;
+
+
+import com.sd.business.service.inventory.InventoryBackupService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Component
+public class InventoryBackupTask {
+
+    @Autowired
+    private InventoryBackupService inventoryBackupService;
+
+    /**
+     * 每天同步库存
+     */
+    @Scheduled(cron = "0 0 0 * * ?")
+    public void syncInventory() {
+        inventoryBackupService.sync();
+    }
+
+}

+ 24 - 0
sd-business/src/main/java/com/sd/business/service/inventory/InventoryBackupService.java

@@ -0,0 +1,24 @@
+package com.sd.business.service.inventory;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.service.BaseService;
+import com.sd.business.entity.inventory.dto.InventorySelectDto;
+import com.sd.business.entity.inventory.po.InventoryBackup;
+import com.sd.business.entity.inventory.vo.InventoryBackupVo;
+
+
+/**
+ * <p>
+ * 库存快照 服务类
+ * </p>
+ *
+ * @author
+ * @since 2023-07-03
+ */
+public interface InventoryBackupService extends BaseService<InventoryBackup> {
+
+    void sync();
+
+    Page<InventoryBackupVo> getPage(InventorySelectDto dto);
+
+}

+ 1 - 1
sd-business/src/main/java/com/sd/business/service/inventory/InventoryService.java

@@ -24,7 +24,7 @@ public interface InventoryService extends BaseService<Inventory> {
     /**
      * 库存分页
      */
-    Page<InventoryVo> getPage(InventorySelectDto dto);
+    Page<InventoryVo> getPage(InventorySelectDto dto, String tableName);
 
     /**
      * 根据仓库获取库存数量

+ 76 - 0
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryBackupServiceImpl.java

@@ -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;
+    }
+
+}

+ 4 - 2
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java

@@ -7,6 +7,7 @@ import com.sd.business.entity.bom.po.Bom;
 import com.sd.business.entity.bom.po.BomSpec;
 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.InventoryVo;
 import com.sd.business.entity.inventory.vo.QuantityByDepartmentVo;
 import com.sd.business.entity.inventory.vo.QuantityByWarehouseVo;
@@ -29,7 +30,7 @@ import java.util.List;
 public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory> implements InventoryService {
 
     @Override
-    public Page<InventoryVo> getPage(InventorySelectDto dto) {
+    public Page<InventoryVo> getPage(InventorySelectDto dto, String tableName) {
         IWrapper<Inventory> wrapper = getWrapper();
 
         wrapper.orderByDesc("i", Inventory::getId);
@@ -46,8 +47,9 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
         wrapper.like("bs", BomSpec::getWidth, dto.getBomSpecWidth());
         wrapper.eq("i", Inventory::getWarehouseId, dto.getWarehouseId());
         wrapper.eq("i", Inventory::getDepartmentId, dto.getDepartmentId());
+        wrapper.eq("i", InventoryBackup::getBackupDate, dto.getBackupDate());
 
-        Page<InventoryVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        Page<InventoryVo> page = this.baseMapper.getPage(dto.getPage(), wrapper, tableName);
         return page;
     }
 

+ 10 - 0
sd-business/src/main/resources/mapper/inventory/InventoryBackupMapper.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sd.business.mapper.inventory.InventoryBackupMapper">
+
+    <select id="getPage" resultType="com.sd.business.entity.inventory.vo.InventoryBackupVo">
+        select ib.backup_date
+        from inventory_backup ib ${ew.customSqlSegment}
+    </select>
+
+</mapper>

+ 1 - 1
sd-business/src/main/resources/mapper/inventory/InventoryMapper.xml

@@ -13,7 +13,7 @@
                bs.name bomSpecName,
                bs.code bomSpecCode,
                d.name  departmentName
-        from inventory i
+        from ${tableName} i
                  left join bom_spec bs on i.bom_spec_id = bs.id
                  left join bom b on bs.bom_id = b.id
                  left join warehouse w on i.warehouse_id = w.id

+ 2 - 0
sd-starter/src/main/java/com/sd/SdApplication.java

@@ -4,8 +4,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 @Slf4j
+@EnableScheduling
 @SpringBootApplication(scanBasePackages = {"com.ruoyi.**", "com.fjhx.**", "com.sd.**"})
 @MapperScan("com.sd.**.mapper")
 public class SdApplication {