diff --git a/nladmin-system/pom.xml b/nladmin-system/pom.xml index 2419605..5aba8f1 100644 --- a/nladmin-system/pom.xml +++ b/nladmin-system/pom.xml @@ -26,6 +26,13 @@ 6.6 + + + e-iceblue + spire.xls + 3.11.2 + + org.mongodb mongo-java-driver diff --git a/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java b/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java index fb1221b..7b15465 100644 --- a/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java +++ b/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java @@ -2,17 +2,25 @@ package org.nl.acs.order.rest; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.order.service.ProduceshiftorderService; import org.nl.annotation.Log; +import org.nl.domain.LocalStorage; +import org.nl.exception.BadRequestException; +import org.nl.service.LocalStorageService; +import org.nl.utils.SecurityUtils; +import org.nl.wql.core.bean.WQLObject; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -30,6 +38,8 @@ import java.util.Map; public class ProduceshiftorderController { private final ProduceshiftorderService produceshiftorderService; + private final LocalStorageService localStorageService; + @GetMapping @Log("查询工单") @@ -185,6 +195,22 @@ public class ProduceshiftorderController { return new ResponseEntity<>(produceshiftorderService.selectTemplateList(),HttpStatus.OK); } + @Log("上传Excel模板") + @ApiOperation("上传Excel模板") + @PostMapping({"/pictures"}) + public ResponseEntity uploadTemplate(@RequestParam MultipartFile file) { + LocalStorage localStorage = this.localStorageService.create((String) null, file); + return new ResponseEntity<>(localStorage,HttpStatus.OK); + } + + @Log("打印") + @ApiOperation("打印") + @PostMapping("/print") + public ResponseEntity print(@RequestBody JSONObject whereJson) { + produceshiftorderService.print(whereJson); + return new ResponseEntity<>(HttpStatus.OK); + } + } diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java b/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java index 5669204..9cc7657 100644 --- a/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java @@ -2,6 +2,7 @@ package org.nl.acs.order.service; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.nl.acs.order.service.dto.ProduceshiftorderDto; import org.springframework.data.domain.Pageable; @@ -227,4 +228,9 @@ public interface ProduceshiftorderService { */ JSONArray selectTemplateList(); + /** + * 打印 + * @param whereJson + */ + void print(JSONObject whereJson); } diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderdetailDto.java b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderdetailDto.java index 4e7681d..e9c2286 100644 --- a/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderdetailDto.java +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderdetailDto.java @@ -214,4 +214,7 @@ public class ProduceshiftorderdetailDto implements Serializable { /** 结束时间 */ private String end_time; + + /** 模板id */ + private String template_id; } diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java index e2a2e1b..fa26716 100644 --- a/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java @@ -6,9 +6,12 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.spire.xls.Workbook; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.device_driver.hailiang.hailiang_feeding_trunk.HaiLiangFeedingTrunkDeviceDriver; @@ -33,6 +36,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; +import java.awt.print.PageFormat; +import java.awt.print.Paper; +import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; import java.io.IOException; import java.util.*; @@ -417,6 +424,8 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A String labeling_template = jsonObject.getString("labeling_template"); //优先级 String priority = jsonObject.getString("priority"); + //优先级 + String template_id = jsonObject.getString("template_id"); ProduceshiftorderdetailDto detaildto = new ProduceshiftorderdetailDto(); detaildto.setOrder_id(order_id); @@ -442,6 +451,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A detaildto.setLettering_icon(lettering_icon); detaildto.setStrap_number(strap_number); detaildto.setStrap_tailint_number(strap_tailint_number); + detaildto.setTemplate_id(template_id); produceshiftorderdetailService.create(detaildto); } } @@ -860,4 +870,54 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A return result; } + @Override + public void 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); + + // 3.创建模板工作簿 并指定储存路径 + String path = jsonStor.getString("path"); + String pathName = "D:\\work\\"+jsonStor.getString("name")+ jsonStor.getString("storage_id") + ".xlsx"; + ExcelWriter workBook = EasyExcel.write(pathName).withTemplate(path).build(); + // 获取第一个sheet + WriteSheet sheet = EasyExcel.writerSheet().build(); + + // 4.将主表当中的属性填充到excel当中 + HashMap map = new HashMap<>(); + map.put("material_name",jsonMst.getString("material_code")); + map.put("qty",jsonMst.getString("qty")); + map.put("tttt",jsonMst.getString("qty")); + workBook.fill(map, sheet); + workBook.finish(); + + // 5.打印 + Workbook workbook = new Workbook(); + workbook.loadFromFile(pathName); + //创建 PrinterJob对象 + PrinterJob printerJob = PrinterJob.getPrinterJob(); + //指定打印页面为默认大小和方向 + PageFormat pageFormat = printerJob.defaultPage(); + //设置相关打印选项 + Paper paper = pageFormat.getPaper(); + paper.setSize(1240,1754); + paper.setImageableArea(0, 0, 1240, 1754); + pageFormat.setPaper(paper); + printerJob.setCopies(1); + printerJob.setPrintable(workbook, pageFormat); + try { + // 执行打印 + printerJob.print(); + } catch (PrinterException e) { + e.printStackTrace(); + } + } + } \ No newline at end of file diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/QPRODUCESHIFTORDER.wql b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/QPRODUCESHIFTORDER.wql index f2f6cee..5d650c6 100644 --- a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/QPRODUCESHIFTORDER.wql +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/QPRODUCESHIFTORDER.wql @@ -16,6 +16,7 @@ 输入.flag TYPEAS s_string 输入.template_code TYPEAS s_string 输入.template_address TYPEAS s_string + 输入.storage_id TYPEAS s_string [临时表] --这边列出来的临时表就会在运行期动态创建 @@ -68,4 +69,20 @@ ENDPAGEQUERY ENDIF + IF 输入.flag = "3" + QUERY + SELECT + * + FROM + tool_local_storage + WHERE + 1=1 + OPTION 输入.storage_id <> "" + storage_id = 输入.storage_id + ENDOPTION + + ENDSELECT + ENDQUERY + ENDIF + diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls index f34fb47..1abfe24 100644 Binary files a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls and b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls differ diff --git a/qd/src/views/acs/order/AddDialog.vue b/qd/src/views/acs/order/AddDialog.vue index 695413e..a763957 100644 --- a/qd/src/views/acs/order/AddDialog.vue +++ b/qd/src/views/acs/order/AddDialog.vue @@ -157,12 +157,19 @@ - - - - - - + + + + + + + + +