| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | |
| | | 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;
|
| | |
| | | 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")
|
| | |
| | | * @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();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
| | | * @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();
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | * @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();
|
| | |
| | | }
|
| | |
|
| | | } catch (LabelException e) {
|
| | | // TODO Auto-generated catch block
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("删除失败")));
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | * @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("上传失败")));
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | * @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);
|
| | |
|
| | |
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadFalseResult("操作失败"));
|
| | | }
|
| | |
| | | * @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);
|