This commit is contained in:
2022-11-24 16:51:17 +08:00
2 changed files with 62 additions and 44 deletions

View File

@@ -373,6 +373,13 @@
<artifactId>poi-ooxml-schemas</artifactId> <artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version> <version>3.17</version>
</dependency> </dependency>
<!--访问共享文件-->
<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.17</version>
</dependency>
</dependencies> </dependencies>
<distributionManagement> <distributionManagement>

View File

@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import jcifs.smb.SmbFile;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.exception.BadRequestException;
@@ -45,58 +46,65 @@ public class PrintServiceImpl implements PrintService {
public JSONObject customerPrint(JSONObject whereJson) { public JSONObject customerPrint(JSONObject whereJson) {
JSONObject jo = new JSONObject(); JSONObject jo = new JSONObject();
String box_no = whereJson.getString("box_no"); String box_no = whereJson.getString("box_no");
JSONObject box_jo = WQL.getWO("PDA_ST_01").addParam("flag", "5").addParam("box_no", box_no).process().uniqueResult(0); JSONObject box_jo = WQL.getWO("PDA_ST_01").addParam("flag", "5").addParam("box_no", box_no).process().uniqueResult(0);
if (ObjectUtil.isEmpty(box_jo)) { if (ObjectUtil.isEmpty(box_jo)) {
throw new BadRequestException("未查询到木箱相关信息!"); throw new BadRequestException("未查询到木箱相关信息!");
} }
//组织木箱打印信息 //组织木箱打印信息
//箱号 //箱号
String package_box_sn = box_jo.getString("package_box_sn"); String package_box_sn = box_jo.getString("package_box_sn");
//订单号 //订单号
String sale_order_name = box_jo.getString("sale_order_name"); String sale_order_name = box_jo.getString("sale_order_name");
//品名 //品名
String product_description = box_jo.getString("product_description"); String product_description = box_jo.getString("product_description");
//物料号 //物料号
String product_name = box_jo.getString("product_name"); String product_name = box_jo.getString("product_name");
//规格 //规格
String width = box_jo.getString("width"); String width = box_jo.getString("width");
//批号 //批号
String pcsn = ""; String pcsn = "";
//入库日期 //入库日期
String date_of_FG_inbound = box_jo.getString("date_of_FG_inbound"); String date_of_FG_inbound = box_jo.getString("date_of_FG_inbound");
//毛重 //毛重
String box_weight = box_jo.getString("box_weight"); String box_weight = box_jo.getString("box_weight");
//生产日期 //生产日期
String date_of_production = box_jo.getString("date_of_production"); String date_of_production = box_jo.getString("date_of_production");
//卷数 //卷数
String quanlity_in_box = box_jo.getString("quanlity_in_box"); String quanlity_in_box = box_jo.getString("quanlity_in_box");
//保质期 //保质期
String quality_guaran_period = box_jo.getString("quality_guaran_period"); String quality_guaran_period = box_jo.getString("quality_guaran_period");
//检验员 //检验员
String nspector = ""; String nspector = "";
//储存条件 //储存条件
String storage_conditions = ""; String storage_conditions = "";
double weight = 0; double weight = 0;
JSONArray rows = WQL.getWO("PDA_ST_01").addParam("flag", "5").addParam("box_no", box_no).process().getResultJSONArray(0); JSONArray rows = WQL.getWO("PDA_ST_01").addParam("flag", "5").addParam("box_no", box_no).process().getResultJSONArray(0);
for (int i = 0; i < rows.size(); i++) { for (int i = 0; i < rows.size(); i++) {
JSONObject row = rows.getJSONObject(i); JSONObject row = rows.getJSONObject(i);
weight += row.getDoubleValue("net_weight"); weight += row.getDoubleValue("net_weight");
} }
// 生成txt文件 // 生成txt文件
String filePath = "//10.1.3.21" + "/LMSPrinter" + "外包标签.txt"; String filePath = "smb://10.1.3.21" + "/LMSPrinter" + "外包标签.txt";
FileWriter fw = null; FileWriter fw = null;
try { try {
File file = new File(filePath); /* File file = new File(filePath);
if (!file.exists()) { if (!file.exists()) {
// 判断此文件是否存在 不存在则创建 存在则覆盖
file.createNewFile();
}*/
SmbFile file = new SmbFile(filePath);
if (!file.exists()) {
// 判断此文件是否存在 不存在则创建 存在则覆盖
file.createNewFile(); file.createNewFile();
} }
fw = new FileWriter(filePath); fw = new FileWriter(filePath);
BufferedWriter bw = new BufferedWriter(fw); BufferedWriter bw = new BufferedWriter(fw);
bw.write("package_box_sn,sale_order_name,product_description,product_name,width,pcsn,date_of_FG_inbound,box_weight,date_of_production,quanlity_in_box,quality_guaran_period,nspector,storage_conditions,weight\n"); bw.write("package_box_sn,sale_order_name,product_description,product_name,width,pcsn,date_of_FG_inbound,box_weight,date_of_production,quanlity_in_box,quality_guaran_period,nspector,storage_conditions,weight\n");
@@ -119,15 +127,18 @@ public class PrintServiceImpl implements PrintService {
bw.close(); bw.close();
} catch (Exception e) { } catch (Exception e) {
jo.put("message", "打印失败!"+e.getMessage()); jo.put("message", "打印失败!" + e.getMessage());
return jo;
} finally { } finally {
try { try {
fw.close(); fw.close();
} catch (Exception e) { } catch (Exception e) {
jo.put("message", "打印失败!"+e.getMessage()); jo.put("message", "打印失败!" + e.getMessage());
} }
} }
jo.put("message", "打印成功!"); jo.put("message", "打印成功!");
return jo; return jo;
} }
} }