...
|
...
|
@@ -682,7 +682,7 @@ func (c *OrderInfoController) DownloadTemplate() { |
|
|
} else {
|
|
|
logs.Info(resp)
|
|
|
ret = map[string]interface{}{
|
|
|
"url": "http://" + c.Ctx.Request.Host + "/download/订单数据模板.xlsx",
|
|
|
"url": "http://" + c.Ctx.Request.Host + "/" + constant.APP_NAME + "/download/订单数据模板.xlsx",
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
}
|
...
|
...
|
@@ -690,7 +690,7 @@ func (c *OrderInfoController) DownloadTemplate() { |
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 导入excel订单
|
|
|
* @Description // 导入excel订单
|
|
|
* @Date 10:52 2021/1/6
|
|
|
* @Param
|
|
|
* @return
|
...
|
...
|
@@ -701,14 +701,6 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
file, h, _ := c.GetFile("file")
|
|
|
companyId := c.GetUserCompany()
|
|
|
|
|
|
// Json数据解析
|
|
|
//jsonMap := make(map[string]interface{})
|
|
|
//err := json.Unmarshal([]byte(where), &jsonMap)
|
|
|
//if err != nil {
|
|
|
// logs.Error(err)
|
|
|
// c.ResponseError(errors.New("json数据解析失败"))
|
|
|
//}
|
|
|
|
|
|
if typeCode != "PARTNER_ORDER_FILE" {
|
|
|
c.ResponseError(errors.New("类型编码错误"))
|
|
|
}
|
...
|
...
|
@@ -716,8 +708,8 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
// 返回字段定义
|
|
|
ret := map[string]interface{}{}
|
|
|
|
|
|
// 返回信息表头定义 0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 编号, 5: 合伙人, 6: 类型, 7: 业务抽成比例, 8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
|
|
|
var tableHeader = []string{"错误详情", "行号", "订单号", "发货单号", "客户名称", "订单区域", "编号", "合伙人", "类型", "业务抽成比例", "产品名称", "数量", "单价", "合伙人分红比例"}
|
|
|
// 返回信息表头定义 0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 编号, 5: 合伙人, 6: 类型, 7: 业务员抽成比例, 8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
|
|
|
var tableHeader = []string{"错误详情", "行号", "订单号", "发货单号", "客户名称", "订单区域", "编号", "合伙人", "类型", "业务员抽成比例", "产品名称", "数量", "单价", "合伙人分红比例"}
|
|
|
|
|
|
// 文件后缀名校验
|
|
|
ext := path.Ext(h.Filename)
|
...
|
...
|
@@ -743,6 +735,32 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
return
|
|
|
}
|
|
|
|
|
|
// 文件列数据校验
|
|
|
overColumnLine := make([]interface{}, 0)
|
|
|
for i, row := range rows {
|
|
|
if i > 2 && row != nil {
|
|
|
if len(row) > constant.EXCEL_COLUMN {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "存在无效的数据列,请删除无效的列数据") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
overColumnLine = append(overColumnLine, tmpRow)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if len(overColumnLine) > 0 {
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": 0,
|
|
|
"fail": map[string]interface{}{
|
|
|
"tableHeader": tableHeader,
|
|
|
"tableData": overColumnLine,
|
|
|
},
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 数据行计数
|
|
|
rowCnt := 0
|
|
|
|
...
|
...
|
@@ -753,38 +771,52 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
|
|
|
// 必填项校验
|
|
|
nullLine := make([]interface{}, 0)
|
|
|
|
|
|
nullFlag := false
|
|
|
for i, row := range rows {
|
|
|
if i > 2 && row != nil {
|
|
|
rowCnt++
|
|
|
if len(row) == constant.EXCEL_COLUMN { // 中间空字符校验
|
|
|
if len(row) == constant.EXCEL_COLUMN { // 必填项内容为空
|
|
|
var tmpRow = row
|
|
|
nullCell := make([]interface{}, 0)
|
|
|
var myRow []string
|
|
|
for j, cell := range row {
|
|
|
if j != 8 { // 业务员抽成比例非必填
|
|
|
if cell == "" || cell == " " { // 空字符串填充
|
|
|
tmpRow[j] = "null"
|
|
|
for j, _ := range row {
|
|
|
if j != 7 { // 业务员抽成比例非必填
|
|
|
if row[j] == "" || row[j] == " " { // 空字符补位
|
|
|
tmpRow[j] = ""
|
|
|
col := strconv.Itoa(j + 1)
|
|
|
nullCell = append(nullCell, col)
|
|
|
nullFlag = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if nullFlag {
|
|
|
myRow = append(myRow, "必填项不能为空") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
myRow = append(myRow, s) // 行号
|
|
|
myRow = append(myRow, tmpRow...) // 错误行数据
|
|
|
b := strings.Replace(strings.Trim(fmt.Sprint(nullCell), "[]"), " ", ",", -1)
|
|
|
myRow = append(myRow, "第"+s+"行的第"+b+"列必填项为空") // 错误信息
|
|
|
myRow = append(myRow, s) // 行号
|
|
|
myRow = append(myRow, tmpRow...) // 错误行数据
|
|
|
nullLine = append(nullLine, myRow)
|
|
|
nullFlag = false
|
|
|
}
|
|
|
} else if len(row) > 0 && len(row) < constant.EXCEL_COLUMN { // 尾部空字符校验
|
|
|
} else if len(row) > 0 && len(row) < constant.EXCEL_COLUMN { // 必填项不存在
|
|
|
var myRow []string
|
|
|
for i := 0; i < constant.EXCEL_COLUMN-len(row); i++ { // null补位
|
|
|
myRow = append(myRow, "null")
|
|
|
}
|
|
|
myRow = append(myRow, "必填项不能为空") // 错误信息
|
|
|
myRow = append(myRow, "必填项为空")
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
myRow = append(myRow, s) // 行号
|
|
|
myRow = append(myRow, row...) // 错误行数据
|
|
|
emptyCell := make([]interface{}, 0)
|
|
|
// 错误信息
|
|
|
for k := 0; k < constant.EXCEL_COLUMN-len(row); k++ { // 空字符补位
|
|
|
myRow = append(myRow, "")
|
|
|
}
|
|
|
for k, cell := range myRow {
|
|
|
if k != 0 && cell == "" {
|
|
|
emptyCell = append(emptyCell, k-1)
|
|
|
}
|
|
|
}
|
|
|
b := strings.Replace(strings.Trim(fmt.Sprint(emptyCell), "[]"), " ", ",", -1)
|
|
|
myRow[0] = "第" + s + "行的第" + b + "列必填项为空"
|
|
|
nullLine = append(nullLine, myRow)
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -810,17 +842,21 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
if i > 2 && row != nil && len(row) == constant.EXCEL_COLUMN { // 数据行
|
|
|
var myRow []string
|
|
|
for j, cell := range row {
|
|
|
|
|
|
r := strconv.Itoa(i + 1)
|
|
|
col := strconv.Itoa(j + 1)
|
|
|
|
|
|
switch j {
|
|
|
case 0, 1, 2, 3, 4, 5, 8: // 订单号、发货单号、客户名称、订单区域、编号、合伙人、产品名称长度校验
|
|
|
{
|
|
|
cellStr := strings.TrimSpace(cell)
|
|
|
lenCellStr := utf8.RuneCountInString(cellStr)
|
|
|
|
|
|
if lenCellStr > 50 {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, tableHeader[j+2]+"长度超过50位,请重新输入") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列"+tableHeader[j+2]+"长度超过50位,请重新输入") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -828,139 +864,120 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
{
|
|
|
if !utils.IsContain(partnerType, cell) {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "合伙人类型须为以下类型:事业合伙、业务合伙、研发合伙、业务-产品应用合伙") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人类型错误,合伙人类型必须为以下类型:事业合伙、业务合伙、研发合伙、业务-产品应用合伙") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
case 7: // 业务员抽成比例,非必填,精确到小数点后两位
|
|
|
{
|
|
|
var (
|
|
|
typeErrFlag bool
|
|
|
lenErrFlag bool
|
|
|
ratioErrFlag bool
|
|
|
)
|
|
|
if len(cell) > 0 {
|
|
|
|
|
|
// 参数类型转换
|
|
|
shareRatio, err := strconv.ParseFloat(cell, 64)
|
|
|
if err != nil {
|
|
|
typeErrFlag = true
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列业务员抽成比例格式错误,业务员抽成比例必须为数字") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 比例不能超过100%
|
|
|
if shareRatio > 100 {
|
|
|
ratioErrFlag = true
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列业务员抽成比例超过限额,请输入正确的业务员抽成比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度校验
|
|
|
regexpStr := `^(100|[1-9]\d|\d)(.\d{1,2})?$`
|
|
|
ok := regexp.MustCompile(regexpStr).MatchString(cell)
|
|
|
if !ok {
|
|
|
lenErrFlag = true
|
|
|
}
|
|
|
|
|
|
if typeErrFlag || lenErrFlag || ratioErrFlag {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "业务员抽成比例格式错误,请输入正确的业务员抽成比例比例,保留两位小数") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列业务员抽成比例超过最大长度,请输入正确的业务员抽成比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
typeErrFlag = false
|
|
|
lenErrFlag = false
|
|
|
ratioErrFlag = false
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
case 9: // 数量不超过16位正整数
|
|
|
{
|
|
|
var (
|
|
|
typeErrFlag bool
|
|
|
lenErrFlag bool
|
|
|
)
|
|
|
|
|
|
//参数类型转换
|
|
|
orderNum, err := strconv.ParseInt(cell, 10, 64)
|
|
|
if err != nil {
|
|
|
typeErrFlag = true
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列产品数量格式错误,产品数量必须整数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度校验
|
|
|
if orderNum > 1e16 {
|
|
|
lenErrFlag = true
|
|
|
}
|
|
|
|
|
|
if typeErrFlag || lenErrFlag {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "数量长度超过最大限制十六位整数,请重新填写") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列产品数量长度超过最大限制十六位整数,请重新填写") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
typeErrFlag = false
|
|
|
lenErrFlag = false
|
|
|
}
|
|
|
}
|
|
|
case 10: // 单价,精确到小数点后两位,小数点左侧最多可输入16位数字
|
|
|
{
|
|
|
|
|
|
// 参数类型转换
|
|
|
univalent, err := strconv.ParseFloat(cell, 64)
|
|
|
if err != nil {
|
|
|
univalent, typeErr := strconv.ParseFloat(cell, 64)
|
|
|
if typeErr != nil {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "单价格式错误,请输入正确的单价,保留两位小数点,小数点前面不能超过十六位数字") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列单价格式错误,产品单价必须为数字类型") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度校验
|
|
|
if univalent >= 1e16 {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "单价格式错误,请输入正确的单价,保留两位小数点,小数点前面不能超过十六位数字") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列产品单价超过最大限制,产品单价小数点前面不能超过十六位数字,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
case 11: // 合伙人分红比例,精确到小数点后两位
|
|
|
{
|
|
|
var (
|
|
|
typeErrFlag bool
|
|
|
lenErrFlag bool
|
|
|
ratioErrFlag bool
|
|
|
)
|
|
|
|
|
|
//参数类型转换
|
|
|
partnerRatio, err := strconv.ParseFloat(cell, 64)
|
|
|
if err != nil {
|
|
|
typeErrFlag = true
|
|
|
partnerRatio, parseErr := strconv.ParseFloat(cell, 64)
|
|
|
if parseErr != nil {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人分红比例类型错误,合伙人分红比例必须为数字") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 合伙人分红比例超额
|
|
|
if partnerRatio > 100 {
|
|
|
ratioErrFlag = true
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人分红比例超过限额,请输入正确的合伙人分红比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度判断
|
|
|
regexpStr := `^(100|[1-9]\d|\d)(.\d{1,2})?$`
|
|
|
ok := regexp.MustCompile(regexpStr).MatchString(cell)
|
|
|
if !ok {
|
|
|
lenErrFlag = true
|
|
|
}
|
|
|
|
|
|
if typeErrFlag || lenErrFlag || ratioErrFlag {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "合伙人分红比例格式错误,请输入正确的合伙人分红比例,保留两位小数") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人分红比例超过最大长度,请输入正确的合伙人分红比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
typeErrFlag = false
|
|
|
lenErrFlag = false
|
|
|
ratioErrFlag = false
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -1006,6 +1023,29 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
price, _ := strconv.ParseFloat(row[10], 64) // 单价
|
|
|
percent, _ := strconv.ParseFloat(row[11], 64) // 合伙人分红比例
|
|
|
|
|
|
// 获取partnerId
|
|
|
var partnerInfo *domain.PartnerInfo
|
|
|
|
|
|
orderQueryData := orderQuery.GetPartnerIdQuery{
|
|
|
Code: row[4],
|
|
|
PartnerCategory: 0,
|
|
|
CompanyId: companyId,
|
|
|
}
|
|
|
|
|
|
// 1: 事业合伙、2: 业务合伙、3: 研发合伙、4: 业务-产品应用合伙
|
|
|
switch row[6] {
|
|
|
case "事业合伙":
|
|
|
orderQueryData.PartnerCategory = 1
|
|
|
case "业务合伙":
|
|
|
orderQueryData.PartnerCategory = 2
|
|
|
case "研发合伙":
|
|
|
orderQueryData.PartnerCategory = 3
|
|
|
case "业务-产品应用合伙":
|
|
|
orderQueryData.PartnerCategory = 4
|
|
|
default:
|
|
|
orderQueryData.PartnerCategory = 0
|
|
|
}
|
|
|
|
|
|
// 初始化建订单命令集
|
|
|
orderCommands[hashString] = &orderCmd.CreateOrderCommand{
|
|
|
OrderType: 0,
|
...
|
...
|
@@ -1025,30 +1065,10 @@ func (c *OrderInfoController) ImportOrderFromExcel() { |
|
|
},
|
|
|
},
|
|
|
CompanyId: companyId,
|
|
|
PartnerCategory: 1,
|
|
|
PartnerCategory: int64(orderQueryData.PartnerCategory),
|
|
|
LineNumbers: []int{i}, // 记录行号
|
|
|
}
|
|
|
|
|
|
// 获取partnerId
|
|
|
var partnerInfo *domain.PartnerInfo
|
|
|
orderQueryData := orderQuery.GetPartnerIdQuery{
|
|
|
Code: row[4],
|
|
|
PartnerCategory: 0,
|
|
|
CompanyId: companyId,
|
|
|
}
|
|
|
// 1: 事业合伙、2: 业务合伙、3: 研发合伙、4: 业务-产品应用合伙
|
|
|
switch row[6] {
|
|
|
case "事业合伙":
|
|
|
orderQueryData.PartnerCategory = 1
|
|
|
case "业务合伙":
|
|
|
orderQueryData.PartnerCategory = 2
|
|
|
case "研发合伙":
|
|
|
orderQueryData.PartnerCategory = 3
|
|
|
case "业务-产品应用合伙":
|
|
|
orderQueryData.PartnerCategory = 4
|
|
|
default:
|
|
|
orderQueryData.PartnerCategory = 0
|
|
|
}
|
|
|
partnerInfo, err = orderSrv.GetPartnerIdByCodeAndCategory(orderQueryData)
|
|
|
if err != nil || partnerInfo == nil { // 检索合伙人错误
|
|
|
var tmpRow []string
|
...
|
...
|
|