admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
fanli/src/main/java/com/yeshi/fanli/controller/admin/GoodsSubClassAdminController.java
@@ -18,8 +18,10 @@
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabelMap;
import com.yeshi.fanli.entity.bus.clazz.TaoBaoClass;
import com.yeshi.fanli.exception.FloatADException;
import com.yeshi.fanli.exception.goods.GoodsSubClassException;
import com.yeshi.fanli.service.inter.clazz.GoodsSubClassLabelService;
import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
import com.yeshi.fanli.service.inter.lable.LabelClassService;
@@ -39,6 +41,9 @@
   @Resource
   private TaoBaoClassService taoBaoClassService;
   @Resource
   private GoodsSubClassLabelService goodsSubClassLabelService;
   /**
    * 保存信息
    * 
@@ -47,8 +52,8 @@
    * @param out
    */
   @RequestMapping(value = "save")
   public void save(String callback, GoodsSubClass goodsSubClass, Long pid, Integer type, HttpServletRequest request,
         PrintWriter out) {
   public void save(String callback, GoodsSubClass goodsSubClass, Long pid, Integer type, Long labelId,
         HttpServletRequest request, PrintWriter out) {
      if (goodsSubClass.getTaobaoCids() != null)
         goodsSubClass.setTaobaoCids(goodsSubClass.getTaobaoCids().replace(",", ","));
@@ -57,16 +62,36 @@
         if (request instanceof MultipartHttpServletRequest) {
            MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request;
            goodsSubClassService.saveObject(fileRequest.getFile("file"), fileRequest.getFile("file2"),
                  goodsSubClass, type, pid);
                  goodsSubClass, type, pid, labelId);
         } else {
            goodsSubClassService.saveObject(null, null, goodsSubClass, type, pid);
            goodsSubClassService.saveObject(null, null, goodsSubClass, type, pid, labelId);
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
      } catch (FloatADException e) {
      } catch (GoodsSubClassException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
         e.printStackTrace();
      }
   }
   /**
    * 修改状态
    * @param callback
    * @param id
    * @param out
    */
   @RequestMapping(value = "switchState")
   public void switchState(String callback, Long id, PrintWriter out) {
      try {
         goodsSubClassService.switchState(id);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (GoodsSubClassException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
         e.printStackTrace();
      }
   }
@@ -80,9 +105,7 @@
    */
   @RequestMapping(value = "deleteBatch")
   public void deleteBatch(String callback, String ids, PrintWriter out) {
      Gson gson = new Gson();
      try {
         List<String> recordIds = gson.fromJson(ids, new TypeToken<ArrayList<String>>() {
         }.getType());
@@ -94,7 +117,6 @@
            goodsSubClassService.deleteByPrimaryKeyBatch(recordIds);
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("删除成功")));
         }
      } catch (Exception e) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
         e.printStackTrace();
@@ -111,7 +133,6 @@
    */
   @RequestMapping(value = "removePicture")
   public void removePicture(String callback, Long id, PrintWriter out) {
      try {
         GoodsSubClass goodsSubClass = goodsSubClassService.selectByPrimaryKey(id);
@@ -129,12 +150,10 @@
         } else {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("图片删除成功,数据更新失败")));
         }
      } catch (Exception e) {
         e.printStackTrace();
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
      }
   }
   /**
@@ -146,9 +165,7 @@
    */
   @RequestMapping(value = "querySub")
   public void querySub(String callback, Long pid, Integer type, PrintWriter out) {
      try {
         if (pid == null) {
            out.print(JsonUtil.loadFalseResult("上级id为空"));
            return;
@@ -212,6 +229,12 @@
               }
               goodsSubClass.setTaobaoCids(taobaoCids);
            }
            // 查询标签
            GoodsSubClassLabelMap map = goodsSubClassLabelService.selectBySubClassId(goodsSubClass.getId());
            if (map != null)
               goodsSubClass.setClassLabel(map.getLabel());
         }
         GsonBuilder gsonBuilder = new GsonBuilder();
@@ -221,7 +244,6 @@
         JSONObject data = new JSONObject();
         data.put("subClassList", gson.toJson(goodsSubClassList));
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
      } catch (Exception e) {
         e.printStackTrace();
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
@@ -236,7 +258,6 @@
    */
   @RequestMapping(value = "queryOverSecond")
   public void queryOverSecond(String callback, Long pid, PrintWriter out) {
      try {
         Integer state = null;
         List<GoodsSubClass> goodsSubClassList = goodsSubClassService.queryByPid(pid, state);
@@ -253,7 +274,6 @@
         JSONObject data = new JSONObject();
         data.put("subClassList", gson.toJson(goodsSubClassList));
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
      } catch (Exception e) {
         e.printStackTrace();
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
@@ -270,7 +290,6 @@
   @RequestMapping(value = "saveOrder")
   public void saveOrder(String callback, Long id, Integer type, Integer moveType, PrintWriter out) {
      try {
         if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递的类型不正确"));
            return;
@@ -306,9 +325,7 @@
         resultObj.setUpdatetime(new Date());
         goodsSubClassService.updateByPrimaryKeySelective(resultObj);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (Exception e) {
         e.printStackTrace();
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));