|
@@ -26,6 +26,15 @@ const (
|
|
|
|
|
|
FenweiYangBenIndexNamePre = "样本焦企炼焦煤库存可用天数"
|
|
|
FenweiYangBenIndexClassifyId = 5 // 样本焦企炼焦分类ID
|
|
|
+
|
|
|
+ FenweiExcelNameF = "焦炭产销存-61家"
|
|
|
+ FenweiNewExcelNameF = "炼焦煤产销存分省-61家"
|
|
|
+ FenweiExcelNameG = "焦炭产销存-100家"
|
|
|
+ FenweiNewExcelNameG = "炼焦炭产销存分省-100家"
|
|
|
+ FenweiExcelNameH = "样本钢厂焦炭库存"
|
|
|
+
|
|
|
+ FenweiYangBenSteelCoalIndexNamePre = "样本钢厂焦炭可用天数"
|
|
|
+ FenweiYangBenSteelCoalIndexClassifyId = 35 // 样本焦企炼焦分类ID
|
|
|
)
|
|
|
|
|
|
var FenweiProvinces = []string{
|
|
@@ -58,6 +67,9 @@ var FenweiFirstClassifyMap = map[string]int{
|
|
|
FenweiExcelNameC: 3,
|
|
|
FenweiExcelNameD: 4,
|
|
|
FenweiExcelNameE: 5,
|
|
|
+ FenweiExcelNameF: 33,
|
|
|
+ FenweiExcelNameG: 34,
|
|
|
+ FenweiExcelNameH: 35,
|
|
|
}
|
|
|
|
|
|
// FenweiNewDlm66DiffIndexNameReplaceMapping 动力煤66家-指标名称不同的进行替换
|
|
@@ -171,11 +183,66 @@ var FenweiNewJm88DiffIndexNameReplaceMapping = map[string]string{
|
|
|
// FenweiNewJm88IgnoreIndexNameMapping 焦煤88家-需要忽略的指标名称
|
|
|
var FenweiNewJm88IgnoreIndexNameMapping = make([]string, 0)
|
|
|
|
|
|
+// FenweiNewJt61DiffIndexNameReplaceMapping 焦炭61家-指标名称不同的进行替换
|
|
|
+var FenweiNewJt61DiffIndexNameReplaceMapping = map[string]string{
|
|
|
+ "价格情况焦化厂数量": "焦化厂数量",
|
|
|
+ "价格情况上涨煤矿数量": "上涨煤矿数量",
|
|
|
+ "价格情况平均上涨(元/吨)": "价格平均上涨",
|
|
|
+ "下跌焦化厂数量": "价格下跌焦化厂数量",
|
|
|
+ "价格情况平均下跌(元/吨)": "价格平均下跌",
|
|
|
+ "价格情况持平焦化厂数量": "价格持平焦化厂数量",
|
|
|
+ "原煤库存情况库存总量(万吨)": "原煤库存",
|
|
|
+ "焦炭库存情况库存总量(万吨)": "精煤库存",
|
|
|
+ "焦炭库存情况库存销售比(天数)": "库存销售比(天数)",
|
|
|
+ "开工情况平均开工率(算数)": "算数平均开工率",
|
|
|
+ "开工情况开工率(加权)": "加权开工率",
|
|
|
+ "开工情况本周焦炭产量(万吨)": "本周焦炭产量",
|
|
|
+ "销售良好": "销售良好焦炭数量",
|
|
|
+ "销售正常": "销售正常焦炭数量",
|
|
|
+ "销售不好": "销售不好焦炭数量",
|
|
|
+ "成本盈利企业数量": "盈利企业数量",
|
|
|
+ "成本平均利润": "焦炭平均利润",
|
|
|
+ "成本亏损企业数量": "亏损企业数量",
|
|
|
+}
|
|
|
+
|
|
|
+// FenweiNewJt61IgnoreIndexNameMapping 焦炭61家-需要忽略的指标名称
|
|
|
+var FenweiNewJt61IgnoreIndexNameMapping = []string{
|
|
|
+ "焦炭库存情况环比(万吨)", "焦炭库存情况环比(天数)", "开工情况开工率变化", "开工情况开工率变化(加权)", "开工情况环比产量变化",
|
|
|
+}
|
|
|
+
|
|
|
+// FenweiNewJt100DiffIndexNameReplaceMapping 焦炭100家-指标名称不同的进行替换
|
|
|
+var FenweiNewJt100DiffIndexNameReplaceMapping = map[string]string{
|
|
|
+ "价格情况焦化厂数量": "焦化厂数量",
|
|
|
+ "价格情况上涨煤矿数量": "价格上涨煤矿数量",
|
|
|
+ "价格情况平均上涨(元/吨)": "价格平均上涨",
|
|
|
+ "下跌焦化厂数量": "价格下跌焦化厂数量",
|
|
|
+ "价格情况平均下跌(元/吨)": "价格平均下跌",
|
|
|
+ "价格情况持平焦化厂数量": "价格持平焦化厂数量",
|
|
|
+ "原煤库存情况库存总量(万吨)": "原煤库存",
|
|
|
+ "焦炭库存情况库存总量(万吨)": "精煤库存",
|
|
|
+ "焦炭库存情况库存销售比(天数)": "库存销售比(天数)",
|
|
|
+ "开工情况产能利用率": "产能利用率",
|
|
|
+ "开工情况本周焦炭产量(万吨)": "本周焦炭产量",
|
|
|
+ "销售良好": "销售良好焦炭数量",
|
|
|
+ "销售正常": "销售正常焦炭数量",
|
|
|
+ "销售不好": "销售不好焦炭数量",
|
|
|
+ "成本盈利企业数量": "盈利企业数量",
|
|
|
+ "成本平均利润": "焦炭平均利润",
|
|
|
+ "成本亏损企业数量": "亏损企业数量",
|
|
|
+}
|
|
|
+
|
|
|
+// FenweiNewJt100IgnoreIndexNameMapping 焦炭100家-需要忽略的指标名称
|
|
|
+var FenweiNewJt100IgnoreIndexNameMapping = []string{
|
|
|
+ "焦炭库存情况环比(万吨)", "焦炭库存情况环比(天数)", "开工情况开工率变化", "开工情况开工率变化(加权)", "开工情况环比产量变化",
|
|
|
+}
|
|
|
+
|
|
|
var FenweiNewDiffIndexNameReplaceMapping = map[string]map[string]string{
|
|
|
FenweiExcelNameA: FenweiNewDlm66DiffIndexNameReplaceMapping,
|
|
|
FenweiExcelNameB: FenweiNewDlm100DiffIndexNameReplaceMapping,
|
|
|
FenweiExcelNameC: FenweiNewJm53DiffIndexNameReplaceMapping,
|
|
|
FenweiExcelNameD: FenweiNewJm88DiffIndexNameReplaceMapping,
|
|
|
+ FenweiExcelNameE: FenweiNewJt61DiffIndexNameReplaceMapping,
|
|
|
+ FenweiExcelNameF: FenweiNewJt100DiffIndexNameReplaceMapping,
|
|
|
}
|
|
|
|
|
|
var FenweiNewIgnoreIndexNameMapping = map[string][]string{
|
|
@@ -183,6 +250,8 @@ var FenweiNewIgnoreIndexNameMapping = map[string][]string{
|
|
|
FenweiExcelNameB: FenweiNewDlm100IgnoreIndexNameMapping,
|
|
|
FenweiExcelNameC: FenweiNewJm53IgnoreIndexNameMapping,
|
|
|
FenweiExcelNameD: FenweiNewJm88IgnoreIndexNameMapping,
|
|
|
+ FenweiExcelNameE: FenweiNewJt61IgnoreIndexNameMapping,
|
|
|
+ FenweiExcelNameF: FenweiNewJt100IgnoreIndexNameMapping,
|
|
|
}
|
|
|
|
|
|
var FenweiNewIndexNameSuffixMapping = map[string]string{
|
|
@@ -190,6 +259,8 @@ var FenweiNewIndexNameSuffixMapping = map[string]string{
|
|
|
FenweiExcelNameB: "/动力煤/100家样本",
|
|
|
FenweiExcelNameC: "/焦煤/53家样本",
|
|
|
FenweiExcelNameD: "/焦煤/88家样本",
|
|
|
+ FenweiExcelNameE: "/焦炭/61家样本",
|
|
|
+ FenweiExcelNameF: "/焦炭/100家样本",
|
|
|
}
|
|
|
|
|
|
var FenweiNewExcelProvinceMapping = map[string]string{
|
|
@@ -229,6 +300,12 @@ func AnalysisFenweiHistoryExcel(filePath string) (err error) {
|
|
|
indexes, e = AnalysisFenweiHistoryExcelNormal(filePath, FenweiExcelNameD)
|
|
|
} else if strings.Contains(fileName, FenweiExcelNameE) {
|
|
|
indexes, e = AnalysisFenweiExcelYangBen(filePath)
|
|
|
+ } else if strings.Contains(fileName, FenweiExcelNameF) {
|
|
|
+ indexes, e = AnalysisFenweiHistoryExcelNormal(filePath, FenweiExcelNameF)
|
|
|
+ } else if strings.Contains(fileName, FenweiExcelNameG) {
|
|
|
+ indexes, e = AnalysisFenweiHistoryExcelNormal(filePath, FenweiExcelNameG)
|
|
|
+ } else if strings.Contains(fileName, FenweiExcelNameH) {
|
|
|
+ indexes, e = AnalysisFenweiExcelYangBenSteelCoal(filePath)
|
|
|
} else {
|
|
|
utils.FileLog.Info(fmt.Sprintf("文件名有误, FileName: %s", fileName))
|
|
|
return
|
|
@@ -264,7 +341,7 @@ func AnalysisFenweiHistoryExcel(filePath string) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// AnalysisFenweiHistoryExcelNormal 历史数据-动力煤产销存/焦煤产销存
|
|
|
+// AnalysisFenweiHistoryExcelNormal 历史数据-动力煤产销存/焦煤产销存/焦炭产销存
|
|
|
func AnalysisFenweiHistoryExcelNormal(filePath, excelName string) (indexes []*models.FenweiExcelIndex, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -670,6 +747,12 @@ func AnalysisFenweiNewExcel(filePath string) (err error) {
|
|
|
indexes, e = AnalysisFenweiNewExcelNormal(filePath, FenweiExcelNameD)
|
|
|
} else if strings.Contains(fileName, FenweiExcelNameE) {
|
|
|
indexes, e = AnalysisFenweiExcelYangBen(filePath) // 样本焦化厂-增量数据和历史数据excel格式相同
|
|
|
+ } else if strings.Contains(fileName, FenweiNewExcelNameF) {
|
|
|
+ indexes, e = AnalysisFenweiNewExcelNormal(filePath, FenweiExcelNameF)
|
|
|
+ } else if strings.Contains(fileName, FenweiNewExcelNameG) {
|
|
|
+ indexes, e = AnalysisFenweiNewExcelNormal(filePath, FenweiExcelNameG)
|
|
|
+ } else if strings.Contains(fileName, FenweiExcelNameH) {// 样本钢厂焦炭-增量数据和历史数据excel格式相同
|
|
|
+ indexes, e = AnalysisFenweiExcelYangBenSteelCoal(filePath)
|
|
|
} else {
|
|
|
utils.FileLog.Info(fmt.Sprintf("文件名有误, FileName: %s", fileName))
|
|
|
return
|
|
@@ -705,7 +788,7 @@ func AnalysisFenweiNewExcel(filePath string) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// AnalysisFenweiNewExcelNormal 增量数据-动力煤/焦煤
|
|
|
+// AnalysisFenweiNewExcelNormal 增量数据-动力煤/焦煤/焦炭
|
|
|
func AnalysisFenweiNewExcelNormal(filePath, excelName string) (indexes []*models.FenweiExcelIndex, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -901,3 +984,140 @@ func AnalysisFenweiNewExcelNormal(filePath, excelName string) (indexes []*models
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// AnalysisFenweiExcelYangBen 样本钢厂焦炭
|
|
|
+func AnalysisFenweiExcelYangBenSteelCoal(filePath string) (indexes []*models.FenweiExcelIndex, err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("AnalysisFenweiExcelYangBenSteel ErrMsg: %s\n", err.Error())
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("AnalysisFenweiExcelYangBenSteel ErrMsg: %s", err.Error()))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ indexColIndex := make(map[int]*models.FenweiExcelIndex) // 列对应的指标(C列-D列)
|
|
|
+ provinces := []string{"河北", "山东", "其他", "汇总"}
|
|
|
+ for k, v := range provinces {
|
|
|
+ //if k < 2 {
|
|
|
+ // continue
|
|
|
+ //}
|
|
|
+ if indexColIndex[k] == nil {
|
|
|
+ indexColIndex[k] = new(models.FenweiExcelIndex)
|
|
|
+ indexColIndex[k].ExcelDataMap = make(map[string]string)
|
|
|
+ indexColIndex[k].TerminalCode = utils.TerminalCode
|
|
|
+ indexColIndex[k].ClassifyId = FenweiYangBenSteelCoalIndexClassifyId
|
|
|
+ indexColIndex[k].Frequency = "周度"
|
|
|
+ indexColIndex[k].Unit = "天"
|
|
|
+ indexColIndex[k].IndexName = fmt.Sprintf("%s/%s", FenweiYangBenSteelCoalIndexNamePre, v)
|
|
|
+
|
|
|
+ // 指标编码, 例:样本焦企炼焦煤库存可用天数/全国->fwsjybjqljmkckytsquanguo
|
|
|
+ name := strings.ReplaceAll(indexColIndex[k].IndexName, "/", "")
|
|
|
+ var middle, suffix string
|
|
|
+ for _, p := range provinces {
|
|
|
+ if strings.Contains(name, p) {
|
|
|
+ suffix = utils.GetFullPingYin(p)
|
|
|
+ name = strings.ReplaceAll(name, p, "")
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if suffix == "" {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("指标名称转换编码有误, IndexName: %s", indexColIndex[k].IndexName))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ middle = utils.GetFirstPingYin(name)
|
|
|
+ indexColIndex[k].IndexCode = fmt.Sprint(FenweiIndexNamePrefix, middle, suffix)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ maxCols := 4 // 每行只读取前4列即可
|
|
|
+ startDateRow := 0 // 数据日期起始行(第一行), 后面依次6行读取
|
|
|
+ startDataRow := 3 // 数据值起始行(第四行), 后面依次加1行读取
|
|
|
+ sumDateRow := 0 // 数据日期累加的行, 每加4次重置0
|
|
|
+ sumDataRow := 0 // 数据值累加的行, 每加4次重置0
|
|
|
+ currDate := "" // 最近的一次日期
|
|
|
+ stop := false // 结束读取excel
|
|
|
+
|
|
|
+ xlsxFile, e := xlsx.OpenFile(filePath)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("open xls file err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sheet := xlsxFile.Sheets[0]
|
|
|
+ //if e != nil {
|
|
|
+ // err = fmt.Errorf("GetSheet err: %s", e.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ rows := sheet.Rows
|
|
|
+ for i, row := range rows {
|
|
|
+ sumDateRow += 1
|
|
|
+ sumDataRow += 1
|
|
|
+
|
|
|
+ // 第一个日期行/后续每4行取一次日期
|
|
|
+ if i == startDateRow || sumDateRow == 7 {
|
|
|
+ if stop {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ sumDateRow = 0
|
|
|
+
|
|
|
+ for k, cell := range row.Cells {
|
|
|
+ // 日期只取第一个单元格中的
|
|
|
+ if k > 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ strDates := strings.TrimSpace(cell.String())
|
|
|
+ strDates = strings.ReplaceAll(strDates, "\x00", "")
|
|
|
+ strDateArr := strings.Split(strDates, "-")
|
|
|
+ // 正常情况下, 长度不为2说明读取到了最后一行了
|
|
|
+ if len(strDateArr) != 2 {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("第%d行数据日期长度有误, 结束读取", i+1))
|
|
|
+ stop = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ t, e := time.Parse("2006.1.2", strDateArr[1])
|
|
|
+ if e != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("第%d行数据日期有误, err: %s", i+1, e.Error()))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ currDate = t.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第一个数据行/后续每4行取一次数据
|
|
|
+ if i == startDataRow || sumDataRow > 3 {
|
|
|
+ if currDate == "" {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("第%d行数据对应日期有误", i+1))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ for k, cell := range row.Cells {
|
|
|
+ if k >= maxCols {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if k == 2 {
|
|
|
+ val,_ := cell.Float()
|
|
|
+ // 保留四位小数
|
|
|
+ provinceIndex := 0
|
|
|
+ if sumDataRow > 3 {
|
|
|
+ provinceIndex = sumDataRow - 4
|
|
|
+ }
|
|
|
+ indexColIndex[provinceIndex].ExcelDataMap[currDate] = fmt.Sprintf("%.4f", val)
|
|
|
+ if sumDataRow == 7 {
|
|
|
+ sumDataRow = 0
|
|
|
+ // 重置日期
|
|
|
+ currDate = ""
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ indexes = make([]*models.FenweiExcelIndex, 0)
|
|
|
+ for _, v := range indexColIndex {
|
|
|
+ if v.IndexCode == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ indexes = append(indexes, v)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|