From 98b1a0affd69bbe63223c21fdd2c404e8bedfccb Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 20 五月 2020 17:25:08 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into 2.1.2 --- fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java | 210 ++++++++++++++++++++------------------------------- 1 files changed, 83 insertions(+), 127 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java index df38509..fdaeb37 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java @@ -10,7 +10,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; @@ -20,13 +19,14 @@ 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.lable.Label; import com.yeshi.fanli.entity.common.AdminUser; -import com.yeshi.fanli.exception.LabelException; +import com.yeshi.fanli.exception.goods.quality.LabelException; import com.yeshi.fanli.service.AdminUserService; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.lable.LabelGoodsService; @@ -35,8 +35,6 @@ import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TimeUtil; -import com.yeshi.fanli.util.annotation.RequestNoLogin; -import org.yeshi.utils.JsonUtil; @Controller @RequestMapping("admin/new/api/v1/lable") @@ -61,59 +59,44 @@ * @param request * @param out */ - @RequestNoLogin() @RequestMapping(value = "saveAdd") - public void saveAdd(String callback,Long uid, Label label, - HttpServletRequest request, PrintWriter out, HttpServletResponse response) { - response.setHeader("Access-Control-Allow-Origin", "*"); - response.setHeader("Access-Control-Allow-Methods", "*"); - - // // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 - AdminUser admin = adminUserService.selectByPrimaryKey(uid); - if (admin == null) { - out.print(JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄嗐��")); - } else { - - try { - String title = label.getTitle(); - if (StringUtil.isNullOrEmpty(title)) { - out.print( JsonUtil.loadFalseResult("鏍囩鍚嶇О涓虹┖")); - } else { - - List<Label> labels = labelService.selectByTitle(title.trim()); - - if (labels == null || labels.size() == 0) { - - label.setTitle(label.getTitle().trim()); - - if(request instanceof MultipartHttpServletRequest){ - - List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file"); - - if (files != null && files.size() > 0) { - labelService.insertSingle(label, admin, files.get(0)); - } else { - labelService.insertSingle(label, admin, null); - } - - } else { - labelService.insertSingle(label, admin, null); - } - - out.print( JsonUtil.loadTrueResult("娣诲姞鎴愬姛")); - - } else { - out.print( JsonUtil.loadTrueResult("宸插瓨鍦ㄦ鏍囩")); - } - } - - } catch (Exception e) { - // TODO Auto-generated catch block - out.print(JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); - e.printStackTrace(); + public void saveAdd(String callback, Long uid, Label label, HttpServletRequest request, PrintWriter out) { + try { + String title = label.getTitle(); + if (StringUtil.isNullOrEmpty(title)) { + out.print(JsonUtil.loadFalseResult("鏍囩鍚嶇О涓虹┖")); + return; } - } + List<Label> labels = labelService.selectByTitle(title.trim()); + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + if (labels == null || labels.size() == 0) { + + label.setTitle(label.getTitle().trim()); + + if (request instanceof MultipartHttpServletRequest) { + + List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file"); + + if (files != null && files.size() > 0) { + labelService.insertSingle(label, admin, files.get(0)); + } else { + labelService.insertSingle(label, admin, null); + } + + } else { + labelService.insertSingle(label, admin, null); + } + + out.print(JsonUtil.loadTrueResult("娣诲姞鎴愬姛")); + + } else { + out.print(JsonUtil.loadTrueResult("宸插瓨鍦ㄦ鏍囩")); + } + } catch (Exception e) { + out.print(JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); + e.printStackTrace(); + } } @@ -126,44 +109,36 @@ * @param out */ @RequestMapping(value = "addBatch") - public void addBatch(String callback, String param, - HttpServletRequest request, PrintWriter out) { - // // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 - AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + public void addBatch(String callback, String param, HttpServletRequest request, PrintWriter out) { - if (admin == null) { - out.print(JsonUtil.loadJSONP(callback,JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄嗐��"))); - } else { - - try { - Gson gson = new Gson(); - List<Label> labs = gson.fromJson(param, new TypeToken<ArrayList<Label>>() {}.getType()); + try { + Gson gson = new Gson(); + List<Label> labs = gson.fromJson(param, new TypeToken<ArrayList<Label>>() {}.getType()); + + List<Label> newList = new ArrayList<Label>(); + if (labs == null || labs.size() == 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈绱㈠埌鏁版嵁"))); + return; + } - List<Label> newList = new ArrayList<Label>(); - if (labs == null || labs.size() == 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈绱㈠埌鏁版嵁"))); - } else { - for (Label label: labs) { - String title = label.getTitle(); - if (!StringUtil.isNullOrEmpty(title)) { - - List<Label> labels = labelService.selectByTitle(title.trim()); - if (labels == null || labels.size() == 0) { - newList.add(label); - } - } + for (Label label: labs) { + String title = label.getTitle(); + if (!StringUtil.isNullOrEmpty(title)) { + + List<Label> labels = labelService.selectByTitle(title.trim()); + if (labels == null || labels.size() == 0) { + newList.add(label); } } - - - labelService.insertList(newList, admin); - - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("娣诲姞鎴愬姛"))); - } catch (LabelException e) { - // TODO Auto-generated catch block - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("娣诲姞寮傚父"))); - e.printStackTrace(); } + + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + labelService.insertList(newList, admin); + + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("娣诲姞鎴愬姛"))); + } catch (LabelException e) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("娣诲姞寮傚父"))); + e.printStackTrace(); } } @@ -179,7 +154,7 @@ * @param out */ @RequestMapping(value = "saveModify") - public void saveModify(String callback, Label label, HttpServletRequest request,PrintWriter out) { + public void saveModify(String callback, Label label, PrintWriter out) { try { Long id = label.getId(); @@ -246,7 +221,6 @@ } } catch (LabelException e) { - // TODO Auto-generated catch block out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鍒犻櫎澶辫触"))); e.printStackTrace(); } @@ -262,34 +236,25 @@ * @param out * @param response */ - @RequestNoLogin() @RequestMapping(value = "uploadFile") - public void uploadFile(@RequestParam("file") CommonsMultipartFile file, Long uid, - HttpServletRequest request, PrintWriter out,HttpServletResponse response) { - // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 - response.setHeader("Access-Control-Allow-Origin", "*"); - response.setHeader("Access-Control-Allow-Methods", "*"); - - AdminUser admin = adminUserService.selectByPrimaryKey(uid); - - if (admin == null) { - out.print( JsonUtil.loadFalseResult("褰撳墠璐︽埛澶辨晥,璇烽噸鏂扮櫥闄嗐��")); - } else { - if (file == null) { - out.print(JsonUtil.loadFalseResult("鏂囦欢涓嶈兘涓虹┖!")); - } else { - - try { - labelService.analysisExcel(file.getInputStream(), admin); - out.print((JsonUtil.loadTrueResult("涓婁紶鎴愬姛"))); - //response.getWriter().print(JsonUtil.loadTrueResult("涓婁紶鎴愬姛")); - } catch (Exception e) { - e.printStackTrace(); - out.print((JsonUtil.loadFalseResult("涓婁紶澶辫触"))); - } - - } - + public void uploadFile(@RequestParam("file") CommonsMultipartFile file, HttpServletRequest request, + PrintWriter out) { + + if (file == null) { + out.print(JsonUtil.loadFalseResult("鏂囦欢涓嶈兘涓虹┖!")); + return; + } + + try { + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + labelService.analysisExcel(file.getInputStream(), admin); + + out.print((JsonUtil.loadTrueResult("涓婁紶鎴愬姛"))); + // response.getWriter().print(JsonUtil.loadTrueResult("涓婁紶鎴愬姛")); + + } catch (Exception e) { + e.printStackTrace(); + out.print((JsonUtil.loadFalseResult("涓婁紶澶辫触"))); } } @@ -303,16 +268,9 @@ * @param out * @param response */ - @RequestNoLogin() @RequestMapping(value = "uploadImg") - public void uploadImg(Long id, @RequestParam("file") CommonsMultipartFile file, - HttpServletRequest request, PrintWriter out, HttpServletResponse response) { + public void uploadImg(Long id, @RequestParam("file") CommonsMultipartFile file, PrintWriter out) { - response.setHeader("Access-Control-Allow-Origin", "*"); - response.setHeader("Access-Control-Allow-Methods", "*"); - - // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 - try { Label label = labelService.selectByPrimaryKey(id); @@ -336,7 +294,6 @@ } } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); out.print(JsonUtil.loadFalseResult("鎿嶄綔澶辫触")); } @@ -352,8 +309,7 @@ * @param response */ @RequestMapping(value = "deleteImg") - public void deleteImg(String callback, Long id, HttpServletRequest request, PrintWriter out, - HttpServletResponse response) { + public void deleteImg(String callback, Long id, PrintWriter out) { try { Label label = labelService.selectByPrimaryKey(id); -- Gitblit v1.8.0