package controllers

import (
	"git.rosy.net.cn/jx-callback/business/jxstore/cms"
	"git.rosy.net.cn/jx-callback/business/jxstore/misc"
	"git.rosy.net.cn/jx-callback/business/jxstore/tempop"
	"git.rosy.net.cn/jx-callback/business/jxutils"
	"github.com/astaxie/beego/server/web"
)

type TempOpController struct {
	web.Controller
}

// @Title 将为份的商品在京东转成SPU
// @Description 将为份的商品在京东转成SPU
// @Param	token			header		string	true	"认证token"
// @Param	count			formData	int		false	"转换的数量，缺省0表示全部"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /Convert2JDSPU [post]
func (c *InitDataController) Convert2JDSPU() {
	c.callConvert2JDSPU(func(params *tInitdataConvert2JDSPUParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.Convert2JDSPU(params.Ctx, params.Count, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 将京东商店为份的SPU转换
// @Description 将京东商店为份的SPU转换
// @Param	token			header		string	true	"认证token"
// @Param	step			formData	int		true	"门店列表"
// @Param	storeIDs		formData	string	false	"门店列表"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /Change2JDSPU4Store [post]
func (c *InitDataController) Change2JDSPU4Store() {
	c.callChange2JDSPU4Store(func(params *tInitdataChange2JDSPU4StoreParams) (retVal interface{}, errCode string, err error) {
		var storeIDs []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
			retVal, err = tempop.Change2JDSPU4Store(params.Ctx, storeIDs, params.Step, params.IsAsync, params.IsContinueWhenError)
		}
		return retVal, "", err
	})
}

// // @Title 将遗留JD订单合并
// // @Description 将遗留JD订单合并
// // @Param	token			header		string	true	"认证token"
// // @Param	isAsync			formData	bool	false	"是否异步操作"
// // @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// // @Success 200 {object} controllers.CallResult
// // @Failure 200 {object} controllers.CallResult
// // @router /TransferLegacyJdOrder [post]
// func (c *InitDataController) TransferLegacyJdOrder() {
// 	c.callTransferLegacyJdOrder(func(params *tInitdataTransferLegacyJdOrderParams) (retVal interface{}, errCode string, err error) {
// 		retVal, err = tempop.TransferLegacyJdOrder(params.Ctx, params.IsAsync, params.IsContinueWhenError)
// 		return retVal, "", err
// 	})
// }

// // @Title 将goods_order中缺失的订单从goods_order_original中恢复
// // @Description 将goods_order中缺失的订单从goods_order_original中恢复
// // @Param	token			header		string	true	"认证token"
// // @Param	isAsync			formData	bool	false	"是否异步操作"
// // @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// // @Success 200 {object} controllers.CallResult
// // @Failure 200 {object} controllers.CallResult
// // @router /CreateOrderFromOriginal [post]
// func (c *InitDataController) CreateOrderFromOriginal() {
// 	c.callCreateOrderFromOriginal(func(params *tInitdataCreateOrderFromOriginalParams) (retVal interface{}, errCode string, err error) {
// 		retVal, err = tempop.CreateOrderFromOriginal(params.Ctx, params.IsAsync, params.IsContinueWhenError)
// 		return retVal, "", err
// 	})
// }

// @Title 拉取京东订单补齐本地
// @Description 拉取京东订单补齐本地
// @Param	token			header		string	true	"认证token"
// @Param	fromTime		formData	string	true	"开始时间"
// @Param	toTime			formData	string	true	"结束时间"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /PullJdOrder [post]
func (c *InitDataController) PullJdOrder() {
	c.callPullJdOrder(func(params *tInitdataPullJdOrderParams) (retVal interface{}, errCode string, err error) {
		timeList, err := jxutils.BatchStr2Time(params.FromTime, params.ToTime)
		if err != nil {
			return retVal, "", err
		}
		retVal, err = tempop.PullJdOrder(params.Ctx, timeList[0], timeList[1], params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 删除错误创建的SPU
// @Description 删除错误创建的SPU
// @Param	token			header		string	true	"认证token"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /DeleteWrongSpu [delete]
func (c *InitDataController) DeleteWrongSpu() {
	c.callDeleteWrongSpu(func(params *tInitdataDeleteWrongSpuParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.DeleteWrongSpu(params.Ctx, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 将京东的SPU转为非SPU，保持转后的SKU商家自编号不变
// @Description 将京东的SPU转为非SPU，保持转后的SKU商家自编号不变
// @Param	token			header		string	true	"认证token"
// @Param	nameIDs			formData	string	false	"需要转换的nameID列表，缺省空表示全部"
// @Param	count			formData	int		false	"转换的数量，缺省0表示全部（按ID排序）"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /TransformJdSpu2Sku [post]
func (c *InitDataController) TransformJdSpu2Sku() {
	c.callTransformJdSpu2Sku(func(params *tInitdataTransformJdSpu2SkuParams) (retVal interface{}, errCode string, err error) {
		var nameIDs []int
		if err = jxutils.Strings2Objs(params.NameIDs, &nameIDs); err != nil {
			return retVal, "", err
		}
		retVal, err = tempop.TransformJdSpu2Sku(params.Ctx, nameIDs, params.Count, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 重新处理京东差评
// @Description 重新处理京东差评
// @Param	token			header		string	true	"认证token"
// @Param	isForce			formData	bool	false	"是否强制处理"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ReProcessJdBadComment [post]
func (c *InitDataController) ReProcessJdBadComment() {
	c.callReProcessJdBadComment(func(params *tInitdataReProcessJdBadCommentParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.ReProcessJdBadComment(params.Ctx, params.IsForce, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 刷新
// @Description 重新处理京东差评
// @Param	token			header		string	true	"认证token"
// @Param	fromTime		formData	string	false	"起始时间"
// @Param	toTime			formData	string	false	"结束时间"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshEbaiBadComment [post]
func (c *InitDataController) RefreshEbaiBadComment() {
	c.callRefreshEbaiBadComment(func(params *tInitdataRefreshEbaiBadCommentParams) (retVal interface{}, errCode string, err error) {
		if timeList, err := jxutils.BatchStr2Time(params.FromTime, params.ToTime); err == nil {
			retVal, err = tempop.RefreshEbaiBadComment(params.Ctx, timeList[0], timeList[1], params.IsAsync, params.IsContinueWhenError)
		}
		return retVal, "", err
	})
}

// @Title 测试打印
// @Description 测试打印
// @Param	token			header		string	true	"认证token"
// @Param	vendorID		formData	int		true	"打印机厂商ID"
// @Param	id1				formData	string	true	"id1"
// @Param	id2				formData	string	false	"id2"
// @Param	msgTitle		formData	string	false	"消息标题"
// @Param	msgContent		formData	string	true	"消息内容"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /PrintMsg [post]
func (c *TempOpController) PrintMsg() {
	c.callPrintMsg(func(params *tTempopPrintMsgParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.PrintMsg(params.Ctx, params.VendorID, params.Id1, params.Id2, params.MsgTitle, params.MsgContent)
		return retVal, "", err
	})
}

// @Title 刷新微信备注
// @Description 刷新微信备注
// @Param	token			header		string	true	"认证token"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateAllWeiXinRemark [post]
func (c *TempOpController) UpdateAllWeiXinRemark() {
	c.callUpdateAllWeiXinRemark(func(params *tTempopUpdateAllWeiXinRemarkParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.UpdateAllWeiXinRemark(params.Ctx, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title XXXX
// @Description XXXX
// @Param	token			header		string	true	"认证token"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RetrieveEbaiShopLicence [post]
func (c *TempOpController) RetrieveEbaiShopLicence() {
	c.callRetrieveEbaiShopLicence(func(params *tTempopRetrieveEbaiShopLicenceParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.RetrieveEbaiShopLicence(params.Ctx, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 刷新美团配送价格
// @Description 刷新美团配送价格
// @Param	token			header		string	true	"认证token"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshMtpsWaybillFee [post]
func (c *TempOpController) RefreshMtpsWaybillFee() {
	c.callRefreshMtpsWaybillFee(func(params *tTempopRefreshMtpsWaybillFeeParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.RefreshMtpsWaybillFee(params.Ctx, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 查询三方运单费用信息
// @Description 查询三方运单费用信息
// @Param	token			header		string	true	"认证token"
// @Param	isAsync				query	bool	false	"是否异步操作"
// @Param	isContinueWhenError	query	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /TestIt [get]
func (c *TempOpController) TestIt() {
	c.callTestIt(func(params *tTempopTestItParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.CheckImages(params.Ctx, params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 开启或结束所有平台商店的额外时间
// @Description 开启或结束所有平台商店的额外时间，并且修改所有商品库存为0或99999(开启：0 ， 结束：99999)
// @Param	token				header		string	true	"认证token"
// @Param	vendorIDs			formData	string	false	"运营商ID列表(美团1 饿百3)"
// @Param	storeIDs			formData	string	false	"京西门店ID列表"
// @Param	startOrEndStore		formData	bool	true	"开启或结束"
// @Param	startTime			formData	int		false	"开始营业时间(格式：930代表早上9点30分)"
// @Param	endTime				formData	int		false	"结束营业时间"
// @Param	isAsync				formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /TestStartOrEndOpStore [post]
func (c *TempOpController) TestStartOrEndOpStore() {
	c.callTestStartOrEndOpStore(func(params *tTempopTestStartOrEndOpStoreParams) (retVal interface{}, errCode string, err error) {
		var vendorIDList []int
		var storeIDList []int
		if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil {
			retVal, err = misc.StartOrEndOpStore(params.Ctx, params.StartOrEndStore, vendorIDList, storeIDList, int16(params.StartTime), int16(params.EndTime), params.IsAsync, params.IsContinueWhenError)
		}
		return retVal, "", err
	})
}

// @Title 京西平台和其他平台商品的对比
// @Description 京西平台和其他平台商品的对比
// @Param	token			header		string	true	"认证token"
// @Param	vendorIDs		formData	string	false	"运营商ID列表(京东0 美团1 饿百3,14抖音,16淘宝)"
// @Param	storeIDs		formData	string	false	"京西门店ID列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CheckSkuDiffBetweenJxAndVendor [post]
func (c *TempOpController) CheckSkuDiffBetweenJxAndVendor() {
	c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) {
		var vendorIDList []int
		var storeIDList []int
		if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil {
			cms.CheckSkuDiffBetweenJxAndVendor(params.Ctx, vendorIDList, storeIDList)
		}

		return retVal, "", err
	})
}

// @Title 京西平台和其他平台商品的对比Test
// @Description 对比Test
// @Param	token			header		string	true	"认证token"
// @Param	vendorIDs		formData	string	false	"运营商ID列表(京东0 美团1 饿百3 14抖音 16淘宝)"
// @Param	storeIDs		formData	string	false	"京西门店ID列表"
// @Success 200 {object} controllers.CallResult
// @Failure 404 User not found
// @router /StoreSkuCheckDiff [post]
func (c *TempOpController) StoreSkuCheckDiff() {
	c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) {
		var vendorIDList []int
		var storeIDList []int
		if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil {

		}
		return retVal, "", err
	})
}

// @Title 把所有营业的门店，京西商城门店都打开，默认范围3km，默认100-100京西价格套餐
// @Description 对比Test
// @Param	token			header		string	true	"认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 404 User not found
// @router /StoreOpenAll [post]
func (c *TempOpController) StoreOpenAll() {
	c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) {
		var vendorIDList []int
		var storeIDList []int
		if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil {
			cms.StoreOpenAll(params.Ctx)
		}
		return retVal, "", err
	})
}

// @Title 通过订单创建消费者用户
// @Description 通过订单创建消费者用户
// @Param	token			header		string	true	"认证token"
// @Param	fromDate		formData	string	true	"开始日期"
// @Param	vendorIDs		formData	string	false	"运营商ID列表(京东0 美团1 饿百3)"
// @Param	toDate			formData	string	false	"结束日期（缺省不限制）"
// @Param	isForce			formData	bool	false	"是否强制"
// @Param	isAsync				formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateConsumerFromOrders [post]
func (c *TempOpController) CreateConsumerFromOrders() {
	c.callCreateConsumerFromOrders(func(params *tTempopCreateConsumerFromOrdersParams) (retVal interface{}, errCode string, err error) {
		var vendorIDs []int
		timeList, err := jxutils.BatchStr2Time(params.FromDate, params.ToDate)
		if err == nil {
			if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs); err == nil {
				retVal, err = tempop.CreateConsumerFromOrders(params.Ctx, vendorIDs, timeList[0], timeList[1], params.IsForce, params.IsAsync, params.IsContinueWhenError)
			}
		}
		return retVal, "", err
	})
}

// @Title 触犯红线通知
// @Description 触犯红线通知
// @Param	token			header		string	true	"认证token"
// @Param	storeIDs		formData	string	false	"门店列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CheckStoreAlert [post]
func (c *TempOpController) CheckStoreAlert() {
	c.callCheckStoreAlert(func(params *tTempopCheckStoreAlertParams) (retVal interface{}, errCode string, err error) {
		var storeIDs []int
		if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
			misc.CheckStoreAlert(params.Ctx, storeIDs)
		}
		return retVal, "", err
	})
}

// @Title 修复美团商品分类(emoji)
// @Description 修复美团商品分类(emoji)
// @Param	token			header		string	true	"认证token"
// @Param	mtwmStoreIDs	formData	string	false	"门店列表"
// @Param	isAsync				formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /FixMtwmCategory [post]
func (c *TempOpController) FixMtwmCategory() {
	c.callFixMtwmCategory(func(params *tTempopFixMtwmCategoryParams) (retVal interface{}, errCode string, err error) {
		var mtwmStoreIDs []int
		if err = jxutils.Strings2Objs(params.MtwmStoreIDs, &mtwmStoreIDs); err == nil {
			retVal, err = tempop.FixMtwmCategory(params.Ctx, mtwmStoreIDs, params.IsAsync, params.IsContinueWhenError)
		}
		return retVal, "", err
	})
}

// @Title 从饿百店建商品
// @Description 从饿百店建商品
// @Param	token			header		string	true	"认证token"
// @Param	baiduShopID		formData	int		true	"skuNameID"
// @Param	isAsync			formData	bool	false	"是否异步操作"
// @Param	isContinueWhenError	formData	bool	false	"单个同步失败是否继续，缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /BuildSkuFromEbaiStore [post]
func (c *TempOpController) BuildSkuFromEbaiStore() {
	c.callBuildSkuFromEbaiStore(func(params *tTempopBuildSkuFromEbaiStoreParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.BuildSkuFromEbaiStore(params.Ctx, int64(params.BaiduShopID), params.IsAsync, params.IsContinueWhenError)
		return retVal, "", err
	})
}

// @Title 上传京东商城图片
// @Description 上传京东商城图片
// @Param	token			header		string	true	"认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UploadJdsImage [post]
func (c *TempOpController) UploadJdsImage() {
	c.callUploadJdsImage(func(params *tTempopUploadJdsImageParams) (retVal interface{}, errCode string, err error) {
		err = tempop.UploadJdsImage(params.Ctx)
		return retVal, "", err
	})
}

// @Title 京西刷新调价包和门店价格
// @Description 京西刷新调价包和门店价格
// @Param	token			header		string	true	"认证token"
// @Param	storeID			formData	int		false	"门店ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshJXPriceChange [post]
func (c *TempOpController) RefreshJXPriceChange() {
	c.callRefreshJXPriceChange(func(params *tTempopRefreshJXPriceChangeParams) (retVal interface{}, errCode string, err error) {
		retVal, err = tempop.RefreshJXPriceChange(params.Ctx, params.StoreID)
		return retVal, "", err
	})
}
