Commit 1f63568c by kangxiaoshan

合同导入

parent a4666868
......@@ -13,6 +13,8 @@ import dic.RoleEnum;
import net.sf.json.JSONArray;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
......@@ -2066,8 +2068,23 @@ public class ContractServiceImpl implements ContractService {
}
String platform = SHEET_NAMES.get(sheetName);
Map<String, Long> tradTypeMap = tradeTypeRepsitory.findAll().stream().collect(Collectors.toMap(TradeType::getName, TradeType::getId));
Map<String, Long> salseMap = salesRepository.findSaleByStatus(0).stream().collect(Collectors.toMap(Sales::getName, Sales::getId));
Map<String, Long> tradTypeMap = tradeTypeRepsitory.findAll()
.stream().collect(Collectors.toMap(TradeType::getName, TradeType::getId));
Map<String, Long> salseMap = salesRepository.findSaleByStatus(0)
.stream().collect(Collectors.toMap(Sales::getName, Sales::getId));
Map<String, Long> packageMap = null;
if ("tkio".equals(platform) || "io".equals(platform)) {
packageMap = packageTypeRepository.findIsNewAll()
.stream().collect(Collectors.toMap(PackageType::getPackageName, PackageType::getId));
} else {
packageMap = packageBaseRepository.findByPlatAndStatus(platform, 1)
.stream().collect(Collectors.toMap(PackageBase::getPackageName, PackageBase::getId));
}
Map<String, String> cBodyMap = contractBodyRepository.findAllDis()
.stream().collect(Collectors.toMap(ContractBody::getName, ContractBody::getCode));
Row row = sheet.getRow(0);
if (!UPLOAD_TITLE.equals(parseRowData(row, row_length, null))) {
......@@ -2078,9 +2095,15 @@ public class ContractServiceImpl implements ContractService {
int rowNumber = sheet.getLastRowNum();
List<Object[]> args_data = new ArrayList<>();
String extend_row_sql = ",platform,product,my_body_code";
int extend_row = 3;
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/mm/dd");
for (int j = 1; j <= rowNumber; j++) {
Row row_data = sheet.getRow(j);
Object[] s_data = new Object[row_length];
Object[] s_data = new Object[row_length + extend_row];
String bodyCode = null;
for (int w = 0; w < row_length; w++) {
Cell cell = row_data.getCell(w);
if (null != cell && !cell.getCellTypeEnum().equals(CellType.BLANK)) {
......@@ -2088,23 +2111,75 @@ public class ContractServiceImpl implements ContractService {
} else {
String dataSTR = formatter.formatCellValue(cell);
int line_num = j + 1;
if (w == 2 && !tradTypeMap.containsKey(dataSTR)) {
return ResultModel.ERROR("第" + (j + 1) + "行[行业分类]错误");
} else if (w == 5 && !salseMap.containsKey(dataSTR)) {
return ResultModel.ERROR("第" + (j + 1) + "行[签约销售]错误");
}
s_data[w] = dataSTR;
if (w == 0) {
if (!cBodyMap.containsKey(dataSTR)) {
return ResultModel.ERROR("第" + line_num + "行[我方签约主体]错误");
} else {
s_data[w] = dataSTR;
bodyCode = cBodyMap.get(dataSTR);
}
} else if (w == 2) {
if (!tradTypeMap.containsKey(dataSTR)) {
return ResultModel.ERROR("第" + line_num + "行[行业分类]错误");
} else {
s_data[w] = tradTypeMap.get(dataSTR);
}
} else if (w == 5) {
if (!salseMap.containsKey(dataSTR)) {
return ResultModel.ERROR("第" + line_num + "行[签约销售]错误");
} else {
s_data[w] = salseMap.get(dataSTR);
}
} else if (w == 8) {
if (!CONTRACT_TYPE.containsKey(dataSTR)) {
return ResultModel.ERROR("第" + line_num + "行[签约类型]错误");
} else {
s_data[w] = salseMap.get(dataSTR);
}
} else if (w == 9) {
if (packageMap != null && !packageMap.containsKey(dataSTR)) {
return ResultModel.ERROR("第" + line_num + "行[套餐]错误");
} else {
s_data[w] = packageMap.get(dataSTR);
}
} else if (w == 3 || w == 4) {
try {
String pattern = "yyyy/MM/dd";
DateTime dateTime = DateTime.parse(dataSTR, DateTimeFormat.forPattern(pattern));
s_data[w] = dateTime.toString("yyyy-MM-dd");
} catch (Exception e) {
return ResultModel.ERROR("第" + line_num + "行[日期]错误");
}
} else {
s_data[w] = dataSTR;
}
}
}
s_data[extend_row] = platform;
s_data[extend_row + 1] = platform;
s_data[extend_row + 2] = bodyCode;
args_data.add(s_data);
}
jdbcTemplate.batchUpdate("insert into contract (my_body_name,customer_body,trade_type,start_date,end_date,sale,email,contract_code, type_id,price_level,money) " +
"values (?,?,?,?,?,?,?,?,?,?,?)", args_data);
String baseSql = "my_body_name,customer_body,trade_type,start_date,end_date,sale,email,contract_code, contract_type,price_level,money";
baseSql = baseSql + extend_row_sql;
String endSql = null;
for (int ed = 0, s = baseSql.split(",").length; ed < s; ed++) {
if (endSql == null) {
endSql = "?";
} else {
endSql = endSql + ",?";
}
}
jdbcTemplate.batchUpdate("insert into contract (" + baseSql + " ) values (" + endSql + ")", args_data);
return ResultModel.OK();
return null;
}
......@@ -2131,4 +2206,19 @@ public class ContractServiceImpl implements ContractService {
return content;
}
public static void main(String[] args) {
String dateStr = "2019/4/31";
// //根据时间表达式生成DateTimeFormatter对象
// DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd");
// //2019-10-28T10:23:12.000+08:00
// DateTime dateTime = fmt.parseDateTime(dateStr);
// System.out.println(dateTime.getDayOfMonth());
// dateTime = dateTime.plusDays(-1);
// System.out.println(dateTime.toString("yyyy-MM-dd"));
String pattern = "yyyy/MM/dd";
DateTime dateTime2 = DateTime.parse(dateStr, DateTimeFormat.forPattern(pattern));
System.out.println(dateTime2.toString("yyyy-MM-dd"));
}
}
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