From c583c1e540cd5443cd446c3f499f2b0481184c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=98=89=E4=BC=9F?= <1724121454@qq.com> Date: Fri, 30 Jul 2021 17:34:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=98=E5=B7=A5=E8=B5=84=E6=BA=90=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataimport/handler/HandlerFactory.java | 2 + .../handler/UserResourceHandler.java | 112 +++++++----------- .../dispatch/service/UserResourceService.java | 3 +- .../service/impl/UserResourceServiceImpl.java | 17 ++- 4 files changed, 62 insertions(+), 72 deletions(-) diff --git a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/HandlerFactory.java b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/HandlerFactory.java index c0110de6..985693b0 100644 --- a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/HandlerFactory.java +++ b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/HandlerFactory.java @@ -30,6 +30,8 @@ public class HandlerFactory { //return new MessageTypeHandler(); case "tool" : return new ToolHandler(); + case "userResource" : + return new UserResourceHandler(); } return null; diff --git a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java index e39c28d6..ba1e049d 100644 --- a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java +++ b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java @@ -8,10 +8,13 @@ import com.foreverwin.mesnac.dataimport.reader.FileReader; import com.foreverwin.mesnac.dataimport.reader.FileReaderBuilder; import com.foreverwin.mesnac.dataimport.reader.RowVisitor; import com.foreverwin.mesnac.dataimport.service.MasterObjectDefine; -import com.foreverwin.mesnac.dataimport.util.AppUtil; import com.foreverwin.mesnac.dispatch.mapper.UserResourceMapper; import com.foreverwin.mesnac.dispatch.model.UserResource; import com.foreverwin.mesnac.dispatch.service.UserResourceService; +import com.foreverwin.mesnac.meapi.mapper.NwaUserMapper; +import com.foreverwin.mesnac.meapi.mapper.ResrceMapper; +import com.foreverwin.mesnac.meapi.model.NwaUser; +import com.foreverwin.mesnac.meapi.model.Resrce; import com.foreverwin.modular.core.exception.BusinessException; import com.foreverwin.modular.core.util.CommonMethods; import com.foreverwin.modular.core.util.I18nUtil; @@ -30,11 +33,17 @@ import java.util.Map; public class UserResourceHandler extends BaseHandler { @Autowired - private UserResourceMapper userResourceMapper; + private ResrceMapper resrceMapper; @Autowired private UserResourceService userResourceService; + @Autowired + private NwaUserMapper nwaUserMapper; + + @Autowired + private UserResourceMapper userResourceMapper; + @Override public String importFile(String site, InputStream inputStream, String fileType, String mode) throws Exception { int row = 0; @@ -72,18 +81,18 @@ public class UserResourceHandler extends BaseHandler { LocalDateTime now = LocalDateTime.now(); String user = CommonMethods.getUser(); - String resrce = StringUtil.toString(jsonObject.getString(jsonObject.getString("resrce"))); - String resrceDescription = StringUtil.toString(jsonObject.getString(jsonObject.getString("resrceDescription"))); - String userId = StringUtil.toString(jsonObject.getString(jsonObject.getString("userId"))); - String userDescription = StringUtil.toString(jsonObject.getString(jsonObject.getString("userDescription"))); - String temporaryUser = StringUtil.toString(jsonObject.getString(jsonObject.getString("temporaryUser"))); - String status = StringUtil.toString(jsonObject.getString(jsonObject.getString("status"))); + String resrce = StringUtil.toString(jsonObject.getString("resrce")); + // String resrceDescription = StringUtil.toString(jsonObject.getString("resrceDescription")); + String userId = StringUtil.toString(jsonObject.getString("userId")); + String userDescription = StringUtil.toString(jsonObject.getString("userDescription")); + String temporaryUser = StringUtil.toString(jsonObject.getString("temporaryUser")); + String status = StringUtil.toString(jsonObject.getString("status")); UserResource userResource = new UserResource(); userResource.setHandle(HandleEnum.USER_RESOURCE.getHandle(site, resrce, userId)); userResource.setSite(site); userResource.setResourceBo(HandleEnum.RESOURCE.getHandle(site,resrce)); userResource.setResrce(resrce); - userResource.setResrceDescription(resrceDescription); + // userResource.setResrceDescription(resrceDescription); userResource.setUserId(userId); userResource.setUserDescription(userDescription); if("Y".equals(temporaryUser)){ @@ -92,12 +101,13 @@ public class UserResourceHandler extends BaseHandler { userResource.setTemporaryUser("false"); } - if("Y".equals(status)){ - userResource.setStatus("true"); - }else { + if("N".equals(status)){ userResource.setStatus("false"); + }else { + userResource.setStatus("true"); } + //判断是否是更新还是插入,如果是更新,则没有创建时间和人员 UserResource result = userResourceMapper.selectById(userResource.getHandle()); if(result == null){ userResource.setCreatedUser(user); @@ -105,66 +115,19 @@ public class UserResourceHandler extends BaseHandler { } userResource.setModifiedUser(user); userResource.setModifiedDateTime(now); - - - - Object[] params = new Object[10]; - //错误信息提示 - params[0] = index; - params[1] = resrce; - boolean insert = false; try { - //如果资源为空或者员工编号为空,则直接跳过 if (StringUtil.notEmpty(resrce) && StringUtil.notEmpty(userId)) { //站点 jsonObject.put("site", site); - //错误提示信息 - boolean resultMessage = false; - // WorkCenterFullConfiguration result = WorkCenterWSClient.find(jsonObject); - if (result != null) { - if (AppUtil.canUpdate(mode)) { - resultMessage = this.update(userResource); - if (resultMessage) { - return 1; - } - }else{ - throw BusinessException.build("第"+index+"行的数据不存在,不能更新,应该选更新插入"); - } - } else { - if (AppUtil.canInsert(mode)) { - insert = true; - // resultMessage = WorkCenterWSClient.insert(userResource); -// if (resultMessage == null) { -// return 1; -// } - } else if (AppUtil.canUpdate(mode)) { - //resultMessage = "第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n"; - } - } - -// if (resultMessage != null) { -// params[2] = resultMessage; -// failedNumber[0]++; -// if (insert) { -// buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", params) + "\n"); -// } else { -// buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", params) + "\n"); -// } -// } + //不管用户选啥模式,都是更新和插入 + this.updateAndInsert(userResource,index); + userResourceService.saveOrUpdate(userResource); } - return 0; - + return 1; } catch (Exception e) { - params[2] = e.getMessage(); - failedNumber[0]++; - if (insert) { - buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", new Object[]{e.getMessage()}) + "\n"); - } else { - buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", new Object[]{e.getMessage()}) + "\n"); - } + throw BusinessException.build(e.getMessage()); } - return 0; } @Override @@ -172,10 +135,25 @@ public class UserResourceHandler extends BaseHandler { return null; } - boolean update(UserResource userResource){ - + boolean updateAndInsert(UserResource userResource,Long index){ + //判断资源是否存在 + Resrce resrce = resrceMapper.selectById(userResource.getResourceBo()); - return false; + if(resrce == null){ + throw BusinessException.build("第"+index+"行的资源不存在"); + } + //设置资源描述 + userResource.setResrceDescription(resrce.getDescription()); + //设置员工描述 + NwaUser nwaUser = nwaUserMapper.selectById(HandleEnum.USER.getHandle(userResource.getSite(), userResource.getUserId())); + if(nwaUser != null){ + userResource.setUserDescription(nwaUser.getFullName()); + }else if("true".equals(userResource.getTemporaryUser())){ + //不做任何操作 + }else{ + throw BusinessException.build("第"+index+"行的用户不存在,必须为临时员工"); + } + return true; } }; diff --git a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/UserResourceService.java b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/UserResourceService.java index dc14e96d..35fb6aef 100644 --- a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/UserResourceService.java +++ b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/UserResourceService.java @@ -7,6 +7,7 @@ import com.foreverwin.mesnac.dispatch.model.UserResource; import com.foreverwin.mesnac.meapi.model.NwaUser; import com.foreverwin.modular.core.util.FrontPage; +import java.util.HashMap; import java.util.List; /** @@ -32,7 +33,7 @@ public interface UserResourceService extends IService { List findEnableList(String site, String resource, String user); - List findAll(UserResourceDto userResourceDto); + HashMap findAll(UserResourceDto userResourceDto); void saveAll(List userResourceDtoList,String resource,String user); diff --git a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/UserResourceServiceImpl.java b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/UserResourceServiceImpl.java index c4987f72..f57ea7b5 100644 --- a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/UserResourceServiceImpl.java +++ b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/UserResourceServiceImpl.java @@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** *

@@ -69,11 +70,18 @@ public class UserResourceServiceImpl extends ServiceImpl findAll(UserResourceDto userResourceDto) { + public HashMap findAll(UserResourceDto userResourceDto) { String site = CommonMethods.getSite(); String resource = userResourceDto.getResrce(); String userId = userResourceDto.getUserId(); - return userResourceMapper.findAll(site, resource, userId); + + HashMap hashMap = new HashMap<>();; + List nwaUserList = nwaUserService.selectList(null); + List userResourceList = userResourceMapper.findAll(site, resource, userId); + hashMap.put("users",nwaUserList); + hashMap.put("userResources",userResourceList); + return hashMap; + } @Override @@ -99,7 +107,8 @@ public class UserResourceServiceImpl extends ServiceImpl 0){ this.saveOrUpdateBatch(userResourceList); } - } + } \ No newline at end of file