Commit 8b45c19a authored by 刘文胜's avatar 刘文胜

excel转换

parent 4353c979
...@@ -2,7 +2,10 @@ package com.hdp.pi.dto.kolon; ...@@ -2,7 +2,10 @@ package com.hdp.pi.dto.kolon;
import java.io.Serializable; import java.io.Serializable;
import org.apache.commons.lang.StringUtils;
import com.hdp.pi.utils.kolon.CONSTANTS; import com.hdp.pi.utils.kolon.CONSTANTS;
import com.hdp.pi.utils.kolon.Util;
public class KolonMemberDTO implements Serializable { public class KolonMemberDTO implements Serializable {
...@@ -35,18 +38,22 @@ public class KolonMemberDTO implements Serializable { ...@@ -35,18 +38,22 @@ public class KolonMemberDTO implements Serializable {
public KolonMemberDTO(){ public KolonMemberDTO(){
} }
public KolonMemberDTO(String[] s) {
public KolonMemberDTO(String[] row) {
super(); super();
this.csNo = Long.valueOf(s[1]); this.csNo = Long.valueOf(Util.getByIndex(row, 1));
this.status = CONSTANTS.STATUS.get(s[2]); this.status = CONSTANTS.STATUS.get(Util.getByIndex(row, 2));
this.bonus = Integer.valueOf(s[3]); String b_str = Util.getByIndex(row, 3);
this.cardNo = s[4]; if(StringUtils.isNotEmpty(b_str)){
this.lifecycle = s[5]; this.bonus = Integer.valueOf(b_str);
this.customerType = CONSTANTS.CUSTERMERTYPE.get(s[6]); }
this.lastName = s[7]; this.cardNo = Util.getByIndex(row, 4);
this.firstName = s[8]; this.lifecycle = Util.getByIndex(row, 5);
this.email = s[9]; this.customerType = CONSTANTS.CUSTERMERTYPE.get(Util.getByIndex(row, 6));
this.phone = s[10]; this.lastName = Util.getByIndex(row, 7);
this.firstName = Util.getByIndex(row, 8);
this.email = Util.getByIndex(row, 9);
this.phone = Util.getByIndex(row, 10);
this.wechatLastName= this.lastName; this.wechatLastName= this.lastName;
this.wechatFirstName= this.firstName; this.wechatFirstName= this.firstName;
} }
......
...@@ -202,31 +202,20 @@ public class KolonMemberServiceImpl implements KolonMemberService { ...@@ -202,31 +202,20 @@ public class KolonMemberServiceImpl implements KolonMemberService {
saleRepository.save(sale); saleRepository.save(sale);
} }
private String getByIndex(String[] row,int index){
if(row == null){
return "";
}
if(index < 0 || index >= row.length){
return "";
}
return row[index];
}
private Product newProduct(String[] row){ private Product newProduct(String[] row){
Product p = new Product(); Product p = new Product();
try{ try{
p.id = getByIndex(row, 0); p.id = Util.getByIndex(row, 0);
p.title = getByIndex(row, 1); p.title = Util.getByIndex(row, 1);
p.category = getByIndex(row, 2); p.category = Util.getByIndex(row, 2);
p.image = getByIndex(row, 3); p.image = Util.getByIndex(row, 3);
p.link = getByIndex(row, 4); p.link = Util.getByIndex(row, 4);
p.avaliable = getByIndex(row, 5); p.avaliable = Util.getByIndex(row, 5);
p.dept = getByIndex(row, 6); p.dept = Util.getByIndex(row, 6);
p.seaons = getByIndex(row, 7); p.seaons = Util.getByIndex(row, 7);
p.planyy = getByIndex(row, 8); p.planyy = Util.getByIndex(row, 8);
p.color = getByIndex(row, 9); p.color = Util.getByIndex(row, 9);
p.price = getByIndex(row, 10); p.price = Util.getByIndex(row, 10);
}catch(Throwable e){ }catch(Throwable e){
e.printStackTrace(); e.printStackTrace();
} }
...@@ -236,12 +225,12 @@ public class KolonMemberServiceImpl implements KolonMemberService { ...@@ -236,12 +225,12 @@ public class KolonMemberServiceImpl implements KolonMemberService {
private Sale newSale(String[] row){ private Sale newSale(String[] row){
Sale s = new Sale(); Sale s = new Sale();
try{ try{
s.oId = getByIndex(row, 0); s.oId = Util.getByIndex(row, 0);
s.oDate = Integer.valueOf(getByIndex(row, 1)); s.oDate = Integer.valueOf(Util.getByIndex(row, 1));
s.customer = getByIndex(row, 2); s.customer = Util.getByIndex(row, 2);
s.item = getByIndex(row, 3); s.item = Util.getByIndex(row, 3);
s.quantity = Integer.valueOf(getByIndex(row, 4)); s.quantity = Integer.valueOf(Util.getByIndex(row, 4));
s.amount = Double.valueOf(getByIndex(row, 5)); s.amount = Double.valueOf(Util.getByIndex(row, 5));
}catch(Throwable e){ }catch(Throwable e){
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -55,7 +55,9 @@ public class FtpScheduledTask { ...@@ -55,7 +55,9 @@ public class FtpScheduledTask {
* 同步数据 * 同步数据
*/ */
public void readCSVFile() { public void readCSVFile() {
kolonMemberService.syncData(); kolonMemberService.syncMemberData();
kolonMemberService.syncProductData();
kolonMemberService.syncSaleData();
} }
/** /**
......
...@@ -19,4 +19,14 @@ public class Util { ...@@ -19,4 +19,14 @@ public class Util {
return (s == null || "".equals(s)) ? false : true; return (s == null || "".equals(s)) ? false : true;
} }
public static String getByIndex(String[] row,int index){
if(row == null){
return "";
}
if(index < 0 || index >= row.length){
return "";
}
return row[index];
}
} }
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