lzh
2025-06-19 3a6436e0c88042c6ce8dca2fe8adb0109f0ad9e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
--[[
    编码: hh-mobox-002
    名称: 货位状态
    作者:SGX
    日期:2024-11-27
    函数: GenChartJson
 
    功能:
       叠柱状图
 
    更改记录:
 
--]]
json = require("json")
mobox = require("OILua_JavelinExt")
m3 = require("oi_base_mobox")
 
function GenChartJson1(strLuaDEID)
    local nRet, strRetInfo
    --[[ 标题颜色 ]]
    local strTitle = "物料数量"
    --[[ 文字颜色 ]]
    local strColor = "#fff"
    --[[ 柱状图柱子名称,对应 series 下name ]]
    local tabLegendData = { '数量' }
    --[[ X轴数据 从左向右 ]]
    local tabXAxis = { '胶料', '钢丝', '粉料', '辅材', '碳黑', '帘子布' }
    --[[ Y轴 最上方显示文字 ]]
    local strYAxisName = "物料数量"
    --[[ 满仓颜色 ]]
    local strMCColor = '#45A048'
    --[[ 空仓颜色 ]]
    -- local strKCColor = '#FE9700'
    --[[ 柱状图数据 对应X轴数据 ]]
    --[[ 满仓 ]]
    -- local tabSeriesMCData = {}
    -- for i = 1, 6 do
    --     -- 获取对应物料的总托数
    --     local item_type = tabXAxis[i]
    --     -- 获取物料的托数
 
    --     tabSeriesMCData[i] = lua.StrToNumber(29)
    -- end
 
    local jl_num = 0
    local gs_num = 0
    local fl_num = 0
    local fc_num = 0
    local th_num = 0
    local lzb_num = 0
 
    local strCondition = "S_CNTR_CODE IN (SELECT S_CNTR_CODE FROM TN_Loc_Container)"
    local nRet, cg_detail = mobox.queryDataObjAttr2(strLuaDEID, "CG_Detail", strCondition, "", 100, "S_ITEM_CODE")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "查询【容器货品明细】信息失败!" .. cg_detail) end
    if (cg_detail == nil or cg_detail == '') then return end
    local queryInfo = json.decode(cg_detail)
    local nPageCount = queryInfo.pageCount
    local dataSet = queryInfo.dataSet
    local queryID = queryInfo.queryID
    lua.Debug(strLuaDEID, debug.getinfo(1), 'queryInfo:', queryInfo)
 
    -- 分页获取货位的数据
    for i = 1, nPageCount do
        for j = 1, #dataSet do
            local attrs
            nRet, attrs = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(dataSet[j].attrs))
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj失败!" .. attrs) end
 
            -- 通过物料编码获取物料类型
            local item_type_new, material
            nRet, item_type_new, material = GT_Get_ItemType(strLuaDEID, attrs.item_code)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type_new) end
 
            if (item_type_new == '胶料' or item_type_new == '天然胶' or item_type_new == '散装胶') then
                jl_num = jl_num + 1
            elseif (item_type_new == '钢丝') then
                gs_num = gs_num + 1
            elseif (item_type_new == '粉料') then
                fl_num = fl_num + 1
            elseif (item_type_new == '辅材') then
                fc_num = fc_num + 1
            elseif (item_type_new == '碳黑') then
                th_num = th_num + 1
            elseif (item_type_new == '帘子布') then
                lzb_num = lzb_num + 1
            end
        end
 
        if ((i + 1) <= nPageCount) then
            -- 取下一页
            local data
            nRet, data = mobox.queryDataObjAttr2(queryID, (i + 1))
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "queryDataObjAttr2失败! nPage=" .. i + 1 .. "  " .. data)
            end
            data = json.decode(data)
            dataSet = data.dataSet
        end
    end
    local tabSeriesMCData = { jl_num, gs_num, fl_num, fc_num, th_num, lzb_num }
 
    --[[ 空仓 ]]
    -- local tabSeriesKCData = {}
    -- for i = 1 ,8 do
    --     local strCondition = "N_ROADWAY = "..i.." AND N_CURRENT_NUM = 0"
    --     nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
    --     if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "getDataObjCount 失败! " .. strRetInfo) end
    --     tabSeriesKCData[i] = lua.StrToNumber(strRetInfo)
    -- end
 
    -- local option = {
    --     title = {
    --         text = strTitle,
    --         left = 20,
    --         textStyle = {
    --             color = strColor
    --         },
    --         top = 10
    --     },
    --     legend = {
    --         data = tabLegendData,
    --         textStyle = {
    --             color = strColor
    --         },
    --         top = 10
    --     },
    --     grid = {
    --         left = '5%',
    --         right = '5%',
    --         bottom = '5%',
    --         top = '22%',
    --         containLabel = true
    --     },
    --     xAxis = {
    --         type = 'category',
    --         data = tabXAxis,
    --         axisLabel = {
    --             textStyle = {
    --                 color = strColor
    --             }
    --         }
    --     },
    --     yAxis = {
 
    --         type = 'value',
    --         nameTextStyle = {
    --             color = strColor
    --         },
    --         axisLabel = {
    --             textStyle = {
    --                 color = strColor
    --             }
    --         }
    --     },
    --     series = { {
    --         name = '数量',
    --         type = 'bar',
    --         stack = 'total',
    --         label = {
    --             show = true
    --         },
    --         color = strMCColor,
    --         data = tabSeriesMCData
    --     } }
    -- }
 
    local option = {
        xAxis = {
            type = 'category',
            data = { '胶料', '钢丝', '粉料', '辅材', '碳黑', '帘子布' }
        },
        yAxis = {
            type = 'value'
        },
        series = {
            {
                data = { jl_num, gs_num, fl_num, fc_num, th_num, lzb_num },
                type = 'bar'
            }
        }
    };
 
    local action = {}
    action[1] = {
        action_type = "chart",
        value = {
            graphicType = "echart",
            title = {
                text = strTitle,
                align = "center",
                color = "#515a6e",
                font = "微软雅黑",
                fontSize = 12
            },
            option = option
        }
    }
 
    lua.Debug( strLuaDEID, debug.getinfo(1), "action! ", action )
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "setAction失败! " .. strRetInfo .. ' action = ' .. strAction)
    end
end