From 486e0582e486714a3833198cf425ef054a539f22 Mon Sep 17 00:00:00 2001 From: liuxy Date: Mon, 25 Jul 2022 17:11:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/DevicerepairmstController.java | 11 ++ .../service/DevicerepairmstService.java | 1 + .../impl/DevicerepairmstServiceImpl.java | 78 ++++++++ .../sb/repair/wql/EM_BI_DEVICEREPAIR002.wql | 79 ++++++++ .../rest/DevicemaintenancemstController.java | 10 + .../service/DevicemaintenancemstService.java | 6 + .../impl/DevicemaintenancemstServiceImpl.java | 187 +++++++++++++----- .../wql/EM_BIDEVICEMAINTENANCEPLAN002.wql | 80 ++++++++ .../wms/sb/repair/devicerepairudit/index.vue | 22 +++ .../wms/sb/upkeep/devicemaintenance/index.vue | 22 +++ 10 files changed, 445 insertions(+), 51 deletions(-) create mode 100644 mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/wql/EM_BI_DEVICEREPAIR002.wql create mode 100644 mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/wql/EM_BIDEVICEMAINTENANCEPLAN002.wql diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/rest/DevicerepairmstController.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/rest/DevicerepairmstController.java index 8c1168fb..b3986064 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/rest/DevicerepairmstController.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/rest/DevicerepairmstController.java @@ -19,6 +19,8 @@ import java.util.Map; import lombok.extern.slf4j.Slf4j; +import javax.servlet.http.HttpServletResponse; + /** * @author Liuxy * @date 2022-06-22 @@ -190,4 +192,13 @@ public class DevicerepairmstController { devicerepairmstService.submitReceive(whereJson); return new ResponseEntity<>(HttpStatus.OK); } + + @GetMapping("/createExcel") + @Log("下载Excel") + @ApiOperation("下载Excel") + public ResponseEntity createExcel(@RequestParam Map whereJson, HttpServletResponse response) { + devicerepairmstService.createExcel(whereJson,response); + return new ResponseEntity<>(HttpStatus.OK); + } + } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/DevicerepairmstService.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/DevicerepairmstService.java index 71c3b98e..c994a32c 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/DevicerepairmstService.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/DevicerepairmstService.java @@ -182,4 +182,5 @@ public interface DevicerepairmstService { Map queryBom(Map whereJson, Pageable page); + void createExcel(Map whereJson, HttpServletResponse response); } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/impl/DevicerepairmstServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/impl/DevicerepairmstServiceImpl.java index b017c2a4..a1e9c88a 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/impl/DevicerepairmstServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/service/impl/DevicerepairmstServiceImpl.java @@ -4,11 +4,17 @@ package org.nl.wms.sb.repair.service.impl; import cn.hutool.core.map.MapUtil; 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.excel.write.metadata.fill.FillWrapper; import com.alibaba.fastjson.JSON; import lombok.RequiredArgsConstructor; import org.nl.exception.BadRequestException; import org.nl.modules.security.service.dto.JwtUserDto; +import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.system.util.CodeUtil; +import org.nl.utils.SpringContextHolder; import org.nl.wms.basedata.master.service.ClassstandardService; import org.nl.wms.basedata.st.service.StorattrService; import org.nl.wms.basedata.st.service.dto.StorattrDto; @@ -17,6 +23,7 @@ import org.nl.wms.sb.core.service.impl.SparePartInServiceImpl; import org.nl.wms.sb.core.service.impl.SparePartOutServiceImpl; import org.nl.wms.sb.repair.service.DevicerepairmstService; import org.nl.wms.sb.repair.service.dto.DevicerepairmstDto; +import org.nl.wms.test.service.dto.DataDto; import org.nl.wql.WQL; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -24,6 +31,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Pageable; +import java.net.URLEncoder; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -39,6 +48,9 @@ import org.nl.wql.util.WqlUtil; import lombok.extern.slf4j.Slf4j; import cn.hutool.core.util.ObjectUtil; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + /** * @author Liuxy * @description 服务实现 @@ -803,4 +815,70 @@ public class DevicerepairmstServiceImpl implements DevicerepairmstService { return jsonObject; } + @Override + public void createExcel(Map whereJson, HttpServletResponse response) { + String repair_id = MapUtil.getStr(whereJson,"repair_id"); + WQLObject reMstTab = WQLObject.getWQLObject("EM_BI_DeviceRepairMst"); // 维修单主表 + + try { + JSONObject jsonReMst = reMstTab.query("repair_id = '" + repair_id + "'").uniqueResult(0); + + HashMap param1 = new HashMap<>(); + param1.put("flag", "1"); + param1.put("devicerecord_id", jsonReMst.getString("devicerecord_id")); + + JSONObject jsonFile = WQL.getWO("EM_BI_DEVICEREPAIR002").addParamMap(param1).process().uniqueResult(0); + + String template = SpringContextHolder.getBean(ParamServiceImpl.class).findByCode("REQUEST_EXCEL_PATH").getValue(); + // 设置文件名和防止乱码现象 + String fileName = URLEncoder.encode("eee", "UTF-8"); + response.setHeader("Content-Disposition", "attachment; filename*=UTf-8''"+fileName+".xlsx"); + // 获取输出流 + ServletOutputStream outputStream = response.getOutputStream(); + // 创建模板工作簿 + ExcelWriter workBook = EasyExcel.write(outputStream, DataDto.class).withTemplate(template).build(); + // 获取第一个sheet + WriteSheet sheet = EasyExcel.writerSheet().build(); + + // 1.准备数据 - 单组填充 + HashMap map = new HashMap<>(); + if (ObjectUtil.isNotEmpty(jsonFile)) { + map.put("dept_name", jsonFile.getString("dept_name")); // 部门 + map.put("device_name", jsonFile.getString("device_name")); // 设备名称 + } + map.put("input_time", jsonReMst.getString("input_time").substring(0,10)); // 故障发生时间 + map.put("plan_start_date", jsonReMst.getString("plan_start_date")); // 计划维修时间 + map.put("real_start_date", jsonReMst.getString("real_start_date").substring(0,10)); // 实际维修时间 + // 维修内容 + map.put("update_optname", jsonReMst.getString("update_optname")); // 维修人员 + map.put("real_end_date", jsonReMst.getString("real_end_date").substring(0,10)); // 完工时间 + + // 2.准备数据 - 多组填充 + HashMap param2 = new HashMap<>(); + param2.put("flag","2"); + param2.put("repair_id",repair_id); + JSONArray changArr = WQL.getWO("EM_BI_DEVICEREPAIR002").addParamMap(param2).process().getResultJSONArray(0); + + ArrayList> data = new ArrayList<>(); + if (ObjectUtil.isNotEmpty(changArr)) { + for (int i = 0; i < changArr.size(); i++) { + JSONObject json = changArr.getJSONObject(i); + HashMap mapData = new HashMap<>(); + mapData.put("material_name",json.getString("material_name")); // 配件名称 + mapData.put("real_qty",json.getString("real_qty")); // 配件数量 + data.add(mapData); + } + } + // 下载 + workBook.fill(map, sheet); + workBook.fill(new FillWrapper("data", data), sheet); + workBook.finish(); + } catch (Exception e) { + System.out.println(e.getMessage()); + throw new BadRequestException("下载异常"); + } + + + } + } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/wql/EM_BI_DEVICEREPAIR002.wql b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/wql/EM_BI_DEVICEREPAIR002.wql new file mode 100644 index 00000000..60117442 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/repair/wql/EM_BI_DEVICEREPAIR002.wql @@ -0,0 +1,79 @@ +[交易说明] + 交易名: 维修单维护-Excel + 所属模块: + 功能简述: + 版权所有: + 表引用: + 版本经历: + +[数据库] + --指定数据库,为空采用默认值,默认为db.properties中列出的第一个库 + +[IO定义] + ################################################# + ## 表字段对应输入参数 + ################################################# + 输入.flag TYPEAS s_string + 输入.devicerecord_id TYPEAS s_string + 输入.repair_id TYPEAS s_string + + +[临时表] + --这边列出来的临时表就会在运行期动态创建 + +[临时变量] + --所有中间过程变量均可在此处定义 + +[业务过程] + + ########################################## + # 1、输入输出检查 # + ########################################## + + + ########################################## + # 2、主过程前处理 # + ########################################## + + + ########################################## + # 3、业务主过程 # + ########################################## + + IF 输入.flag = "1" + QUERY + SELECT + file.*, + dept.name AS dept_name + FROM + EM_BI_EquipmentFile file + LEFT JOIN sys_dept dept ON file.use_groupid = dept.dept_id + WHERE + file.is_delete = '0' + + OPTION 输入.devicerecord_id <> "" + file.devicerecord_id = 输入.devicerecord_id + ENDOPTION + + ENDSELECT + ENDQUERY + ENDIF + + IF 输入.flag = "2" + QUERY + SELECT + recourd.*, + mater.material_name + FROM + EM_BI_DeviceRepairReplaceRecord recourd + LEFT JOIN md_me_materialbase mater ON recourd.material_id = mater.material_id + WHERE + 1=1 + + OPTION 输入.repair_id <> "" + recourd.repair_id = 输入.repair_id + ENDOPTION + + ENDSELECT + ENDQUERY + ENDIF \ No newline at end of file diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/rest/DevicemaintenancemstController.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/rest/DevicemaintenancemstController.java index e58eda49..76dbc493 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/rest/DevicemaintenancemstController.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/rest/DevicemaintenancemstController.java @@ -19,6 +19,8 @@ import java.util.Map; import lombok.extern.slf4j.Slf4j; +import javax.servlet.http.HttpServletResponse; + /** * @author Liuxy * @date 2022-06-17 @@ -129,4 +131,12 @@ public class DevicemaintenancemstController { devicemaintenancemstService.auditMaintain(whereJson); return new ResponseEntity<>(HttpStatus.OK); } + + @GetMapping("/createExcel") + @Log("下载Excel") + @ApiOperation("下载Excel") + public ResponseEntity createExcel(@RequestParam Map whereJson, HttpServletResponse response) { + devicemaintenancemstService.createExcel(whereJson,response); + return new ResponseEntity<>(HttpStatus.OK); + } } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/DevicemaintenancemstService.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/DevicemaintenancemstService.java index fd702010..ed9e271e 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/DevicemaintenancemstService.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/DevicemaintenancemstService.java @@ -131,4 +131,10 @@ public interface DevicemaintenancemstService { */ void auditMaintain(JSONObject whereJson); + /** + * 下载excel + * + * @param whereJson / + */ + void createExcel(Map whereJson, HttpServletResponse response); } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/impl/DevicemaintenancemstServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/impl/DevicemaintenancemstServiceImpl.java index 1d4cda8b..8c8f3e31 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/impl/DevicemaintenancemstServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/service/impl/DevicemaintenancemstServiceImpl.java @@ -4,20 +4,29 @@ package org.nl.wms.sb.upkeep.service.impl; import cn.hutool.core.map.MapUtil; 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.excel.write.metadata.fill.FillWrapper; import com.alibaba.fastjson.JSON; import lombok.RequiredArgsConstructor; import org.nl.exception.BadRequestException; import org.nl.modules.security.service.dto.JwtUserDto; +import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.system.util.CodeUtil; +import org.nl.utils.SpringContextHolder; import org.nl.wms.basedata.master.service.ClassstandardService; import org.nl.wms.sb.upkeep.service.DevicemaintenancemstService; import org.nl.wms.sb.upkeep.service.dto.DevicemaintenancemstDto; +import org.nl.wms.test.service.dto.DataDto; import org.nl.wql.WQL; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Pageable; +import java.net.URLEncoder; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,6 +42,9 @@ import org.nl.wql.util.WqlUtil; import lombok.extern.slf4j.Slf4j; import cn.hutool.core.util.ObjectUtil; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + /** * @author Liuxy * @description 服务实现 @@ -57,12 +69,12 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ HashMap map = new HashMap<>(); map.put("flag", "1"); - map.put("maintenancecycle",maintenancecycle); - map.put("invstatus",invstatus); + map.put("maintenancecycle", maintenancecycle); + map.put("invstatus", invstatus); map.put("begin_time", begin_time); map.put("end_time", end_time); - if (ObjectUtil.isNotEmpty(device_code)) map.put("device_code","%"+device_code+"%"); - if (ObjectUtil.isNotEmpty(maint_code)) map.put("maint_code","%"+maint_code+"%"); + if (ObjectUtil.isNotEmpty(device_code)) map.put("device_code", "%" + device_code + "%"); + if (ObjectUtil.isNotEmpty(maint_code)) map.put("maint_code", "%" + maint_code + "%"); //处理物料当前节点的所有子节点 if (!StrUtil.isEmpty(material_type_id)) { map.put("material_type_id", material_type_id); @@ -89,12 +101,12 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ HashMap map = new HashMap<>(); map.put("flag", "3"); - map.put("maintenancecycle",maintenancecycle); - map.put("invstatus",invstatus); + map.put("maintenancecycle", maintenancecycle); + map.put("invstatus", invstatus); map.put("begin_time", begin_time); map.put("end_time", end_time); - if (ObjectUtil.isNotEmpty(device_code)) map.put("device_code","%"+device_code+"%"); - if (ObjectUtil.isNotEmpty(maint_code)) map.put("maint_code","%"+maint_code+"%"); + if (ObjectUtil.isNotEmpty(device_code)) map.put("device_code", "%" + device_code + "%"); + if (ObjectUtil.isNotEmpty(maint_code)) map.put("maint_code", "%" + maint_code + "%"); //处理物料当前节点的所有子节点 if (!StrUtil.isEmpty(material_type_id)) { map.put("material_type_id", material_type_id); @@ -151,25 +163,25 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ // 插入主表 JSONObject jsonMst = new JSONObject(); - jsonMst.put("maint_id", IdUtil.getSnowflake(1,1).nextId()); + jsonMst.put("maint_id", IdUtil.getSnowflake(1, 1).nextId()); jsonMst.put("maint_code", CodeUtil.getNewCode("MAINT_CODE")); jsonMst.put("devicerecord_id", whereJson.get("devicerecord_id")); jsonMst.put("maintenancecycle", whereJson.getString("maintenancecycle")); jsonMst.put("invstatus", "01"); jsonMst.put("plan_start_date", whereJson.getString("plan_start_date")); - jsonMst.put("detail_count",tableData.size()); - jsonMst.put("input_optid",currentUserId); - jsonMst.put("input_optname",nickName); - jsonMst.put("input_time",now); - jsonMst.put("sysdeptid",deptId); - jsonMst.put("syscompanyid",deptId); + jsonMst.put("detail_count", tableData.size()); + jsonMst.put("input_optid", currentUserId); + jsonMst.put("input_optname", nickName); + jsonMst.put("input_time", now); + jsonMst.put("sysdeptid", deptId); + jsonMst.put("syscompanyid", deptId); mstTab.insert(jsonMst); // 插入明细表 for (int i = 0; i < tableData.size(); i++) { JSONObject json = tableData.getJSONObject(i); JSONObject jsonDtl = new JSONObject(); - jsonDtl.put("maint_dtl_id", IdUtil.getSnowflake(1,1).nextId()); + jsonDtl.put("maint_dtl_id", IdUtil.getSnowflake(1, 1).nextId()); jsonDtl.put("maint_id", jsonMst.get("maint_id")); jsonDtl.put("device_item_id", json.get("maint_item_id")); jsonDtl.put("dtl_remark", json.getString("dtl_remark")); @@ -191,15 +203,15 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ jsonMst.put("devicerecord_id", whereJson.get("devicerecord_id")); jsonMst.put("maintenancecycle", whereJson.getString("maintenancecycle")); jsonMst.put("plan_start_date", whereJson.getString("plan_start_date")); - jsonMst.put("detail_count",tableData.size()); + jsonMst.put("detail_count", tableData.size()); mstTab.update(jsonMst); // 插入明细表 - dtlTab.delete("maint_id = '"+whereJson.getString("maint_id")+"'"); + dtlTab.delete("maint_id = '" + whereJson.getString("maint_id") + "'"); for (int i = 0; i < tableData.size(); i++) { JSONObject json = tableData.getJSONObject(i); JSONObject jsonDtl = new JSONObject(); - jsonDtl.put("maint_dtl_id", IdUtil.getSnowflake(1,1).nextId()); + jsonDtl.put("maint_dtl_id", IdUtil.getSnowflake(1, 1).nextId()); jsonDtl.put("maint_id", jsonMst.get("maint_id")); jsonDtl.put("device_item_id", json.get("maint_item_id")); jsonDtl.put("dtl_remark", json.getString("dtl_remark")); @@ -269,19 +281,19 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ // 插入设备声明周期表 JSONObject jsonLife = new JSONObject(); - jsonLife.put("devicechangedtl_id", IdUtil.getSnowflake(1,1).nextId()); - jsonLife.put("devicerecord_id",jsonMainMst.get("devicerecord_id")); - jsonLife.put("changetype","20"); - jsonLife.put("change_id",currentUserId); - jsonLife.put("change_name",nickName); - jsonLife.put("change_time",DateUtil.now()); - jsonLife.put("change_reason","保养开始"); - jsonLife.put("invtype","保养单"); - jsonLife.put("invsid",jsonMainMst.get("maint_id")); - jsonLife.put("invcode",jsonMainMst.getString("maint_code")); - jsonLife.put("create_id",currentUserId); - jsonLife.put("create_name",nickName); - jsonLife.put("create_time",DateUtil.now()); + jsonLife.put("devicechangedtl_id", IdUtil.getSnowflake(1, 1).nextId()); + jsonLife.put("devicerecord_id", jsonMainMst.get("devicerecord_id")); + jsonLife.put("changetype", "20"); + jsonLife.put("change_id", currentUserId); + jsonLife.put("change_name", nickName); + jsonLife.put("change_time", DateUtil.now()); + jsonLife.put("change_reason", "保养开始"); + jsonLife.put("invtype", "保养单"); + jsonLife.put("invsid", jsonMainMst.get("maint_id")); + jsonLife.put("invcode", jsonMainMst.getString("maint_code")); + jsonLife.put("create_id", currentUserId); + jsonLife.put("create_name", nickName); + jsonLife.put("create_time", DateUtil.now()); lifeTab.insert(jsonLife); // 根据来源标识 : 为空不处理、否则更新设备保养计划表 @@ -328,18 +340,18 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ // 插入设备声明周期表 JSONObject jsonLife = new JSONObject(); - jsonLife.put("devicechangedtl_id", IdUtil.getSnowflake(1,1).nextId()); - jsonLife.put("devicerecord_id",jsonMainMst.get("devicerecord_id")); - jsonLife.put("changetype","21"); - jsonLife.put("change_id",currentUserId); - jsonLife.put("change_name",nickName); - jsonLife.put("change_time",DateUtil.now()); - jsonLife.put("change_reason","保养结束"); - jsonLife.put("invsid",jsonMainMst.get("maint_id")); - jsonLife.put("invcode",jsonMainMst.getString("maint_code")); - jsonLife.put("create_id",currentUserId); - jsonLife.put("create_name",nickName); - jsonLife.put("create_time",DateUtil.now()); + jsonLife.put("devicechangedtl_id", IdUtil.getSnowflake(1, 1).nextId()); + jsonLife.put("devicerecord_id", jsonMainMst.get("devicerecord_id")); + jsonLife.put("changetype", "21"); + jsonLife.put("change_id", currentUserId); + jsonLife.put("change_name", nickName); + jsonLife.put("change_time", DateUtil.now()); + jsonLife.put("change_reason", "保养结束"); + jsonLife.put("invsid", jsonMainMst.get("maint_id")); + jsonLife.put("invcode", jsonMainMst.getString("maint_code")); + jsonLife.put("create_id", currentUserId); + jsonLife.put("create_name", nickName); + jsonLife.put("create_time", DateUtil.now()); lifeTab.insert(jsonLife); } @@ -356,15 +368,15 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ // 更新主表 JSONObject jsonMst = mstTab.query("maint_id ='" + maint_id + "'").uniqueResult(0); - jsonMst.put("update_optname",whereJson.getString("update_optname")); - jsonMst.put("update_time",DateUtil.now()); + jsonMst.put("update_optname", whereJson.getString("update_optname")); + jsonMst.put("update_time", DateUtil.now()); mstTab.update(jsonMst); // 更新明细表 for (int i = 0; i < tableData.size(); i++) { JSONObject json = tableData.getJSONObject(i); JSONObject jsonDtl = dtlTab.query("maint_dtl_id = '" + json.getString("maint_dtl_id") + "'").uniqueResult(0); - jsonDtl.put("isfinish",json.getString("isfinish")); + jsonDtl.put("isfinish", json.getString("isfinish")); dtlTab.update(jsonDtl); } } @@ -391,7 +403,8 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ // 2.保养人,保养时间不能为空 String update_optname = jsonMst.getString("update_optname"); String update_time = jsonMst.getString("update_time"); - if (ObjectUtil.isEmpty(update_optname) || ObjectUtil.isEmpty(update_time)) throw new BadRequestException("保养人或保养时间不能为空"); + if (ObjectUtil.isEmpty(update_optname) || ObjectUtil.isEmpty(update_time)) + throw new BadRequestException("保养人或保养时间不能为空"); // 3.更新主表 jsonMst.put("invstatus", "05"); @@ -414,9 +427,9 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ // 1.更新主表 JSONObject jsonMst = mstTab.query("maint_id = '" + maint_id + "'").uniqueResult(0); jsonMst.put("invstatus", "99"); - jsonMst.put("audit_optid",currentUserId); - jsonMst.put("audit_optname",nickName); - jsonMst.put("audit_time",DateUtil.now()); + jsonMst.put("audit_optid", currentUserId); + jsonMst.put("audit_optname", nickName); + jsonMst.put("audit_time", DateUtil.now()); mstTab.update(jsonMst); // 2.根据来源标识 : 为空不处理、否则更新设备保养计划表 @@ -434,4 +447,76 @@ public class DevicemaintenancemstServiceImpl implements DevicemaintenancemstServ } } + @Override + @Transactional(rollbackFor = Exception.class) + public void createExcel(Map whereJson, HttpServletResponse response) { + + String maint_id = MapUtil.getStr(whereJson, "maint_id"); + WQLObject mainMstTab = WQLObject.getWQLObject("EM_BI_DeviceMaintenanceMst"); // 设备保养主表 + try { + + JSONObject jsonMainMst = mainMstTab.query("maint_id ='" + maint_id + "'").uniqueResult(0); + + HashMap paramMap1 = new HashMap<>(); + paramMap1.put("flag", "1"); + paramMap1.put("devicerecord_id", jsonMainMst.getString("devicerecord_id")); + + JSONObject jsonFile = WQL.getWO("EM_BIDEVICEMAINTENANCEPLAN002").addParamMap(paramMap1).process().uniqueResult(0); + + String template = SpringContextHolder.getBean(ParamServiceImpl.class).findByCode("MAIN_EXCEL_PATH").getValue(); + // 设置文件名和防止乱码现象 + String fileName = URLEncoder.encode("eee", "UTF-8"); + response.setHeader("Content-Disposition", "attachment; filename*=UTf-8''" + fileName + ".xlsx"); + // 获取输出流 + ServletOutputStream outputStream = response.getOutputStream(); + // 创建模板工作簿 + ExcelWriter workBook = EasyExcel.write(outputStream, DataDto.class).withTemplate(template).build(); + // 获取第一个sheet + WriteSheet sheet = EasyExcel.writerSheet().build(); + + // 1.准备数据 - 单组填充 + HashMap sheetMap = new HashMap<>(); + sheetMap.put("input_time", jsonMainMst.getString("input_time").substring(0, 10)); // 时间 + sheetMap.put("plan_start_date", jsonMainMst.getString("plan_start_date")); // 计划日期 + if (ObjectUtil.isNotEmpty(jsonFile)) { + sheetMap.put("device_name", jsonFile.getString("device_name")); // 设备名称 + sheetMap.put("leavefactory_number", jsonFile.getString("leavefactory_number")); // 出厂编号 + sheetMap.put("device_model", jsonFile.getString("device_model")); // 型号 + sheetMap.put("dept_name", jsonFile.getString("dept_name")); // 班组 + } + + // 2.准备数据 - 多组填充 + HashMap paramMap2 = new HashMap<>(); + paramMap2.put("flag", "2"); + paramMap2.put("maint_id", maint_id); + + JSONArray jsonMainDtlArr = WQL.getWO("EM_BIDEVICEMAINTENANCEPLAN002").addParamMap(paramMap2).process().getResultJSONArray(0); + ArrayList> data1 = new ArrayList<>(); + ArrayList> data2 = new ArrayList<>(); + + if (ObjectUtil.isNotEmpty(jsonMainDtlArr)) { + for (int i = 0; i < jsonMainDtlArr.size(); i++) { + JSONObject json = jsonMainDtlArr.getJSONObject(i); + HashMap dataMap1 = new HashMap<>(); + HashMap dataMap2 = new HashMap<>(); + dataMap1.put("requirement", String.valueOf(i+1) + "." + json.getString("requirement")); + dataMap2.put("acceptancecriteria", String.valueOf(i+1) + "." + json.getString("acceptancecriteria")); + data1.add(dataMap1); + data2.add(dataMap2); + } + } + + // 下载 + workBook.fill(sheetMap, sheet); + workBook.fill(new FillWrapper("data1", data1), sheet); + workBook.fill(new FillWrapper("data2", data2), sheet); + workBook.finish(); + + } catch (Exception e) { + System.out.println(e.getMessage()); + throw new BadRequestException("下载异常"); + } + + } + } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/wql/EM_BIDEVICEMAINTENANCEPLAN002.wql b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/wql/EM_BIDEVICEMAINTENANCEPLAN002.wql new file mode 100644 index 00000000..ca2f03c0 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sb/upkeep/wql/EM_BIDEVICEMAINTENANCEPLAN002.wql @@ -0,0 +1,80 @@ +[交易说明] + 交易名: 设备保养EXCEL + 所属模块: + 功能简述: + 版权所有: + 表引用: + 版本经历: + +[数据库] + --指定数据库,为空采用默认值,默认为db.properties中列出的第一个库 + +[IO定义] + ################################################# + ## 表字段对应输入参数 + ################################################# + 输入.flag TYPEAS s_string + 输入.devicerecord_id TYPEAS s_string + 输入.maint_id TYPEAS s_string + + +[临时表] + --这边列出来的临时表就会在运行期动态创建 + +[临时变量] + --所有中间过程变量均可在此处定义 + +[业务过程] + + ########################################## + # 1、输入输出检查 # + ########################################## + + + ########################################## + # 2、主过程前处理 # + ########################################## + + + ########################################## + # 3、业务主过程 # + ########################################## + + IF 输入.flag = "1" + QUERY + SELECT + file.*, + dept.name AS dept_name + FROM + EM_BI_EquipmentFile file + LEFT JOIN sys_dept dept ON file.use_groupid = dept.dept_id + WHERE + file.is_delete = '0' + + OPTION 输入.devicerecord_id <> "" + file.devicerecord_id = 输入.devicerecord_id + ENDOPTION + + ENDSELECT + ENDQUERY + ENDIF + + IF 输入.flag = "2" + QUERY + SELECT + dtl.*, + item.requirement, + item.acceptancecriteria + FROM + EM_BI_DeviceMaintenanceDtl dtl + LEFT JOIN EM_BI_DeviceMaintenanceItems item ON dtl.device_item_id = item.maint_item_id + WHERE + 1=1 + + OPTION 输入.maint_id <> "" + dtl.maint_id = 输入.maint_id + ENDOPTION + + ENDSELECT + ENDQUERY + ENDIF \ No newline at end of file diff --git a/mes/qd/src/views/wms/sb/repair/devicerepairudit/index.vue b/mes/qd/src/views/wms/sb/repair/devicerepairudit/index.vue index 7efcdf77..a375d8ae 100644 --- a/mes/qd/src/views/wms/sb/repair/devicerepairudit/index.vue +++ b/mes/qd/src/views/wms/sb/repair/devicerepairudit/index.vue @@ -100,6 +100,17 @@ > 维修结果 + + 生成派工单 + @@ -152,6 +163,8 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css' import crudMaterialbase from '@/api/wms/basedata/master/materialbase' import resuftDialog from '@/views/wms/sb/repair/devicerepairudit/resuftDialog' import ReceiveDialog from '@/views/wms/sb/repair/devicerepairudit/ReceiveDialog' +import {download} from "@/api/data"; +import {downloadFile} from "@/utils"; export default { name: 'Devicerepairudit', @@ -270,6 +283,15 @@ export default { } this.receiveDialog = true }) + }, + createExcel() { + const _selectData = this.$refs.table.selection + const data = _selectData[0] + download('api/devicerepairmst/createExcel', { 'repair_id': data.repair_id }).then(result => { + const name = data.repair_code + '派工单' + this.crud.toQuery() + downloadFile(result, name, 'xlsx') + }) } } } diff --git a/mes/qd/src/views/wms/sb/upkeep/devicemaintenance/index.vue b/mes/qd/src/views/wms/sb/upkeep/devicemaintenance/index.vue index 94c01d48..e8013a46 100644 --- a/mes/qd/src/views/wms/sb/upkeep/devicemaintenance/index.vue +++ b/mes/qd/src/views/wms/sb/upkeep/devicemaintenance/index.vue @@ -89,6 +89,17 @@ > 提交 + + 生成设备保养 + @@ -140,6 +151,8 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css' import crudMaterialbase from '@/api/wms/basedata/master/materialbase' import DateRangePicker from '@/components/DateRangePicker' import AddDialog from '@/views/wms/sb/upkeep/devicemaintenance/AddDialog' +import {download} from "@/api/data"; +import {downloadFile} from "@/utils"; export default { name: 'Devicemaintenance', @@ -234,6 +247,15 @@ export default { return obj }) }) + }, + createExcel() { + const _selectData = this.$refs.table.selection + const data = _selectData[0] + download('api/devicemaintenancemst/createExcel', { 'maint_id': data.maint_id }).then(result => { + const name = data.maint_code + '保养工单' + this.crud.toQuery() + downloadFile(result, name, 'xlsx') + }) } } }