|
|
@ -8,10 +8,13 @@ import com.foreverwin.mesnac.dataimport.reader.FileReader;
|
|
|
|
import com.foreverwin.mesnac.dataimport.reader.FileReaderBuilder;
|
|
|
|
import com.foreverwin.mesnac.dataimport.reader.FileReaderBuilder;
|
|
|
|
import com.foreverwin.mesnac.dataimport.reader.RowVisitor;
|
|
|
|
import com.foreverwin.mesnac.dataimport.reader.RowVisitor;
|
|
|
|
import com.foreverwin.mesnac.dataimport.service.MasterObjectDefine;
|
|
|
|
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.mapper.UserResourceMapper;
|
|
|
|
import com.foreverwin.mesnac.dispatch.model.UserResource;
|
|
|
|
import com.foreverwin.mesnac.dispatch.model.UserResource;
|
|
|
|
import com.foreverwin.mesnac.dispatch.service.UserResourceService;
|
|
|
|
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.exception.BusinessException;
|
|
|
|
import com.foreverwin.modular.core.util.CommonMethods;
|
|
|
|
import com.foreverwin.modular.core.util.CommonMethods;
|
|
|
|
import com.foreverwin.modular.core.util.I18nUtil;
|
|
|
|
import com.foreverwin.modular.core.util.I18nUtil;
|
|
|
@ -30,11 +33,17 @@ import java.util.Map;
|
|
|
|
public class UserResourceHandler extends BaseHandler {
|
|
|
|
public class UserResourceHandler extends BaseHandler {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserResourceMapper userResourceMapper;
|
|
|
|
private ResrceMapper resrceMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserResourceService userResourceService;
|
|
|
|
private UserResourceService userResourceService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private NwaUserMapper nwaUserMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private UserResourceMapper userResourceMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String importFile(String site, InputStream inputStream, String fileType, String mode) throws Exception {
|
|
|
|
public String importFile(String site, InputStream inputStream, String fileType, String mode) throws Exception {
|
|
|
|
int row = 0;
|
|
|
|
int row = 0;
|
|
|
@ -72,18 +81,18 @@ public class UserResourceHandler extends BaseHandler {
|
|
|
|
|
|
|
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
String user = CommonMethods.getUser();
|
|
|
|
String user = CommonMethods.getUser();
|
|
|
|
String resrce = StringUtil.toString(jsonObject.getString(jsonObject.getString("resrce")));
|
|
|
|
String resrce = StringUtil.toString(jsonObject.getString("resrce"));
|
|
|
|
String resrceDescription = StringUtil.toString(jsonObject.getString(jsonObject.getString("resrceDescription")));
|
|
|
|
// String resrceDescription = StringUtil.toString(jsonObject.getString("resrceDescription"));
|
|
|
|
String userId = StringUtil.toString(jsonObject.getString(jsonObject.getString("userId")));
|
|
|
|
String userId = StringUtil.toString(jsonObject.getString("userId"));
|
|
|
|
String userDescription = StringUtil.toString(jsonObject.getString(jsonObject.getString("userDescription")));
|
|
|
|
String userDescription = StringUtil.toString(jsonObject.getString("userDescription"));
|
|
|
|
String temporaryUser = StringUtil.toString(jsonObject.getString(jsonObject.getString("temporaryUser")));
|
|
|
|
String temporaryUser = StringUtil.toString(jsonObject.getString("temporaryUser"));
|
|
|
|
String status = StringUtil.toString(jsonObject.getString(jsonObject.getString("status")));
|
|
|
|
String status = StringUtil.toString(jsonObject.getString("status"));
|
|
|
|
UserResource userResource = new UserResource();
|
|
|
|
UserResource userResource = new UserResource();
|
|
|
|
userResource.setHandle(HandleEnum.USER_RESOURCE.getHandle(site, resrce, userId));
|
|
|
|
userResource.setHandle(HandleEnum.USER_RESOURCE.getHandle(site, resrce, userId));
|
|
|
|
userResource.setSite(site);
|
|
|
|
userResource.setSite(site);
|
|
|
|
userResource.setResourceBo(HandleEnum.RESOURCE.getHandle(site,resrce));
|
|
|
|
userResource.setResourceBo(HandleEnum.RESOURCE.getHandle(site,resrce));
|
|
|
|
userResource.setResrce(resrce);
|
|
|
|
userResource.setResrce(resrce);
|
|
|
|
userResource.setResrceDescription(resrceDescription);
|
|
|
|
// userResource.setResrceDescription(resrceDescription);
|
|
|
|
userResource.setUserId(userId);
|
|
|
|
userResource.setUserId(userId);
|
|
|
|
userResource.setUserDescription(userDescription);
|
|
|
|
userResource.setUserDescription(userDescription);
|
|
|
|
if("Y".equals(temporaryUser)){
|
|
|
|
if("Y".equals(temporaryUser)){
|
|
|
@ -92,12 +101,13 @@ public class UserResourceHandler extends BaseHandler {
|
|
|
|
userResource.setTemporaryUser("false");
|
|
|
|
userResource.setTemporaryUser("false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if("Y".equals(status)){
|
|
|
|
if("N".equals(status)){
|
|
|
|
userResource.setStatus("true");
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
userResource.setStatus("false");
|
|
|
|
userResource.setStatus("false");
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
userResource.setStatus("true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否是更新还是插入,如果是更新,则没有创建时间和人员
|
|
|
|
UserResource result = userResourceMapper.selectById(userResource.getHandle());
|
|
|
|
UserResource result = userResourceMapper.selectById(userResource.getHandle());
|
|
|
|
if(result == null){
|
|
|
|
if(result == null){
|
|
|
|
userResource.setCreatedUser(user);
|
|
|
|
userResource.setCreatedUser(user);
|
|
|
@ -105,66 +115,19 @@ public class UserResourceHandler extends BaseHandler {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userResource.setModifiedUser(user);
|
|
|
|
userResource.setModifiedUser(user);
|
|
|
|
userResource.setModifiedDateTime(now);
|
|
|
|
userResource.setModifiedDateTime(now);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object[] params = new Object[10];
|
|
|
|
|
|
|
|
//错误信息提示
|
|
|
|
|
|
|
|
params[0] = index;
|
|
|
|
|
|
|
|
params[1] = resrce;
|
|
|
|
|
|
|
|
boolean insert = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
//如果资源为空或者员工编号为空,则直接跳过
|
|
|
|
//如果资源为空或者员工编号为空,则直接跳过
|
|
|
|
if (StringUtil.notEmpty(resrce) && StringUtil.notEmpty(userId)) {
|
|
|
|
if (StringUtil.notEmpty(resrce) && StringUtil.notEmpty(userId)) {
|
|
|
|
//站点
|
|
|
|
//站点
|
|
|
|
jsonObject.put("site", site);
|
|
|
|
jsonObject.put("site", site);
|
|
|
|
//错误提示信息
|
|
|
|
//不管用户选啥模式,都是更新和插入
|
|
|
|
boolean resultMessage = false;
|
|
|
|
this.updateAndInsert(userResource,index);
|
|
|
|
// WorkCenterFullConfiguration result = WorkCenterWSClient.find(jsonObject);
|
|
|
|
userResourceService.saveOrUpdate(userResource);
|
|
|
|
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");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
params[2] = e.getMessage();
|
|
|
|
throw BusinessException.build(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");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -172,10 +135,25 @@ public class UserResourceHandler extends BaseHandler {
|
|
|
|
return null;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|