소스 검색

后端:目录管理模块,新增更新字段

baichengfei 5 년 전
부모
커밋
899b9bb61e

+ 20 - 0
src/dashoo.cn/backend/api/business/oilsupplier/oilcatalog/oilcatalogService.go

@@ -3,6 +3,8 @@ package oilcatalog
 import (
 	. "dashoo.cn/backend/api/mydb"
 	"github.com/go-xorm/xorm"
+	"regexp"
+	"strings"
 )
 
 type OilCatalogService struct {
@@ -14,3 +16,21 @@ func GetOilCatalogService(xormEngine *xorm.Engine) *OilCatalogService {
 	s.DBE = xormEngine
 	return s
 }
+
+func (s *OilCatalogService) TrimSpaceForString(originStr string) string {
+	if originStr == "" {
+		return originStr
+	}
+	s1 := strings.Replace(originStr, "  ", " ", -1) //替换tab为空格
+	s1 = strings.Replace(s1, ",", ",", -1)          //替换英文逗号为中文,解决导出Excel时字段值拼接错误问题
+	regStr := "\\s{2,}"                             //两个及两个以上空格的正则表达式
+	reg, _ := regexp.Compile(regStr)                //编译正则表达式
+	s2 := make([]byte, len(s1))                     //定义字符数组切片
+	copy(s2, s1)                                    //将字符串复制到切片
+	spcIndex := reg.FindStringIndex(string(s2))     //在字符串中搜索
+	for len(spcIndex) > 0 {                         //找到适配项
+		s2 = append(s2[:spcIndex[0]+1], s2[spcIndex[1]:]...) //删除多余空格
+		spcIndex = reg.FindStringIndex(string(s2))           //继续在字符串中搜索
+	}
+	return string(s2)
+}

+ 23 - 27
src/dashoo.cn/backend/api/controllers/oilsupplier/oilcatalog.go

@@ -8,13 +8,13 @@ import (
 	"dashoo.cn/utils"
 	"encoding/json"
 	"fmt"
+	. "github.com/linxGnu/goseaweedfs"
 	"github.com/tealeg/xlsx"
 	"log"
 	"os"
 	"strconv"
 	"strings"
 	"time"
-	. "github.com/linxGnu/goseaweedfs"
 )
 
 type OilCatalogController struct {
@@ -29,12 +29,12 @@ func (this *OilCatalogController) GetEntityList() {
 	//获取分页信息
 	page := this.GetPageInfoForm()
 	where := " 1=1 "
-	orderby := "Id"
+	orderBy := "Id"
 	asc := false
 	Order := this.GetString("Order")
 	Prop := this.GetString("Prop")
 	if Order != "" && Prop != "" {
-		orderby = Prop
+		orderBy = Prop
 		if Order == "asc" {
 			asc = true
 		}
@@ -54,7 +54,7 @@ func (this *OilCatalogController) GetEntityList() {
 		where = where + " and CatalogType=" + catalogType
 	}
 	if CompanyName != "" {
-		where = where + " and CompanyName like '%" + CompanyName +"%' "
+		where = where + " and CompanyName like '%" + CompanyName + "%' "
 	}
 	if Business != "" {
 		where = where + " and Business like '%" + Business + "%' "
@@ -75,7 +75,7 @@ func (this *OilCatalogController) GetEntityList() {
 
 	svc := oilcatalog.GetOilCatalogService(utils.DBE)
 	var list []oilcatalog.OilCatalog
-	total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
+	total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderBy, asc, &list, where)
 	var datainfo DataInfo
 	datainfo.Items = list
 	datainfo.CurrentItemCount = total
@@ -84,8 +84,6 @@ func (this *OilCatalogController) GetEntityList() {
 	this.Data["json"] = &datainfo
 	this.ServeJSON()
 
-
-
 }
 
 // @Title 添加
@@ -138,7 +136,7 @@ func (this *OilCatalogController) DeleteEntity() {
 	}
 	var model oilcatalog.OilCatalog
 	svc := oilcatalog.GetOilCatalogService(utils.DBE)
-	err := svc.DeleteEntityById(Id,&model)
+	err := svc.DeleteEntityById(Id, &model)
 	if err == nil {
 		errinfo.Message = "删除成功"
 		errinfo.Code = 0
@@ -170,7 +168,7 @@ func (this *OilCatalogController) UpdateEntity() {
 	var model oilcatalog.OilCatalog
 	svc := oilcatalog.GetOilCatalogService(utils.DBE)
 
-	var jsonBlob= this.Ctx.Input.RequestBody
+	var jsonBlob = this.Ctx.Input.RequestBody
 	json.Unmarshal(jsonBlob, &model)
 	model.ModifiedOn = time.Now()
 	model.ModifiedBy = this.User.Realname
@@ -183,7 +181,8 @@ func (this *OilCatalogController) UpdateEntity() {
 		"LegalPerson",
 		"RecordScope",
 		"IDCode",
-
+		"DutyDept",
+		"Dept",
 		"CatalogType",
 		"OrderNo",
 		"CompanyName",
@@ -220,28 +219,28 @@ func (this *OilCatalogController) ExportExcelAll() {
 	where := "CatalogType=" + CatalogType
 	svc.GetEntities(&list, where)
 
-	filetitle := "大港油田" + CardTitle + "目录"
-	showcolumnarr := "序号,企业名称,业务范围,有效期起,有效期止,备注"
+	fileTitle := "大港油田" + CardTitle + "目录"
+	showColumnArr := "序号,企业名称,业务范围,有效期起,有效期止,备注"
 
 	f := xlsx.NewFile()
-	sheet, _ := f.AddSheet(filetitle)
-	cellname := strings.Split(showcolumnarr, ",")
+	sheet, _ := f.AddSheet(fileTitle)
+	cellName := strings.Split(showColumnArr, ",")
 	row := sheet.AddRow()
-	row.WriteSlice(&cellname, -1)
+	row.WriteSlice(&cellName, -1)
 
 	for idx, item := range list {
-		datastring := strconv.Itoa(idx + 1) + "," + item.CompanyName + "," + item.Business + "," + utils.ToStr(item.ValidityFrom.Format("2006-01-02")) + "," +
-			utils.ToStr(item.ValidityTo.Format("2006-01-02"))+ "," + item.Remark
-		cellname := strings.Split(datastring, ",")
+		dataString := strconv.Itoa(idx+1) + "," + item.CompanyName + "," + svc.TrimSpaceForString(item.Business) + "," + utils.ToStr(item.ValidityFrom.Format("2006-01-02")) + "," +
+			utils.ToStr(item.ValidityTo.Format("2006-01-02")) + "," + item.Remark
+		cellName := strings.Split(dataString, ",")
 		row := sheet.AddRow()
-		row.WriteSlice(&cellname, -1)
+		row.WriteSlice(&cellName, -1)
 	}
 	for c, cl := 0, len(sheet.Cols); c < cl; c++ {
 		sheet.Cols[c].Width = 20
 	}
 	dir := "static/file/excel/report/" + this.GetAccode()
 	SaveDirectory(dir)
-	path := dir + "/" + utils.TimeFormat(time.Now(), "20060102") + filetitle + ".xlsx"
+	path := dir + "/" + utils.TimeFormat(time.Now(), "20060102") + fileTitle + ".xlsx"
 	f.Save(path)
 	var sw *Seaweed
 	var filer []string
@@ -282,7 +281,7 @@ func (this *OilCatalogController) ExportExcelIncome() {
 	row.WriteSlice(&cellname, -1)
 
 	for _, item := range list {
-		datastring := item.CompanyName + "," + item.LegalPerson + "," + item.IDCode + "," +  item.Address + "," + item.USCCode +
+		datastring := item.CompanyName + "," + item.LegalPerson + "," + item.IDCode + "," + item.Address + "," + item.USCCode +
 			"," + strconv.FormatFloat(item.RegCapital, 'f', 2, 64) + "," + item.RecordScope + "," + item.Remark
 		cellname := strings.Split(datastring, ",")
 		row := sheet.AddRow()
@@ -326,7 +325,6 @@ func (this *OilCatalogController) IsAccess() {
 		res = true
 	}
 
-
 	this.Data["json"] = res
 	this.ServeJSON()
 }
@@ -349,7 +347,6 @@ func (this *OilCatalogController) ImportExcel() {
 		this.ServeJSON()
 	}
 
-
 	svc := oilcatalog.GetOilCatalogService(utils.DBE)
 
 	log.Printf("url:==" + url) // http://60.30.245.229//upfile/dc1/2,063156edd288
@@ -378,8 +375,8 @@ func (this *OilCatalogController) ImportExcel() {
 				ValidityFrom, err1 := time.Parse("2006-01-02", cells[3].Value)
 				ValidityTo, err2 := time.Parse("2006-01-02", cells[4].Value)
 				CompanyName := cells[1].Value
-				Business    := cells[2].Value
-				Remark      := cells[5].Value
+				Business := cells[2].Value
+				Remark := cells[5].Value
 				if err1 != nil || err2 != nil {
 					errLineNo = errLineNo + "," + strconv.Itoa(i)
 					continue
@@ -414,5 +411,4 @@ func (this *OilCatalogController) ImportExcel() {
 		this.ServeJSON()
 	}
 
-
-}
+}