| | |
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.springframework.web.multipart.MultipartHttpServletRequest;
|
| | | import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.admin.GoodsClassAdmin;
|
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
|
| | | import com.yeshi.fanli.entity.system.System;
|
| | | import com.yeshi.fanli.service.inter.config.SystemService;
|
| | | import com.yeshi.fanli.service.inter.goods.ClassRecommendGoodsService;
|
| | | 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.tag.PageEntity;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.Utils;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("admin/new/api/v1/goodsclass")
|
| | |
| | | @Resource
|
| | | private SuperGoodsClassService superGoodsClassService;
|
| | |
|
| | | @Resource
|
| | | private ClassRecommendGoodsService classRecommendGoodsService;
|
| | |
|
| | | @Resource
|
| | | private GoodsSecondClassService goodsSecondClassService;
|
| | |
| | | private LabelClassService labelClassService;
|
| | |
|
| | | @Resource
|
| | | private SystemService systemService;
|
| | | private BusinessSystemService businessSystemService;
|
| | |
|
| | | // private static final String IMGPATH="/upload/class";
|
| | |
|
| | | @RequestMapping(value = "getGoodsClassList"/* , method = RequestMethod.POST */)
|
| | | public void getGoodsClassList(String callback, Integer pageIndex, String platform, String packages, String key, PrintWriter out) {
|
| | |
|
| | | List<GoodsClassAdmin> goodsClassList = goodsClassService.getGoodsClassAdmins(pageIndex - 1, platform, packages, key);
|
| | |
|
| | | int count = goodsClassService.getCount(platform, packages, key);
|
| | | int totalPage = count % Constant.PAGE_SIZE == 0 ? count / Constant.PAGE_SIZE : count / Constant.PAGE_SIZE + 1;
|
| | | PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count, totalPage);
|
| | | Map<String, String> map = new HashMap<String, String>();
|
| | | map.put("platform", platform);
|
| | | map.put("packages", packages);
|
| | | map.put("key", key);
|
| | | pe.setParams(map);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("pe", pe);
|
| | | List<System> systemList = systemService.getSystems();
|
| | |
|
| | | data.put("systemList", systemList);
|
| | | data.put("goodsClassList", goodsClassList);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | |
|
| | | // out.print(JsonUtil.loadTrueResult(data));
|
| | |
|
| | | return;
|
| | |
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "queryAll")
|
| | | public void queryAll(String callback, String platform, String packages, PrintWriter out) {
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | Map<String, String> map = new HashMap<String, String>();
|
| | | map.put("platform", platform);
|
| | | map.put("packages", packages);
|
| | | JSONObject data = new JSONObject();
|
| | |
|
| | | // List<System> systemList = systemService.getSystems();
|
| | | // data.put("systemList", systemList);
|
| | |
|
| | | data.put("goodsClassList", goodsClassList);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "getGoodsClasAll"/* , method = RequestMethod.POST */)
|
| | | |
| | | @RequestMapping(value = "getGoodsClasAll")
|
| | | public void getGoodsClassAll(String callback, PrintWriter out) {
|
| | | List<GoodsClass> goodsClassList = goodsClassService.getGoodsClassAll();
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "addGoodsClass", method = RequestMethod.POST)
|
| | | public void addGoodsClass(GoodsClass goodsClass, PrintWriter out) {
|
| | | if (goodsClass == null) {
|
| | | out.print(JsonUtil.loadFalseResult("goodsClass不能为空"));
|
| | | return;
|
| | | }
|
| | | Integer res = goodsClassService.addGoodsClass(goodsClass);
|
| | | if (res == null) {
|
| | | out.print(JsonUtil.loadTrueResult("添加分类成功"));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult("添加失败"));
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | // @RequestMapping(value="uploadImg",method=RequestMethod.POST)
|
| | | // public void uploadImg(@RequestParam("file") CommonsMultipartFile
|
| | | // file,HttpServletRequest request,PrintWriter out){
|
| | | // ServletContext servletContext = request.getSession().getServletContext();
|
| | | // JSONObject json=new JSONObject();
|
| | | // if(file != null){
|
| | | // String root=servletContext.getRealPath(IMGPATH);
|
| | | // if (!new File(root).exists()){
|
| | | // new File(root).mkdirs();
|
| | | // }
|
| | | // File newFile=new File(root+"/"+file.getOriginalFilename());
|
| | | // //通过CommonsMultipartFile的方法直接写文件(注意这个时候)
|
| | | // try {
|
| | | // file.transferTo(newFile);
|
| | | // json.put("code", "0");
|
| | | // json.put("path", IMGPATH+"/"+newFile.getName());
|
| | | // } catch (IllegalStateException e) {
|
| | | // e.printStackTrace();
|
| | | // json.put("code", "1");
|
| | | // } catch (IOException e) {
|
| | | // e.printStackTrace();
|
| | | // json.put("code", "1");
|
| | | // }finally{
|
| | | // out.print(json);
|
| | | // }
|
| | | // }else{
|
| | | // json.put("code", "1");
|
| | | // out.print(json);
|
| | | // }
|
| | | // }
|
| | |
|
| | | @RequestMapping(value = "setGoodsClassSystem", method = RequestMethod.POST)
|
| | | public void setGoodsClassSystem(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) {
|
| | | out.print(JsonUtil.loadTrueResult("删除成功"));
|
| | | } else {
|
| | | out.print(JsonUtil.loadTrueResult("删除失败"));
|
| | | }
|
| | | } else {
|
| | | superGoodsClassService.addSuperGoodsClass(gcid, platform, packageName);
|
| | | out.print(JsonUtil.loadTrueResult("添加成功"));
|
| | | }
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "getGoodsClass", method = RequestMethod.POST)
|
| | | public void getGoodsClass(long id, PrintWriter out) {
|
| | | GoodsClass rb = goodsClassService.getGoodsClass(id);
|
| | | if (rb != null) {
|
| | | out.print(JsonUtil.loadTrueResult(rb));
|
| | | return;
|
| | | }
|
| | | out.print(JsonUtil.loadFalseResult("不存在该GoodsClass"));
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "deleteGoodsClass", method = RequestMethod.POST)
|
| | | public void deleteGoodsClass(long[] gcids, PrintWriter out) {
|
| | | goodsClassService.deleteGoodsClasss(gcids);
|
| | | out.print(JsonUtil.loadTrueResult("删除成功"));
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "updateGoodsClass", method = RequestMethod.POST)
|
| | | public void updateGoodsClass(GoodsClass goodsClass, PrintWriter out) {
|
| | | goodsClassService.updateGoodsClass(goodsClass);
|
| | | out.print(JsonUtil.loadTrueResult("修改成功"));
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 添加类别
|
| | | * 保存信息
|
| | | *
|
| | | * @param callback
|
| | | * @param goodsClass
|
| | | * @param request
|
| | | * @param special
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "saveAdd", method = RequestMethod.POST)
|
| | | public void saveAdd(String callback, GoodsClass goodsClass, HttpServletRequest request, PrintWriter out) {
|
| | | @RequestMapping(value = "save")
|
| | | public void save(String callback, GoodsClass goodsClass, String jumpType, HttpServletRequest request,PrintWriter out) {
|
| | | try {
|
| | |
|
| | | String name = goodsClass.getName();
|
| | | if (StringUtil.isNullOrEmpty(name)) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("类别名称不能为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 1. 先判断httpRequest 是否含有文件类型 |
| | | if (request instanceof MultipartHttpServletRequest) {
|
| | |
|
| | | long result;
|
| | | List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
|
| | |
|
| | | goodsClass.setAndroidClick(0L);
|
| | | goodsClass.setIosClick(0L);
|
| | | // 搜索条件:有券、在售价20-200、牛皮癣轻微
|
| | | goodsClass.setSearchParam("{\"quan\":1,\"endPrice\":220,\"includeGoodRate\":true,\"baoYou\":true,\"ip\":\"218.72.111.105\"}");
|
| | | |
| | | if (files != null && files.size() > 0) {
|
| | | // 图片文件上传
|
| | | result = goodsClassService.saveAdd(goodsClass, files.get(0));
|
| | | } else {
|
| | | // 无图保存
|
| | | result = goodsClassService.saveAdd(goodsClass, null);
|
| | | }
|
| | |
|
| | | if (result > 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
|
| | | } else {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
|
| | | }
|
| | |
|
| | | } else {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请传递正确的参数"));
|
| | | }
|
| | |
|
| | | 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("操作异常"));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 保存修改信息
|
| | | * 修改排序
|
| | | *
|
| | | * @param callback
|
| | | * @param goodsClass
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "saveModify")
|
| | | public void saveModify(String callback, GoodsClass goodsClass, PrintWriter out) {
|
| | |
|
| | | @RequestMapping(value = "updateOrder")
|
| | | public void updateOrder(String callback, Long id, Integer moveType, PrintWriter out) {
|
| | | try {
|
| | |
|
| | | Long id = goodsClass.getId();
|
| | |
|
| | | GoodsClass resultObj = goodsClassService.getGoodsClass(id);
|
| | |
|
| | | if (resultObj == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该类别不存在或已被删除"));
|
| | | } else {
|
| | | String name = goodsClass.getName();
|
| | | if (!StringUtil.isNullOrEmpty(name)) {
|
| | | resultObj.setName(name);
|
| | | }
|
| | | |
| | | String key = goodsClass.getKey();
|
| | | if (!StringUtil.isNullOrEmpty(key)) {
|
| | | resultObj.setKey(key);
|
| | | }
|
| | |
|
| | | goodsClassService.updateGoodsClass(resultObj);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
|
| | | }
|
| | |
|
| | | 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();
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | * 保存修改信息
|
| | | * |
| | | * @param callback
|
| | | * @param goodsClass
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "saveOrderby")
|
| | | public void saveOrderby(String callback, Long id, int orderby, PrintWriter out) {
|
| | |
|
| | | try {
|
| | |
|
| | | GoodsClass resultObj = goodsClassService.getGoodsClass(id);
|
| | |
|
| | | if (resultObj == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该类别不存在或已被删除"));
|
| | | } else {
|
| | |
|
| | | List<GoodsClass> glist = goodsClassService.getByorderby(orderby);
|
| | | if (glist != null && glist.size() > 0) {
|
| | | GoodsClass changeObj = glist.get(0);
|
| | | changeObj.setOrderby(resultObj.getOrderby());
|
| | | goodsClassService.updateGoodsClass(changeObj);
|
| | | }
|
| | |
|
| | | resultObj.setOrderby(orderby);
|
| | | goodsClassService.updateGoodsClass(resultObj);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 批量删除
|
| | | *
|
| | |
| | | Long recordId = Long.parseLong(id);
|
| | |
|
| | | superGoodsClassService.deleteSuperGoodsClass(recordId);
|
| | | classRecommendGoodsService.deleteClassGoodsByGC(recordId);
|
| | |
|
| | | // goodsSecondClassService.deleteSecondClassByGC(recordId); |
| | | |
| | | // 删除子类分类
|
| | | goodsSubClassService.deleteByRootId(recordId);
|
| | | // 删除类别关联标签
|
| | |
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | //
|
| | | /**
|
| | | * 上传/修改 图片
|
| | | * |
| | | * @param callback
|
| | | * @param file
|
| | | * @param request
|
| | | * @param out
|
| | | * @param response
|
| | | */
|
| | | @RequestMapping(value = "uploadPicture")
|
| | | public void uploadPicture(Long id, @RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | GoodsClass goodsClass = goodsClassService.getGoodsClass(id);
|
| | |
|
| | | if (goodsClass == null ) {
|
| | | out.print(JsonUtil.loadFalseResult("该类别不存在或已被删除"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (file == null) {
|
| | | out.print(JsonUtil.loadFalseResult("图片文件不能为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | goodsClassService.uploadPicture(goodsClass, file);
|
| | | out.print(JsonUtil.loadTrueResult("上传成功"));
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 删除图片
|
| | |
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "setSuperSystem")
|