yujian
2019-01-16 e5ade1fdbd87e085f5be5460c6e3f0adb47704e6
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,6 +19,7 @@
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;
@@ -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,27 +59,18 @@
    * @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 {
   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("标签名称为空"));
            } else {
            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());
@@ -105,15 +94,10 @@
               } else {
                  out.print( JsonUtil.loadTrueResult("已存在此标签"));
               }
            }
         } catch (Exception e) {
            // TODO Auto-generated catch block
            out.print(JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
         }
      }
   }
   
   
@@ -126,14 +110,7 @@
    * @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);
      if (admin == null) {
         out.print(JsonUtil.loadJSONP(callback,JsonUtil.loadFalseResult("当前账户已失效,请重新登陆。")));
      } else {
   public void addBatch(String callback, String param,   HttpServletRequest request, PrintWriter out) {
         try {
            Gson gson = new Gson();
@@ -142,7 +119,9 @@
            List<Label> newList = new ArrayList<Label>();
            if (labs == null || labs.size() == 0) {
               out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("未检索到数据")));
            } else {
            return;
         }
               for (Label label: labs) {
                  String title = label.getTitle();
                  if (!StringUtil.isNullOrEmpty(title)) {
@@ -153,17 +132,14 @@
                     }
                  }
               }
            }
            
         AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
            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();
         }
      }
   }
@@ -179,7 +155,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 +222,6 @@
         }
         
      } catch (LabelException e) {
         // TODO Auto-generated catch block
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("删除失败")));
         e.printStackTrace();
      }
@@ -262,34 +237,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", "*");
   public void uploadFile(@RequestParam("file") CommonsMultipartFile file,   HttpServletRequest request,
         PrintWriter out) {
      
      AdminUser admin = adminUserService.selectByPrimaryKey(uid);
      if (admin == null) {
         out.print( JsonUtil.loadFalseResult("当前账户失效,请重新登陆。"));
      } else {
         if (file == null) {
            out.print(JsonUtil.loadFalseResult("文件不能为空!"));
         } else {
         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,15 +269,8 @@
    * @param out
    * @param response
    */
   @RequestNoLogin()
   @RequestMapping(value = "uploadImg")
   public void uploadImg(Long id, @RequestParam("file") CommonsMultipartFile file,
         HttpServletRequest request, PrintWriter out, HttpServletResponse response) {
      response.setHeader("Access-Control-Allow-Origin", "*");
      response.setHeader("Access-Control-Allow-Methods", "*");
      // 获取当前操作用户
   public void uploadImg(Long id, @RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
   
      try {
         Label label = labelService.selectByPrimaryKey(id);
@@ -336,7 +295,6 @@
         }
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         out.print(JsonUtil.loadFalseResult("操作失败"));
      }
@@ -352,8 +310,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);