Jelajahi Sumber

Merge remote-tracking branch 'gitlab/dev'

# Conflicts:
#	ruoyi-admin/src/main/java/com/ruoyi/inventory/controller/TbInventoryDetailController.java
#	ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/AssetInventoryStatement.java
LinWuTai 1 tahun lalu
induk
melakukan
125a387798

+ 18 - 18
ruoyi-admin/src/main/java/com/ruoyi/inventory/controller/TbAssetInventoryController.java

@@ -171,22 +171,22 @@ public class TbAssetInventoryController extends BaseController
         QRCodeUtils.createCodeToOutputStream(qrDTO, response.getOutputStream());
     }
 
-    /**
-     * 查询部门资产报表(两次盘点间的资产损耗)
-     * @param depId 部门ID
-     * @return
-     */
-//    我粘贴过来的 @PreAuthorize("@ss.hasPermi('inventory:inventory:query')")
-    @GetMapping("/getDepAssetLossTb")
-    public AjaxResult getDepAssetLossTb(String depId){
-        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
-        return success(results);
-    }
-
-    @PostMapping("/exportDepAssetLossTb/{deptId}")
-    public void exportDepAssetLossTb(HttpServletResponse response, @PathVariable("deptId") String depId){
-        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
-        ExcelUtil<DepAssetLossResultDto> util = new ExcelUtil<DepAssetLossResultDto>(DepAssetLossResultDto.class);
-        util.exportExcel(response, results, "近两次资产盘点损耗统计");
-    }
+//    /**
+//     * 查询部门资产报表(两次盘点间的资产损耗)
+//     * @param depId 部门ID
+//     * @return
+//     */
+////    我粘贴过来的 @PreAuthorize("@ss.hasPermi('inventory:inventory:query')")
+//    @GetMapping("/getDepAssetLossTb")
+//    public AjaxResult getDepAssetLossTb(String depId){
+//        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
+//        return success(results);
+//    }
+//
+//    @PostMapping("/exportDepAssetLossTb/{deptId}")
+//    public void exportDepAssetLossTb(HttpServletResponse response, @PathVariable("deptId") String depId){
+//        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
+//        ExcelUtil<DepAssetLossResultDto> util = new ExcelUtil<DepAssetLossResultDto>(DepAssetLossResultDto.class);
+//        util.exportExcel(response, results, "近两次资产盘点损耗统计");
+//    }
 }

+ 166 - 9
ruoyi-admin/src/main/java/com/ruoyi/inventory/controller/TbInventoryDetailController.java

@@ -12,22 +12,18 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.ruoyi.asset.domain.TbAssetInformation;
 import com.ruoyi.inventory.domain.TbAssetInventory;
+import com.ruoyi.inventory.domain.TbInventoryCompare;
+import com.ruoyi.inventory.domain.TbInventoryCompareResult;
 import com.ruoyi.inventory.domain.dto.AssetInventoryStatement;
 import com.ruoyi.inventory.domain.enums.InventoryPlanResult;
 import com.ruoyi.inventory.domain.enums.InventoryResult;
 import com.ruoyi.inventory.domain.enums.InventoryStatus;
 import com.ruoyi.inventory.mapper.TbAssetInventoryMapper;
+import com.ruoyi.inventory.mapper.TbInventoryDetailMapper;
 import com.ruoyi.inventory.service.ITbAssetInventoryService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -63,6 +59,68 @@ public class TbInventoryDetailController extends BaseController
     }
 
     @Autowired
+    private TbInventoryDetailMapper tbInventoryDetailMapper;
+
+    /**
+     * 查询全单位或者部门的资产对比分析报表
+     * @return
+     */
+    @PreAuthorize("@ss.hasPermi('inventory:compare:list')")
+    @GetMapping("/getDepAssetLossTb")
+    public TableDataInfo compareList(@RequestParam(required = false) String deptId){
+        startPage();
+        TbInventoryCompareResult tbInventoryCompareResult = new TbInventoryCompareResult();
+        List<TbInventoryCompareResult> tbInventoryCompareResultList = new ArrayList<>();
+
+        List<TbAssetInventory> tbAssetInventoryList = tbInventoryDetailService.selectTbInventoryCompareList(deptId);
+        if(tbAssetInventoryList.size() == 0){
+            throw new RuntimeException("该组织不存在盘点完毕的盘点或者该部门不存在盘点完毕的盘点");
+        }
+        if(tbAssetInventoryList.size() == 1){
+            throw new RuntimeException("该组织只存在一个盘点,不能进行盘点间类别数量损耗对比");
+        }
+
+        //最近一次盘点
+        String orderNumber = tbAssetInventoryList.get(0).getOrderNumber();
+        if (StrUtil.isBlank(orderNumber)) {
+            throw new RuntimeException("盘点计划编码不能为空");
+        }
+        List<TbInventoryDetail> tbInventoryDetailList1 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
+        List<AssetInventoryStatement> inventoryStatement1 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList1);
+        List<TbInventoryCompare> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1);
+        double total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult.setAssetResultList(tbInventoryCompareList);
+        tbInventoryCompareResult.setInventoryDepartment(tbAssetInventoryList.get(0).getInventoryDepartmentName());
+        tbInventoryCompareResult.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult);
+
+        //最近一次的上一次盘点
+        TbInventoryCompareResult tbInventoryCompareResult2 = new TbInventoryCompareResult();
+        orderNumber = tbAssetInventoryList.get(1).getOrderNumber();
+        if (StrUtil.isBlank(orderNumber)) {
+            throw new RuntimeException("盘点计划编码不能为空");
+        }
+        List<TbInventoryDetail> tbInventoryDetailList2 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
+        List<AssetInventoryStatement> inventoryStatement2 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList2);
+        List<TbInventoryCompare> tbInventoryCompareList2 = getTbInventoryCompareList(inventoryStatement2);
+        total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList2) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult2.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult2.setAssetResultList(tbInventoryCompareList2);
+        tbInventoryCompareResult2.setInventoryDepartment(tbAssetInventoryList.get(1).getInventoryDepartmentName());
+        tbInventoryCompareResult2.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult2);
+
+        return getDataTable(tbInventoryCompareResultList);
+    }
+
+    @Autowired
     private ITbAssetInventoryService inventoryService;
 
     /**
@@ -97,7 +155,7 @@ public class TbInventoryDetailController extends BaseController
     @PostMapping("/export/detail")
     public void exportDetail(HttpServletResponse response, TbAssetInventory tbAssetInventory)
     {
-        List<TbAssetInventory> tbAssetInventoryList = inventoryService.selectTbAssetInventoryList(tbAssetInventory);
+        List<TbAssetInventory> tbAssetInventoryList = tbAssetInventoryMapper.selectTbAssetInventoryList(tbAssetInventory);
         List<AssetInventoryStatement> assetInventoryStatements = new ArrayList<>();
 
         for (TbAssetInventory assetInventory : tbAssetInventoryList) {
@@ -114,6 +172,67 @@ public class TbInventoryDetailController extends BaseController
     }
 
     /**
+     * 导出全单位或者部门的资产对比分析报表
+     * @param response
+     */
+    @PreAuthorize("@ss.hasPermi('inventory:compare:export')")
+    @Log(title = "全单位资产对比分析报表", businessType = BusinessType.EXPORT)
+    @PostMapping("/exportDepAssetLossTb")
+    public void exportCompare(HttpServletResponse response,@RequestParam(required = false) String deptId){
+        TbInventoryCompareResult tbInventoryCompareResult = new TbInventoryCompareResult();
+        List<TbInventoryCompareResult> tbInventoryCompareResultList = new ArrayList<>();
+
+        List<TbAssetInventory> tbAssetInventoryList = tbInventoryDetailService.selectTbInventoryCompareList(deptId);
+        if(tbAssetInventoryList.size() == 0){
+            throw new RuntimeException("该组织不存在盘点完毕的盘点或者该部门不参在盘点完毕的盘点");
+        }
+        if(tbAssetInventoryList.size() == 1){
+            throw new RuntimeException("该组织只存在一个盘点,不能进行盘点间类别数量损耗对比");
+        }
+
+        //最近一次盘点
+        String orderNumber = tbAssetInventoryList.get(0).getOrderNumber();
+        if (StrUtil.isBlank(orderNumber)) {
+            throw new RuntimeException("盘点计划编码不能为空");
+        }
+        List<TbInventoryDetail> tbInventoryDetailList1 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
+        List<AssetInventoryStatement> inventoryStatement1 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList1);
+        List<TbInventoryCompare> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1);
+        double total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult.setAssetResultList(tbInventoryCompareList);
+        tbInventoryCompareResult.setInventoryDepartment(tbAssetInventoryList.get(0).getInventoryDepartmentName());
+        tbInventoryCompareResult.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult);
+
+        //最近一次的上一次盘点
+        TbInventoryCompareResult tbInventoryCompareResult2 = new TbInventoryCompareResult();
+        orderNumber = tbAssetInventoryList.get(1).getOrderNumber();
+        if (StrUtil.isBlank(orderNumber)) {
+            throw new RuntimeException("盘点计划编码不能为空");
+        }
+        List<TbInventoryDetail> tbInventoryDetailList2 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
+        List<AssetInventoryStatement> inventoryStatement2 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList2);
+        List<TbInventoryCompare> tbInventoryCompareList2 = getTbInventoryCompareList(inventoryStatement2);
+        total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList2) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult2.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult2.setAssetResultList(tbInventoryCompareList2);
+        tbInventoryCompareResult2.setInventoryDepartment(tbAssetInventoryList.get(1).getInventoryDepartmentName());
+        tbInventoryCompareResult2.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult2);
+
+        ExcelUtil<TbInventoryCompareResult> util = new ExcelUtil<>(TbInventoryCompareResult.class);
+
+        util.exportExcel(response, tbInventoryCompareResultList , "资产对比分析报表");
+    }
+
+    /**
      * 获取盘点报表
      *
      * @param tbAssetInventory 盘点计划信息
@@ -189,6 +308,9 @@ public class TbInventoryDetailController extends BaseController
             String inventoryPlanResultName = InventoryPlanResult.getName(inventoryPlanResult);
             assetInventoryStatement.setInventoryPlanResult(inventoryPlanResultName);
 
+            // 设置资产原值
+            assetInventoryStatement.setOriginalValue(assetInformation.getOriginalValue());
+
             // 设置备注
             assetInventoryStatement.setRemark(inventoryDetail.getRemark());
 
@@ -241,4 +363,39 @@ public class TbInventoryDetailController extends BaseController
         return toAjax(tbInventoryDetailService.deleteTbInventoryDetailByIds(ids));
     }
 
+    /**
+     * 获取全单位资产对比分析报表
+     * @param inventoryStatementList
+     * @return
+     */
+    private List<TbInventoryCompare> getTbInventoryCompareList
+            (List<AssetInventoryStatement> inventoryStatementList){
+        List<TbInventoryCompare> tbInventoryCompareList = new ArrayList<>();
+
+        for (AssetInventoryStatement assetInventoryStatement : inventoryStatementList) {
+            String inventoryStatus = assetInventoryStatement.getInventoryStatus();
+            if(inventoryStatus.equals("已盘点")) {
+                TbInventoryCompare tbInventoryCompare = new TbInventoryCompare();
+                String assetName = assetInventoryStatement.getAssetName();
+                String inventoryLocation = assetInventoryStatement.getAssetLocation();
+                Integer quantity = assetInventoryStatement.getQuantity();
+                Integer inventoryQuantity = assetInventoryStatement.getInventoryQuantity();
+                tbInventoryCompare.setInventoryName(assetName);
+                tbInventoryCompare.setInventoryLocationName(inventoryLocation);
+                tbInventoryCompare.setExpectInventoryNumber(quantity);
+                tbInventoryCompare.setRealityInventoryNumber(inventoryQuantity);
+                if(quantity>inventoryQuantity){
+                    tbInventoryCompare.setLossNumber(quantity - inventoryQuantity);
+                    tbInventoryCompare.setLossVal(assetInventoryStatement.getOriginalValue()*(quantity - inventoryQuantity));
+
+                }else {
+                    tbInventoryCompare.setLossNumber(0);
+                    tbInventoryCompare.setLossVal(0.0);
+                }
+                tbInventoryCompare.setUnits(assetInventoryStatement.getUnits());
+                tbInventoryCompareList.add(tbInventoryCompare);
+            }
+        }
+        return tbInventoryCompareList;
+    }
 }

+ 42 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/TbInventoryCompare.java

@@ -0,0 +1,42 @@
+package com.ruoyi.inventory.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+
+import java.util.Date;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class TbInventoryCompare extends BaseEntity {
+    @Excel(name = "资产名称")
+    private String inventoryName;
+
+    @Excel(name = "资产位置")
+    private String inventoryLocationName;
+
+    @Excel(name = "账面资产数量")
+    private Integer expectInventoryNumber;
+
+    @Excel(name = "实点资产数量")
+    private Integer realityInventoryNumber;
+
+    @Excel(name = "数量损耗")
+    private Integer lossNumber;
+
+    /** 计量单位 */
+    @Excel(name = "计量单位")
+    private String units;
+
+    @Excel(name = "资产损耗金额")
+    private Double lossVal;
+
+
+}

+ 3 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/AssetInventoryStatement.java

@@ -73,6 +73,9 @@ public class AssetInventoryStatement {
     @Excel(name = "盘点计划结果")
     private String inventoryPlanResult;
 
+    /**原值*/
+    private Double originalValue;
+
     /** 备注 */
     @Excel(name = "备注")
     private String remark;

+ 5 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/mapper/TbAssetInventoryMapper.java

@@ -37,6 +37,11 @@ public interface TbAssetInventoryMapper
     public List<TbAssetInventory> selectTbAssetInventoryList(TbAssetInventory tbAssetInventory);
 
     /**
+     * 查询全单位盘点资产对比分析列表
+     * @return
+     */
+    public List<TbAssetInventory> selectTbAssetInventoryListBy(String deptId);
+    /**
      * 新增资产盘点记录
      *
      * @param tbAssetInventory 资产盘点记录

+ 8 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/service/ITbInventoryDetailService.java

@@ -1,6 +1,9 @@
 package com.ruoyi.inventory.service;
 
 import java.util.List;
+
+import com.ruoyi.inventory.domain.TbAssetInventory;
+import com.ruoyi.inventory.domain.TbInventoryCompare;
 import com.ruoyi.inventory.domain.TbInventoryDetail;
 import com.ruoyi.inventory.domain.dto.AssetInventoryStatement;
 
@@ -31,6 +34,11 @@ public interface ITbInventoryDetailService
     public List<TbInventoryDetail> selectTbInventoryDetailList(TbInventoryDetail tbInventoryDetail);
 
     /**
+     * 查询全单位盘点资产对比分析列表
+     * @return
+     */
+    public List<TbAssetInventory> selectTbInventoryCompareList(String deptId);
+    /**
      * 新增资产盘点明细
      * 
      * @param tbInventoryDetail 资产盘点明细

+ 6 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/service/impl/TbInventoryDetailServiceImpl.java

@@ -10,6 +10,7 @@ import com.ruoyi.asset.domain.TbAssetInformation;
 import com.ruoyi.asset.mapper.TbAssetInformationMapper;
 import com.ruoyi.asset.mapper.TbLocationMapper;
 import com.ruoyi.inventory.domain.TbAssetInventory;
+import com.ruoyi.inventory.domain.TbInventoryCompare;
 import com.ruoyi.inventory.mapper.TbAssetInventoryMapper;
 import com.ruoyi.utils.RecursionUtil;
 import org.apache.commons.collections.map.HashedMap;
@@ -56,6 +57,11 @@ public class TbInventoryDetailServiceImpl implements ITbInventoryDetailService
         return tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
     }
 
+    @Override
+    public List<TbAssetInventory> selectTbInventoryCompareList(String deptId){
+        return tbAssetInventoryMapper.selectTbAssetInventoryListBy(deptId);
+    }
+
 
     /**
      * 查询资产盘点明细列表

+ 13 - 4
ruoyi-admin/src/main/resources/mapper/inventory/TbAssetInventoryMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.inventory.mapper.TbAssetInventoryMapper">
-
+    
     <resultMap type="TbAssetInventory" id="TbAssetInventoryResult">
         <result property="id"    column="id"    />
         <result property="orderNumber"    column="order_number"    />
@@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectTbAssetInventoryList" parameterType="TbAssetInventory" resultType="TbAssetInventory">
         <include refid="selectTbAssetInventory"/>
-        <where>
+        <where>  
             <if test="orderNumber != null  and orderNumber != ''"> and a.order_number = #{orderNumber}</if>
             <if test="name != null  and name != ''"> and a.name like concat('%', #{name}, '%')</if>
             <if test="inventoryDepartment != null  and inventoryDepartment != ''"> and a.inventory_department = #{inventoryDepartment} OR a.inventory_department in (
@@ -61,6 +61,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
+    <select id="selectTbAssetInventoryListBy" parameterType="string" resultType="TbAssetInventory">
+        <include refid="selectTbAssetInventory"/>
+        where a.inventory_status = "2"
+        and a.inventory_result != "0"
+        <if test="deptId != null  and  deptId != ''">and inventory_department = #{deptId}</if>
+        order by a.updated_time DESC
+    </select>
+
     <select id="selectTbAssetInventoryById" parameterType="Long" resultType="TbAssetInventory">
         <include refid="selectTbAssetInventory"/>
         where a.id = #{id}
@@ -78,7 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectTbAssetInventory"/>
         where a.order_number = #{orderNumber}
     </select>
-
+        
     <insert id="insertTbAssetInventory" parameterType="TbAssetInventory" useGeneratedKeys="true" keyProperty="id">
         insert into tb_asset_inventory
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -135,7 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteTbAssetInventoryByIds" parameterType="String">
-        delete from tb_asset_inventory where id in
+        delete from tb_asset_inventory where id in 
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
@@ -194,6 +202,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select order_number orderNumber,inventory_date inventDate
         from tb_asset_inventory
         where inventory_status = 2 and inventory_department = #{depId}
+        and inventory_result != "0"
         order by inventory_date desc
     </select>
     <!-- limit #{whichOne},1 -->