/**
|
* 根据粮情数据到后台获取打印模板,然后开始渲染数据
|
*/
|
builderModel = function (grainData, isPrint) {
|
var depotData = grainData.depotData;
|
if (!depotData.depotType) {
|
depotData.depotType = DepotType.T_01;
|
}
|
var key = builderModelKey(depotData.depotType, grainData.cable, grainData.cableCir);
|
|
var modelData = CACHE_PRINT_MODEL.get(key);
|
if (modelData) {
|
return builderModelStep2(modelData, grainData, isPrint);
|
}
|
|
//从后台获取报表模板
|
$.ajax({
|
type: "POST",
|
url: "../../basic/grain/build-print-model",
|
dataType: "json",
|
contentType: "application/json;charset=UTF-8",
|
data: JSON.stringify({
|
companyId: grainData.companyId,
|
cableRule: grainData.cable,
|
cableCir: grainData.cableCir,
|
depotId: grainData.depotId,
|
depotType: depotData.depotType
|
}),
|
success: function (result) {
|
if (result.code != "0000") {
|
layer.msg(result.msg);
|
return null;
|
} else {
|
//存放在缓存中
|
modelData = result.data;
|
CACHE_PRINT_MODEL.set(key, modelData);
|
return builderModelStep2(modelData, grainData, isPrint);
|
}
|
},
|
error: function () {
|
layer.msg("获取粮情的打印模板失败!!");
|
}
|
});
|
};
|
|
|
/**
|
* 获取模板后添加数据
|
* @param grainData
|
* @param isPrint
|
*/
|
builderModelStep2 = function (modelData, grainData, isPrint) {
|
var attCable = grainData.cable.split("-");
|
numZ = attCable[0];
|
numY = attCable[1];
|
numX = attCable[2];
|
var model = modelData.model;
|
|
var depotData = grainData.depotData;
|
//替换基础数据
|
if (dept) {
|
model = model.replace("companyName", dept.name);
|
} else {
|
model = model.replace("companyName", "智慧粮库");
|
}
|
model = model.replace("depotName", depotData.name)
|
.replace("weather", grainData.weather == null ? "" : grainData.weather)
|
.replace("orientation", depotData.orientation == null ? "" : depotData.orientation)
|
.replace("checkDate", grainData.receiveDate)
|
.replace("remark", grainData.remark == null ? "正常" : grainData.remark)
|
.replace("c_max_all", grainData.tempMax)
|
.replace("c_min_all", grainData.tempMin)
|
.replace("c_ave_all", grainData.tempAve);
|
|
model = model.replace("c_out_ave_all", "");//暂时不用
|
model = model.replace("c_in_ave_all", "");//暂时不用
|
|
model = model.replace("c_tIn", grainData.tempIn)
|
.replace("c_hIn", grainData.humidityIn)
|
.replace("c_tOut", grainData.tempOut)
|
.replace("c_hOut", grainData.humidityOut)
|
.replace("c_depotType", depotData.depotTypeName)
|
.replace("c_storeDate", depotData.storeDate == null ? "" : depotData.storeDate)
|
.replace("c_foodLocation", depotData.foodLocation == null ? "" : depotData.foodLocation)
|
.replace("c_perImpurity", depotData.perImpurity == null ? "" : depotData.perImpurity)
|
.replace("c_storeDate", depotData.storeDate == null ? "" : depotData.storeDate)
|
.replace("c_checkUser", grainData.checkUser)
|
.replace("c_storeKeeperName", depotData.storeKeeperName == null ? "" : depotData.storeKeeperName)
|
.replace("createBillDate", grainData.sysDate);
|
|
//动态数据信息--平方仓
|
if (DepotType.T_01 == depotData.depotType) {
|
if("ROW" == modelData.modelType){
|
model = addPointsRow1(model, grainData, numX);
|
}else{
|
model = addPoints1(model, grainData, numX);
|
}
|
}
|
//动态数据信息--浅圆仓
|
if (DepotType.T_02 == depotData.depotType) {
|
model = addPoints4(model, grainData);
|
}
|
//动态数据信息--油罐
|
if (DepotType.T_03 == depotData.depotType) {
|
var oilHeight = grainData.oilHeight;
|
if (oilHeight) {
|
var att = oilHeight.split("-");
|
model = model.replace("c_depotHeight", att[1]).replace("c_oilHeight", att[0]);
|
} else {
|
model = model.replace("c_depotHeight", "#").replace("c_oilHeight", "#");
|
}
|
model = addPoints4(model, grainData);
|
}
|
//动态数据信息--立筒仓
|
if (DepotType.T_04 == depotData.depotType) {
|
model = addPoints4(model, grainData);
|
}
|
|
if (!isPrint) return model;
|
layer.msg("开始调用打印机……");
|
previewA4(model);
|
return model;
|
};
|
|
/**
|
* 模板缓存KEY的生成
|
* @param depotType
|
* @param cable
|
* @param cableCir
|
*/
|
builderModelKey = function (depotType, cable, cableCir) {
|
if (cableCir) {
|
return depotType + "_" + cable + "_" + cableCir;
|
}
|
return depotType + "_" + cable;
|
};
|
|
//根据采集点赋值,注意数据库生成的坐标是从0开始的
|
addPoints1 = function (model, numX) {
|
var listPoints = grainData.listPoints;
|
var listLays = grainData.listLays;
|
var point;
|
var key;
|
var lay;
|
var temp;
|
for (var i = 0; i < listPoints.length; i++) {
|
point = listPoints[i];
|
temp = point.temp;
|
lay = listLays[point.z];
|
//层最
|
if (lay.z <= listLays.length) {
|
key = "c_max_" + (lay.z + 1);
|
model = model.replace(key, lay.tempMax);
|
key = "c_min_" + (lay.z + 1);
|
model = model.replace(key, lay.tempMin);
|
key = "c_ave_" + (lay.z + 1);
|
model = model.replace(key, lay.tempAve);
|
key = "c_out_ave_" + (lay.z + 1);
|
model = model.replace(key, lay.tempAveOut);
|
key = "c_in_ave_" + (lay.z + 1);
|
model = model.replace(key, lay.tempAveIn);
|
}
|
|
key = "c_" + (point.z + 1) + (point.y + 1) + (point.x + 1);
|
if (-100.0 == temp) {
|
temp = "备用";
|
}
|
if (-101.0 == temp) {
|
temp = "故障";
|
}
|
if (temp == lay.tempMax) {
|
temp = temp + "*";
|
}
|
if (temp == lay.tempMin) {
|
temp = temp + "#";
|
}
|
//key = c_z+1 + 1 + numX表示第一列
|
if (key == ("c_" + (point.z + 1) + "1" + numX)) {
|
temp = "<" + temp + ">";
|
}
|
model = model.replace(key, temp);
|
}
|
return model;
|
};
|
|
//横向通风赋值
|
addPointsRow1 = function (model, grainData,numX) {
|
var listPoints = grainData.listPoints;
|
var listRows = grainData.listRows;
|
var point;
|
var key;
|
var lay;
|
var temp;
|
for (var i = 0; i < listRows.length; i++) {
|
point = listPoints[i];
|
temp = point.temp;
|
row = listRows[point.y];
|
//行最大
|
if (row.y <= listRows.length) {
|
key = "c_max_" + (row.z + 1);
|
model = model.replace(key, row.tempMax);
|
key = "c_min_" + (row.z + 1);
|
model = model.replace(key, row.tempMin);
|
key = "c_ave_" + (row.z + 1);
|
model = model.replace(key, row.tempAve);
|
}
|
|
key = "c_" + (point.z + 1) + (point.y + 1) + (point.x + 1);
|
if (-100.0 == temp) {
|
temp = "备用";
|
}
|
if (-101.0 == temp) {
|
temp = "故障";
|
}
|
if (temp == lay.tempMax) {
|
temp = temp + "*";
|
}
|
if (temp == lay.tempMin) {
|
temp = temp + "#";
|
}
|
//key = c_z+1 + 1 + numX表示第一列
|
if (key == ("c_" + (point.z + 1) + "1" + numX)) {
|
temp = "<" + temp + ">";
|
}
|
model = model.replace(key, temp);
|
}
|
return model;
|
};
|
|
//筒仓添加采集点和层温度信息
|
addPoints4 = function (model, grainData) {
|
// console.log(grainData);
|
var listPoints = grainData.listPoints;
|
var listLays = grainData.listLays;
|
var point;
|
var key;
|
var lay;
|
var temp;
|
for (var i = 0; i < listPoints.length; i++) {
|
point = listPoints[i];
|
lay = listLays[point.z];
|
temp = point.temp;
|
//层最
|
if (lay.z <= listLays.length) {
|
key = "c_max_" + lay.z;
|
model = model.replace(key, lay.tempMax);
|
key = "c_min_" + lay.z;
|
model = model.replace(key, lay.tempMin);
|
key = "c_ave_" + lay.z;
|
model = model.replace(key, lay.tempAve);
|
key = "c_out_ave_" + lay.z;
|
model = model.replace(key, lay.tempAveOut);
|
key = "c_in_ave_" + lay.z;
|
model = model.replace(key, lay.tempAveIn);
|
}
|
|
key = "c_" + (point.x + 1) + "_" + (point.y + 1) + "_" + (point.z + 1);
|
//判断层高低温
|
if (-100.0 == temp) {
|
temp = "备用";
|
}
|
if (-101.0 == temp) {
|
temp = "故障";
|
}
|
if (temp == lay.tempMax) {
|
temp = temp + "*";
|
}
|
if (temp == lay.tempMin) {
|
temp = temp + "#";
|
}
|
model = model.replace(key, temp);
|
}
|
return model;
|
};
|
/**
|
* 根据HTML模版打印为A4
|
* @param strHtml
|
*/
|
previewA4 = function (strHtml) {
|
var LODOP = CLODOP;
|
LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
|
LODOP.PRINT_INIT("粮情报表");
|
LODOP.ADD_PRINT_HTM(30, 40, "180mm", "100%", strHtml);
|
//设置默认满张打印
|
LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Page");
|
LODOP.PREVIEW();
|
};
|