Commit 0c0003a7 authored by zuoyh's avatar zuoyh

Merge branch 'saff_update_feature' into dev

parents 2ff4f531 93801ca3
......@@ -9,9 +9,11 @@ import com.github.wxiaoqi.security.admin.entity.AppUserPosition;
import com.github.wxiaoqi.security.admin.mapper.AppShareholderDetailMapper;
import com.github.wxiaoqi.security.admin.vo.AppShareholderDetailVo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.google.common.collect.Lists;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.entity.BranchCompany;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
......@@ -263,9 +265,9 @@ public class AppShareholderDetailBiz extends BaseBiz<AppShareholderDetailMapper,
* 批量导入
*/
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public int importShareholder(List<String[]> shareholderData, Integer operatorId) {
public Map<String, Object> importShareholder(List<String[]> shareholderData, Integer operatorId) {
List<AppShareholderDetail> appShareholderDetail = new ArrayList<>();
int size = wrapperData(shareholderData, operatorId);
Map<String, Object> mapResult = wrapperData(shareholderData, operatorId);
/*int threadNums = shareholderData.size() / BORDER_NUM == 0 ? 1 : shareholderData.size() / BORDER_NUM;
CountDownLatch latch = new CountDownLatch(threadNums);
......@@ -283,26 +285,48 @@ public class AppShareholderDetailBiz extends BaseBiz<AppShareholderDetailMapper,
throw new BaseException("导入数据失败");
}
}*/
return size;
return mapResult;
}
/**
* @param subResultDate
*/
private int wrapperData(List<String[]> subResultDate, Integer operatorId) {
private Map<String, Object> wrapperData(List<String[]> subResultDate, Integer operatorId) {
Map<String, Object> result = new HashMap<>(1);
Map<String, Object> errorResultMap;
List<Map<String, Object>> errorResult = Lists.newArrayList();
// Map<String, Object> exist;
List<Map<String, Object>> existResult = Lists.newArrayList();
int size = subResultDate.get(0).length;
int total = 0;
int exist = 0;
int error = 0;
subResultDate.remove(0);
for (String[] data : subResultDate) {
error++;
data = Arrays.copyOf(data, size);
String name = data[0];
String phone = data[1];
String companyName = data[2];
String time = data[3];
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(phone) && StringUtils.isNotBlank(companyName)) {
try {
total++;
if (StringUtils.isBlank(phone)) {
throw new BaseException("手机号为空");
}
if (StringUtils.isBlank(companyName)) {
throw new BaseException("股东入股公司为空");
}
if (StringUtils.isBlank(name)) {
throw new BaseException("股东名称为空");
}
if (StringUtils.isNotBlank(name)) {
name.replaceAll(" ", "");
}
if (StringUtils.isNotBlank(companyName)) {
name.replaceAll(" ", "");
}
Date relTime = StringUtils.isNoneBlank(time) ? formatter.parse(time) : null;
BranchCompany branchCompany = vehicleFeign.companyId(companyName);
if (branchCompany != null) {
......@@ -322,6 +346,7 @@ public class AppShareholderDetailBiz extends BaseBiz<AppShareholderDetailMapper,
detailBiz.updateUserPositionByUserId(userId, positionId);
}
}
exist++;
appShareholderDetailDTO.setUserId(userId);
appShareholderDetailDTO.setPositionId(positionId);
appShareholderDetailDTO.setCompanyId(branchCompany.getId());
......@@ -333,6 +358,7 @@ public class AppShareholderDetailBiz extends BaseBiz<AppShareholderDetailMapper,
appShareholderDetailDTO.setCrtTime(System.currentTimeMillis());
AppShareholderDetail appShareholderDetail = new AppShareholderDetail();
BeanUtils.copyProperties(appShareholderDetailDTO, appShareholderDetail);
//判断股东表是否有数据,有则不插入
Example example = new Example(AppShareholderDetail.class);
Example.Criteria criteria = example.createCriteria();
......@@ -343,6 +369,7 @@ public class AppShareholderDetailBiz extends BaseBiz<AppShareholderDetailMapper,
}
List<AppShareholderDetail> listappShareholderDetai = selectByExample(example);
if (listappShareholderDetai.size() == 0) {
total++;
Integer id = appShareholderDetailDTO.getId() == null ? 0 : appShareholderDetailDTO.getId();
BeanUtils.copyProperties(appShareholderDetailDTO, appShareholderDetail);
appShareholderDetail.setPositionId(positionId);
......@@ -353,11 +380,37 @@ public class AppShareholderDetailBiz extends BaseBiz<AppShareholderDetailMapper,
}
}
}
} catch (ParseException e) {
log.error("股东导入失败:【{}】", e);
} catch (BaseException ex) {
errorResultMap = new HashMap<>(1);
errorResultMap.put("num", error);
errorResultMap.put("msg", ex.getMessage());
errorResult.add(errorResultMap);
} catch (ArrayIndexOutOfBoundsException ex) {
errorResultMap = new HashMap<>(1);
errorResultMap.put("num", error);
String msg = "";
if (StringUtils.isEmpty(phone)) {
msg += "手机号码缺失";
}
if (StringUtils.isEmpty(companyName)) {
msg += ",股东入股公司确实";
}
if (StringUtils.isEmpty(name)) {
msg += "股东姓名缺失";
}
errorResultMap.put("msg", msg);
errorResult.add(errorResultMap);
} catch (Exception ex) {
errorResultMap = new HashMap<>(1);
errorResultMap.put("num", error);
errorResultMap.put("msg", "数据" + Arrays.toString(data) + "保存失败");
errorResult.add(errorResultMap);
}
}
return total;
result.put("success", total);
result.put("error", errorResult.size());
result.put("data", errorResult);
result.put("exist", exist - total);
return result;
}
}
......@@ -51,12 +51,8 @@ public class AppShareholderDetailController {
return ObjectRestResponse.createFailedResult(1001, "导入不能没数据!!!");
}
// appShareholderData.remove(0);
try {
int effectSize = appShareholderDetailBiz.importShareholder(appShareholderData, operatorId);
return ObjectRestResponse.succ(effectSize);
} catch (BaseException ex) {
return ObjectRestResponse.createDefaultFail();
}
return ObjectRestResponse.succ(appShareholderDetailBiz.importShareholder(appShareholderData, operatorId))
;
} catch (Exception e) {
throw new BaseException(e);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment