1. 数据采集
将 EAS 系统和OA 系统存储的数据,通过数据开发-定时任务将数据同步至同一数据库。功能详情请参见:数据同步概述
1.1 设置单个同步任务
将系统的数据库通过[通用]配置数据连接接入 FineDataLink 中。
以 EAS出库单ods_SaleIssueBill 为例,源表跨库迁移至指定的数据库环境中,如下图所示:
设计定时全量更新数据,因此写入方式选择「清空目标表,再写入数据」。
其他源表也是相同的操作方案。
1.2 设置更新调度
设计调度任务,定时全量更新数据。
新建调度文件夹,用来存放不同层级的调度任务,更好的管理一个个单独的数据开发任务,如下图所示:
新建 ODS 任务,使用调用任务功能,在一个任务中调用 ODS 层多个其他数据同步任务,便于进行任务的管控。
由于这些被调用的 ODS 层采集的数据表并没有上下游数据关联,因此不需要进行连线顺序执行,如下图所示:
然后设置更新频率,例如可以通过任务控制进行定时任务调度配置,设置每天执行一次进行定时同步更新,如下图所示:
2. 数据加工
2.1 业务系统合并计算形成DW明细数据
2.1.1 MID_XSMXTJ_STEM明细宽表加工
通过将数据采集阶段采集的数据表以及数据库手动维护的出库单分类统计对照表 FILL_DIM_XSMTZ_MASTAT 关联合并以及初步加工成「销售明细统计宽表」。
基于 ODS 层数据,以出库单表关联「物料单」、「物料成本」、「销售订单」、「客户表」、「物料分类统计」,形成销售明细中间表 MID_XSMXTJ_STEM,便于后续使用明细数据制作销售明细表,如下图所示:
SQL 代码:
SELECT
a.FBIZTYPEID as BIZTYPE1 /* AS 业务类型*/ ,
case a.FBIZTYPEID when 'emo001' then '样品出库' when 'emo002' then '普通销售' when 'emo003' then '副产品销售' when 'emo004' then '销售退货' else '账务调整' end AS BIZTYPENAME,
case when a.FBIZTYPEID in ('emo001','emo002','emo003') and CA.DEPARTMENT='无锡' then 2 else 1 end mark,
a.FNumber as BILLNUMBER /* AS 单据编号*/ ,
a.CFCKLX AS CFCKLX_1 /* AS 出库类型*/ ,
case a.CFCKLX when '0' then '总部出库' when '1' then '办事处出库' else null end AS CFCKLX,
a.FBizDate AS BIZDATE /* AS 业务日期*/ ,
a.FMATERIALID,
a.FBASEQTY AS QTY/*基本数量*/,
a.FSalePrice AS SALEPRICE /* AS 单价*/ ,
a.FNoTaxAmount AS NONTAXAMOUNT /* AS 金额*/ ,
a.FACTUALCOST AS ACTUALCOST /* AS 账上成本*/ ,
m.FID AS MAID /* AS 物料ID*/ ,
m.FNUMBER AS MANUMBER /* AS 物料编码*/ ,
m.FCREATETIME AS MACREATETIME /* AS 物料创建时间*/ ,
m.FNUMBER AS INCOMETYPE2 /* AS 收入类型*/ ,
case when right(m.FNUMBER,1) IN(4,5) then '主营业务收入' else '其他业务收入' end as INCOMETYPE ,
m.FStatus AS MASTATUS1 /* AS 物料状态*/ ,
case m.FStatus when '0' then '核准' when '1' then '禁用' else m.FStatus end as MASTATUS ,
CB.XISHU AS CBXISHU,
CB.Standard_COST * CB.XISHU * a.FBASEQTY AS STANDARDCOST_L_N /* AS 标准成本料n*/ ,
CB.Standard_COST,
L.FBIZDAT, /* AS 销售订单日期*/
L.FNUMBER AS SALENUMBER /* AS 销售订单单号*/ ,
L.CFMYFSNEW AS CFMYFSNEW_W /* AS 贸易方式w*/ ,
L.AMOUNT*a.FBASEQTY AS SALECOST /* AS 销售费用*/ ,
e.FNAME_L2 AS CUSNAME /* AS 送货客户*/ ,
CA.DEPARTMENT AS DEPARTMENT /* AS 部门*/ ,
CA.AREA AS TYPE1/* AS 一级级分类*/ ,
CA.TYPE_2 AS TYPE2 /* AS 2级分类*/ ,
CA.TYPE_3 AS TYPE3/* AS 三级分类*/
FROM
demotest.ods_SaleIssueBill a
left join demotest.ODS_MATERIAL m on a.FMATERIALID = m.FID
left join demotest.ODS_XSMXTZ_CB CB on m.FNUMBER=CB.MNUMBER AND DATE_FORMAT(a.FBizDate,'%Y-%m-%d')=DATE_FORMAT(CB.FCREATETIME,'%Y-%m-%d')
left join demotest.ODS_SALEORDER L on a.FSALEORDERID = L.FNUMBER
left join demotest.ODS_CUSTOMER e on a.FOrderCustomerID = e.FID
LEFT JOIN demo1.出库单分类FILL_DIM_XSMTZ_MASTAT CA ON m.FNUMBER = CA.MANUMBER
where
FBizDate >= '${MONTH}'
and XISHU is not null
其中出库单物料ID关联「物料单」的「物料编码」,并与数据库后台维护的「出库单分类统计对照表「FILL_DIM_XSMTZ_MASTAT」物料编码列匹配,如下图所示:
2.1.2 DW_XSMXTJ_STEM_WM 带计算指标的宽表生成
根据收入中的两种贸易方式:内贸和外贸,分别进行数据特殊的数据处理并计算收入额、毛利额、净额等等,形成收入(内贸和外贸的明细数据)表DW_XSMXTJ_STEM_WM、DW_XSMXTJ_STEM_NM,如下图所示:
SQL 代码:
WITH A AS (
SELECT
'外贸' as TRANSTYPE_1
,CONCAT(a.DEPARTMENT,'外贸') as TRANSTYPEDETAIL_1,
a.BIZTYPENAME,
a.BIZTYPE1 /* AS 业务类型*/ ,
a.BILLNUMBER /* AS 单据编号*/ ,
a.CFCKLX /* AS 出库类型*/ ,
a.BIZDATE /* AS 业务日期*/ ,
a.FMATERIALID,
a.QTY/*基本数量*/,
a.SALEPRICE /* AS 单价*/ ,
a.NONTAXAMOUNT /* AS 金额*/ ,
a.ACTUALCOST /* AS 账上成本*/ ,
a.MAID /* AS 物料ID*/ ,
a.MANUMBER /* AS 物料编码*/ ,
a.MACREATETIME /* AS 物料创建时间*/ ,
a.INCOMETYPE /* AS 收入类型*/ ,
a.MASTATUS /* AS 物料状态*/ ,
a.CBXISHU,
a.STANDARDCOST_L_N /* AS 标准成本料n*/ ,
a.Standard_COST,
a.FBIZDAT, /* AS 销售订单日期*/
a.SALENUMBER /* AS 销售订单单号*/ ,
a.CFMYFSNEW_W /* AS 贸易方式w*/ ,
a.SALECOST /* AS 销售费用*/ ,
a.CUSNAME /* AS 送货客户*/ ,
a.DEPARTMENT /* AS 部门*/ ,
a.TYPE1/* AS 一级级分类*/ ,
a.TYPE2 /* AS 2级分类*/ ,
a.TYPE3/* AS 三级分类*/
FROM demotest.MID_XSMXTJ_STEM a
where a.MARK = '2'
AND a.BizDate>= '${MONTH}'
)
SELECT
A.*
/* 销售净额 = */
, ifnull(A.NONTAXAMOUNT,0) - ifnull(A.SALECOST,0) as xsje
/* 销售净额-标准成本料 */
, ifnull(A.NONTAXAMOUNT,0) - ifnull(A.SALECOST,0) - ifnull(A.STANDARDCOST_L_N,0) as ywymle
/* 业务员毛利额/销售净额 */
, case (ifnull(A.NONTAXAMOUNT,0) - ifnull(A.SALECOST,0)) when 0 then 0 else (ifnull(A.NONTAXAMOUNT,0) - ifnull(A.SALECOST,0) - ifnull(A.STANDARDCOST_L_N,0))/(ifnull(A.NONTAXAMOUNT,0) - ifnull(A.SALECOST,0)) end as ywymll
/* 金额-实际成本合计 */
, ifnull(A.NONTAXAMOUNT,0) - ifnull(A.ACTUALCOST,0) as cpmle
-- /* 产品毛利额/金额 */
, case ifnull(A.NONTAXAMOUNT,0) when 0 then 0 else (ifnull(A.NONTAXAMOUNT,0) - ifnull(A.ACTUALCOST,0))/ifnull(A.NONTAXAMOUNT,0) end as cpmll
FROM A
2.1.3 轻度汇总数据并通过填报调整收入,生成DWS层
将明细层的数据:内外贸收入 DW_XSMXTJ_STEM_WM、DW_XSMXTJ_STEM_NM 进行合并和汇总,降维并轻度汇总成本、收入、毛利等等数据,生成中间表汇总数据 MID_XS_BASIC,如下图所示:
SQL 代码:
SELECT
date_format(BIZDATE,'%Y-%c-%d') AS YM,
DEPARTMENT,
TRANSTYPE_1,
case when DEPARTMENT = '无锡' then '非关联' else '关联' end as TRANSTYPE_2,
BIZTYPENAME,
TYPE1,
TYPE2,
TYPE3,
TRANSTYPEDETAIL_1 as SYBTRADETYPE,
SUM(NONTAXAMOUNT) AS AMT,
SUM(QTY) AS QTY,
SUM(ACTUALCOST) AS ACOST,
SUM(STANDARDCOST_L_N) AS SCOSTL,/* AS 标准成本料n*/
SUM(Standard_COST) AS SCOSTG,/* AS 标准成本n*/
SUM(SALECOST) AS COSTL
FROM
DW_XSMXTJ_STEM_WM
WHERE MANUMBER NOT IN ('EW003')
AND BIZDATE >= '${MONTH}'
GROUP BY
date_format(BIZDATE,'%Y-%c-%d'),
DEPARTMENT,
TRANSTYPE_1,
TRANSTYPE_2,
TRANSTYPEDETAIL_1,
BIZTYPENAME,
TYPE1,
TYPE2,
TYPE3
UNION ALL
SELECT
date_format(BIZDATE,'%Y-%c-%d') AS YM,
DEPARTMENT,
'关联' as TRANSTYPE_2,
TRANSTYPE_1,
BIZTYPENAME,
TYPE1,
TYPE2,
TYPE3,
TRANSTYPEDETAIL_1 as SYBTRADETYPE,
SUM(NONTAXAMOUNT) AS AMT,
SUM(QTY) AS QTY,
SUM(ACTUALCOST) AS ACOST,
SUM(STANDARDCOST_L_N) AS SCOSTL,/* AS 标准成本料n*/
SUM(Standard_COST) AS SCOSTG,/* AS 标准成本n*/
SUM(SALECOST) AS COSTL
FROM
DW_XSMXTJ_STEM_NM
WHERE MANUMBER NOT IN ('EW003')
AND BIZDATE >= '${MONTH}'
GROUP BY
date_format(BIZDATE,'%Y-%c-%d'),
DEPARTMENT,
TRANSTYPE_1,
TRANSTYPE_2,
TRANSTYPEDETAIL_1,
BIZTYPENAME,
TYPE1,
TYPE2,
TYPE3
将降维汇总数据与财务调账填报报表「收入调整表」(财务人员手动填报调账)合并,生成最终的 DWS 汇总数据 DWS_XS_BASIC,便于后续进行数据分析表报表的制作,如下图所示:
SQL 代码:
SELECT
*
FROM
MID_XS_BASIC
WHERE YM >= '${MONTH}'
UNION ALL
SELECT
YM,
DEPARTMENTD AS DEPARTMENT,
TRANSTYPE_1,
TRANSTYPE_2,
BIZTYPENAME,
TYPE1,
TYPE2,
TYPE3,
CONCAT(DEPARTMENTD,'外贸') as SYBTRADETYPE,
SUM(NONTAXAMOUNT) AS AMT,
SUM(QTY) AS QTY,
SUM(ACTUALCOST) AS ACOST,
SUM(STANDARDCOST_L_N) AS SCOSTL,/* AS 标准成本料n*/
SUM(Standard_COST) AS SCOSTG,/* AS 标准成本n*/
SUM(SALECOST) AS COSTL
FROM
DWS_XS_BASIC_ALTER
WHERE YM >= '${MONTH}'
GROUP BY
YM,
DEPARTMENTD,
TRANSTYPE_1,
TRANSTYPE_2,
SYBTRADETYPE,
BIZTYPENAME,
TYPE1,
TYPE2,
TYPE3
2.2 设置更新调度
其中这些数据由于字段多、数据量大、计算复杂,因此数据加工中的任务都使用增量更新。
在每个任务中设置 MONTH 参数,按月份先删除指定月数据,然后在追加写入当月数据,如下图所示:
然后写入方式选择「追加写入数据」。
在调度文件夹下新建 DW 调度任务,使用调用任务功能,在一个任务中调用多个任务,便于进行任务的管控。
由于这些被调用的 DW 层数据加工数据表有着上下游数据关系,因此需要使用连线将其左右相连,按照数据加工处理的层级执行任务,如下图所示:
上文中的 MONTH 月份参数则是通过调度任务中的参数赋值实现,也就是当数据库中的日期时间被财务人员设定为已经关账,可以进行销售明细的财务核算,则取出当月数据作为参数,如下图所示:
3. 数据报表
本节介绍如何通过 FineReport 对销售账目进行报表展示。
为了便于进行财务收入数据的应用,将数仓搭建好的数据制作了多个看板实现即时监控。
报表具体场景如下:
3.1 销售明细台账
使用「DW_XSMXTJ_STEM_WM 」销售明细宽表分别制作内外贸「收入明细台账」,用来展示销售收入的明细数据,如下图所示:
3.2 事业部分析
使用「DWS_XS_BASIC 」经过轻度汇总并进行填报收入调账后的数据制作「事业部分析」,用来展示收入核算的汇总数据,如下图所示: