@ -17,6 +17,8 @@ import com.spire.xls.Workbook;
import com.spire.xls.Worksheet ;
import com.spire.xls.Worksheet ;
import lombok.RequiredArgsConstructor ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
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_feeding_trunk.HaiLiangFeedingTrunkDeviceDriver ;
import org.nl.acs.device_driver.hailiang.hailiang_labeling.HaiLiangLabelingDeviceDriver ;
import org.nl.acs.device_driver.hailiang.hailiang_labeling.HaiLiangLabelingDeviceDriver ;
import org.nl.acs.opc.DeviceAppService ;
import org.nl.acs.opc.DeviceAppService ;
@ -65,6 +67,9 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
@Autowired
@Autowired
ProduceshiftorderdetailService produceshiftorderdetailService ;
ProduceshiftorderdetailService produceshiftorderdetailService ;
@Autowired
AcsConfigService acsConfigService ;
@Override
@Override
public void autoInitial ( ) throws Exception {
public void autoInitial ( ) throws Exception {
this . reload ( ) ;
this . reload ( ) ;
@ -310,6 +315,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
WQLObject wo = WQLObject . getWQLObject ( "acs_produceshiftorder" ) ;
WQLObject wo = WQLObject . getWQLObject ( "acs_produceshiftorder" ) ;
JSONObject json = ( JSONObject ) JSONObject . toJSON ( orderDto ) ;
JSONObject json = ( JSONObject ) JSONObject . toJSON ( orderDto ) ;
wo . insert ( json ) ;
wo . insert ( json ) ;
this . reload ( ) ;
}
}
@Override
@Override
@ -498,7 +504,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
iterator . remove ( ) ;
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 ) ;
order . add ( entity ) ;
}
}
@ -539,9 +545,10 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
iterator . remove ( ) ;
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 ) ;
order . add ( entity ) ;
}
}
produceshiftorderdetailService . reload ( ) ;
}
}
@Override
@Override
@ -644,9 +651,10 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
jo . put ( "inspector" , detaildto . getInspector ( ) ) ;
jo . put ( "inspector" , detaildto . getInspector ( ) ) ;
jo . put ( "mg_weight" , detaildto . getMg_weight ( ) ) ;
jo . put ( "mg_weight" , detaildto . getMg_weight ( ) ) ;
//打印纸张大小
//打印纸张大小
//1cm = 118px
jo . put ( "page_length" , "500" ) ;
jo . put ( "page_length" , 590 ) ;
jo . put ( "page_height" , "400" ) ;
jo . put ( "page_height" , 472 ) ;
jo . put ( "labeling_template" , detaildto . getLabeling_template ( ) ) ;
print ( jo ) ;
print ( jo ) ;
}
}
@ -1000,81 +1008,117 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
@Override
@Override
public Boolean print ( JSONObject whereJson ) {
public Boolean print ( JSONObject whereJson ) {
String order_id = whereJson . getString ( "order_id" ) ;
// String order_id = whereJson.getString("order_id");
String template_id = whereJson . getString ( "template_id" ) ;
// String template_id = whereJson.getString("template_id");
//
WQLObject mst = WQLObject . getWQLObject ( "acs_produceshiftorder" ) ; // 主表
// WQLObject mst = WQLObject.getWQLObject("acs_produceshiftorder"); // 主表
//
// 1.根据明细找主表
// // 1.根据明细找主表
JSONObject jsonMst = mst . query ( "order_id = '" + order_id + "' and is_deleted ='0'" ) . uniqueResult ( 0 ) ;
// JSONObject jsonMst = mst.query("order_id = '" + order_id + "' and is_deleted ='0'").uniqueResult(0);
//
// 2.根据明细template_id 找到对应的模板
// // 2.根据明细template_id 找到对应的模板
JSONObject jsonStor = WQL . getWO ( "QPRODUCESHIFTORDER" ) . addParam ( "flag" , "3" ) . addParam ( "storage_id" , template_id ) . process ( ) . uniqueResult ( 0 ) ;
// 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 url = acsConfigService . findConfigFromCache ( ) . get ( AcsConfig . PRINTURL ) ;
String path = jsonStor . getString ( "path" ) ;
String printName = acsConfigService . findConfigFromCache ( ) . get ( AcsConfig . PRINTNAME ) ;
String pathName = whereJson . getString ( "url" ) ;
String labeling_template = whereJson . get ( "labeling_template" ) . toString ( ) ;
ExcelWriter workBook = EasyExcel . write ( pathName ) . withTemplate ( path ) . build ( ) ;
String alloy = whereJson . getString ( "alloy" ) ;
// 获取第一个sheet
String temper = whereJson . getString ( "temper" ) ;
WriteSheet sheet = EasyExcel . writerSheet ( ) . build ( ) ;
String material_spec = whereJson . getString ( "material_spec" ) ;
String number = whereJson . getString ( "number" ) ;
// 4.将主表当中的属性填充到excel当中
String outer_diameter = whereJson . getString ( "outer_diameter" ) ;
HashMap < String , String > map = new HashMap < > ( ) ;
String standard = whereJson . getString ( "standard" ) ;
map . put ( "alloy" , whereJson . getString ( "alloy" ) ) ;
String batch = whereJson . getString ( "batch" ) ;
map . put ( "temper" , whereJson . getString ( "temper" ) ) ;
String prod_date = whereJson . getString ( "prod_date" ) ;
map . put ( "material_spec" , whereJson . getString ( "material_spec" ) ) ;
String present_strap_pack_number = whereJson . getString ( "present_strap_pack_number" ) ;
map . put ( "number" , whereJson . getString ( "number" ) ) ;
String inspector = whereJson . getString ( "inspector" ) ;
map . put ( "outer_diameter" , whereJson . getString ( "outer_diameter" ) ) ;
String mg_weight = whereJson . getString ( "mg_weight" ) ;
map . put ( "standard" , whereJson . getString ( "standard" ) ) ;
Process printProcess ;
map . put ( "batch" , whereJson . getString ( "batch" ) ) ;
try
map . put ( "prod_date" , whereJson . getString ( "prod_date" ) ) ;
{
map . put ( "present_strap_pack_number" , whereJson . getString ( "present_strap_pack_number" ) ) ;
printProcess = Runtime
map . put ( "inspector" , whereJson . getString ( "inspector" ) ) ;
. getRuntime ( )
map . put ( "mg_weight" , whereJson . getString ( "mg_weight" ) ) ;
. exec ( new String [ ] {
workBook . fill ( map , sheet ) ;
url ,
workBook . finish ( ) ;
"PrinterName=" + printName ,
"LabelName=Label" + labeling_template + ".ct" ,
Book book = new Book ( ) ;
"alloy=" + alloy , "temper=" + temper , "size=" + material_spec , "pcs=" + number , "outer_diameter=" + outer_diameter ,
Workbook loDoc = new Workbook ( ) ;
"standard=" + standard , "batch=" + batch , "prod_date=" + prod_date , "present_strap_pack_number=" + present_strap_pack_number ,
loDoc . loadFromFile ( pathName ) ;
"inspector=" + inspector , "mg_weight=" + mg_weight } ) ;
Worksheet worksheet = loDoc . getWorksheets ( ) . get ( 0 ) ;
}
PageSetup pageSetup = worksheet . getPageSetup ( ) ;
catch ( Exception e )
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 ) {
e . printStackTrace ( ) ;
e . printStackTrace ( ) ;
return false ;
System . out . println ( "aaa" ) ;
}
}
return true ;
return true ;
}
}