Commit 1dc524df5777ea868c1845b5e490299b1a4dda1c
1 parent
18a60f74
Exists in
master
1.增加参数支持
Showing
8 changed files
with
130 additions
and
35 deletions
Show diff stats
src/main/java/com/taover/bazhuayun/analysis/script/goodscollect/GoodsDataFileParser.java
| ... | ... | @@ -9,6 +9,7 @@ import java.util.List; |
| 9 | 9 | import java.util.Set; |
| 10 | 10 | |
| 11 | 11 | import com.taover.bazhuayun.analysis.util.ExcelUtil; |
| 12 | +import com.taover.util.UtilString; | |
| 12 | 13 | |
| 13 | 14 | public class GoodsDataFileParser { |
| 14 | 15 | private String fileNameIgnorePreffix; |
| ... | ... | @@ -31,10 +32,15 @@ public class GoodsDataFileParser { |
| 31 | 32 | |
| 32 | 33 | public void parse(GroupInfoExcelData groupInfoData, File[] listFiles) throws Exception { |
| 33 | 34 | for(int i=0; i<listFiles.length; ++i) { |
| 35 | +// if(!listFiles[i].getName().contains("8.24海囤新系统报单(730份)8.23 一般贸易货!法国本土版!兰蔻大粉水400ml(1)")) { | |
| 36 | +// continue; | |
| 37 | +// } | |
| 34 | 38 | try { |
| 39 | + this.logStrBuffer.append("=================文件名称["+listFiles[i].getName()+"]==================\n"); | |
| 35 | 40 | this.parseFile(listFiles[i]); |
| 36 | 41 | }catch(Exception e) { |
| 37 | 42 | e.printStackTrace(); |
| 43 | + this.logStrBuffer.append("ERROR:处理报错"+e.getMessage()+"\n"); | |
| 38 | 44 | } |
| 39 | 45 | } |
| 40 | 46 | } |
| ... | ... | @@ -50,15 +56,45 @@ public class GoodsDataFileParser { |
| 50 | 56 | return; |
| 51 | 57 | } |
| 52 | 58 | |
| 53 | - //写入set | |
| 54 | - GoodsInfoExcelDataHeader header = new GoodsInfoExcelDataHeader(this.goodsNamePatternArr, this.goodsSkuNameParrternArr, data.get(0)); | |
| 55 | - if(!header.available()) { | |
| 56 | - this.logStrBuffer.append("=================文件名称["+item.getName()+"]==================\n"); | |
| 57 | - this.logStrBuffer.append("没找到商品列或规格列\n"); | |
| 59 | + //计算起始行及表头索引 | |
| 60 | + int headerRowIndex = 0; | |
| 61 | + GoodsInfoExcelDataHeader header = null; | |
| 62 | + while(headerRowIndex<data.size()) { | |
| 63 | + List<Object> tempHeaderData = data.get(headerRowIndex); | |
| 64 | + if(this.notBlankDataCount(tempHeaderData) < 3) { | |
| 65 | + ++headerRowIndex; | |
| 66 | + continue; | |
| 67 | + } | |
| 68 | + header = new GoodsInfoExcelDataHeader(this.goodsNamePatternArr, this.goodsSkuNameParrternArr, tempHeaderData); | |
| 69 | + if(!header.available()) { | |
| 70 | + this.logStrBuffer.append("ERROR:没找到商品列或规格列\n"); | |
| 71 | + return; | |
| 72 | + } | |
| 73 | + break; | |
| 58 | 74 | } |
| 59 | - for(int j=1; j<data.size(); ++j) { | |
| 60 | - this.rowSet.add(new GoodsInfoRow(groupInfo, header, data.get(j))); | |
| 75 | + | |
| 76 | + //写入结果集 | |
| 77 | + for(int j=headerRowIndex+1; j<data.size(); ++j) { | |
| 78 | + this.rowSet.add(new GoodsInfoRow(groupInfo, header, data.get(j), fileName)); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + private int notBlankDataCount(List<Object> tempHeaderData) { | |
| 83 | + if(tempHeaderData == null || tempHeaderData.isEmpty()) { | |
| 84 | + return 0; | |
| 85 | + } | |
| 86 | + int count = 0; | |
| 87 | + for(int i=0; i<tempHeaderData.size(); ++i) { | |
| 88 | + Object item = tempHeaderData.get(i); | |
| 89 | + if(item == null) { | |
| 90 | + continue; | |
| 91 | + } | |
| 92 | + String itemStr = UtilString.trimByRegexS(item.toString()); | |
| 93 | + if(!"".equals(itemStr)) { | |
| 94 | + ++count; | |
| 95 | + } | |
| 61 | 96 | } |
| 97 | + return count; | |
| 62 | 98 | } |
| 63 | 99 | |
| 64 | 100 | public List<GoodsInfoRow> getResult() { | ... | ... |
src/main/java/com/taover/bazhuayun/analysis/script/goodscollect/GoodsInfoExcelDataHeader.java
| ... | ... | @@ -14,11 +14,11 @@ public class GoodsInfoExcelDataHeader { |
| 14 | 14 | if(item == null) { |
| 15 | 15 | continue; |
| 16 | 16 | } |
| 17 | - if(this.goodsNameIndex == null && StringTool.getStartWithStringIndex(item.toString(), goodsNamePattern) != -1) { | |
| 17 | + if(this.goodsNameIndex == null && StringTool.getStringIndexByPatternContains(item.toString(), goodsNamePattern) != -1) { | |
| 18 | 18 | this.goodsNameIndex = i; |
| 19 | 19 | continue; |
| 20 | 20 | } |
| 21 | - if(this.goodsSkuNameIndex == null && StringTool.getStartWithStringIndex(item.toString(), goodsSkuNamePattern) != -1) { | |
| 21 | + if(this.goodsSkuNameIndex == null && StringTool.getStringIndexByPatternContains(item.toString(), goodsSkuNamePattern) != -1) { | |
| 22 | 22 | this.goodsSkuNameIndex = i; |
| 23 | 23 | continue; |
| 24 | 24 | } | ... | ... |
src/main/java/com/taover/bazhuayun/analysis/script/goodscollect/GoodsInfoRow.java
| ... | ... | @@ -9,8 +9,9 @@ public class GoodsInfoRow implements Comparable<GoodsInfoRow>{ |
| 9 | 9 | private String originGoodsSkuName; |
| 10 | 10 | private String commonGoodsSkuName; |
| 11 | 11 | private String senderNickname; |
| 12 | + private String fileName; | |
| 12 | 13 | |
| 13 | - public GoodsInfoRow(GroupInfoExcelDataRow groupInfo, GoodsInfoExcelDataHeader header, List<Object> data) { | |
| 14 | + public GoodsInfoRow(GroupInfoExcelDataRow groupInfo, GoodsInfoExcelDataHeader header, List<Object> data, String fileName) { | |
| 14 | 15 | if(groupInfo != null) { |
| 15 | 16 | this.groupNickname = groupInfo.getGroupName(); |
| 16 | 17 | this.senderNickname = groupInfo.getSendNickname(); |
| ... | ... | @@ -20,6 +21,7 @@ public class GoodsInfoRow implements Comparable<GoodsInfoRow>{ |
| 20 | 21 | } |
| 21 | 22 | this.originGoodsName = this.getEmptyStrWhenNull(data, header.getGoodsNameIndex()); |
| 22 | 23 | this.originGoodsSkuName = this.getEmptyStrWhenNull(data, header.getGoodsSkuNameIndex()); |
| 24 | + this.fileName = fileName; | |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | private String getEmptyStrWhenNull(List<Object> data, Integer goodsNameIndex) { |
| ... | ... | @@ -37,43 +39,63 @@ public class GoodsInfoRow implements Comparable<GoodsInfoRow>{ |
| 37 | 39 | return ""; |
| 38 | 40 | } |
| 39 | 41 | } |
| 40 | - | |
| 42 | + | |
| 41 | 43 | public String getOriginGoodsName() { |
| 42 | 44 | return originGoodsName; |
| 43 | 45 | } |
| 46 | + | |
| 44 | 47 | public void setOriginGoodsName(String originGoodsName) { |
| 45 | 48 | this.originGoodsName = originGoodsName; |
| 46 | 49 | } |
| 50 | + | |
| 47 | 51 | public String getCommonGoodsName() { |
| 48 | 52 | return commonGoodsName; |
| 49 | 53 | } |
| 54 | + | |
| 50 | 55 | public void setCommonGoodsName(String commonGoodsName) { |
| 51 | 56 | this.commonGoodsName = commonGoodsName; |
| 52 | 57 | } |
| 58 | + | |
| 53 | 59 | public String getGroupNickname() { |
| 54 | 60 | return groupNickname; |
| 55 | 61 | } |
| 56 | - public void setGroupNickname(String groupName) { | |
| 57 | - this.groupNickname = groupName; | |
| 62 | + | |
| 63 | + public void setGroupNickname(String groupNickname) { | |
| 64 | + this.groupNickname = groupNickname; | |
| 58 | 65 | } |
| 66 | + | |
| 59 | 67 | public String getOriginGoodsSkuName() { |
| 60 | 68 | return originGoodsSkuName; |
| 61 | 69 | } |
| 70 | + | |
| 62 | 71 | public void setOriginGoodsSkuName(String originGoodsSkuName) { |
| 63 | 72 | this.originGoodsSkuName = originGoodsSkuName; |
| 64 | 73 | } |
| 74 | + | |
| 65 | 75 | public String getCommonGoodsSkuName() { |
| 66 | 76 | return commonGoodsSkuName; |
| 67 | 77 | } |
| 68 | - public void setCommonGooodsSkuName(String commonSkuName) { | |
| 69 | - this.commonGoodsSkuName = commonSkuName; | |
| 78 | + | |
| 79 | + public void setCommonGoodsSkuName(String commonGoodsSkuName) { | |
| 80 | + this.commonGoodsSkuName = commonGoodsSkuName; | |
| 70 | 81 | } |
| 82 | + | |
| 71 | 83 | public String getSenderNickname() { |
| 72 | 84 | return senderNickname; |
| 73 | 85 | } |
| 86 | + | |
| 74 | 87 | public void setSenderNickname(String senderNickname) { |
| 75 | 88 | this.senderNickname = senderNickname; |
| 76 | 89 | } |
| 90 | + | |
| 91 | + public String getFileName() { | |
| 92 | + return fileName; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public void setFileName(String fileName) { | |
| 96 | + this.fileName = fileName; | |
| 97 | + } | |
| 98 | + | |
| 77 | 99 | @Override |
| 78 | 100 | public int hashCode() { |
| 79 | 101 | final int prime = 31; |
| ... | ... | @@ -115,12 +137,8 @@ public class GoodsInfoRow implements Comparable<GoodsInfoRow>{ |
| 115 | 137 | public int compareTo(GoodsInfoRow o) { |
| 116 | 138 | if(o == null) { |
| 117 | 139 | return 1; |
| 118 | - } | |
| 119 | - if(this.equals(o)) { | |
| 120 | - return 0; | |
| 121 | - }else { | |
| 122 | - return this.calcDistince(o); | |
| 123 | - } | |
| 140 | + } | |
| 141 | + return this.calcDistince(o); | |
| 124 | 142 | } |
| 125 | 143 | |
| 126 | 144 | private int calcDistince(GoodsInfoRow o) { |
| ... | ... | @@ -155,6 +173,6 @@ public class GoodsInfoRow implements Comparable<GoodsInfoRow>{ |
| 155 | 173 | goodsSkuNameDistince = this.originGoodsSkuName.hashCode()-o.originGoodsSkuName.hashCode(); |
| 156 | 174 | } |
| 157 | 175 | |
| 158 | - return (int)(1.0*groupDistince/Integer.MAX_VALUE*1000)+(int)(1.0*goodsNameDistince/Integer.MAX_VALUE*100)+(int)(1.0*goodsSkuNameDistince/Integer.MAX_VALUE*10); | |
| 159 | - } | |
| 176 | + return (int)(1.0*groupDistince/Integer.MAX_VALUE*1000+groupDistince==0?0:1000)+(int)(1.0*goodsNameDistince/Integer.MAX_VALUE*100+goodsNameDistince==0?0:100)+(int)(1.0*goodsSkuNameDistince/Integer.MAX_VALUE*10+goodsSkuNameDistince==0?0:10); | |
| 177 | + } | |
| 160 | 178 | } | ... | ... |
src/main/java/com/taover/bazhuayun/analysis/script/goodscollect/Main.java
| ... | ... | @@ -19,13 +19,13 @@ public class Main { |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public static void analysisGoodsName() throws Exception { |
| 22 | - String[] goodsNamePatternArr = new String[]{"商品名称","商品标题","货品名称","商品名称","商品信息","品名","商品名","商品简称","产品名称","物品名称","货品摘要","发货信息"}; | |
| 22 | + String[] goodsNamePatternArr = new String[]{"商品名称","商品标题","货品名称","商品名称","商品信息","品名","商品名","商品简称","产品名称","物品名称","货品摘要","发货信息","商家SPU编码"}; | |
| 23 | 23 | String[] goodsSkuNameParrternArr = new String[]{"商品规格名","规格","商品规格","规格名称","商品型号"}; |
| 24 | - String dataDirPath = "C:\\Users\\Administrator\\Desktop\\悟空家21-25"; | |
| 25 | - String groupInfoFilePath = dataDirPath + File.separator + "悟空家-仓库群文件-21-25.xlsx"; | |
| 26 | - String goodsDataFileDirPath = dataDirPath + File.separator + "data"; | |
| 27 | - String logFilePath = dataDirPath + File.separator + "dealinfo.log"; | |
| 28 | - String resultDataFilePath = dataDirPath + File.separator + "result.xls"; | |
| 24 | + String dataDirPath = "C:\\Users\\Administrator\\Desktop\\悟空家数据\\25-27"; | |
| 25 | + String groupInfoFilePath = dataDirPath + File.separator + "仓库群文件.xlsx"; | |
| 26 | + String goodsDataFileDirPath = dataDirPath + File.separator + "订单数据"; | |
| 27 | + String logFilePath = dataDirPath + File.separator + "异常文件信息.log"; | |
| 28 | + String resultDataFilePath = dataDirPath + File.separator + "程序商品识别结果.xls"; | |
| 29 | 29 | |
| 30 | 30 | //加载基础数据,文件来源 |
| 31 | 31 | GroupInfoExcelData groupInfoData = new GroupInfoExcelData(); |
| ... | ... | @@ -54,10 +54,11 @@ public class Main { |
| 54 | 54 | header.add("自选规格"); |
| 55 | 55 | header.add("仓库群名称"); |
| 56 | 56 | header.add("发文件的人"); |
| 57 | + header.add("来源文件"); | |
| 57 | 58 | data.add(header); |
| 58 | 59 | |
| 59 | 60 | //加入BODY |
| 60 | - for(int i=1; i<result.size(); ++i) { | |
| 61 | + for(int i=0; i<result.size(); ++i) { | |
| 61 | 62 | GoodsInfoRow row = result.get(i); |
| 62 | 63 | List<Object> item = new ArrayList<Object>(); |
| 63 | 64 | item.add(row.getOriginGoodsName()); |
| ... | ... | @@ -66,6 +67,7 @@ public class Main { |
| 66 | 67 | item.add(row.getCommonGoodsSkuName()); |
| 67 | 68 | item.add(row.getGroupNickname()); |
| 68 | 69 | item.add(row.getSenderNickname()); |
| 70 | + item.add(row.getFileName()); | |
| 69 | 71 | data.add(item); |
| 70 | 72 | } |
| 71 | 73 | ... | ... |
src/main/java/com/taover/bazhuayun/analysis/script/orderdownload/Main.java
| ... | ... | @@ -14,9 +14,9 @@ public class Main { |
| 14 | 14 | public static final String ossUrlPreffix = "https://8zyun-oss.oss-cn-beijing.aliyuncs.com"; |
| 15 | 15 | |
| 16 | 16 | public static void main(String[] args) throws Exception { |
| 17 | - String dirPath = "C:\\Users\\Administrator\\Desktop\\悟空家21-25"; | |
| 18 | - String urlFileName = "悟空家-仓库群文件-21-25.xlsx"; | |
| 19 | - String dataDirName = "data"; | |
| 17 | + String dirPath = "C:\\Users\\Administrator\\Desktop\\悟空家数据\\25-27"; | |
| 18 | + String urlFileName = "仓库群文件.xlsx"; | |
| 19 | + String dataDirName = "订单数据"; | |
| 20 | 20 | |
| 21 | 21 | List<List<Object>> fieldData = ExcelUtil.readExcelSheet(new File(dirPath+File.separator+urlFileName), false); |
| 22 | 22 | ExcelParser<GroupInfoExcelDataBean> parser = new ExcelAnnoParser<GroupInfoExcelDataBean>(); | ... | ... |
src/main/java/com/taover/bazhuayun/analysis/util/StringTool.java
| ... | ... | @@ -127,6 +127,21 @@ public class StringTool { |
| 127 | 127 | return result; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | + public static int getStringIndexByPatternContains(String pattern, String compares[]){ | |
| 131 | + //参数检验 | |
| 132 | + if(pattern==null || compares==null){ | |
| 133 | + return -1; | |
| 134 | + } | |
| 135 | + | |
| 136 | + //循环遍历compares | |
| 137 | + for(int i=0; i<compares.length; ++i){ | |
| 138 | + if(pattern.contains(compares[i])){ | |
| 139 | + return i; | |
| 140 | + } | |
| 141 | + } | |
| 142 | + return -1; | |
| 143 | + } | |
| 144 | + | |
| 130 | 145 | public static int getStartWithStringIndex(String pattern, String compares[]){ |
| 131 | 146 | //参数检验 |
| 132 | 147 | if(pattern==null || compares==null){ | ... | ... |
src/main/java/com/taover/bazhuayun/analysis/web/controller/ExportCenterController.java
| ... | ... | @@ -31,9 +31,13 @@ public class ExportCenterController { |
| 31 | 31 | public void wareOrderFile(@RequestParam(name="tenantId", required=true) Integer tenantId, |
| 32 | 32 | @RequestParam(name="startDate", defaultValue = "") String startDateStr, |
| 33 | 33 | @RequestParam(name="endDate", defaultValue = "") String endDateStr, |
| 34 | + @RequestParam(name="wareCreateStartDate", defaultValue = "") String wareCreateStartDateStr, | |
| 35 | + @RequestParam(name="wareCreateEndDate", defaultValue = "") String wareCreateEndDateStr, | |
| 34 | 36 | HttpServletResponse response) { |
| 35 | 37 | Date startDate = new Date(); |
| 36 | 38 | Date endDate = new Date(); |
| 39 | + Date wareCreateStartDate = null; | |
| 40 | + Date wareCreateEndDate = null; | |
| 37 | 41 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| 38 | 42 | if(StringUtils.isNotBlank(startDateStr)) { |
| 39 | 43 | try { |
| ... | ... | @@ -49,10 +53,24 @@ public class ExportCenterController { |
| 49 | 53 | e.printStackTrace(); |
| 50 | 54 | } |
| 51 | 55 | } |
| 56 | + if(StringUtils.isNotBlank(wareCreateStartDateStr)) { | |
| 57 | + try { | |
| 58 | + wareCreateStartDate = sdf.parse(wareCreateStartDateStr.substring(0, 10)); | |
| 59 | + } catch (ParseException e) { | |
| 60 | + e.printStackTrace(); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + if(StringUtils.isNotBlank(wareCreateEndDateStr)) { | |
| 64 | + try { | |
| 65 | + wareCreateEndDate = sdf.parse(wareCreateEndDateStr.substring(0, 10)); | |
| 66 | + } catch (ParseException e) { | |
| 67 | + e.printStackTrace(); | |
| 68 | + } | |
| 69 | + } | |
| 52 | 70 | |
| 53 | 71 | File orderFile = null; |
| 54 | 72 | try { |
| 55 | - orderFile = this.exportCenterService.wareOrderFile(tenantId, startDate, endDate); | |
| 73 | + orderFile = this.exportCenterService.wareOrderFile(tenantId, startDate, endDate, wareCreateStartDate, wareCreateEndDate); | |
| 56 | 74 | } catch (IOException e1) { |
| 57 | 75 | UtilLog.errorForException(e1, this.getClass()); |
| 58 | 76 | return; | ... | ... |
src/main/java/com/taover/bazhuayun/analysis/web/service/ExportCenterService.java
| ... | ... | @@ -20,13 +20,19 @@ public class ExportCenterService { |
| 20 | 20 | @Resource |
| 21 | 21 | private JdbcTemplate jdbcTemplate; |
| 22 | 22 | |
| 23 | - public File wareOrderFile(Integer tenantId, Date startDate, Date endDate) throws IOException { | |
| 23 | + public File wareOrderFile(Integer tenantId, Date startDate, Date endDate, Date wareCreateStartDate, Date wareCreateEndDate) throws IOException { | |
| 24 | 24 | //查询agentID |
| 25 | 25 | String agentIdQuery = "select agent_id from wxorder_agent_pc where tenant_id="+tenantId+" limit 1 "; |
| 26 | 26 | Integer agentId = this.jdbcTemplate.queryForObject(agentIdQuery, Integer.class); |
| 27 | 27 | |
| 28 | 28 | //查询仓库对应群列表 |
| 29 | 29 | String wareGroupQuery = "select wx_group_ssid,wx_group_nickname,name from wxorder_ware where tenant_id="+tenantId; |
| 30 | + if(wareCreateStartDate != null) { | |
| 31 | + wareGroupQuery += " and create_time>'"+new SimpleDateFormat("yyyy-MM-dd").format(wareCreateStartDate)+" 00:00:00' "; | |
| 32 | + } | |
| 33 | + if(wareCreateEndDate != null) { | |
| 34 | + wareGroupQuery += " and create_time<='"+new SimpleDateFormat("yyyy-MM-dd").format(wareCreateEndDate)+" 23:59:59' "; | |
| 35 | + } | |
| 30 | 36 | List<Map<String, Object>> groupData = this.jdbcTemplate.queryForList(wareGroupQuery); |
| 31 | 37 | |
| 32 | 38 | //依据群id,获取数据列表 | ... | ... |