|
@@ -8,8 +8,12 @@ import java.util.Map.Entry;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.biz.dal.dao.*;
|
|
|
import com.ym.mec.biz.dal.entity.*;
|
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.excel.IniFileUtil;
|
|
|
import com.ym.mec.util.excel.POIUtil;
|
|
@@ -22,11 +26,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
|
|
|
import com.ym.mec.biz.dal.dto.PageInfoOrder;
|
|
|
import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
|
|
|
import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
|
|
@@ -61,6 +60,10 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
private GoodsService goodsService;
|
|
|
@Autowired
|
|
|
private SellOrderService sellOrderService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
+ @Autowired
|
|
|
+ private TeacherDao teacherDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, StudentPaymentRouteOrder> getDAO() {
|
|
@@ -312,13 +315,18 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public List<StudentPaymentRouteOrder> importRouteOrder(MultipartFile file) throws Exception{
|
|
|
+ public HttpResponseResult<List<StudentPaymentRouteOrder>> importRouteOrder(MultipartFile file) throws Exception{
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if(sysUser == null || sysUser.getId() == null){
|
|
|
+ throw new BizException("用户信息获取失败");
|
|
|
+ }
|
|
|
Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
Map<String,String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.ROUTE_ORDER.getMsg());
|
|
|
List<StudentPaymentRouteOrder> studentPaymentRouteOrders = new ArrayList<>();
|
|
|
Map<String, Integer> organMap = getMap("organization", "name_", "id_", true, String.class, Integer.class);
|
|
|
Map<String, Integer> cooperationOrganMap = getMap("cooperation_organ", "name_", "id_", true, String.class, Integer.class);
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
for (String e : sheetsListMap.keySet()) {
|
|
|
List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
List<Object> collect = sheet.stream().map(m -> m.get("交易流水号")).collect(Collectors.toList());
|
|
@@ -330,24 +338,43 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
throw new BizException("导入数据错误 重复的交易流水号:{}",list.get(0));
|
|
|
}
|
|
|
|
|
|
- valueIsNull: for (Map<String, Object> row : sheet) {
|
|
|
-
|
|
|
+ valueIsNull: for (int j = 0; j < sheet.size(); j++) {
|
|
|
+ int rowNum = j + 2;
|
|
|
+ Map<String, Object> row = sheet.get(j);
|
|
|
if (row.size() == 0){
|
|
|
continue;
|
|
|
}
|
|
|
JSONObject objectMap = new JSONObject();
|
|
|
- for (String s : row.keySet()) {
|
|
|
+ Iterator<String> iterator = row.keySet().iterator();
|
|
|
+ for (int i = 0; i < row.keySet().size(); i++) {
|
|
|
+ String s = iterator.next();
|
|
|
if(!columns.containsKey(s)){
|
|
|
continue;
|
|
|
}
|
|
|
String columnValue = columns.get(s);
|
|
|
+ if (columnValue.equals("incomeType")) {
|
|
|
+ if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:收入类型不可为空;");
|
|
|
+ continue valueIsNull;
|
|
|
+ } else {
|
|
|
+ objectMap.put("incomeType", row.get(s));
|
|
|
+ }
|
|
|
+ }
|
|
|
if (columnValue.equals("transNo")) {
|
|
|
if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:交易流水号不可为空;");
|
|
|
+ continue valueIsNull;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (columnValue.equals("payTime") && StringUtils.isEmpty(row.get(s).toString())) {
|
|
|
+ if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:交易日期不可为空;");
|
|
|
continue valueIsNull;
|
|
|
}
|
|
|
}
|
|
|
if (columnValue.equals("merNo")) {
|
|
|
if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:收款账户不可为空;");
|
|
|
continue valueIsNull;
|
|
|
}else {
|
|
|
objectMap.put("merNo", row.get(s));
|
|
@@ -357,6 +384,7 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
Integer integer = organMap.get(row.get(s));
|
|
|
if(integer == null){
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:分部名称不存在;");
|
|
|
continue valueIsNull;
|
|
|
}else {
|
|
|
objectMap.put("routeOrganId", integer);
|
|
@@ -367,26 +395,42 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
Integer integer = cooperationOrganMap.get(row.get(s));
|
|
|
if(integer != null){
|
|
|
objectMap.put("schoolId", integer);
|
|
|
+ }else {
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:所属学校名称不存在;");
|
|
|
+ continue valueIsNull;
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
- if (columnValue.equals("payTime") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ if (columnValue.equals("userId") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ Boolean flag = teacherDao.existUser(row.get(s));
|
|
|
+ if(flag){
|
|
|
+ objectMap.put("userId", row.get(s));
|
|
|
+ }else {
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:学员编号不存在;");
|
|
|
+ continue valueIsNull;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (columnValue.equals("payTime")) {
|
|
|
String toString = row.get(s).toString();
|
|
|
- if(StringUtils.isNotEmpty(toString)){
|
|
|
- Date date = DateUtil.stringToDate(toString, DateUtil.DEFAULT_PATTERN);
|
|
|
- if(date == null){
|
|
|
- throw new BizException("导入数据错误 交易日期格式错误");
|
|
|
- }else {
|
|
|
- objectMap.put(columnValue, DateUtil.format(date,DateUtil.DEFAULT_PATTERN));
|
|
|
- }
|
|
|
+ Date date = DateUtil.stringToDate(toString, DateUtil.DEFAULT_PATTERN);
|
|
|
+ if(date == null){
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:交易日期格式错误;");
|
|
|
+ continue valueIsNull;
|
|
|
+ }else {
|
|
|
+ objectMap.put(columnValue, DateUtil.format(date,DateUtil.DEFAULT_PATTERN));
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
objectMap.put(columnValue, row.get(s));
|
|
|
}
|
|
|
StudentPaymentRouteOrder studentPaymentRouteOrder = JSONObject.parseObject(objectMap.toJSONString(),StudentPaymentRouteOrder.class);
|
|
|
- //是否有销售金额
|
|
|
- if(studentPaymentRouteOrder.getSaleAmount() != null && studentPaymentRouteOrder.getSaleAmount().longValue() != 0l){
|
|
|
+ //销售收入
|
|
|
+ if("销售收入".equals(studentPaymentRouteOrder.getIncomeType())){
|
|
|
+ if(studentPaymentRouteOrder.getSaleAmount() == null){
|
|
|
+ throw new BizException("导入失败:交易流水号{},收入类型为销售收入时,销售金额不可为空",studentPaymentRouteOrder.getTransNo());
|
|
|
+ }
|
|
|
+ studentPaymentRouteOrder.setServiceAmount(null);
|
|
|
String goodsIds = studentPaymentRouteOrder.getGoodsIds();
|
|
|
String goodsNums = studentPaymentRouteOrder.getGoodsNums();
|
|
|
|
|
@@ -416,7 +460,16 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
}
|
|
|
}
|
|
|
studentPaymentRouteOrder.setGoodsJson(goodsJSON.toJSONString());
|
|
|
+ //服务收入
|
|
|
+ }else {
|
|
|
+ studentPaymentRouteOrder.setSaleAmount(null);
|
|
|
+ if(studentPaymentRouteOrder.getServiceAmount() == null){
|
|
|
+ throw new BizException("导入失败:交易流水号{},收入类型为服务收入时,服务金额不可为空",studentPaymentRouteOrder.getTransNo());
|
|
|
+ }
|
|
|
}
|
|
|
+ studentPaymentRouteOrder.setCreateBy(sysUser.getId());
|
|
|
+ studentPaymentRouteOrder.setUpdateBy(sysUser.getId());
|
|
|
+ studentPaymentRouteOrder.setUserId(sysUser.getId());
|
|
|
studentPaymentRouteOrders.add(studentPaymentRouteOrder);
|
|
|
}
|
|
|
}
|
|
@@ -426,8 +479,13 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
throw new BizException("导入失败:请勿录入重复的交易流水号");
|
|
|
}
|
|
|
studentPaymentRouteOrderDao.batchAdd(studentPaymentRouteOrders);
|
|
|
+ }else {
|
|
|
+ throw new BizException("导入失败:没有可以录入的数据");
|
|
|
}
|
|
|
- return studentPaymentRouteOrders;
|
|
|
+ HttpResponseResult httpResponseResult = new HttpResponseResult();
|
|
|
+ httpResponseResult.setData(studentPaymentRouteOrders);
|
|
|
+ httpResponseResult.setMsg(sb.toString());
|
|
|
+ return httpResponseResult;
|
|
|
}
|
|
|
|
|
|
}
|