diff --git a/common/src/main/java/com/foreverwin/mesnac/common/controller/ToolController.java b/common/src/main/java/com/foreverwin/mesnac/common/controller/ToolController.java index ca5a858a..f339eb78 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/controller/ToolController.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/controller/ToolController.java @@ -146,11 +146,11 @@ public class ToolController { @ResponseBody @GetMapping("/getOneToolByToolNo") - public R getOneToolByToolNo(String tool) { + public R getOneToolByToolNo(Tool tool) { try{ return R.ok(toolService.getOneToolByToolNo(tool)); }catch (Exception e){ - return R.failed("数据查询失败" + e.getMessage()); + return R.failed("数据查询失败:" + e.getMessage()); } } diff --git a/common/src/main/java/com/foreverwin/mesnac/common/service/ToolService.java b/common/src/main/java/com/foreverwin/mesnac/common/service/ToolService.java index 45cdd70e..00f1b8d5 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/service/ToolService.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/service/ToolService.java @@ -38,7 +38,7 @@ public interface ToolService extends IService { * @param tool * @return */ - Tool getOneToolByToolNo(String tool); + Tool getOneToolByToolNo(Tool tool); /** * 删除刀具: diff --git a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/ToolServiceImpl.java b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/ToolServiceImpl.java index eecaf520..3a445a94 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/ToolServiceImpl.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/ToolServiceImpl.java @@ -76,10 +76,15 @@ public class ToolServiceImpl extends ServiceImpl implements To } @Override - public Tool getOneToolByToolNo(String tool) { + public Tool getOneToolByToolNo(Tool tool) { String site = CommonMethods.getSite(); - String handle = HandleEnum.TOOL.getHandle(site, tool); - return toolMapper.selectById(handle); + String handle = HandleEnum.TOOL.getHandle(site, tool.getTool()); + tool.setHandle(handle); + List tools = toolService.selectList(tool); + if (tools.size() == 1){ + return tools.get(0); + } + throw BusinessException.build("查询失败!"); } @Override @@ -100,7 +105,6 @@ public class ToolServiceImpl extends ServiceImpl implements To @Override public String saveOrUpdateToolByImport(JSONObject json, String sqlType) { String user = CommonMethods.getUser(); - Tool target = new Tool(); String site = json.getString("site").trim(); String tool = json.getString("tool").trim(); String handle = HandleEnum.TOOL.getHandle(site, tool).trim(); @@ -108,9 +112,13 @@ public class ToolServiceImpl extends ServiceImpl implements To String specification = json.getString("specification").trim(); String brand = json.getString("brand").trim(); String remark = json.getString("remark").trim(); - if (tool==null || tool != ""){ + if (tool == null || tool.equals("")){ return "刀具编号不能为空"; + //throw BusinessException.build("刀具编号不能为空!"); } + Tool target = new Tool(); + target.setStatus(Constants.TOOL_STATUS_Y); + target.setSite(site); switch (sqlType){ case "insert": target.setTool(tool); @@ -121,10 +129,11 @@ public class ToolServiceImpl extends ServiceImpl implements To target.setCreateUser(user); target.setCreatedDateTime(LocalDateTime.now()); toolMapper.insert(target); - break; + return "新增一条数据成功"; case "update": Tool byId = toolMapper.selectById(handle); if (byId == null){ + //throw BusinessException.build("更新失败,刀具编号不存在!"); return "更新失败,刀具编号不存在!"; } if (description != ""){ @@ -140,40 +149,39 @@ public class ToolServiceImpl extends ServiceImpl implements To byId.setRemark(remark); } toolMapper.updateById(byId); - break; + return "更新一条数据成功"; case "both": Tool selId = toolMapper.selectById(handle); - if (selId != null){ - if (description != ""){ - selId.setDescription(description); - } - if (specification != ""){ - selId.setSpecification(specification); - } - if (brand != ""){ - selId.setBrand(brand); - } - if (remark != ""){ - selId.setRemark(remark); - } - selId.setModifyUser(user); - selId.setModifiedDateTime(LocalDateTime.now()); - toolMapper.updateById(selId); - break; + if (selId == null){ + target.setTool(tool); + target.setHandle(handle); + target.setDescription(description); + target.setSpecification(specification); + target.setBrand(brand); + target.setCreateUser(user); + target.setCreatedDateTime(LocalDateTime.now()); + toolMapper.insert(target); + return "新增一条数据成功"; } - target.setTool(tool); - target.setHandle(handle); - target.setDescription(description); - target.setSpecification(specification); - target.setBrand(brand); - target.setCreateUser(user); - target.setCreatedDateTime(LocalDateTime.now()); - toolMapper.insert(target); - break; + if (description != ""){ + selId.setDescription(description); + } + if (specification != ""){ + selId.setSpecification(specification); + } + if (brand != ""){ + selId.setBrand(brand); + } + if (remark != ""){ + selId.setRemark(remark); + } + selId.setModifyUser(user); + selId.setModifiedDateTime(LocalDateTime.now()); + toolMapper.updateById(selId); + return "更新一条数据成功"; default: - return "更新/导入类型未找到!"; + throw BusinessException.build("更新/导入类型未找到!"); } - return "导入成功"; } diff --git a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/ToolHandler.java b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/ToolHandler.java index 61174ce6..72a60aae 100644 --- a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/ToolHandler.java +++ b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/ToolHandler.java @@ -34,10 +34,10 @@ public class ToolHandler extends BaseHandler { buffer.append(e.getMessage() + "\n"); } - if (buffer.length() > 0) { + /*if (buffer.length() > 0) { buffer.insert(0, I18nUtil.getI18nText("MaterData.import.Summary", new Object[]{row + failedNumber[0], row, failedNumber[0]}) + "\n"); throw BusinessException.build(buffer.toString()); - } + }*/ buffer.insert(0, I18nUtil.getI18nText("MaterData.import.Summary", new Object[]{row + failedNumber[0], row, failedNumber[0]}) + "\n"); return buffer.toString(); @@ -61,7 +61,12 @@ public class ToolHandler extends BaseHandler { jsonObject.put("site", site); try { String msg = toolService.saveOrUpdateToolByImport(jsonObject, mode); - buffer.append("第" + index + "行:" + msg + "\n"); + if (msg.indexOf("成功") == -1){ + buffer.append("第" + index + "行【失败】:" + msg + "\n"); + failedNumber[0]++; + return 0; + } + buffer.append("第" + index + "行【成功】:" + msg + "\n"); return 1; } catch (Exception e) { params[2] = e.getMessage();