@WebMethod public ModelAndView save(User user, Integer groupId, String roleIds) { ModelAndView mv = new ModelAndView(); if (StringUtils.isEmpty(user.account)) { throw new GException(PlatformExceptionType.BusinessException, "用户账号不能为空"); } if (StringUtils.isEmpty(user.name)) { throw new GException(PlatformExceptionType.BusinessException, "用户姓名不能为空"); } if (StringUtils.isEmpty(user.pwd)) { throw new GException(PlatformExceptionType.BusinessException, "请先设置密码"); } user.isSuperAdmin = 0; user.addtime = new Date(); user.pwd = SecurityHelper.Md5(user.pwd); // TODO dao.saveOrUpdate(user); if (groupId != null) { UserGroup ug = new UserGroup(); ug.gid = groupId; ug.uid = user.id; dao.saveOrUpdate(ug); } if (roleIds != null && roleIds.length() != 0) { String[] Ids = roleIds.split(","); for (int i = 0; i < Ids.length; i++) { UserRole rg = new UserRole(); rg.roleId = Integer.valueOf(Ids[i]); rg.uid = user.id; dao.saveOrUpdate(rg); } } return mv; }
private JSONArray getChildrenOfGroup(Integer groupId, String _site) { List<Group> groups = dao.listByParams(Group.class, "from Group where parentId = ? and _site=?", groupId, _site); JSONArray arr = new JSONArray(); for (Group g : groups) { JSONObject jobj = new JSONObject(); jobj.put("name", g.name); jobj.put("id", g.id); jobj.put("type", "group"); jobj.put("key", "group_" + g.id); jobj.put("isParent", true); JSONArray children = getChildrenOfGroup(g.id, _site); if (!children.isEmpty()) { jobj.put("children", children); } arr.add(jobj); } List<Map> users = dao.listAsMap( "select u.name as name , u.id as id from User u , UserGroup ug where u.id = ug.uid and ug.gid=? and u._site=?", groupId, _site); for (Map u : users) { JSONObject jobj = new JSONObject(); jobj.put("name", u.get("name")); jobj.put("id", u.get("id")); jobj.put("key", "user_" + u.get("id")); jobj.put("type", "user"); arr.add(jobj); } return arr; }
// 产品搜索 @WebMethod public ModelAndView searchGoods(Page<Map> page, String name, Integer uid) { ModelAndView mv = new ModelAndView(); StringBuilder sql = new StringBuilder( "select goods.id as id , goods.title as title , img.path as img , goods.spec as spec , goods.vender as vender , goods.price as price from Goods goods , Image img where goods.imgId=img.id "); List<Object> params = new ArrayList<Object>(); if (StringUtils.isNotEmpty(name)) { System.out.println(name); sql.append(" and title like ?"); params.add("%" + name + "%"); } page.order = "desc"; page.orderBy = "addtime"; page.setPageSize(10); page = dao.findPage(page, sql.toString(), true, params.toArray()); if (StringUtils.isNotEmpty(name)) { SearchHistory search = new SearchHistory(); search.uid = uid; search.text = name; dao.saveOrUpdate(search); } mv.data.put("page", JSONHelper.toJSON(page)); mv.data.put( "imgUrl", "http://" + ConfigCache.get("image_host", "localhost") + "/article_image_path"); mv.data.put( "goodsDetailUrl", "https://" + ConfigCache.get("app_host", "localhost") + "/goods/view.jsp"); return mv; }
@WebMethod public ModelAndView update(User user, String roleIds) { ModelAndView mv = new ModelAndView(); if (StringUtils.isEmpty(user.name)) { throw new GException(PlatformExceptionType.BusinessException, "用户名不能为空"); } User po = dao.get(User.class, user.id); po.account = user.account; po.name = user.name; // String pwd = user.pwd.replace("*", ""); if (StringUtils.isNotEmpty(user.pwd)) { po.pwd = SecurityHelper.Md5(user.pwd); } po.tel = user.tel; dao.saveOrUpdate(po); ThreadSession.getHttpSession().setAttribute(MakesiteConstant.Session_Attr_User, po); if (roleIds != null && roleIds.length() != 0) { String[] Ids = roleIds.split(","); dao.execute("delete from UserRole where uid=?", user.id); for (int i = 0; i < Ids.length; i++) { if (StringUtils.isEmpty(Ids[i])) { continue; } UserRole rg = new UserRole(); rg.roleId = Integer.valueOf(Ids[i]); rg.uid = user.id; dao.saveOrUpdate(rg); } } else { } return mv; }
@WebMethod public ModelAndView login(User user, String _site) { ModelAndView mv = new ModelAndView(); String pwd = SecurityHelper.Md5(user.pwd); User po = dao.getUniqueByParams( User.class, new String[] {"account", "pwd", "_site"}, new Object[] {user.account, pwd, _site}); if (po == null) { throw new GException(PlatformExceptionType.BusinessException, "用户名或密码不正确。"); } po.lasttime = new Date(); dao.saveOrUpdate(po); ThreadSession.getHttpSession().setAttribute(MakesiteConstant.Session_Attr_User, po); List<Map> result = dao.listAsMap( "select ra.authId as authId from UserRole ur ,RoleAuth ra where ur.roleId=ra.roleId and ur.uid=?", po.id); StringBuilder authList = new StringBuilder(""); for (Map map : result) { authList.append(map.get("authId").toString()); } ThreadSession.getHttpSession() .setAttribute(MakesiteConstant.Session_Auth_List, authList.toString()); String serverName = DataHelper.getServerName(ThreadSession.HttpServletRequest.get()); if (!onlineUserCountMap.containsKey(serverName)) { onlineUserCountMap.put(serverName, 1); } else { onlineUserCountMap.put(serverName, onlineUserCountMap.get(serverName) + 1); } String text; try { text = FileUtils.readFileToString( new File( ThreadSession.HttpServletRequest.get().getServletContext().getRealPath("/") + File.separator + "auths.json"), "utf8"); JSONArray jarr = JSONArray.fromObject(text); List<String> urlList = new ArrayList<String>(); for (int i = 0; i < jarr.size(); i++) { JSONObject jobj = jarr.getJSONObject(i); if (authList.toString().contains(jobj.getString("id"))) { continue; } String urls = jobj.getString("urls"); for (String url : urls.split(",")) { urlList.add(url); } } ThreadSession.getHttpSession().setAttribute(MakesiteConstant.Session_Auth_Urls, urlList); } catch (IOException e) { e.printStackTrace(); } return mv; }
@WebMethod public ModelAndView setCommon(int ndbNo) { Food food = service.get(Food.class, ndbNo); ModelAndView mv = new ModelAndView(); if (food != null) { food.common = true; service.saveOrUpdate(food); } // mv.redirect="list"; mv.data.put("msg", "set common successfully"); return mv; }
// 删除扫描记录 @WebMethod public ModelAndView deleteScanRecord(Integer id) { ModelAndView mv = new ModelAndView(); ScanRecord po = dao.get(ScanRecord.class, id); if (po != null) { dao.delete(po); } else { throw new GException(PlatformExceptionType.BusinessException, "记录不存在或已经删除"); } mv.data.put("result", "success"); return mv; }
@WebMethod public ModelAndView delete(int id) { ModelAndView mv = new ModelAndView(); User po = dao.get(User.class, id); if (po != null) { dao.delete(po); dao.execute("delete from UserGroup where uid=?", id); dao.execute("delete from UserRole where uid=?", id); mv.data.put("msg", "删除用户成功"); } return mv; }
@WebMethod public ModelAndView modifyPwd(int uid, String oldPwd, String newPwd) { ModelAndView mv = new ModelAndView(); User po = dao.get(User.class, uid); if (po != null) { if (!po.pwd.equals(SecurityHelper.Md5(oldPwd))) { throw new GException(PlatformExceptionType.BusinessException, "原密码不正确,请重新输入后重试"); } po.pwd = SecurityHelper.Md5(newPwd); dao.saveOrUpdate(po); } return mv; }
@WebMethod public ModelAndView banUser(int groupId, int uid) { ModelAndView mv = new ModelAndView(); UserGroup po = dao.getUniqueByParams( UserGroup.class, new String[] {"gid", "uid"}, new Object[] {groupId, Integer.valueOf(uid)}); if (po != null) { dao.delete(po); } return mv; }
@WebMethod public ModelAndView add(Food food) { ModelAndView mv = null; Food po = service.getUnique(Food.class, food); if (po != null) { mv = list(); mv.data.put("msg", food.name + "已经存在"); } else { service.saveOrUpdate(food); mv = list(); mv.data.put("msg", "添加成功"); } return mv; }
// 生活帮 @WebMethod public ModelAndView tips(Page<Map> page) { ModelAndView mv = new ModelAndView(); page.setPageSize(3); page = dao.findPage( page, "select art.id as id, art.title as title , art.isAd as isTop, art.conts as conts, img.path as img from Article art , Image img where img.id=art.imgId" + " and art.leibie='tips' and art.publishFlag=1 order by art.setTopTime desc, art.id desc ", true, new Object[] {}); // make abstract for (Map art : page.getResult()) { String conts = art.get("conts").toString(); conts = HTMLSpirithHelper.delHTMLTag(conts); if (conts.length() > 70) { conts = conts.substring(0, 70); } art.put("conts", conts); } mv.data.put("tips", JSONHelper.toJSONArray(page.getResult())); mv.data.put( "imgUrl", "http://" + ConfigCache.get("image_host", "localhost") + "/article_image_path"); mv.data.put( "tipsDetailUrl", "https://" + ConfigCache.get("app_host", "localhost") + "/article/view.jsp"); return mv; }
// 批量删除扫描记录 @WebMethod public ModelAndView deleteBatchScanRecord(String ids) { ModelAndView mv = new ModelAndView(); if (StringUtils.isEmpty(ids)) { throw new GException(PlatformExceptionType.BusinessException, "参数ids不能为空"); } String[] idArr = ids.split(","); for (String id : idArr) { ScanRecord po = dao.get(ScanRecord.class, Integer.valueOf(id)); if (po != null) { dao.delete(po); } } mv.data.put("result", "success"); return mv; }
/** * 扫描历史记录 * * @param page * @param uid * @param type * @param device * @return */ @WebMethod public ModelAndView listScanRecord(Page<Map> page, Integer uid, Integer type, String device) { ModelAndView mv = new ModelAndView(); StringBuilder hql = new StringBuilder( "select p.id as id, p.title as title , p.vender as vender , p.spec as spec,record.addtime as addtime , img.path as img,record.id as scanId from Product p ,ScanRecord record , Image img where record.productId=p.id and p.imgId=img.id "); List<Object> params = new ArrayList<Object>(); hql.append(" and record.type=? "); params.add(type); hql.append(" and (record.device=? "); params.add(device); if (uid != null) { hql.append(" or record.uid=? "); params.add(uid); } hql.append(")"); LogUtil.info( "listScanRecord uid=" + uid + ",device=" + device + ",type=" + type + ",hql=" + hql); page = dao.findPage(page, hql.toString(), true, params.toArray()); mv.data.put("page", JSONHelper.toJSON(page)); mv.data.put( "productDetailUrl", "https://" + ConfigCache.get("app_host", "localhost") + "/product/view.jsp"); mv.data.put( "imgUrl", "http://" + ConfigCache.get("image_host", "localhost") + "/article_image_path"); return mv; }
@WebMethod public ModelAndView get(int id) { ModelAndView mv = new ModelAndView(); FeedBack po = dao.get(FeedBack.class, id); mv.data.put("feedback", JSONHelper.toJSON(po)); return mv; }
@WebMethod public ModelAndView listCommon() { List<Food> foods = service.listByParams(Food.class, "from Food where common=1", null, null); ModelAndView mv = new ModelAndView(); mv.data.put("foods", foods); mv.jsp = "/Food.jsp"; return mv; }
// 首页初始化 @WebMethod public ModelAndView init(String tel) { // https://localhost:8181/c/app/init ModelAndView mv = new ModelAndView(); // 新闻 Page<Map> page = new Page<Map>(); page.setPageSize(2); page = dao.findPage( page, "select art.id as id, art.title as title , art.conts as conts, img.path as img from Article art , Image img where img.id=art.imgId and art.publishFlag=1" + " and art.leibie='news' order by art.setTopTime desc, art.id desc ", true, new Object[] {}); // make abstract for (Map art : page.getResult()) { String conts = art.get("conts").toString(); conts = HTMLSpirithHelper.delHTMLTag(conts); if (conts.length() > 70) { conts = conts.substring(0, 70); } art.put("conts", conts); } mv.data.put("news", JSONHelper.toJSONArray(page.getResult())); page = dao.findPage( page, "select product.id as id, product.title as title , img.path as img from Product product , Image img where img.id=product.imgId and product.isAd=1", true, new Object[] {}); mv.data.put("products", JSONHelper.toJSONArray(page.getResult())); mv.data.put( "imgUrl", "http://" + ConfigCache.get("image_host", "localhost") + "/article_image_path"); mv.data.put( "productDetailUrl", "https://" + ConfigCache.get("app_host", "localhost") + "/product/view.jsp"); mv.data.put( "goodsDetailUrl", "https://" + ConfigCache.get("app_host", "localhost") + "/goods/view.jsp"); mv.data.put( "newsDetailUrl", "https://" + ConfigCache.get("app_host", "localhost") + "/article/view.jsp"); return mv; }
@WebMethod public ModelAndView add(FeedBack fb) { if (fb.conts == null) { throw new GException(PlatformExceptionType.BusinessException, "请先填写反馈已经"); } fb.addtime = new Date(); fb.userId = ThreadSession.getUser().id; dao.saveOrUpdate(fb); return new ModelAndView(); }
@WebMethod public ModelAndView list(Page<Map> page) { ModelAndView mv = new ModelAndView(); StringBuilder hql = new StringBuilder( "select fb.id as id, SubString(fb.conts,1,20) as conts ,fb.addtime as addtime , u.uname as uname, d.namea as deptName from FeedBack fb, User u, " + "Department d where fb.userId=u.id and u.deptId=d.id"); List<Object> params = new ArrayList<Object>(); page = dao.findPage(page, hql.toString(), true, params.toArray()); mv.data.put("page", JSONHelper.toJSON(page)); return mv; }
@WebMethod public ModelAndView addToGroup(int groupId, String ids) { ModelAndView mv = new ModelAndView(); for (String uid : ids.split(",")) { if (StringUtils.isEmpty(uid)) { continue; } UserGroup po = dao.getUniqueByParams( UserGroup.class, new String[] {"gid", "uid"}, new Object[] {groupId, Integer.valueOf(uid)}); if (po != null) { continue; } UserGroup ug = new UserGroup(); ug.gid = groupId; ug.uid = Integer.valueOf(uid); dao.saveOrUpdate(ug); } return mv; }
@WebMethod public ModelAndView getUserTree(String _site) { ModelAndView mv = new ModelAndView(); List<Group> groups = dao.listByParams(Group.class, "from Group where parentId is null and _site=?", _site); JSONArray arr = new JSONArray(); for (Group g : groups) { JSONObject jobj = new JSONObject(); jobj.put("name", g.name); jobj.put("id", g.id); jobj.put("key", "group_" + g.id); jobj.put("isParent", true); jobj.put("type", "group"); JSONArray children = getChildrenOfGroup(g.id, _site); if (!children.isEmpty()) { jobj.put("children", children); } arr.add(jobj); } mv.returnText = arr.toString(); return mv; }