From fea6f098b38159b3aa7717e2a4dd3c14d6ee581c Mon Sep 17 00:00:00 2001 From: erdanergou Date: Mon, 12 Jun 2023 15:29:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E7=89=A9=E6=96=99=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E4=BB=B7=E4=BF=AE=E6=94=B9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ExcelController.java | 23 +++++ .../mapper/MaterialMapper.java | 8 ++ .../mapper/MaterialMapper.xml | 55 ++++++++++++ .../security/pool/ExcelFileInfoPool.java | 84 ++++++++++++++++--- .../service/ExcelService.java | 4 + .../service/impl/ExcelServiceImpl.java | 67 ++++++++++++++- .../pages/material/material-out.html | 33 +++++++- 7 files changed, 259 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java b/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java index c691f4f0..34c36904 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java @@ -38,6 +38,7 @@ public class ExcelController { return excelService.importExcelMaterial(excel,userToken); } + /** * 用于物料类型的导入 * @@ -88,6 +89,28 @@ public class ExcelController { return CrudUtil.insertHandle(1,1); } + /** + * 用于覆盖之前导入的物料数据 + * @param map 覆盖的数据 + * @return + */ + @PostMapping("/overwriteExcelByMaterial") + public RestResponse overwriteExcelByMaterial(@RequestBody Map map,HttpServletRequest request){ + String s = map.get("result"); + String token = request.getHeader("user-token"); + if (token == null) { + token = (String) request.getSession().getAttribute("userToken"); + } + UserByPort userToken = AuthenticationTokenPool.getUserToken(token); + if ("yes".equals(s)) { + excelService.executeOverwriteForMaterial(userToken); + }else{ + excelService.clearImportFileData(userToken); + } + return CrudUtil.updateHandle(1,1); + } + + /** * 用于实际导入物料类型信息 diff --git a/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java b/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java index 528ffed6..ac6e87d1 100644 --- a/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java +++ b/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java @@ -78,6 +78,14 @@ public interface MaterialMapper { */ Integer updateMaterial(Map map); + /** + * 根据条件更改物料信息(用于导入时的重写) + * + * @param map 参数列表 + * @return 受影响的行数 + */ + Integer updateMaterialForImport(Map map); + /** * 更新一条物料信息 * @param material 修改的参数 diff --git a/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml b/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml index d92da8b1..d8d78c83 100644 --- a/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml +++ b/src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml @@ -1154,6 +1154,61 @@ WHERE id = #{id} + + + UPDATE material + + + uid = #{uid}, + + + price = #{price}, + + + + + updateTime = #{updateTime}, + + + + unit = #{unit}, + + + texture = #{texture}, + + + shelfLife = #{shelfLife}, + + + producedDate = #{producedDate}, + + + productionPlace = #{productionPlace}, + + + brand = #{brand}, + + + remark = #{remark} + + + + WHERE + 1 = 1 + + and mname = #{mname} + + + and version = #{version} + + + and version is null + + + and `code` = #{mcode} + + + UPDATE inventory diff --git a/src/main/java/com/dreamchaser/depository_manage/security/pool/ExcelFileInfoPool.java b/src/main/java/com/dreamchaser/depository_manage/security/pool/ExcelFileInfoPool.java index 828db9f0..9f11354b 100644 --- a/src/main/java/com/dreamchaser/depository_manage/security/pool/ExcelFileInfoPool.java +++ b/src/main/java/com/dreamchaser/depository_manage/security/pool/ExcelFileInfoPool.java @@ -4,6 +4,8 @@ import com.dreamchaser.depository_manage.entity.ExcelInfoByInventory; import com.dreamchaser.depository_manage.entity.ExcelInfoByMT; import com.dreamchaser.depository_manage.entity.ExcelInfoForMaterial; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -12,85 +14,145 @@ import java.util.concurrent.ConcurrentHashMap; * 用于设置用户的上传物料信息 */ public class ExcelFileInfoPool { - private static Map> excelVosForInventoryPool = new ConcurrentHashMap<>(1000); - private static Map> excelVosForMaterialTypePool = new ConcurrentHashMap<>(1000); + // 用于存储当前用户导入的库存数据 + private static Map> excelVosForInventoryPool = new ConcurrentHashMap<>(1000); + // 用于存储当前用户导入的物料类型数据 + private static Map> excelVosForMaterialTypePool = new ConcurrentHashMap<>(1000); + // 用于存储当前用户导入的物料数据 private static Map> excelVosForMaterialPool = new ConcurrentHashMap<>(1000); + // 用于存储当前用户导入的物料数据(用于覆盖) + private static Map> excelVosForMaterialPoolByOverwrite = new ConcurrentHashMap<>(1000); /** * 用于暂存当前用户的上传库存数据 + * * @param key 用户工号 */ - public static void addUserExcelInventoryInfo(String key, List excelVosForInventory){ + public static void addUserExcelInventoryInfo(String key, List excelVosForInventory) { excelVosForInventoryPool.put(key, excelVosForInventory); } /** * 获取当前用户上传的库存数据 + * * @param key * @return */ - public static List getUserExcelInventoryInfo(String key){ + public static List getUserExcelInventoryInfo(String key) { return excelVosForInventoryPool.get(key); } /** * 用于删除当前用户上传的库存数据 + * * @param key */ - public static void removeUserExcelInventoryInfo(String key){ + public static void removeUserExcelInventoryInfo(String key) { excelVosForInventoryPool.remove(key); } /** * 用于暂存当前用户的上传物料数据 + * * @param key 用户工号 */ - public static void addUserExcelMaterialInfo(String key, List excelVosForMaterial){ + public static void addUserExcelMaterialInfo(String key, List excelVosForMaterial) { excelVosForMaterialPool.put(key, excelVosForMaterial); } /** * 获取当前用户上传的物料数据 + * * @param key * @return */ - public static List getUserExcelMaterialInfo(String key){ + public static List getUserExcelMaterialInfo(String key) { return excelVosForMaterialPool.get(key); } /** * 用于删除当前用户上传的物料数据 + * * @param key */ - public static void removeUserExcelMaterialInfo(String key){ + public static void removeUserExcelMaterialInfo(String key) { excelVosForMaterialPool.remove(key); } /** * 用于暂存当前用户的上传物料类型数据 + * * @param key 用户工号 */ - public static void addUserExcelMaterialTypeInfo(String key, List excelVosForMaterialType){ + public static void addUserExcelMaterialTypeInfo(String key, List excelVosForMaterialType) { excelVosForMaterialTypePool.put(key, excelVosForMaterialType); } + /** * 获取当前用户上传的物料类型数据 + * * @param key * @return */ - public static List getUserExcelMaterialTypeInfo(String key){ + public static List getUserExcelMaterialTypeInfo(String key) { return excelVosForMaterialTypePool.get(key); } /** * 用于删除当前用户上传的物料类型数据 + * * @param key */ - public static void removeUserExcelMaterialTypeInfo(String key){ + public static void removeUserExcelMaterialTypeInfo(String key) { excelVosForMaterialTypePool.remove(key); } + /** + * 用于暂存当前用户的上传物料数据(用于覆盖) + * + * @param key 用户工号 + */ + public static void addUserExcelMaterialInfoByOverwrite(String key, List excelVosForMaterial) { + excelVosForMaterialPoolByOverwrite.put(key, excelVosForMaterial); + } + + /** + * 获取当前用户上传的物料数据(用于覆盖) + * + * @param key + * @return + */ + public static List getUserExcelMaterialInfoByOverwrite(String key) { + return excelVosForMaterialPoolByOverwrite.get(key); + } + + /** + * 用于删除当前用户上传的物料数据(用于覆盖) + * + * @param key + */ + public static void removeUserExcelMaterialInfoByOverwrite(String key) { + excelVosForMaterialPoolByOverwrite.remove(key); + } + + /** + * 用于添加一条数据到用于覆盖的数据暂存列表中 + * + * @param key 要存储到的列表key + * @param excelInfoForMaterial 要存储的数据 + */ + public static void addExcelMaterialInfoByOverwrite(String key, ExcelInfoForMaterial excelInfoForMaterial) { + List excelInfoForMaterials = excelVosForMaterialPoolByOverwrite.get(key); + if (excelInfoForMaterials != null) { + excelInfoForMaterials.add(excelInfoForMaterial); + } else { + List list = Collections.synchronizedList(new ArrayList<>()); + list.add(excelInfoForMaterial); + excelVosForMaterialPoolByOverwrite.put(key, list); + } + } + } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java b/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java index aba35a47..76f0c2f7 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java @@ -57,6 +57,10 @@ public interface ExcelService { */ void executeImportForMaterial(UserByPort userByPort); + /** + * 用于执行物料覆盖方法 + */ + void executeOverwriteForMaterial(UserByPort userByPort); /** * 用于清空导入的数据 diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java index 4e07707d..c8a90281 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java @@ -16,6 +16,7 @@ import com.dreamchaser.depository_manage.mapper.ConstructionUnitMapper; import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; import com.dreamchaser.depository_manage.mapper.MaterialMapper; import com.dreamchaser.depository_manage.security.pool.ExcelFileInfoPool; +import com.dreamchaser.depository_manage.security.pool.HandlesOtherFunctionalThreadPool; import com.dreamchaser.depository_manage.service.*; import com.dreamchaser.depository_manage.utils.*; import lombok.extern.slf4j.Slf4j; @@ -746,7 +747,7 @@ public class ExcelServiceImpl implements ExcelService { } } ExcelFileInfoPool.removeUserExcelInventoryInfo(number); - log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForInventory) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数为:" + successCount+",导入时间为: "+DateUtil.getNowTime()); + log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForInventory) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数为:" + successCount + ",导入时间为: " + DateUtil.getNowTime()); } @@ -787,7 +788,7 @@ public class ExcelServiceImpl implements ExcelService { } ExcelFileInfoPool.removeUserExcelMaterialTypeInfo(number); - log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForMaterialType) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数" + successNum+",导入时间为: "+DateUtil.getNowTime()); + log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForMaterialType) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数" + successNum + ",导入时间为: " + DateUtil.getNowTime()); } @@ -847,10 +848,63 @@ public class ExcelServiceImpl implements ExcelService { } } ExcelFileInfoPool.removeUserExcelMaterialInfo(number); - log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForMaterial) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数" + successNum+",导入时间为: "+DateUtil.getNowTime()); + log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForMaterial) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数" + successNum + ",导入时间为: " + DateUtil.getNowTime()); } + /** + * 用于执行物料覆盖方法 + */ + @Override + public void executeOverwriteForMaterial(UserByPort userByPort) { + List success = new ArrayList<>(); + String number = userByPort.getNumber(); + List excelMaterialInfoByOverwrite = ExcelFileInfoPool.getUserExcelMaterialInfoByOverwrite(number); + List userExcelMaterialInfo = ExcelFileInfoPool.getUserExcelMaterialInfo(number); + if(userExcelMaterialInfo != null && userExcelMaterialInfo.size() > 0){ + // 如果有需要导入的数据 + HandlesOtherFunctionalThreadPool.execute(()->{ + // 开启一个线程去执行导入方法 + executeImportForMaterial(userByPort); + }); + } + int successNum = 0; + for (int i = 0; i < excelMaterialInfoByOverwrite.size(); i++) { + ExcelInfoForMaterial excelVo = excelMaterialInfoByOverwrite.get(i); + Map map = new HashMap<>(); + String code = excelVo.getCode(); + if (code != null && !"".equals(code)) { + map.put("mcode", code); + } else { + map.put("mname", excelVo.getMname()); + map.put("version", excelVo.getVersion()); + } + String price = excelVo.getPrice(); + if (price != null && !"".equals(price)) { + map.put("price", (int)(ObjectFormatUtil.toDouble(price) * 100)); + } else { + map.put("price", 0); + } + map.put("uid", userByPort.getId()); + map.put("updateTime", System.currentTimeMillis()); + successNum += materialMapper.updateMaterialForImport(map); + success.add(excelVo); + + if ((i + 1) % 100 == 0 || excelMaterialInfoByOverwrite.size() - 1 == i) { + // 如果凑够100条或者已经循环完成 发送消息 + try { + WebSocketController.sendInfo(JSONObject.toJSONString(success), number); + success = new ArrayList<>(); + } catch (IOException e) { + e.printStackTrace(); + } + } + ExcelFileInfoPool.removeUserExcelMaterialInfoByOverwrite(number); + log.info("【批量添加】批量修改数据:{}", JSON.toJSONString(excelMaterialInfoByOverwrite) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数" + successNum + ",导入时间为: " + DateUtil.getNowTime()); + + } + } + /** * 用于清空导入的数据 */ @@ -858,6 +912,7 @@ public class ExcelServiceImpl implements ExcelService { ExcelFileInfoPool.removeUserExcelInventoryInfo(userByPort.getNumber()); ExcelFileInfoPool.removeUserExcelMaterialInfo(userByPort.getNumber()); ExcelFileInfoPool.removeUserExcelMaterialTypeInfo(userByPort.getNumber()); + ExcelFileInfoPool.removeUserExcelMaterialInfoByOverwrite(userByPort.getNumber()); } @@ -1080,6 +1135,9 @@ public class ExcelServiceImpl implements ExcelService { String s = dataIndex.get(i); String msg = s + "出现异常,名称为:" + mname + ",型号为:" + excelInfoForMaterial.getVersion() + "的物料已存在"; errMsg.add(msg); + // 添加一条数据用于覆盖 + ExcelFileInfoPool.addExcelMaterialInfoByOverwrite(userByPort.getNumber(), excelInfoForMaterial); + log.info("要覆盖的数据" + JSONObject.toJSONString(excelInfoForMaterial)); continue; } if (excelInfoForMaterial.getCode() != null) { @@ -1087,6 +1145,9 @@ public class ExcelServiceImpl implements ExcelService { if (materialByCode != null) { String s = dataIndex.get(i); String msg = s + "出现异常,编码为:" + excelInfoForMaterial.getCode() + "的物料已存在"; + // 添加一条数据用于覆盖 + ExcelFileInfoPool.addExcelMaterialInfoByOverwrite(userByPort.getNumber(), excelInfoForMaterial); + log.info("要覆盖的数据" + JSONObject.toJSONString(excelInfoForMaterial)); errMsg.add(msg); continue; } diff --git a/src/main/resources/templates/pages/material/material-out.html b/src/main/resources/templates/pages/material/material-out.html index d641b3f5..705d78f5 100644 --- a/src/main/resources/templates/pages/material/material-out.html +++ b/src/main/resources/templates/pages/material/material-out.html @@ -352,7 +352,7 @@ , shade: 0.8 , id: 'LAY_layuipro' //设定一个id,防止重复弹出 , resize: false - , btn: ['导入', '取消'] + , btn: ['导入', '取消', '覆盖'] , btnAlign: 'c' , moveType: 1 //拖拽模式,0或者1 , content: re @@ -414,6 +414,37 @@ } }) } + , btn3: function (index, layero) { + // 按钮【按钮三】的回调 + $.ajax({ + url: "/excel/overwriteExcelByMaterial", + type: "post", + data: JSON.stringify({"result": "yes"}), + dataType: "json", + contentType: "application/json;charset=utf-8", + success: function () { + if (socket !== null) { + socket.close(); + } else { + layer.close(index); + } + layer.alert("数据修改完成", { + icon: 0 + }, function (indexForMsg, layero) { + layer.close(indexForMsg); + layer.close(loading2); + closeShowDataMessage(); + table.reload('currentTableId', { + url: '/material/material', + page: { + curr: 1 + }, + }, 'data'); + }) + } + }) + return false; + } });