admin
2020-07-03 651a15c78f668bef3859d9ed1bb7ad0b669d3600
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushGoodsController.java
@@ -1,8 +1,10 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
@@ -18,7 +20,7 @@
import com.yeshi.fanli.entity.push.PushGoods;
import com.yeshi.fanli.entity.push.PushGoodsGroup;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.exception.push.PushException;
import com.yeshi.fanli.exception.push.PushGoodsException;
import com.yeshi.fanli.service.AdminUserService;
import com.yeshi.fanli.service.inter.push.PushGoodsGroupService;
@@ -76,13 +78,39 @@
         pushGoodsService.save(pushGoods, list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("添加成功"));
      } catch (PushGoodsException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 新增/修改
    *
    * @param callback
    * @param special
    * @param out
    */
   @RequestMapping(value = "saveInfo")
   public void saveInfo(String callback, PushGoods pushGoods, String arrayIOS,   String arrayAndroid, PrintWriter out) {
      try {
         // 版本处理
         convertVersion(pushGoods, arrayIOS, arrayAndroid);
         // 保存
         pushGoodsService.saveInfo(pushGoods);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("添加成功"));
      } catch (PushGoodsException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 删除
    * 
@@ -143,13 +171,22 @@
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("数据信息已不存在"));
            return;
         }
         Date controlTime = pushGoods.getControlTime();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
         if (controlTime == null) {
            pushGoods.setControlTime_str("");
         } else {
            pushGoods.setControlTime_str(sdf.format(controlTime));
         }
         // 版本处理
         convertVersionList(pushGoods);
         
         List<TaoBaoGoodsBrief> listgoods = new ArrayList<TaoBaoGoodsBrief>();
         
         List<PushGoodsGroup> listGroup = pushGoodsGroupService.getAllInfoByPushId(pushGoods.getId());
         List<PushGoodsGroup> listGroup = pushGoodsGroupService.getAllInfoByPushId(id);
         if (listGroup == null) {
            listGroup = new ArrayList<PushGoodsGroup>();
         } else {
@@ -162,8 +199,12 @@
            }
         }
         
         GsonBuilder gsonBuilder = new GsonBuilder();
         gsonBuilder.serializeNulls();
         Gson gson = gsonBuilder.create();
         JSONObject data = new JSONObject();
         data.put("pushGoods", pushGoods);
         data.put("pushGoods", gson.toJson(pushGoods));
         data.put("listGroup", listgoods);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
@@ -198,13 +239,21 @@
      try {
         List<PushGoods> list = pushGoodsService.listQuery((pageIndex - 1) * pageSize, pageSize, key, state);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
            return;
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
         for (PushGoods pushGoods : list) {
            Date controlTime = pushGoods.getControlTime();
            if (controlTime == null) {
               pushGoods.setControlTime_str("");
            } else {
               pushGoods.setControlTime_str(sdf.format(controlTime));
            }
            long countGoods = pushGoodsGroupService.countByPushId(pushGoods.getId());
            pushGoods.setCountGoods(countGoods);
            
@@ -243,28 +292,23 @@
    */
   @RequestMapping(value = "push")
   public void push(String callback, String idArray, PrintWriter out) throws Exception {
      if (idArray == null || idArray.trim().length() == 0) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不能为空"));
         return;
      }
      
      try {
         Gson gson = new Gson();
         List<Long> list = gson.fromJson(idArray, new TypeToken<ArrayList<Long>>() {}.getType());
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不能为空"));
            return;
         }
            
         for (Long id: list) {
            pushGoodsService.executePush(id);
            pushGoodsService.handPush(id);
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (PushGoodsException e) {
@@ -341,7 +385,7 @@
     } else {
        JSONObject json = JSONObject.fromObject(versions);
         
         String versionsIOS = json.getString("IOS");
         String versionsIOS = json.optString("IOS");
         if (versionsIOS != null && versionsIOS.trim().length() > 0) {
            listIOS = Arrays.asList(versionsIOS.split(","));
         }