员工资源导入

master
赵嘉伟 4 years ago
parent 895046da7d
commit c583c1e540

@ -30,6 +30,8 @@ public class HandlerFactory {
//return new MessageTypeHandler();
case "tool" :
return new ToolHandler();
case "userResource" :
return new UserResourceHandler();
}
return null;

@ -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;
}
};

@ -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<UserResource> {
List<UserResource> findEnableList(String site, String resource, String user);
List<UserResourceDto> findAll(UserResourceDto userResourceDto);
HashMap<String,Object> findAll(UserResourceDto userResourceDto);
void saveAll(List<UserResourceDto> userResourceDtoList,String resource,String user);

@ -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;
/**
* <p>
@ -69,11 +70,18 @@ public class UserResourceServiceImpl extends ServiceImpl<UserResourceMapper, Use
}
@Override
public List<UserResourceDto> findAll(UserResourceDto userResourceDto) {
public HashMap<String,Object> findAll(UserResourceDto userResourceDto) {
String site = CommonMethods.getSite();
String resource = userResourceDto.getResrce();
String userId = userResourceDto.getUserId();
return userResourceMapper.findAll(site, resource, userId);
HashMap<String, Object> hashMap = new HashMap<>();;
List<NwaUser> nwaUserList = nwaUserService.selectList(null);
List<UserResourceDto> 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<UserResourceMapper, Use
userByUserName == null){
throw BusinessException.build("第"+(i+1)+"行的用户不存在,必须为临时用户");
}else if(userByUserName != null){
userByUserName.setFullName(userResource.getUserDescription());
//userByUserName.setFullName(userResource.getUserDescription());
userResource.setUserDescription(userByUserName.getFullName());
nwaUserService.saveOrUpdate(userByUserName);
}
userResource.setStatus(userResourceDto.getStatus());
@ -117,6 +126,6 @@ public class UserResourceServiceImpl extends ServiceImpl<UserResourceMapper, Use
if(userResourceList.size() > 0){
this.saveOrUpdateBatch(userResourceList);
}
}
}
Loading…
Cancel
Save