Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.dlshouwen.jspc.zjpc.controller; import com.dlshouwen.core.base.config.CONFIG; import com.dlshouwen.core.base.extra.grid.model.Pager; import com.dlshouwen.core.base.extra.grid.utils.PagerPropertyUtils; import com.dlshouwen.core.base.model.AjaxResponse; import com.dlshouwen.core.base.model.OperationType; import com.dlshouwen.core.base.model.SessionUser; import com.dlshouwen.core.base.utils.CodeTableUtils; import com.dlshouwen.core.base.utils.DateUtils; import com.dlshouwen.core.base.utils.GUID; import com.dlshouwen.core.base.utils.LogUtils; import com.dlshouwen.jspc.zjpc.dao.ExpreviewDao; import com.dlshouwen.jspc.zjpc.model.Expreview; import com.dlshouwen.core.system.dao.UserDao; import com.dlshouwen.core.system.model.User; import com.dlshouwen.core.system.model.UserVO; import com.dlshouwen.jspc.zwpc.dao.EvalItemDao; import com.dlshouwen.jspc.zwpc.model.EvalItem; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; /** * * * @author xlli */ @Controller @RequestMapping("/jspc/zjpc/zjpc") public class ExpreviewController { /** * */ private String basePath = "jspc/zjpc/"; /** * ?? */ private ExpreviewDao dao; /** * ?? */ private UserDao userDao; /** * ?? */ private EvalItemDao evalItemDao; /** * ?? * * @param dao */ @Resource(name = "expreviewDao") public void setDao(ExpreviewDao dao) { this.dao = dao; } /** * ?? * * @param dao ?? */ @Resource(name = "userDao") public void setUserDao(UserDao userDao) { this.userDao = userDao; } /** * ?? * * @param dao ?? */ @Resource(name = "evalItemDao") public void setDao(EvalItemDao evalItemDao) { this.evalItemDao = evalItemDao; } /** * ? * * @param request * @return basePath + "expreviewList" * @throws Exception */ @RequestMapping(value = "", method = RequestMethod.GET) public String goExpreviewPage(HttpServletRequest request) throws Exception { // ? LogUtils.updateOperationLog(request, OperationType.VISIT, "?"); return basePath + "expreviewList"; } @RequestMapping(value = "/admin", method = RequestMethod.GET) public String goExpreviewPageForAdmin(HttpServletRequest request) throws Exception { // ? LogUtils.updateOperationLog(request, OperationType.VISIT, "(?)?"); return basePath + "expreviewList_admin"; } /** * ?? * * @param gridPager ? * @param request * @param response ? * @throws Exception */ @RequestMapping(value = "/list", method = RequestMethod.POST) @ResponseBody public void getExpreviewList(String gridPager, HttpServletRequest request, HttpServletResponse response) throws Exception { // Pager Pager pager = PagerPropertyUtils.copy(JSONObject.fromObject(gridPager)); // ?? dao.getExpreviewList(pager, request, response); // ? LogUtils.updateOperationLog(request, OperationType.SEARCH, "????"); } /** * ?? * * @param gridPager ? * @param request * @param response ? * @throws Exception */ @RequestMapping(value = "/admin/list", method = RequestMethod.POST) @ResponseBody public void getExpreviewListForAdmin(String gridPager, HttpServletRequest request, HttpServletResponse response) throws Exception { // Pager Pager pager = PagerPropertyUtils.copy(JSONObject.fromObject(gridPager)); // ?? dao.getExpreviewListForAdmin(pager, request, response); // ? LogUtils.updateOperationLog(request, OperationType.SEARCH, "????"); } /** * ? * * @param id ? * @param model ?? * @param request * @return basePath + "editExpreview" * @throws Exception */ @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET) public String editExpreview(@PathVariable String id, Model model, HttpServletRequest request) throws Exception { // ? Expreview expreview = dao.getExpreviewById(id); //? User user = userDao.getUserById(expreview.getUser_id()); //? UserVO UVO = new UserVO(user, expreview); //? request.setAttribute("editalble", "editalble"); model.addAttribute("UVO", UVO); // ? LogUtils.updateOperationLog(request, OperationType.VISIT, "?"); // ? return basePath + "reviewDetail"; } @RequestMapping(value = "/{id}/adminEdit", method = RequestMethod.GET) public String editExpreviewForAdmin(@PathVariable String id, Model model, HttpServletRequest request) throws Exception { // ? Expreview expreview = dao.getExpreviewById(id); //? User user = userDao.getUserById(expreview.getUser_id()); //? UserVO UVO = new UserVO(user, expreview); //? request.setAttribute("editalble", "editalble"); model.addAttribute("UVO", UVO); // ? LogUtils.updateOperationLog(request, OperationType.VISIT, "?"); // ? return basePath + "reviewDetail_admin"; } /** * ?? * * @param expId * @param request * @return AJAX? * @throws Exception */ @RequestMapping(value = "/{expId}/getAllItems", method = RequestMethod.POST) @ResponseBody @Transactional public AjaxResponse getAllItems(@PathVariable String expId, HttpServletRequest request) throws Exception { // AJAX? AjaxResponse aresp = new AjaxResponse(); // ?? List<EvalItem> evalItems = new ArrayList<EvalItem>(); evalItems = evalItemDao.getAllByExpId(expId); // List ET[] = new ArrayList[8]; for (int i = 0; i < ET.length; i++) { ET[i] = new ArrayList<EvalItem>(); } for (EvalItem item : evalItems) { if (item.getType().equals("JSYR")) {// ET[0].add(item); } else if (item.getType().equals("KCJX")) {// ET[1].add(item); } else if (item.getType().equals("JYJXYJ")) {// ET[2].add(item); } else if (item.getType().equals("YXL")) {//? ET[3].add(item); } else if (item.getType().equals("JYJXJL")) {//?? ET[4].add(item); } else if (item.getType().equals("JXJYJL")) {//? ET[5].add(item); } else if (item.getType().equals("ZYJSZC")) {//? ET[6].add(item); } else if (item.getType().equals("QT")) {// ET[7].add(item); } } Map map = new HashMap(); map.put("JSYR", getItemForHtml(ET[0], request.getServletContext())); map.put("KCJX", getItemForHtml(ET[1], request.getServletContext())); map.put("JYJXYJ", getItemForHtml(ET[2], request.getServletContext())); map.put("YXL", getItemForHtml(ET[3], request.getServletContext())); map.put("JYJXJL", getItemForHtml(ET[4], request.getServletContext())); map.put("JXJYJL", getItemForHtml(ET[5], request.getServletContext())); map.put("ZYJSZC", getItemForHtml(ET[6], request.getServletContext())); map.put("QT", getItemForHtml(ET[7], request.getServletContext())); aresp.setExtParam(map); aresp.setSuccess(true); aresp.setSuccessMessage("?"); return aresp; } /** * ? * * @param expreview * @param bindingResult * @param request * @return ajax? * @throws Exception */ @RequestMapping(value = "/ajaxReview", method = RequestMethod.POST) @ResponseBody public AjaxResponse ajaxExpertReview(@Valid Expreview expreview, BindingResult bindingResult, HttpServletRequest request) throws Exception { String id = request.getParameter("id"); String status = request.getParameter("status"); String notes = request.getParameter("notes"); // AJAX? AjaxResponse ajaxResponse = new AjaxResponse(); // ?? if (bindingResult.hasErrors()) { ajaxResponse.bindingResultHandler(bindingResult); // ? LogUtils.updateOperationLog(request, OperationType.UPDATE, "???" + AjaxResponse.getBindingResultMessage(bindingResult) + ""); return ajaxResponse; } // ?? Date nowDate = new Date(); //?? SessionUser sessionUser = (SessionUser) request.getSession().getAttribute(CONFIG.SESSION_USER); String review_name = sessionUser.getUser_name(); // vo expreview.setReview_date(nowDate); expreview.setId(id); expreview.setStatus(status); expreview.setReview_name(review_name); expreview.setNote(notes); // dao.updateExpreview(expreview); // if ("1".equals(status)) { expreview = dao.getExpreviewById(id); User user = new User(); user.setUser_id(expreview.getUser_id()); user.setQualified(expreview.getQualified()); userDao.updateUser(user); } // ???? ajaxResponse.setSuccess(true); ajaxResponse.setSuccessMessage("??"); //URL?? Map map = new HashMap(); map.put("URL", basePath + "zjpc"); ajaxResponse.setExtParam(map); // ? LogUtils.updateOperationLog(request, OperationType.UPDATE, "?" + expreview.getId()); return ajaxResponse; } /** * ?? * * @param expreview * @param bindingResult * @param request * @return ajax? * @throws Exception */ @RequestMapping(value = "/ajaxReviewAdmin", method = RequestMethod.POST) @ResponseBody public AjaxResponse ajaxExpertReviewForAdmin(@Valid Expreview expreview, BindingResult bindingResult, HttpServletRequest request) throws Exception { String id = request.getParameter("id"); String status = request.getParameter("status"); String notes = request.getParameter("notes"); // AJAX? AjaxResponse ajaxResponse = new AjaxResponse(); // ?? if (bindingResult.hasErrors()) { ajaxResponse.bindingResultHandler(bindingResult); // ? LogUtils.updateOperationLog(request, OperationType.UPDATE, "???" + AjaxResponse.getBindingResultMessage(bindingResult) + ""); return ajaxResponse; } // ?? Date nowDate = new Date(); //?? SessionUser sessionUser = (SessionUser) request.getSession().getAttribute(CONFIG.SESSION_USER); String review_name = sessionUser.getUser_name(); // vo expreview.setReview_date(nowDate); expreview.setId(id); expreview.setStatus(status); expreview.setReview_name(review_name); expreview.setNote(notes); // dao.updateExpreview(expreview); // if ("1".equals(status)) { expreview = dao.getExpreviewById(id); User user = new User(); user.setUser_id(expreview.getUser_id()); user.setQualified(expreview.getQualified()); userDao.updateUser(user); } // ???? ajaxResponse.setSuccess(true); ajaxResponse.setSuccessMessage("??"); //URL?? Map map = new HashMap(); map.put("URL", basePath + "zjpc/admin"); ajaxResponse.setExtParam(map); // ? LogUtils.updateOperationLog(request, OperationType.UPDATE, "?" + expreview.getId()); return ajaxResponse; } /** * * * @param request * @return ? * @throws Exception */ @RequestMapping(value = "note", method = RequestMethod.GET) public String goNotePage(HttpServletRequest request) throws Exception { // ? LogUtils.updateOperationLog(request, OperationType.VISIT, "???"); return basePath + "note"; } /** * * * @param ids ? * @param request * @return ajax? * @throws Exception */ @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody public AjaxResponse deleteExpreview(String ids, HttpServletRequest request) throws Exception { // dao.deleteExpreview(ids); // ? AjaxResponse ajaxResponse = new AjaxResponse(); ajaxResponse.setSuccess(true); ajaxResponse.setSuccessMessage("??"); // ? LogUtils.updateOperationLog(request, OperationType.DELETE, "?" + ids); return ajaxResponse; } /** * * * @param expreview * @param bindingResult ? * @param request * @return ajax? * @throws Exception */ @RequestMapping(value = "/ajaxAdd", method = RequestMethod.POST) @ResponseBody public AjaxResponse ajaxAddExpreview(@Valid Expreview expreview, BindingResult bindingResult, HttpServletRequest request) throws Exception { // AJAX? AjaxResponse ajaxResponse = new AjaxResponse(); // ?? if (bindingResult.hasErrors()) { ajaxResponse.bindingResultHandler(bindingResult); // ? LogUtils.updateOperationLog(request, OperationType.INSERT, "???" + AjaxResponse.getBindingResultMessage(bindingResult) + ""); return ajaxResponse; } // ???? SessionUser sessionUser = (SessionUser) request.getSession().getAttribute(CONFIG.SESSION_USER); String userId = sessionUser.getUser_id(); String userName = sessionUser.getUser_id(); Date nowDate = new Date(); // ? expreview.setId(new GUID().toString()); expreview.setCreate_date(nowDate); expreview.setUser_id(userId); expreview.setUser_name(userName); expreview.setStatus("0"); // dao.insertExpreview(expreview); // ???? ajaxResponse.setSuccess(true); ajaxResponse.setSuccessMessage("??"); // ? LogUtils.updateOperationLog(request, OperationType.INSERT, "?" + expreview.getId()); return ajaxResponse; } private String getItemForHtml(List<EvalItem> items, ServletContext sc) { String result = "", preHtml, sufHtml; sufHtml = "</tr>" + "</table>" + "</div>" + "</li>"; if (!items.equals(null) && items.size() > 0) { for (int i = 0; i < items.size(); i++) { preHtml = "<li class='item-table-list-li'>" + "<div class='item-table-list-box'>" // + "<i class='fa fa-edit' style='display:none;' onclick=\"editItem('"+items.get(i).getEvalItem_id()+"','"+items.get(i).getType()+"')\"></i>" // + "<i class='fa fa-times' style='display:none;' id='"+items.get(i).getEvalItem_id()+"' onclick=\"deleteItem('"+items.get(i).getEvalItem_id()+"')\"></i>" + "<table class='table table-responsive item-table-list' width='100%' border='0' cellspacing='0' cellpadding='0'>" + "<tr>"; String bDate = DateUtils.getYearMonth(items.get(i).getBeginDate()); String eDate = DateUtils.getYearMonth(items.get(i).getEndDate()); String level = CodeTableUtils.getValue(sc, "ryjb", items.get(i).getLevel()); String grade = CodeTableUtils.getValue(sc, "hjdj", items.get(i).getGrade()); level = StringUtils.isEmpty(level) ? "" : level; grade = StringUtils.isEmpty(grade) ? "" : grade; result += preHtml; result += "<td class='first_td'>" + bDate + "-" + eDate + "</td>"; result += "<td>" + items.get(i).getName() + "</td>"; result += "<td>" + level + grade + "</td>"; result += "<td><a href='" + sc.getContextPath() + "/jspc/zwpc/zwpc/downloadFile?itemId=" + items.get(i).getEvalItem_id() + "' class='table-tc-fj-open' ></a></td>"; result += sufHtml; } } else { result = "<div class='div_zanwu'></div>"; } return result; } }