admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/controller/admin/LabelGoodsAdminController.java
@@ -1,129 +1,128 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.service.inter.lable.LabelGoodsService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@Controller
@RequestMapping("admin/new/api/v1/labelGoods")
public class LabelGoodsAdminController {
   @Resource
   private LabelGoodsService labelGoodsService;
   /**
    * 批量商品添加标签-关联lableId
    *
    * @param callback
    * @param labIds
    * @param goodIds
    * @param request
    * @param out
    */
   @RequestMapping(value = "batchGoodsAddLables")
   public void batchGoodsAddLables(String callback, String labIds, String ids,
         HttpServletRequest request, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(ids)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
         return;
      }
      Gson gson = new Gson();
      List<Long> goodsIdList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() {}.getType());
      if (goodsIdList == null || goodsIdList.size() == 0) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
         return;
      }
      try {
         // 获取当前操作用户
         AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
         if (goodsIdList.size() == 1) {
            List<Long> labIdList = null;
            if (!StringUtil.isNullOrEmpty(labIds)) {
               labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
            }
            // 单个处理
            Long goodsId = goodsIdList.get(0);
            labelGoodsService.singleGoodsAddLables(goodsId, labIdList, admin);
         } else {
            if (StringUtil.isNullOrEmpty(labIds)) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择添加的标签"));
               return;
            }
            List<Long> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
            if (labIdList == null || labIdList.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择添加的标签"));
               return;
            }
            // 批量处理
            labelGoodsService.batchGoodsAddLables(goodsIdList, labIdList, admin);
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (Exception e) {
         // TODO Auto-generated catch block
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 批量商品添加标签-关联lableId
    *
    * @param callback
    * @param labIds
    * @param goodIds
    * @param request
    * @param out
    */
   @RequestMapping(value = "singleGoodsAddLables")
   public void singleGoodsAddLables(String callback, String labIds, Long goodsId,
         HttpServletRequest request, PrintWriter out) {
      try {
         // 获取当前操作用户
         AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
         if (goodsId == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
            return;
         }
         Gson gson = new Gson();
         List<Long> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
         labelGoodsService.singleGoodsAddLables(goodsId, labIdList, admin);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (Exception e) {
         // TODO Auto-generated catch block
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
}
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.yeshi.fanli.entity.accept.AdminAcceptData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.service.inter.lable.LabelGoodsService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@Controller
@RequestMapping("admin/new/api/v1/labelGoods")
public class LabelGoodsAdminController {
   @Resource
   private LabelGoodsService labelGoodsService;
   /**
    * 批量商品添加标签-关联lableId
    *
    * @param callback
    * @param labIds
    * @param request
    * @param out
    */
   @RequestMapping(value = "batchGoodsAddLables")
   public void batchGoodsAddLables(AdminAcceptData acceptData, String callback, String labIds, String ids,
                           HttpServletRequest request, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(ids)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
         return;
      }
      Gson gson = new Gson();
      List<String> goodsIdList = gson.fromJson(ids, new TypeToken<ArrayList<String>>() {}.getType());
      if (goodsIdList == null || goodsIdList.size() == 0) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
         return;
      }
      try {
         // 获取当前操作用户
         AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
         if (goodsIdList.size() == 1) {
            List<Long> labIdList = null;
            if (!StringUtil.isNullOrEmpty(labIds)) {
               labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
            }
            // 单个处理
            String goodsId = goodsIdList.get(0);
            labelGoodsService.singleGoodsAddLables(goodsId, labIdList, admin);
         } else {
            if (StringUtil.isNullOrEmpty(labIds)) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择添加的标签"));
               return;
            }
            List<Long> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
            if (labIdList == null || labIdList.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择添加的标签"));
               return;
            }
            // 批量处理
            labelGoodsService.batchGoodsAddLables(goodsIdList, labIdList, admin);
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (Exception e) {
         // TODO Auto-generated catch block
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 批量商品添加标签-关联lableId
    *
    * @param callback
    * @param labIds
    * @param request
    * @param out
    */
   @RequestMapping(value = "singleGoodsAddLables")
   public void singleGoodsAddLables(AdminAcceptData acceptData,String callback, String labIds, String goodsId,
         HttpServletRequest request, PrintWriter out) {
      try {
         // 获取当前操作用户
         AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
         if (goodsId == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需操作的商品"));
            return;
         }
         Gson gson = new Gson();
         List<Long> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<Long>>() {}.getType());
         labelGoodsService.singleGoodsAddLables(goodsId, labIdList, admin);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (Exception e) {
         // TODO Auto-generated catch block
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
}