Browse Source

成本分配 面料

liuchaohui 2 years ago
parent
commit
295a620508

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/mapper/SyCostAllocationFabricMapper.java

@@ -1,6 +1,8 @@
 package org.jeecg.modules.cost.mapper;
 
 import java.util.List;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
 import org.jeecg.modules.cost.entity.SyCostAllocationFabric;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -15,4 +17,7 @@ public interface SyCostAllocationFabricMapper extends BaseMapper<SyCostAllocatio
 	public boolean deleteByMainId(String mainId);
     
 	public List<SyCostAllocationFabric> selectByMainId(String mainId);
+
+	@DS("multi-three")
+	List<SyCostAllocationFabric> queryByCostFabric(String mainId);
 }

+ 26 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/mapper/xml/SyCostAllocationFabricMapper.xml

@@ -15,4 +15,30 @@
 		WHERE
 			 sy_cost_allocation_id = #{id} 		
 	</select>
+
+	<select id="queryByCostFabric" parameterType="java.lang.String" resultType="org.jeecg.modules.cost.entity.SyCostAllocationFabric">
+		select oti.cInvName as goodsName,sum(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as usageQuantity,sum(ot.iSendQTY) as planQuantity,sum(rs.iQuantity) as purchaseQuantity
+		from UFDATA_903_2021.dbo.om_momain om
+		join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_903_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID
+		join UFDATA_903_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
+		join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		join UFDATA_903_2021.dbo.rdrecords01 rs on rs.iOMoDID=od.MODetailsID
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%' and om.cCode LIKE CONCAT(#{code},'%')
+				and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
+		GROUP BY oti.cInvName
+
+		union all
+
+		select oti.cInvName as goodsName,sum(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as usageQuantity,sum(ot.iSendQTY) as planQuantity,sum(rs.iQuantity) as purchaseQuantity
+		from UFDATA_901_2021.dbo.om_momain om  
+		join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_901_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID 
+		join UFDATA_901_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
+		join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		join UFDATA_901_2021.dbo.rdrecords01 rs on rs.iOMoDID=od.MODetailsID 
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%' and om.cCode LIKE CONCAT(#{code},'%')
+				and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
+		GROUP BY oti.cInvName
+	</select>
 </mapper>

+ 4 - 78
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/service/impl/SyCostAllocationServiceImpl.java

@@ -197,82 +197,9 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
         }
 
         /*查询U8数据 面料*/
-
-        String sqlFabric ="SELECT cInvName as goodsName,sum(yi) as usageQuantity,sum(ying) as planQuantity,sum(gou) as purchaseQuantity," +
-                "processUnit,isnull(sum(gou),0)-isnull(sum(yuu),0) as fabricremainingQuantity,sum(yu) as fabrictransferQuantity FROM (  " +
-                " " +
-                "                select sum(r.iQuantity) as yu,r.cBatch ,b.cSource,b.cPOID,sum(b.gou) as gou,sum(b.yi) as yi,sum(b.ying) as ying " +
-                "    ,c.cInvName ,v.cVenName as processUnit ,( " +
-                "                    SELECT sum(r.iQuantity) " +
-                "                    FROM UFDATA_903_2021.dbo.rdrecords01 rs1  " +
-                "          left join UFDATA_903_2021.dbo.rdrecord01 r1 on r1.id=rs1.id " +
-                "          where rs1.cBatch = '"+plannum+"' and rs1.cPOID  like '"+plannum+"%' and " +
-                "                     r.cBatch = rs1.cBatch and rs1.cInvCode=r.cInvCode  " +
-                "    group by rs1.cInvCode, rs1.cBatch  ) as yuu " +
-                "                 FROM UFDATA_903_2021.dbo.rdrecords11  r  " +
-                "                  JOIN (  " +
-                "                   SELECT od.MODetailsID,od.cInvCode,om.cVenCode    " +
-                "                   FROM UFDATA_903_2021.dbo.OM_MOMain om LEFT JOIN UFDATA_903_2021.dbo.OM_MODetails od ON om.MOID = od.MOID   " +
-                "                   WHERE om.iVerifyStateNew = 2 and om.cCode like '"+plannum+"%'  " +
-                "                   ) o ON r.iOMoDID  = o.MODetailsID   " +
-                "                  LEFT JOIN (  " +
-                "                    SELECT r1.id,r1.cSource,rs1.cBatch,rs1.cInvCode ,rs1.cPOID, " +
-                "     rs1.iQuantity as gou,isnull(od.iQuantity,0)+isnull(p.iQuantity,0) as ying,isnull(od.iSendQTY,0)+isnull(p.iQuantity,0) as yi " +
-                "                    FROM UFDATA_903_2021.dbo.rdrecords01 rs1  " +
-                "          left join UFDATA_903_2021.dbo.rdrecord01 r1 on r1.id=rs1.id " +
-                "          left join UFDATA_903_2021.dbo.PO_Podetails p on p.ID=rs1.iPOsID " +
-                "          left join UFDATA_903_2021.dbo.OM_MODetails o on o.MODetailsID =rs1.iOMoDID " +
-                "          left join UFDATA_903_2021.dbo.OM_MOMaterials od on od.MoDetailsID=o.MODetailsID  " +
-                "          where rs1.cBatch = '"+plannum+"' " +
-                "                    ) b on r.cBatch = b.cBatch and b.cInvCode=r.cInvCode   " +
-                " " +
-                "      JOIN (SELECT * FROM  UFDATA_903_2021.dbo.Inventory where (cInvCCode like '03%' or cInvCCode like '04%'  )  " +
-                "           and cInvCCode != '0399' and cInvCCode != '0499') c on c.cInvCode=r.cInvCode  " +
-                "                 LEFT JOIN UFDATA_903_2021.dbo.Vendor v ON o.cVenCode= v.cVenCode  " +
-                "                  GROUP BY c.cInvName,r.cBatch,b.cSource,b.cPOID,v.cVenName ,r.cInvCode " +
-                "         " +
-                "         ) as ta GROUP BY cInvName,processUnit" +
-                " UNION all " +
-                "SELECT cInvName as goodsName,sum(yi) as usageQuantity,sum(ying) as planQuantity,sum(gou) as purchaseQuantity," +
-                "processUnit,isnull(sum(gou),0)-isnull(sum(yuu),0) as fabricremainingQuantity,sum(yu) as fabrictransferQuantity FROM (  " +
-                " " +
-                "                select sum(r.iQuantity) as yu,r.cBatch ,b.cSource,b.cPOID,sum(b.gou) as gou,sum(b.yi) as yi,sum(b.ying) as ying " +
-                "    ,c.cInvName ,v.cVenName as processUnit ,( " +
-                "                    SELECT sum(r.iQuantity) " +
-                "                    FROM rdrecords01 rs1  " +
-                "          left join rdrecord01 r1 on r1.id=rs1.id " +
-                "          where rs1.cBatch = '"+plannum+"' and rs1.cPOID  like '"+plannum+"%' and " +
-                "                     r.cBatch = rs1.cBatch and rs1.cInvCode=r.cInvCode  " +
-                "    group by rs1.cInvCode, rs1.cBatch  ) as yuu " +
-                "                 FROM rdrecords11  r  " +
-                "                  JOIN (  " +
-                "                   SELECT od.MODetailsID,od.cInvCode,om.cVenCode    " +
-                "                   FROM OM_MOMain om LEFT JOIN OM_MODetails od ON om.MOID = od.MOID   " +
-                "                   WHERE om.iVerifyStateNew = 2 and om.cCode like '"+plannum+"%'  " +
-                "                   ) o ON r.iOMoDID  = o.MODetailsID   " +
-                "                  LEFT JOIN (  " +
-                "                    SELECT r1.id,r1.cSource,rs1.cBatch,rs1.cInvCode ,rs1.cPOID, " +
-                "     rs1.iQuantity as gou,isnull(od.iQuantity,0)+isnull(p.iQuantity,0) as ying,isnull(od.iSendQTY,0)+isnull(p.iQuantity,0) as yi " +
-                "                    FROM rdrecords01 rs1  " +
-                "          left join rdrecord01 r1 on r1.id=rs1.id " +
-                "          left join PO_Podetails p on p.ID=rs1.iPOsID " +
-                "          left join OM_MODetails o on o.MODetailsID =rs1.iOMoDID " +
-                "          left join OM_MOMaterials od on od.MoDetailsID=o.MODetailsID  " +
-                "          where rs1.cBatch = '"+plannum+"' " +
-                "                    ) b on r.cBatch = b.cBatch and b.cInvCode=r.cInvCode   " +
-                " " +
-                "      JOIN (SELECT * FROM  Inventory where (cInvCCode like '03%' or cInvCCode like '04%'  )  " +
-                "           and cInvCCode != '0399' and cInvCCode != '0499') c on c.cInvCode=r.cInvCode  " +
-                "                 LEFT JOIN Vendor v ON o.cVenCode= v.cVenCode  " +
-                "                  GROUP BY c.cInvName,r.cBatch,b.cSource,b.cPOID,v.cVenName ,r.cInvCode " +
-                "         " +
-                "         ) as ta GROUP BY cInvName,processUnit" ;
-        
-        List<Map<String, Object>> list1  = senYuDataSourceOne.queryForList(sqlFabric);
-        List<JSONObject> jianSon1 = JsonChangeUtils.toJSONObject(list1);
-        List<SyCostAllocationFabric> list3 = new ArrayList<>();
-        for (int i=0;i<jianSon1.size();i++) {
-            SyCostAllocationFabric Fabric = JSONObject.toJavaObject(jianSon1.get(i), SyCostAllocationFabric.class);
+        List<SyCostAllocationFabric> list3 = syCostAllocationFabricMapper.queryByCostFabric(plannum);
+        for (int i=0;i<list3.size();i++) {
+            SyCostAllocationFabric Fabric = list3.get(i);
             /*
             1.转入:从材料出库起手,找到委外订单下使用的出库,然后关联采购排除不是自己买的;
                   -- 1.委外订单关联材料出库单,根据计划号查出所有材料出库;
@@ -360,7 +287,6 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
                 Fabric.setFabrictransferQuantity(BigDecimal.ZERO);
                 Fabric.setTransferCost(BigDecimal.ZERO);
             }
-            list3.add(Fabric);
         }
 
 
@@ -467,7 +393,7 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
             }
         }
 
-
+        //发运
         List<SyCostAllocationShipdetail> Shipdetails = syCostAllocationShipdetailMapper.queryByCostShipdetail(plannum);
         for (int i=0;i<Shipdetails.size();i++) {
             SyCostAllocationShipdetail ship = Shipdetails.get(i);