You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
5.3 KiB
Java

package com.kiisoo.ic.synchronous.controller;
import com.alibaba.fastjson.JSON;
import com.kiisoo.ic.common.KiisooException;
import com.kiisoo.ic.customer.CustomerService;
import com.kiisoo.ic.store.bean.BsdFriendsExistResponse;
import com.kiisoo.ic.store.entity.PoiStore;
import com.kiisoo.ic.synchronous.entity.FriendExistReqDO;
import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
import com.kiisoo.ic.synchronous.entity.TurnBackVO;
import com.kiisoo.ic.synchronous.service.BackReceiveService;
import com.kiisoo.ic.synchronous.service.PromotionCodeService;
import com.kiisoo.ic.utils.DataImportUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 同步数据
*/
@Controller
@RequestMapping("/api")
@Slf4j
public class SynchronousController {
private final CustomerService customerService;
@Autowired
public SynchronousController(CustomerService customerService) {
this.customerService = customerService;
}
@Autowired
private BackReceiveService backReceiveService;
@Autowired
private PromotionCodeService promotionCodeService;
/**
* 导入店铺接口
*
* @return
*/
@RequestMapping(value = "/shop/add", method = RequestMethod.POST)
@ResponseBody
public String addShop(@RequestBody List<PoiStore> PoiStores) {
return DataImportUtil.succ(1);
}
/**
* 导入vip接口
*
* @return
*/
@RequestMapping(value = "/vip/add", method = RequestMethod.POST)
@ResponseBody
public String addVip(@RequestBody List<PoiStore> PoiStores) {
return DataImportUtil.succ(1);
}
/**
* 导入导购接口
*
* @return
*/
@RequestMapping(value = "/staff/add", method = RequestMethod.POST)
@ResponseBody
public String addSeller(@RequestBody List<PoiStore> PoiStores) {
return DataImportUtil.succ(1);
}
/**
* 好友添加回调通知
*
* @return 是否成功
*/
@RequestMapping(value = "/ics/customer", method = RequestMethod.POST, consumes = "application/json")
@ResponseBody
public String turnBack(@RequestBody List<TurnBackDTO> turnBackDTOS, HttpServletResponse response) {
try {
Map<String, Object> returnValue = new HashMap<>();
returnValue.put("code", 1000);
returnValue.put("msg", "操作成功");
for (TurnBackDTO turnBackDTO : turnBackDTOS) {
Map<String, Object> callback = customerService.turnBack(turnBackDTO);
// 目前暂时只取其中一个值
returnValue.putIfAbsent("callback_info", callback);
}
log.info("添加好友回调了: {}", JSON.toJSONString(returnValue));
return JSON.toJSONString(returnValue);
// return DataImportUtil.succ(1);
}catch (Exception e){
log.error("好友回调报错",e);
String str = JSON.toJSONString(turnBackDTOS);
System.out.println(str);
return DataImportUtil.fail(e);
}
}
@RequestMapping(value = "/ics/activity/event/cb", method = RequestMethod.POST, consumes = "application/json")
@ResponseBody
public String activityEventCb(@RequestBody List<TurnBackDTO> turnBackDTOS) {
try {
for (TurnBackDTO turnBackDTO : turnBackDTOS) {
customerService.turnBack(turnBackDTO);
}
return DataImportUtil.succ(1);
}catch (Exception e){
log.error("扫码回调报错",e);
String str = JSON.toJSONString(turnBackDTOS);
System.out.println(str);
return DataImportUtil.fail(e);
}
}
/**
* 好友查询接口
* @param friendExistReqDO 亲故对象
* @return BsdFriendsExistResponse
*/
@RequestMapping(value = "/ics/friends/exist", method = RequestMethod.POST, consumes = "application/json")
@ResponseBody
public BsdFriendsExistResponse getFriendsExist(@RequestBody FriendExistReqDO friendExistReqDO) {
try {
return promotionCodeService.getFriendsExist(friendExistReqDO);
}catch (KiisooException e){
log.error("好友回调报错",e);
BsdFriendsExistResponse bsdFriendsExistResponse = new BsdFriendsExistResponse();
bsdFriendsExistResponse.setResInfo(null);
bsdFriendsExistResponse.setMsg(e.getMsg());
bsdFriendsExistResponse.setCode(e.getCode());
return bsdFriendsExistResponse;
}
}
/**
* 好友添加回调通知
*
* @return 是否成功
*/
@RequestMapping(value = "/ics/queue/customer", method = RequestMethod.POST, consumes = "application/json")
@ResponseBody
public String turnQueueBack(@RequestBody List<TurnBackDTO> turnBackDTOS) {
TurnBackVO turnBackVO = new TurnBackVO();
turnBackVO.setTurnBackDTOS(turnBackDTOS);
backReceiveService.send(turnBackVO);
return DataImportUtil.succ(1);
}
}