@ -17,6 +17,8 @@ import com.spire.xls.Workbook;
import com.spire.xls.Worksheet ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.nl.acs.config.AcsConfig ;
import org.nl.acs.config.server.AcsConfigService ;
import org.nl.acs.device_driver.hailiang.hailiang_feeding_trunk.HaiLiangFeedingTrunkDeviceDriver ;
import org.nl.acs.device_driver.hailiang.hailiang_labeling.HaiLiangLabelingDeviceDriver ;
import org.nl.acs.opc.DeviceAppService ;
@ -65,6 +67,9 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
@Autowired
ProduceshiftorderdetailService produceshiftorderdetailService ;
@Autowired
AcsConfigService acsConfigService ;
@Override
public void autoInitial ( ) throws Exception {
this . reload ( ) ;
@ -310,6 +315,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
WQLObject wo = WQLObject . getWQLObject ( "acs_produceshiftorder" ) ;
JSONObject json = ( JSONObject ) JSONObject . toJSON ( orderDto ) ;
wo . insert ( json ) ;
this . reload ( ) ;
}
@Override
@ -498,7 +504,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
iterator . remove ( ) ;
}
}
if ( ! StrUtil . equals ( entity . getOrder_id ( ) , "07" ) & & ! StrUtil . equals ( entity . getOrder_id ( ) , "08" ) & & ! StrUtil . equals ( entity . getOrder_id ( ) , "09" ) ) {
if ( ! StrUtil . equals ( entity . getOrder_status ( ) , "07" ) & & ! StrUtil . equals ( entity . getOrder_status ( ) , "08" ) & & ! StrUtil . equals ( entity . getOrder_status ( ) , "09" ) ) {
order . add ( entity ) ;
}
@ -539,9 +545,10 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
iterator . remove ( ) ;
}
}
if ( ! StrUtil . equals ( entity . getOrder_id ( ) , "07" ) & & ! StrUtil . equals ( entity . getOrder_id ( ) , "08" ) & & ! StrUtil . equals ( entity . getOrder_id ( ) , "09" ) ) {
if ( ! StrUtil . equals ( entity . getOrder_status ( ) , "07" ) & & ! StrUtil . equals ( entity . getOrder_status ( ) , "08" ) & & ! StrUtil . equals ( entity . getOrder_status ( ) , "09" ) ) {
order . add ( entity ) ;
}
produceshiftorderdetailService . reload ( ) ;
}
@Override
@ -644,9 +651,10 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
jo . put ( "inspector" , detaildto . getInspector ( ) ) ;
jo . put ( "mg_weight" , detaildto . getMg_weight ( ) ) ;
//打印纸张大小
//1cm = 118px
jo . put ( "page_length" , 590 ) ;
jo . put ( "page_height" , 472 ) ;
jo . put ( "page_length" , "500" ) ;
jo . put ( "page_height" , "400" ) ;
jo . put ( "labeling_template" , detaildto . getLabeling_template ( ) ) ;
print ( jo ) ;
}
@ -1000,81 +1008,117 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
@Override
public Boolean print ( JSONObject whereJson ) {
String order_id = whereJson . getString ( "order_id" ) ;
String template_id = whereJson . getString ( "template_id" ) ;
WQLObject mst = WQLObject . getWQLObject ( "acs_produceshiftorder" ) ; // 主表
// 1.根据明细找主表
JSONObject jsonMst = mst . query ( "order_id = '" + order_id + "' and is_deleted ='0'" ) . uniqueResult ( 0 ) ;
// 2.根据明细template_id 找到对应的模板
JSONObject jsonStor = WQL . getWO ( "QPRODUCESHIFTORDER" ) . addParam ( "flag" , "3" ) . addParam ( "storage_id" , template_id ) . process ( ) . uniqueResult ( 0 ) ;
// String order_id = whereJson.getString("order_id");
// String template_id = whereJson.getString("template_id");
//
// WQLObject mst = WQLObject.getWQLObject("acs_produceshiftorder"); // 主表
//
// // 1.根据明细找主表
// JSONObject jsonMst = mst.query("order_id = '" + order_id + "' and is_deleted ='0'").uniqueResult(0);
//
// // 2.根据明细template_id 找到对应的模板
// JSONObject jsonStor = WQL.getWO("QPRODUCESHIFTORDER").addParam("flag", "3").addParam("storage_id", template_id).process().uniqueResult(0);
//
// // 3.创建模板工作簿 并指定储存路径
// String path = jsonStor.getString("path");
// String pathName = whereJson.getString("url");
// ExcelWriter workBook = EasyExcel.write(pathName).withTemplate(path).build();
// // 获取第一个sheet
// WriteSheet sheet = EasyExcel.writerSheet().build();
//
// // 4.将主表当中的属性填充到excel当中
// HashMap<String, String> map = new HashMap<>();
// map.put("alloy",whereJson.getString("alloy"));
// map.put("temper",whereJson.getString("temper"));
// map.put("material_spec",whereJson.getString("material_spec"));
// map.put("number",whereJson.getString("number"));
// map.put("outer_diameter",whereJson.getString("outer_diameter"));
// map.put("standard",whereJson.getString("standard"));
// map.put("batch",whereJson.getString("batch"));
// map.put("prod_date",whereJson.getString("prod_date"));
// map.put("present_strap_pack_number",whereJson.getString("present_strap_pack_number"));
// map.put("inspector",whereJson.getString("inspector"));
// map.put("mg_weight",whereJson.getString("mg_weight"));
// workBook.fill(map, sheet);
// workBook.finish();
// Book book=new Book();
// Workbook loDoc = new Workbook();
// loDoc.loadFromFile(pathName);
// Worksheet worksheet = loDoc.getWorksheets().get(0);
// PageSetup pageSetup = worksheet.getPageSetup();
// String printArea="A2:B8";
// pageSetup.setPrintArea(printArea);
// pageSetup.setLeftMargin(0);
// pageSetup.setRightMargin(0);
// pageSetup.setTopMargin(0);
// pageSetup.setBottomMargin(0);
// CellRange cellRanges = worksheet.getCellRange(printArea);
// int height=0;
// for (CellRange row : cellRanges.getRows()) {
// height+= worksheet.getRowHeightPixels(row.getRow());
// }
//
// int width=0;
// for (CellRange column : cellRanges.getColumns()) {
// width+=worksheet.getColumnWidthPixels(column.getColumn());
// }
//
// PrinterJob loPrinterJob = PrinterJob.getPrinterJob();
// PageFormat loPageFormat = loPrinterJob.defaultPage();
// Paper loPaper = loPageFormat.getPaper();
//
// loPaper.setImageableArea(0, 0, loPageFormat.getWidth(), loPageFormat.getHeight());
//
// String page_height = whereJson.getString("page_height");
// String page_length = whereJson.getString("page_length");
//
// loPaper.setSize(Double.parseDouble(page_length),Double.parseDouble(page_height));
//// loPaper.setSize(width/96.0*72,height/96.0*72);
// loPageFormat.setPaper(loPaper);
// loPrinterJob.setCopies(1);
// loPrinterJob.setPrintable(loDoc, loPageFormat);
// book.append(loDoc,loPageFormat);
// loPrinterJob.setPageable(book);
// try {
// // 执行打印
// loPrinterJob.print();
// } catch (PrinterException e) {
// e.printStackTrace();
// return false;
// }
// 3.创建模板工作簿 并指定储存路径
String path = jsonStor . getString ( "path" ) ;
String pathName = whereJson . getString ( "url" ) ;
ExcelWriter workBook = EasyExcel . write ( pathName ) . withTemplate ( path ) . build ( ) ;
// 获取第一个sheet
WriteSheet sheet = EasyExcel . writerSheet ( ) . build ( ) ;
// 4.将主表当中的属性填充到excel当中
HashMap < String , String > map = new HashMap < > ( ) ;
map . put ( "alloy" , whereJson . getString ( "alloy" ) ) ;
map . put ( "temper" , whereJson . getString ( "temper" ) ) ;
map . put ( "material_spec" , whereJson . getString ( "material_spec" ) ) ;
map . put ( "number" , whereJson . getString ( "number" ) ) ;
map . put ( "outer_diameter" , whereJson . getString ( "outer_diameter" ) ) ;
map . put ( "standard" , whereJson . getString ( "standard" ) ) ;
map . put ( "batch" , whereJson . getString ( "batch" ) ) ;
map . put ( "prod_date" , whereJson . getString ( "prod_date" ) ) ;
map . put ( "present_strap_pack_number" , whereJson . getString ( "present_strap_pack_number" ) ) ;
map . put ( "inspector" , whereJson . getString ( "inspector" ) ) ;
map . put ( "mg_weight" , whereJson . getString ( "mg_weight" ) ) ;
workBook . fill ( map , sheet ) ;
workBook . finish ( ) ;
Book book = new Book ( ) ;
Workbook loDoc = new Workbook ( ) ;
loDoc . loadFromFile ( pathName ) ;
Worksheet worksheet = loDoc . getWorksheets ( ) . get ( 0 ) ;
PageSetup pageSetup = worksheet . getPageSetup ( ) ;
String printArea = "A2:B8" ;
pageSetup . setPrintArea ( printArea ) ;
pageSetup . setLeftMargin ( 0 ) ;
pageSetup . setRightMargin ( 0 ) ;
pageSetup . setTopMargin ( 0 ) ;
pageSetup . setBottomMargin ( 0 ) ;
CellRange cellRanges = worksheet . getCellRange ( printArea ) ;
int height = 0 ;
for ( CellRange row : cellRanges . getRows ( ) ) {
height + = worksheet . getRowHeightPixels ( row . getRow ( ) ) ;
}
int width = 0 ;
for ( CellRange column : cellRanges . getColumns ( ) ) {
width + = worksheet . getColumnWidthPixels ( column . getColumn ( ) ) ;
}
PrinterJob loPrinterJob = PrinterJob . getPrinterJob ( ) ;
PageFormat loPageFormat = loPrinterJob . defaultPage ( ) ;
Paper loPaper = loPageFormat . getPaper ( ) ;
loPaper . setImageableArea ( 0 , 0 , loPageFormat . getWidth ( ) , loPageFormat . getHeight ( ) ) ;
loPaper . setSize ( 142 , 113 ) ;
// loPaper.setSize(width/96.0*72,height/96.0*72);
loPageFormat . setPaper ( loPaper ) ;
loPrinterJob . setCopies ( 1 ) ;
loPrinterJob . setPrintable ( loDoc , loPageFormat ) ;
book . append ( loDoc , loPageFormat ) ;
loPrinterJob . setPageable ( book ) ;
try {
// 执行打印
loPrinterJob . print ( ) ;
} catch ( PrinterException e ) {
String url = acsConfigService . findConfigFromCache ( ) . get ( AcsConfig . PRINTURL ) ;
String printName = acsConfigService . findConfigFromCache ( ) . get ( AcsConfig . PRINTNAME ) ;
String labeling_template = whereJson . get ( "labeling_template" ) . toString ( ) ;
String alloy = whereJson . getString ( "alloy" ) ;
String temper = whereJson . getString ( "temper" ) ;
String material_spec = whereJson . getString ( "material_spec" ) ;
String number = whereJson . getString ( "number" ) ;
String outer_diameter = whereJson . getString ( "outer_diameter" ) ;
String standard = whereJson . getString ( "standard" ) ;
String batch = whereJson . getString ( "batch" ) ;
String prod_date = whereJson . getString ( "prod_date" ) ;
String present_strap_pack_number = whereJson . getString ( "present_strap_pack_number" ) ;
String inspector = whereJson . getString ( "inspector" ) ;
String mg_weight = whereJson . getString ( "mg_weight" ) ;
Process printProcess ;
try
{
printProcess = Runtime
. getRuntime ( )
. exec ( new String [ ] {
url ,
"PrinterName=" + printName ,
"LabelName=Label" + labeling_template + ".ct" ,
"alloy=" + alloy , "temper=" + temper , "size=" + material_spec , "pcs=" + number , "outer_diameter=" + outer_diameter ,
"standard=" + standard , "batch=" + batch , "prod_date=" + prod_date , "present_strap_pack_number=" + present_strap_pack_number ,
"inspector=" + inspector , "mg_weight=" + mg_weight } ) ;
}
catch ( Exception e )
{
e . printStackTrace ( ) ;
return false ;
System . out . println ( "aaa" ) ;
}
return true ;
}