/** 新增系数; */ public void save() { JSONObject obj = new JSONObject(); obj.put("success", true); try { BarProportion barProportion = (BarProportion) EntityReflect.createObjectFromRequest( ServletActionContext.getRequest(), BarProportion.class); List<BarProportion> proportionList = barProportionService.selectProportionByDate(barProportion); UserInfoEty user = this.getLoginUser(); if (barProportion.getId() == null) { if (proportionList.isEmpty()) { barProportion.setStatus(START_STATUS); barProportion.setCreateTime(new Date()); barProportion.setCreator(user.getUsername()); barProportionService.insert(barProportion); obj.put("result", "success"); } else { obj.put("result", "use"); // use 表示要插入或更改的日期已经存在. } } else { if (proportionList.isEmpty()) { barProportionService.updateById(barProportion); obj.put("result", "success"); } else { obj.put("result", "use"); } } } catch (Exception e) { logger.error("", e); } AjaxOut.responseText(ServletActionContext.getResponse(), obj.toString()); }
/** 获得系数列表; */ @SuppressWarnings("unchecked") public void showAll() { try { String barId = ServletActionContext.getRequest().getParameter("barId"); ExtLimit limit = (ExtLimit) EntityReflect.createObjectFromRequest( ServletActionContext.getRequest(), ExtLimit.class); BarProportion barProportion = (BarProportion) EntityReflect.createObjectFromRequest( ServletActionContext.getRequest(), BarProportion.class); barProportion.setExtLimit(limit); barProportion.setBarId(TypeConverterUtil.parseInt(barId)); int count = barProportionService.selectLimitCount(barProportion); List<Department> barProportionList = barProportionService.selectByLimit(barProportion); AjaxOut.responseJSonGrid( ServletActionContext.getResponse(), barProportionList, count, new SimpleDateFormat("yyyy-MM-dd")); } catch (Exception e) { logger.error("", e); } }
/** * 将JSon格式的grid输出到页面<br> * * @param response * @param jsonArray 现成的json数组 */ @SuppressWarnings("unchecked") public static void responseJSonGrid(HttpServletResponse response, JSONArray jsonArray) { try { JSONObject dataObj = new JSONObject(); dataObj.put("invdata", jsonArray); AjaxOut.responseText(response, dataObj.toString()); } catch (Exception e) { e.printStackTrace(); } }
public void searchAllChannel() { List<Channel> channelList = channelDao.selectByEntity(null); StringBuffer sb = new StringBuffer(); sb.append("["); for (int i = 0; i < channelList.size(); i++) { Channel channel = channelList.get(i); sb.append("['" + channel.getSourceId() + "','" + channel.getName() + "']"); if (i < channelList.size() - 1) sb.append(","); } sb.append("]"); AjaxOut.responseText(ServletActionContext.getResponse(), sb.toString()); }
/** 获得对应的部门信息; */ public void getBarProportionDetail() { JSONObject retObj = new JSONObject(); retObj.put("success", true); try { String id = ServletActionContext.getRequest().getParameter("barProportionId"); BarProportion barProportion = (BarProportion) barProportionService.selectById(TypeConverterUtil.parseInt(id)); retObj.put("data", barProportion); } catch (Exception e) { retObj.put("result", "error"); retObj.put("info", e.getMessage()); logger.error("", e); } AjaxOut.responseText(ServletActionContext.getResponse(), retObj.toString()); }
/** 删除系数; */ public void delete() { JSONObject retObj = new JSONObject(); retObj.put("success", true); try { String ids = ServletActionContext.getRequest().getParameter("barProportionList"); String[] idList = StringUtils.split(ids, ","); for (int i = 0; i < idList.length; i++) { barProportionService.deleteById(TypeConverterUtil.parseInt(idList[i])); } retObj.put("result", "success"); } catch (Exception e) { retObj.put("result", "error"); logger.error("", e); } AjaxOut.responseText(ServletActionContext.getResponse(), retObj.toString()); }
public static void responseJSonGrid( HttpServletResponse response, List displayDataList, int totalCount) { try { JSONObject dataObj = new JSONObject(); dataObj.put("total", totalCount); JSONArray dataArray = new JSONArray(); for (int i = 0; i < displayDataList.size(); i++) { dataArray.add(displayDataList.get(i)); } dataObj.put("invdata", dataArray); AjaxOut.responseText(response, dataObj.toString()); } catch (Exception e) { e.printStackTrace(); } }
/** * 将JSon格式的grid输出到页面<br> * 如果在grid中有特殊要求,如链接等,则需要自己重新实现该方法,不可先遍历dataList再调用该方法 * * @param response * @param displayDataList 显示的列表 * @param recordsCount Grid的总记录数 */ @SuppressWarnings("unchecked") public static void responseJSonGrid( HttpServletResponse response, List displayDataList, int totalCount, SimpleDateFormat df) { try { JSONObject dataObj = new JSONObject(); dataObj.put("total", totalCount); JSONArray dataArray = new JSONArray(); for (int i = 0; i < displayDataList.size(); i++) { JSONObject obj = JSONObject.fromObject(EntityReflect.getObjectJSonString(displayDataList.get(i), df)); dataArray.add(obj); } dataObj.put("invdata", dataArray); AjaxOut.responseText(response, dataObj.toString()); } catch (Exception e) { e.printStackTrace(); } }
public void search() { try { JSONObject retObj = new JSONObject(); retObj.put("action", true); StatisticsAAContextForm sf = (StatisticsAAContextForm) EntityReflect.createObjectFromRequest( ServletActionContext.getRequest(), StatisticsAAContextForm.class); List<StatisticsAAContext> dataList = statisticsAAContextDao.statistSearch(sf); retObj.put("size", dataList.size()); JSONArray columModleArray = new JSONArray(); JSONArray topGroup = new JSONArray(); JSONArray secondGroup = new JSONArray(); JSONObject jobj = new JSONObject(); jobj.put("header", ""); jobj.put("colspan", 2); jobj.put("align", "center"); topGroup.add(jobj); secondGroup.add(jobj); JSONArray dayColumArr = createDayColum(dataList, topGroup, secondGroup); columModleArray.addAll(GridColumModleInfo); columModleArray.addAll(dayColumArr); retObj.put("columns", columModleArray); retObj.put("topGroup", topGroup); retObj.put("secondGroup", secondGroup); retObj.put("data", getData(dataList)); retObj.put("fields", getFieldsNamesArray(dataList)); AjaxOut.responseText(ServletActionContext.getResponse(), retObj.toString()); } catch (Exception e) { e.printStackTrace(); } }