| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | 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.GsonBuilder;
|
| | | 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.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;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.annotation.RequestNoLogin;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("admin/new/api/v1/goodsSubClass")
|
| | |
| | | @Resource
|
| | | private LabelClassService labelClassService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoClassService taoBaoClassService;
|
| | |
|
| | | @Resource
|
| | | private GoodsSubClassLabelService goodsSubClassLabelService;
|
| | |
|
| | | /**
|
| | | * 添加类别
|
| | | * 保存信息
|
| | | *
|
| | | * @param callback
|
| | | * @param goodsSubClass
|
| | | * @param request
|
| | | * @param special
|
| | | * @param out
|
| | | */
|
| | | @RequestNoLogin()
|
| | | @RequestMapping(value = "saveAdd", method = RequestMethod.POST)
|
| | | public void saveAdd(String callback, Long pid, Integer type, GoodsSubClass goodsSubClass, |
| | | HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
|
| | | @RequestMapping(value = "save")
|
| | | 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(",", ","));
|
| | |
|
| | | response.setHeader("Access-Control-Allow-Origin", "*");
|
| | | response.setHeader("Access-Control-Allow-Methods", "*");
|
| | | try {
|
| | |
|
| | | String name = goodsSubClass.getName();
|
| | | if (StringUtil.isNullOrEmpty(name)) {
|
| | | out.print(JsonUtil.loadFalseResult("类别名称不能为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | |
|
| | | if (pid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("上级id为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (type == null) {
|
| | | out.print(JsonUtil.loadFalseResult("等级不能为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (type > 5) {
|
| | | out.print(JsonUtil.loadFalseResult("等级不能超过五级"));
|
| | | return;
|
| | | }
|
| | | |
| | | String key = goodsSubClass.getKey();
|
| | | if (StringUtil.isNullOrEmpty(key)) {
|
| | | goodsSubClass.setKey(name.trim());
|
| | | }
|
| | | |
| | | // 默认停用
|
| | | goodsSubClass.setState(0);
|
| | | |
| | | // 1. 先判断httpRequest 是否含有文件类型
|
| | | if (request instanceof MultipartHttpServletRequest) {
|
| | |
|
| | | int result;
|
| | | List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
|
| | | |
| | | goodsSubClass.setAndroidClick(0L);
|
| | | goodsSubClass.setIosClick(0L);
|
| | | goodsSubClass.setLevel(type);
|
| | | goodsSubClass.setCreatetime(new Date());
|
| | | goodsSubClass.setUpdatetime(new Date());
|
| | | // 搜索条件:有券、在售价20-200、牛皮癣轻微
|
| | | goodsSubClass.setSearchJson("{\"quan\":1,\"endPrice\":220,\"includeGoodRate\":true}");
|
| | | |
| | | if (type == 2) {
|
| | | goodsSubClass.setRootClass(new GoodsClass(pid));
|
| | | int weight = goodsSubClassService.getMaxWeightByRootId(pid);
|
| | | goodsSubClass.setWeight(weight + 1);
|
| | | } else {
|
| | | goodsSubClass.setParent(new GoodsSubClass(pid));
|
| | | int weight = goodsSubClassService.getMaxWeightByPid(pid);
|
| | | goodsSubClass.setWeight(weight + 1);
|
| | | }
|
| | | |
| | | |
| | | |
| | | if (files != null && files.size() > 0) {
|
| | | // 图片文件上传
|
| | | result = goodsSubClassService.save(goodsSubClass, files.get(0));
|
| | | } else {
|
| | | // 无图保存
|
| | | result = goodsSubClassService.save(goodsSubClass, null);
|
| | | }
|
| | |
|
| | | if (result == 1) {
|
| | | out.print(JsonUtil.loadTrueResult("保存成功"));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult("保存失败"));
|
| | | }
|
| | |
|
| | | MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request;
|
| | | goodsSubClassService.saveObject(fileRequest.getFile("file"), fileRequest.getFile("file2"),
|
| | | goodsSubClass, type, pid, labelId);
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult("请传递正确的参数"));
|
| | | goodsSubClassService.saveObject(null, null, goodsSubClass, type, pid, labelId);
|
| | | }
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
|
| | | } catch (GoodsSubClassException e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("操作异常"));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 保存修改信息
|
| | | * |
| | | * 修改状态
|
| | | * @param callback
|
| | | * @param goodsSubClass
|
| | | * @param id
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "saveModify")
|
| | | public void saveModify(String callback, GoodsSubClass goodsSubClass, PrintWriter out) {
|
| | |
|
| | | @RequestMapping(value = "switchState")
|
| | | public void switchState(String callback, Long id, PrintWriter out) {
|
| | | try {
|
| | |
|
| | | Long id = goodsSubClass.getId();
|
| | | if (id == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("不存在该类别"));
|
| | | return;
|
| | | }
|
| | | |
| | | GoodsSubClass resultObj = goodsSubClassService.selectByPrimaryKey(id);
|
| | | if (resultObj == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("不存在该类别"));
|
| | | return;
|
| | | } |
| | | |
| | | GoodsSubClass subClass = new GoodsSubClass();
|
| | | |
| | | String name = goodsSubClass.getName();
|
| | | if (!StringUtil.isNullOrEmpty(name)) {
|
| | | subClass.setName(name);
|
| | | }
|
| | | // 关键词可以为空
|
| | | subClass.setKey(goodsSubClass.getKey());
|
| | | |
| | | subClass.setId(id);
|
| | | subClass.setUpdatetime(new Date());
|
| | | |
| | | goodsSubClassService.updateByPrimaryKeySelective(subClass);
|
| | | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
|
| | |
|
| | | 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.loadTrueResult("修改失败"));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
|
| | | e.printStackTrace();
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @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());
|
| | | List<String> recordIds = gson.fromJson(ids, new TypeToken<ArrayList<String>>() {
|
| | | }.getType());
|
| | |
|
| | | if (recordIds == null || recordIds.size() == 0) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("请选择需删除数据")));
|
| | |
| | | goodsSubClassService.deleteByPrimaryKeyBatch(recordIds);
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("删除成功")));
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | * 上传/修改 图片
|
| | | * |
| | | * @param callback
|
| | | * @param file
|
| | | * @param request
|
| | | * @param out
|
| | | * @param response
|
| | | */
|
| | | @RequestNoLogin()
|
| | | @RequestMapping(value = "uploadPicture")
|
| | | public void uploadPicture(Long id, @RequestParam("file") CommonsMultipartFile file, |
| | | PrintWriter out, HttpServletResponse response) {
|
| | |
|
| | | response.setHeader("Access-Control-Allow-Origin", "*");
|
| | | response.setHeader("Access-Control-Allow-Methods", "*");
|
| | |
|
| | | try {
|
| | |
|
| | | GoodsSubClass goodsSubClass = goodsSubClassService.selectByPrimaryKey(id);
|
| | |
|
| | | if (goodsSubClass == null) {
|
| | | out.print(JsonUtil.loadFalseResult("该类别不存在或已被删除"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (file == null) {
|
| | | out.print(JsonUtil.loadFalseResult("图片文件不能为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | int result = goodsSubClassService.uploadPicture(goodsSubClass, file);
|
| | |
|
| | | if (result == 1) {
|
| | | out.print(JsonUtil.loadTrueResult("上传成功"));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult("上传失败"));
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @RequestMapping(value = "removePicture")
|
| | | public void removePicture(String callback, Long id, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | GoodsSubClass goodsSubClass = goodsSubClassService.selectByPrimaryKey(id);
|
| | |
|
| | |
| | | } else {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("图片删除成功,数据更新失败")));
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("操作异常")));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "querySub")
|
| | | public void querySub(String callback, Long pid, Integer type,PrintWriter out) {
|
| | |
|
| | | public void querySub(String callback, Long pid, Integer type, PrintWriter out) {
|
| | | try {
|
| | | |
| | | if (pid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("上级id为空"));
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | if (type == null) {
|
| | | out.print(JsonUtil.loadFalseResult("等级不能为空"));
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | Integer state = null;
|
| | | List<GoodsSubClass> goodsSubClassList = new ArrayList<GoodsSubClass>();
|
| | | if (type == 2) {
|
| | |
| | | } else {
|
| | | goodsSubClassList = goodsSubClassService.queryByPid(pid, state);
|
| | | }
|
| | | |
| | |
|
| | | if (goodsSubClassList == null || goodsSubClassList.size() == 0) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("暂无数据")));
|
| | | return;
|
| | | } |
| | | |
| | | for (GoodsSubClass goodsSubClass:goodsSubClassList) {
|
| | | }
|
| | |
|
| | | for (GoodsSubClass goodsSubClass : goodsSubClassList) {
|
| | | Long iosClick = goodsSubClass.getIosClick();
|
| | | Long androidClick = goodsSubClass.getAndroidClick();
|
| | | |
| | |
|
| | | if (iosClick != null && androidClick != null) {
|
| | | goodsSubClass.setCountClick(iosClick+androidClick);
|
| | | } else if(androidClick != null) {
|
| | | goodsSubClass.setCountClick(iosClick + androidClick);
|
| | | } else if (androidClick != null) {
|
| | | goodsSubClass.setCountClick(androidClick);
|
| | | } else if(iosClick != null) {
|
| | | } else if (iosClick != null) {
|
| | | goodsSubClass.setCountClick(iosClick);
|
| | | } else{
|
| | | } else {
|
| | | goodsSubClass.setCountClick(0l);
|
| | | }
|
| | | |
| | |
|
| | | String searchJson = goodsSubClass.getSearchJson();
|
| | | if (searchJson == null) {
|
| | | goodsSubClass.setSearchParam("");
|
| | | } else {
|
| | | goodsSubClass.setSearchParam(searchJson);
|
| | | }
|
| | |
|
| | | int countlabel = labelClassService.getCountQueryBySubClassId(goodsSubClass.getId());
|
| | | goodsSubClass.setCountlabel(countlabel);
|
| | |
|
| | | // 查询淘宝分类
|
| | | List<TaoBaoClass> listTB = taoBaoClassService.listBySystemSubCid(0, 10000, goodsSubClass.getId());
|
| | | if (listTB == null || listTB.size() == 0) {
|
| | | goodsSubClass.setTaobaoCids("");
|
| | | } else {
|
| | | String taobaoCids = "";
|
| | | for (TaoBaoClass taoBaoClass : listTB) {
|
| | | taobaoCids = taobaoCids + taoBaoClass.getCategoryName() + "-" + taoBaoClass.getCategoryId()
|
| | | + ",";
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(taobaoCids)) {
|
| | | taobaoCids = taobaoCids.substring(0, taobaoCids.length() - 1);
|
| | | }
|
| | | goodsSubClass.setTaobaoCids(taobaoCids);
|
| | | }
|
| | |
|
| | | // 查询标签
|
| | | GoodsSubClassLabelMap map = goodsSubClassLabelService.selectBySubClassId(goodsSubClass.getId());
|
| | | if (map != null)
|
| | | goodsSubClass.setClassLabel(map.getLabel());
|
| | |
|
| | | }
|
| | | |
| | | |
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder();
|
| | | gsonBuilder.serializeNulls(); // 重点
|
| | |
| | | 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("操作异常")));
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 查找二级下的其他级分类
|
| | | *
|
| | |
| | | */
|
| | | @RequestMapping(value = "queryOverSecond")
|
| | | public void queryOverSecond(String callback, Long pid, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | Integer state = null;
|
| | | List<GoodsSubClass> goodsSubClassList = goodsSubClassService.queryByPid(pid, state);
|
| | |
| | | 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("操作异常")));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 修改排序
|
| | | *
|
| | |
| | | */
|
| | | @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;
|
| | | }
|
| | | |
| | |
|
| | | GoodsSubClass resultObj = goodsSubClassService.selectByPrimaryKey(id);
|
| | | if (resultObj == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("不存在该类别"));
|
| | | return;
|
| | | } |
| | | }
|
| | |
|
| | | int resultWeight = resultObj.getWeight();
|
| | | |
| | |
|
| | | List<GoodsSubClass> list = null;
|
| | | if (type == 2) {
|
| | | GoodsClass rootClass = resultObj.getRootClass();
|
| | | list= goodsSubClassService.queryByRootIdAndWeight(rootClass.getId(), moveType, resultWeight);
|
| | | list = goodsSubClassService.queryByRootIdAndWeight(rootClass.getId(), moveType, resultWeight);
|
| | | } else {
|
| | | GoodsSubClass parent = resultObj.getParent();
|
| | | list = goodsSubClassService.queryByPidAndWeight(parent.getId(), moveType, resultWeight);
|
| | | }
|
| | | |
| | |
|
| | | if (list != null && list.size() > 0) {
|
| | | GoodsSubClass changeObj = list.get(0);
|
| | | // 交换排序序号
|
| | | resultObj.setWeight(changeObj.getWeight());
|
| | | |
| | |
|
| | | changeObj.setWeight(resultWeight);
|
| | | |
| | |
|
| | | changeObj.setUpdatetime(new Date());
|
| | | goodsSubClassService.updateByPrimaryKey(changeObj);
|
| | | goodsSubClassService.updateByPrimaryKeySelective(changeObj);
|
| | | }
|
| | |
|
| | | resultObj.setUpdatetime(new Date());
|
| | | goodsSubClassService.updateByPrimaryKey(resultObj);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
|
| | |
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | |
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 修改排序
|
| | | * |
| | | * @param callback
|
| | | * @param goodsClass
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "saveState")
|
| | | public void saveState(String callback, Long id, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | |
| | | if (id == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("不存在该类别"));
|
| | | return;
|
| | | }
|
| | | |
| | | GoodsSubClass resultObj = goodsSubClassService.selectByPrimaryKey(id);
|
| | | if (resultObj == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("不存在该类别"));
|
| | | return;
|
| | | } |
| | | |
| | | Integer state = resultObj.getState();
|
| | | if (state.equals(1) || state == 1) {
|
| | | state = 0;
|
| | | } else {
|
| | | state = 1;
|
| | | }
|
| | | |
| | | resultObj.setState(state);
|
| | | resultObj.setUpdatetime(new Date());
|
| | | goodsSubClassService.updateByPrimaryKeySelective(resultObj);
|
| | | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(state));
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|