| | |
| | | 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.springframework.web.multipart.MultipartHttpServletRequest;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
|
| | | import com.yeshi.fanli.exception.FloatADException;
|
| | | import com.yeshi.fanli.exception.GoodsClassException;
|
| | | import com.yeshi.fanli.service.inter.config.BusinessSystemService;
|
| | | import com.yeshi.fanli.service.inter.goods.GoodsClassService;
|
| | | import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
|
| | | import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
|
| | | import com.yeshi.fanli.service.inter.goods.SuperGoodsClassService;
|
| | | import com.yeshi.fanli.service.inter.lable.LabelClassService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.Utils;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("admin/new/api/v1/goodsclass")
|
| | | public class GoodsClassAdminCotroller {
|
| | |
|
| | | @Resource
|
| | | private GoodsClassService goodsClassService;
|
| | |
|
| | | @Resource
|
| | | private SuperGoodsClassService superGoodsClassService;
|
| | |
|
| | |
|
| | | @Resource
|
| | | private GoodsSecondClassService goodsSecondClassService;
|
| | |
|
| | | @Resource
|
| | | private GoodsSubClassService goodsSubClassService;
|
| | | |
| | | @Resource
|
| | | private LabelClassService labelClassService;
|
| | |
|
| | | @Resource
|
| | | private BusinessSystemService businessSystemService;
|
| | |
|
| | |
|
| | | @RequestMapping(value = "queryAll")
|
| | | public void queryAll(String callback, String platform, String packages, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | List<GoodsClass> goodsClassList = goodsClassService.queryAll(platform, packages);
|
| | |
|
| | | if (goodsClassList == null || goodsClassList.size() == 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
| | | return;
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("goodsClassList", goodsClassList);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | |
| | | @RequestMapping(value = "getGoodsClasAll")
|
| | | public void getGoodsClassAll(String callback, PrintWriter out) {
|
| | | List<GoodsClass> goodsClassList = goodsClassService.getGoodsClassAll();
|
| | |
|
| | | if (goodsClassList == null || goodsClassList.size() == 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
| | | } else {
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("goodsClassList", goodsClassList);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 保存信息
|
| | | * |
| | | * @param callback
|
| | | * @param special
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "save")
|
| | | public void save(String callback, GoodsClass goodsClass, String jumpType, HttpServletRequest request,PrintWriter out) {
|
| | | try {
|
| | | // 1. 先判断httpRequest 是否含有文件类型 |
| | | if (request instanceof MultipartHttpServletRequest) {
|
| | | MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request;
|
| | | goodsClassService.saveObject(fileRequest.getFile("file"), goodsClass);
|
| | | }else{
|
| | | goodsClassService.saveObject(null, goodsClass);
|
| | | }
|
| | | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
|
| | | } catch (FloatADException e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
| | | } catch (Exception e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 修改排序
|
| | | * |
| | | * @param callback
|
| | | * @param goodsClass
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "updateOrder")
|
| | | public void updateOrder(String callback, Long id, Integer moveType, PrintWriter out) {
|
| | | try {
|
| | | goodsClassService.updateOrder(id, moveType);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
|
| | | } catch (GoodsClassException e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
| | | } catch (Exception e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 批量删除
|
| | | * |
| | | * @param callback
|
| | | * @param ids
|
| | | * @param out
|
| | | */
|
| | | @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());
|
| | |
|
| | | if (recordIds == null || recordIds.size() == 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需删除数据"));
|
| | | } else {
|
| | |
|
| | | for (String id : recordIds) {
|
| | | Long recordId = Long.parseLong(id);
|
| | |
|
| | | superGoodsClassService.deleteSuperGoodsClass(recordId);
|
| | | |
| | | // 删除子类分类
|
| | | goodsSubClassService.deleteByRootId(recordId);
|
| | | // 删除类别关联标签
|
| | | labelClassService.deleteByClassId(recordId);
|
| | | |
| | | goodsClassService.deleteGoodsClass(recordId);
|
| | | }
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功"));
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | |
| | |
|
| | | /**
|
| | | * 删除图片
|
| | | * |
| | | * @param callback
|
| | | * @param file
|
| | | * @param out
|
| | | * @param response
|
| | | */
|
| | | @RequestMapping(value = "removePicture")
|
| | | public void removePicture(String callback, Long id, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | GoodsClass goodsClass = goodsClassService.getGoodsClass(id);
|
| | |
|
| | | if (goodsClass == null) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("该类别不存在或已被删除")));
|
| | | return;
|
| | | }
|
| | |
|
| | | goodsClassService.removePicture(goodsClass);
|
| | |
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("图片删除成功")));
|
| | |
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
|
| | | }
|
| | | }
|
| | | |
| | | @RequestMapping(value = "setSuperSystem")
|
| | | public void setSuperSystem(String callback,String type, Long gcid, String platform, String packageName, PrintWriter out) {
|
| | | platform = Utils.getMap().get(platform);
|
| | | if (Constant.DEL.equals(type)) {
|
| | | Integer integer = superGoodsClassService.deleteSuperGoodsClass(gcid, platform, packageName);
|
| | | if (integer > 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功"));
|
| | | } else {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败"));
|
| | | }
|
| | | } else {
|
| | | superGoodsClassService.addSuperGoodsClass(gcid, platform, packageName);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("添加成功"));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | @RequestMapping(value = "getClassOption")
|
| | | public void getClassOption(String callback, PrintWriter out) {
|
| | |
|
| | | List<GoodsClass> goodsClassList = goodsClassService.getGoodsClassAll();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | |
|
| | | data.put("result_list", goodsClassList);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | |
|
| | | }
|
| | | }
|
| | | 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.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass; |
| | | import com.yeshi.fanli.exception.goods.GoodsClassException; |
| | | import com.yeshi.fanli.service.inter.config.BusinessSystemService; |
| | | import com.yeshi.fanli.service.inter.goods.GoodsClassService; |
| | | import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService; |
| | | import com.yeshi.fanli.service.inter.goods.GoodsSubClassService; |
| | | import com.yeshi.fanli.service.inter.goods.SuperGoodsClassService; |
| | | import com.yeshi.fanli.service.inter.lable.LabelClassService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.Utils; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Controller |
| | | @RequestMapping("admin/new/api/v1/goodsclass") |
| | | public class GoodsClassAdminCotroller { |
| | | |
| | | @Resource |
| | | private GoodsClassService goodsClassService; |
| | | |
| | | @Resource |
| | | private SuperGoodsClassService superGoodsClassService; |
| | | |
| | | @Resource |
| | | private GoodsSecondClassService goodsSecondClassService; |
| | | |
| | | @Resource |
| | | private GoodsSubClassService goodsSubClassService; |
| | | |
| | | @Resource |
| | | private LabelClassService labelClassService; |
| | | |
| | | |
| | | @RequestMapping(value = "queryAll") |
| | | public void listquery(AdminAcceptData acceptData, String callback, Integer sex, PrintWriter out) { |
| | | |
| | | try { |
| | | List<GoodsClass> goodsClassList = goodsClassService.listquery(sex); |
| | | |
| | | if (goodsClassList == null || goodsClassList.size() == 0) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据")); |
| | | return; |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("goodsClassList", goodsClassList); |
| | | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常")); |
| | | } |
| | | |
| | | } |
| | | |
| | | @RequestMapping(value = "getGoodsClasAll") |
| | | public void getGoodsClassAll(AdminAcceptData acceptData,String callback, PrintWriter out) { |
| | | List<GoodsClass> goodsClassList = goodsClassService.getGoodsClassAll(); |
| | | |
| | | if (goodsClassList == null || goodsClassList.size() == 0) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据")); |
| | | } else { |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("goodsClassList", goodsClassList); |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存信息 |
| | | * |
| | | * @param callback |
| | | * @param special |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "save") |
| | | public void save(AdminAcceptData acceptData,String callback, GoodsClass goodsClass, String jumpType, HttpServletRequest request, |
| | | PrintWriter out) { |
| | | if (goodsClass.getTaobaoCids() != null) |
| | | goodsClass.setTaobaoCids(goodsClass.getTaobaoCids().replace(",", ",")); |
| | | try { |
| | | // 1. 先判断httpRequest 是否含有文件类型 |
| | | if (request instanceof MultipartHttpServletRequest) { |
| | | MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request; |
| | | goodsClassService.saveObject(fileRequest.getFile("file"), goodsClass); |
| | | } else { |
| | | goodsClassService.saveObject(null, goodsClass); |
| | | } |
| | | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功")); |
| | | } catch (GoodsClassException 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(AdminAcceptData acceptData,String callback, Long id, PrintWriter out) { |
| | | try { |
| | | goodsClassService.switchState(id); |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功")); |
| | | } catch (GoodsClassException e) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); |
| | | } catch (Exception e) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 修改排序 |
| | | * |
| | | * @param callback |
| | | * @param goodsClass |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "updateOrder") |
| | | public void updateOrder(AdminAcceptData acceptData,String callback, Long id, Integer moveType, PrintWriter out) { |
| | | try { |
| | | goodsClassService.updateOrder(id, moveType); |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功")); |
| | | } catch (GoodsClassException e) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); |
| | | } catch (Exception e) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * |
| | | * @param callback |
| | | * @param ids |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "deleteBatch") |
| | | public void deleteBatch(AdminAcceptData acceptData,String callback, String ids, PrintWriter out) { |
| | | Gson gson = new Gson(); |
| | | try { |
| | | List<String> recordIds = gson.fromJson(ids, new TypeToken<ArrayList<String>>() { |
| | | }.getType()); |
| | | |
| | | if (recordIds == null || recordIds.size() == 0) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择需删除数据")); |
| | | } else { |
| | | |
| | | for (String id : recordIds) { |
| | | Long recordId = Long.parseLong(id); |
| | | |
| | | superGoodsClassService.deleteSuperGoodsClass(recordId); |
| | | |
| | | // 删除子类分类 |
| | | goodsSubClassService.deleteByRootId(recordId); |
| | | // 删除类别关联标签 |
| | | labelClassService.deleteByClassId(recordId); |
| | | |
| | | goodsClassService.deleteGoodsClass(recordId); |
| | | } |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功")); |
| | | } |
| | | } catch (Exception e) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除图片 |
| | | * |
| | | * @param callback |
| | | * @param file |
| | | * @param out |
| | | * @param response |
| | | */ |
| | | @RequestMapping(value = "removePicture") |
| | | public void removePicture(AdminAcceptData acceptData,String callback, Long id, PrintWriter out) { |
| | | try { |
| | | GoodsClass goodsClass = goodsClassService.getGoodsClass(id); |
| | | |
| | | if (goodsClass == null) { |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("该类别不存在或已被删除"))); |
| | | return; |
| | | } |
| | | |
| | | goodsClassService.removePicture(goodsClass); |
| | | |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("图片删除成功"))); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常"))); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "setSuperSystem") |
| | | public void setSuperSystem(AdminAcceptData acceptData,String callback, String type, Long gcid, String platform, String packageName, |
| | | PrintWriter out) { |
| | | platform = Utils.getMap().get(platform); |
| | | if (Constant.DEL.equals(type)) { |
| | | Integer integer = superGoodsClassService.deleteSuperGoodsClass(gcid, platform, packageName); |
| | | if (integer > 0) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功")); |
| | | } else { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败")); |
| | | } |
| | | } else { |
| | | superGoodsClassService.addSuperGoodsClass(gcid, platform, packageName); |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("添加成功")); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "getClassOption") |
| | | public void getClassOption(AdminAcceptData acceptData,String callback, PrintWriter out) { |
| | | List<GoodsClass> goodsClassList = goodsClassService.getGoodsClassAll(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("result_list", goodsClassList); |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); |
| | | } |
| | | } |