老格拓店恢复
This commit is contained in:
@@ -2,26 +2,32 @@ package tempop
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||||||
"github.com/360EntSecGroup-Skylar/excelize"
|
"github.com/360EntSecGroup-Skylar/excelize"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
@@ -1359,3 +1365,84 @@ func JdStoreInfo1125() (hint string, err error) {
|
|||||||
}
|
}
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JdStoreInfoCoordinateRecover(ctx *jxcontext.Context, files []*multipart.FileHeader) (err error) {
|
||||||
|
if len(files) == 0 {
|
||||||
|
return errors.New("没有文件上传!")
|
||||||
|
}
|
||||||
|
fileHeader := files[0]
|
||||||
|
file1, err := fileHeader.Open()
|
||||||
|
defer file1.Close()
|
||||||
|
|
||||||
|
db := dao.GetDB()
|
||||||
|
storeList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
|
||||||
|
if err == nil {
|
||||||
|
var validStoreList []*dao.StoreDetail
|
||||||
|
for _, v := range storeList {
|
||||||
|
if v.Status != model.StoreStatusDisabled && v.CreatedAt.Sub(utils.Str2Time("2019-10-01")) > 0 {
|
||||||
|
storeInfo, err := api.JdAPI.GetStoreInfoByStationNo2(v.VendorStoreID)
|
||||||
|
if err == nil && storeInfo.CreateTime.GoTime().Sub(utils.Str2Time("2019-10-25")) > 0 {
|
||||||
|
if storeDetail, err := dao.GetStoreDetail(db, v.StoreID, v.VendorID); err == nil {
|
||||||
|
validStoreList = append(validStoreList, storeDetail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getStoreList := func(lng, lat, lng2, lat2 int) (vendorStoreIDs []string) {
|
||||||
|
for _, v := range validStoreList {
|
||||||
|
if v.Lng >= lng && v.Lng <= lng2 && v.Lat >= lat && v.Lat <= lat2 {
|
||||||
|
vendorStoreIDs = append(vendorStoreIDs, v.VendorStoreID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vendorStoreIDs
|
||||||
|
}
|
||||||
|
sheetName := "老格明细"
|
||||||
|
file, err2 := excelize.OpenReader(file1)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
rows, err2 := file.GetRows(sheetName)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
str2Coords := func(str string) (lng, lat int) {
|
||||||
|
list := strings.Split(str, ",")
|
||||||
|
if len(list) >= 2 {
|
||||||
|
lng, lat = jxutils.StandardCoordinate2Int(utils.Str2Float64WithDefault(list[1], 0)), jxutils.StandardCoordinate2Int(utils.Str2Float64WithDefault(list[0], 0))
|
||||||
|
}
|
||||||
|
return lng, lat
|
||||||
|
}
|
||||||
|
for i := 1; i < len(rows); i++ {
|
||||||
|
lng, lat := str2Coords(rows[i][8])
|
||||||
|
lng2, lat2 := str2Coords(rows[i][7])
|
||||||
|
vendorStoreIDs := getStoreList(lng, lat, lng2, lat2)
|
||||||
|
countInfo := fmt.Sprintf("京西已拓%d", len(vendorStoreIDs))
|
||||||
|
axis, _ := excelize.CoordinatesToCellName(5, i+1)
|
||||||
|
file.SetCellStr(sheetName, axis, countInfo)
|
||||||
|
axis2, _ := excelize.CoordinatesToCellName(6, i+1)
|
||||||
|
file.SetCellStr(sheetName, axis2, strings.Join(vendorStoreIDs, ","))
|
||||||
|
}
|
||||||
|
filename := ExecuteFileName(fileHeader.Filename)
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
if _, err = io.Copy(buf, file1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", filename)
|
||||||
|
downloadURL, err := jxutils.UploadExportContent(buf.Bytes(), filename)
|
||||||
|
if err != nil {
|
||||||
|
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s, failed error:%v", filename, err)
|
||||||
|
} else {
|
||||||
|
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||||
|
noticeMsg := fmt.Sprintf("path=%s\n", downloadURL)
|
||||||
|
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "导出老格恢复拓店进度成功", noticeMsg)
|
||||||
|
}
|
||||||
|
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", filename, downloadURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecuteFileName(filename string) (name string) {
|
||||||
|
filePrefix := filename[strings.LastIndex(filename, "."):len(filename)]
|
||||||
|
fileRealName := filename[0:strings.LastIndex(filename, ".")]
|
||||||
|
name = fileRealName + utils.Int64ToStr(time.Now().Unix()) + filePrefix
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|||||||
@@ -352,3 +352,18 @@ func (c *TempOpController) FixMtwmCategory() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 老格恢复拓店进度
|
||||||
|
// @Description 老格恢复拓店进度
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /JdStoreInfoCoordinateRecover [post]
|
||||||
|
func (c *TempOpController) JdStoreInfoCoordinateRecover() {
|
||||||
|
c.callJdStoreInfoCoordinateRecover(func(params *tTempopJdStoreInfoCoordinateRecoverParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
r := c.Ctx.Request
|
||||||
|
files := r.MultipartForm.File["userfiles"]
|
||||||
|
err = tempop.JdStoreInfoCoordinateRecover(params.Ctx, files)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1791,6 +1791,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "JdStoreInfoCoordinateRecover",
|
||||||
|
Router: `/JdStoreInfoCoordinateRecover`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "PrintMsg",
|
Method: "PrintMsg",
|
||||||
|
|||||||
Reference in New Issue
Block a user