Commit a4666868 by kangxiaoshan

合同导入

parent 6f9126b4
......@@ -14,6 +14,21 @@
<facet type="Spring" name="Spring">
<configuration />
</facet>
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="Hibernate" />
<datasource-mapping>
<factory-entry name="defaultUnit" />
<factory-entry name="dmpUnit" />
<factory-entry name="ioUnit" />
<factory-entry name="officeUnit" />
<factory-entry name="tkioUnit" />
<factory-entry name="tkrackUnit" />
</datasource-mapping>
<naming-strategy-map />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
......
......@@ -94,19 +94,22 @@
<label>product</label>
<!--数据源配置-->
<datasource.driver>com.mysql.jdbc.Driver</datasource.driver>
<default.datasource.url>jdbc:mysql://10.3.20.32:3306/manager?characterEncoding=utf-8
<!--//office-->
<default.datasource.url>
jdbc:mysql://10.3.20.32:3306/manager?characterEncoding=utf-8
</default.datasource.url>
<default.datasource.username>root</default.datasource.username>
<default.datasource.password>reyun.123</default.datasource.password>
<tkio.url>
jdbc:mysql://10.3.20.32:3306/trackingio_test?characterEncoding=utf-8
</tkio.url>
<tkio.username>root</tkio.username>
<tkio.password>reyun.123</tkio.password>
<office.url>jdbc:mysql://10.3.20.32:3306/office?characterEncoding=utf-8</office.url>
<office.username>root</office.username>
<office.password>reyun.123</office.password>
<tkio.url>jdbc:mysql://10.3.20.32:3306/trackingio_trans?characterEncoding=utf-8</tkio.url>
<tkio.username>root</tkio.username>
<tkio.password>reyun.123</tkio.password>
<track.url>jdbc:mysql://10.3.20.32:3306/track_test?characterEncoding=utf-8</track.url>
<track.username>root</track.username>
<track.password>reyun.123</track.password>
......@@ -129,8 +132,11 @@
<!-- 单位是分钟-->
<mail.valid_time>3</mail.valid_time>
<!--<report.url>http://localhost:9010</report.url>-->
<report.url>http://10.3.20.41:11010</report.url>
<contract.uppath></contract.uppath>
<!--Redis setting-->
<redis.key.validtime>120</redis.key.validtime>
<redis.ip.requesttimes>5</redis.ip.requesttimes>
......@@ -174,19 +180,17 @@
</default.datasource.url>
<default.datasource.username>trackingio</default.datasource.username>
<default.datasource.password>trackingio</default.datasource.password>
<office.url>
jdbc:mysql://track.cma5jkozme68.rds.cn-north-1.amazonaws.com.cn:3306/office?characterEncoding=utf-8
</office.url>
<office.username>office</office.username>
<office.password>office</office.password>
<tkio.url>
jdbc:mysql://tkio.cma5jkozme68.rds.cn-north-1.amazonaws.com.cn:3306/trackingio?characterEncoding=utf-8
</tkio.url>
<tkio.username>trackingio</tkio.username>
<tkio.password>trackingio</tkio.password>
<office.url>
jdbc:mysql://track.cma5jkozme68.rds.cn-north-1.amazonaws.com.cn:3306/office?characterEncoding=utf-8
</office.url>
<office.username>office</office.username>
<office.password>office</office.password>
<track.url>
jdbc:mysql://track.cma5jkozme68.rds.cn-north-1.amazonaws.com.cn:3306/track?characterEncoding=utf-8
......@@ -217,7 +221,6 @@
<mail.valid_time>3</mail.valid_time>
<report.url>http://internal-report-api-976419027.cn-north-1.elb.amazonaws.com.cn</report.url>
<!--Redis setting-->
<redis.key.validtime>120</redis.key.validtime>
<redis.ip.requesttimes>5</redis.ip.requesttimes>
......
package common.service;
import common.model.*;
import org.springframework.web.multipart.MultipartFile;
import util.ResultModel;
import java.util.List;
import java.util.Map;
......@@ -72,4 +74,6 @@ public interface ContractService {
Contract findOne(User loginAccount, String startDate, String endDate, String platform, String contractId);
List<ContractMoney> findPayAll(User loginAccount,String startDate, String endDate, String platform, String moneyType, String packageType, String money_ids);
ResultModel uploadBatchInfo(MultipartFile file, String platform);
}
\ No newline at end of file
......@@ -11,10 +11,13 @@ import dic.ContractStatusEnum;
import dic.ContractTypeEnum;
import dic.RoleEnum;
import net.sf.json.JSONArray;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import tkio.model.Account;
import tkio.model.IncrementFlow;
import tkio.model.PackageType;
......@@ -26,11 +29,13 @@ import tkio.service.TkioAccountService;
import userio.service.AccountIOService;
import userio.service.IOAccountService;
import util.*;
import util.DateUtil;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
......@@ -59,6 +64,16 @@ public class ContractServiceImpl implements ContractService {
put("4", "合同管理");
}};
public static final String UPLOAD_TITLE = "我方签约主体,客户签约主体,行业分类,合同开始日期,合同结束日期," +
"签约销售,客户主账号,合同编号,签约类型,套餐,合同金额";
public static final Map<String, String> SHEET_NAMES = new HashMap() {{
put("TrackingIO", "tkio");
put("DMP", "dmp");
put("防作弊卫士", "fake");
put("ADI", "adi");
}};
@Autowired
ContractRepository contractRepository;
@Autowired
......@@ -125,6 +140,9 @@ public class ContractServiceImpl implements ContractService {
@Autowired
AuthService authService;
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public Map<String, Object> checkAccount(String email, String platfrom) {
......@@ -1873,7 +1891,6 @@ public class ContractServiceImpl implements ContractService {
}
}
@Override
......@@ -2019,4 +2036,99 @@ public class ContractServiceImpl implements ContractService {
}
@Override
public ResultModel uploadBatchInfo(MultipartFile file, String platform) {
InputStream stream = null;
try {
int row_length = 11;
stream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(stream);
// Iterator<Sheet> sheetIter = workbook.sheetIterator();
// while (sheetIter.hasNext()) {
// Sheet sheet = sheetIter.next();
// }
saveDataBySheet(workbook.getSheetAt(0), row_length);
} catch (Exception ex) {
return ResultModel.ERROR(ResultStatus.NONE_FILE_EXIST);
}
return null;
}
public ResultModel saveDataBySheet(Sheet sheet, int row_length) {
String sheetName = sheet.getSheetName();
if (!SHEET_NAMES.containsKey(sheetName)) {
return ResultModel.ERROR("模板标签页名称错误");
}
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));
Row row = sheet.getRow(0);
if (!UPLOAD_TITLE.equals(parseRowData(row, row_length, null))) {
return ResultModel.ERROR(ResultStatus.FORMAT_FILE_ERRO);
}
DataFormatter formatter = new DataFormatter();
int rowNumber = sheet.getLastRowNum();
List<Object[]> args_data = new ArrayList<>();
for (int j = 1; j <= rowNumber; j++) {
Row row_data = sheet.getRow(j);
Object[] s_data = new Object[row_length];
for (int w = 0; w < row_length; w++) {
Cell cell = row_data.getCell(w);
if (null != cell && !cell.getCellTypeEnum().equals(CellType.BLANK)) {
return ResultModel.ERROR(ResultStatus.UPLOAD_CONTENT_ERRO);
} 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;
}
}
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);
return null;
}
private Object parseRowData(Row row, int length, StringBuffer content) {
if (row == null) {
return null;
}
if (content == null) {
content = new StringBuffer();
}
DataFormatter formatter = new DataFormatter();
for (int i = 0; i < length; i++) {
Cell cell = row.getCell(i);
if (null != cell && !cell.getCellTypeEnum().equals(CellType.BLANK)) {
if (content.length() == 0) {
content.append(formatter.formatCellValue(cell));
} else {
content.append("," + formatter.formatCellValue(cell));
}
}
}
return content;
}
}
......@@ -39,7 +39,7 @@ public enum ResultStatus {
SURL_NULL(-1105, "短链为空"),
CAMPAIGN_NULL(-1106, "推广活动不存在"),
CAMPAIGN_EXISTS(-1107, "此分包渠道的活动已存在"),
CAMPAIGN_REPEAT(-1008,"批量创建推广活动时名称重复"),
CAMPAIGN_REPEAT(-1008, "批量创建推广活动时名称重复"),
MSG_SMS_OUTOFTIME(-4001, "验证码过时,重新获取"),
MSG_SMS_REQUESTTIMES(-4002, "今天请求验证码次数过多"),
......@@ -52,7 +52,10 @@ public enum ResultStatus {
CHANNELACCOUNT_EXIST(-5003, "该账号ID已创建投放账号,不可重复创建"),
CHANNEL_LINKID_NOEXIST(-5004, "link_id不存在"),
COMMON_IP_EXISTS(-7000, "公共ip已存在"),
EXP_INVALID(11000, "自定义表达式错误");
EXP_INVALID(11000, "自定义表达式错误"),
NONE_FILE_EXIST(-1000, "上传文件为空"),
FORMAT_FILE_ERRO(-10001, "模板文件格式错误"),
UPLOAD_CONTENT_ERRO(-10002, "模板文件内容错误");
/**
......
......@@ -339,4 +339,7 @@
</bean>
<bean id="appUtils" class="common.context.AppUtils" lazy-init="false"/>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
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