package com.yeshi.fanli.controller.apph5;
|
|
import java.io.PrintWriter;
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.core.task.TaskExecutor;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.taobao.TbImgUtil;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.yeshi.fanli.entity.accept.AcceptData;
|
import com.yeshi.fanli.entity.goods.CommonGoods;
|
import com.yeshi.fanli.entity.push.DeviceActive;
|
import com.yeshi.fanli.entity.push.PushGoods;
|
import com.yeshi.fanli.entity.push.PushGoodsGroup;
|
import com.yeshi.fanli.entity.push.PushGoodsRecord;
|
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
|
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
import com.yeshi.fanli.service.inter.push.DeviceActiveService;
|
import com.yeshi.fanli.service.inter.push.PushGoodsGroupService;
|
import com.yeshi.fanli.service.inter.push.PushGoodsRecordService;
|
import com.yeshi.fanli.service.inter.push.PushGoodsService;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
/**
|
* 今日推送
|
*
|
* @author Administrator
|
*
|
*/
|
@Controller
|
@RequestMapping("api/apph5/v1/push")
|
public class AppH5PushController {
|
|
@Resource(name = "taskExecutor")
|
private TaskExecutor executor;
|
|
@Resource
|
private HongBaoManageService manageService;
|
|
@Resource
|
private PushGoodsService pushGoodsService;
|
|
@Resource
|
private PushGoodsGroupService pushGoodsGroupService;
|
|
@Resource
|
private DeviceActiveService deviceActiveService;
|
|
@Resource
|
private PushGoodsRecordService pushGoodsRecordService;
|
|
@Resource
|
private HongBaoManageService hongBaoManageService;
|
|
/**
|
* 推送商品详情页
|
*
|
* @param callback
|
* @param id
|
* @param out
|
*/
|
@RequestMapping(value = "getpushgoods")
|
public void getPushGoodsDetail(String callback, AcceptData acceptData, String deviceToken, Long id, PrintWriter out) {
|
|
if (id == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("参数不正确"));
|
return;
|
}
|
|
try {
|
PushGoods pushGoods = pushGoodsService.selectByPrimaryKey(id);
|
if (pushGoods == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("此推送记录已不存在"));
|
return;
|
}
|
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
List<PushGoodsGroup> list = pushGoodsGroupService.getAllInfoByPushId(id);
|
|
if (list != null && list.size() > 0) {
|
|
Map<String, String> map = manageService.convertMap(acceptData.getSystem());
|
BigDecimal proportion = hongBaoManageService.getFanLiRate(acceptData.getSystem());
|
|
for (PushGoodsGroup pushGoodsGroup : list) {
|
CommonGoods commonGoods = pushGoodsGroup.getCommonGoods();
|
if (commonGoods == null) {
|
continue;
|
}
|
|
TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods);
|
int biz30day = goodsBrief.getBiz30day();
|
if (biz30day >= 10000) {
|
double sales = biz30day;
|
String salesCountMidea = String.format("%.1f", sales / 10000);
|
goodsBrief.setSalesCount(salesCountMidea + "万");
|
} else {
|
goodsBrief.setSalesCount(biz30day + "");
|
}
|
|
// 改变图片尺寸
|
String pictUrl = commonGoods.getPicture();
|
if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
|
commonGoods.setPicture(TbImgUtil.getTBSize320Img(pictUrl));
|
}
|
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion.toString(), null)));
|
}
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("title", pushGoods.getTitle());
|
data.put("content", pushGoods.getContent());
|
data.put("result_list", array);
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
|
DeviceActive deviceActive = deviceActiveService.getDeviceByDeviceAndPlatform(acceptData.getDevice(),
|
deviceToken, acceptData.getPlatform());
|
|
// 列表参数、设备参数信息不为空
|
if (deviceActive != null) {
|
// 记录访问信息
|
executor.execute(new Runnable() {
|
@Override
|
public void run() {
|
try {
|
|
List<PushGoodsRecord> listRecord = pushGoodsRecordService.listByPushIdAndDeviceId(
|
pushGoods.getId(), deviceActive.getId());
|
if (listRecord == null || listRecord.size() == 0) {
|
PushGoodsRecord pushGoodsRecord = new PushGoodsRecord();
|
|
pushGoodsRecord.setCreateTime(new Date());
|
pushGoodsRecord.setPushGoods(pushGoods);
|
pushGoodsRecord.setDeviceActive(deviceActive);
|
pushGoodsRecordService.insert(pushGoodsRecord);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
});
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|