@Override public User findByName(String user_name) { user_name = StringUtil.isEmpty(user_name); if (null == user_name) return null; Example example = new Example(User.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("user_name", user_name); List<User> list = selectByExample(example); return (null == list || 1 != list.size()) ? null : list.get(0); }
@Override public User findByEmail(String email) { email = StringUtil.isEmpty(email); if (null == email) return null; Example example = new Example(User.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("email", email); List<User> list = selectByExample(example); return (null == list || 1 != list.size()) ? null : list.get(0); }
@Override public List<User> findByInviteUserId(String invite_user_id) { invite_user_id = StringUtil.isEmpty(invite_user_id); if (null == invite_user_id) return null; Example example = new Example(User.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("invite_user_id", invite_user_id); List<User> list = selectByExample(example); return list; }
@Test public void testSelectByExample() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151); example.or().andLessThan("id", 41); List<Country> countries = mapper.selectByExample(example); // 查询总数 Assert.assertEquals(90, countries.size()); } finally { sqlSession.close(); } }
@Test public void testSelectByExample2() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.createCriteria().andLike("countryname", "A%"); example.or().andGreaterThan("id", 100); example.setDistinct(true); List<Country> countries = mapper.selectByExample(example); // 查询总数 Assert.assertEquals(true, countries.size() > 83); } finally { sqlSession.close(); } }
@Override public EasyuiDataGridJson datagrid(EasyuiDataGrid dg, String learningcenterId) { EasyuiDataGridJson listjson = new EasyuiDataGridJson(); Example example = new Example(YztChoicenesscontentPic.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("yztChoicenesscontentId", learningcenterId); listjson.setTotal(selectCountByExample(example)); // 分页查询 PageHelper.startPage(dg.getPage(), dg.getRows()); listjson.setRows(selectByExample(example)); return listjson; }
@Test public void testSelectByExampleInNotIn() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example .createCriteria() .andIn("id", Arrays.asList(new Object[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11})) .andNotIn("id", Arrays.asList(new Object[] {11})); List<Country> countries = mapper.selectByExample(example); // 查询总数 Assert.assertEquals(10, countries.size()); } finally { sqlSession.close(); } }
private List<User> findByUser(User user, int page, int rows) { Example example = new Example(User.class); example.setOrderByClause("create_time desc"); example.selectProperties( "id", "user_name", "email", "create_time", "status", "apikey", "seckey", "real_name", "alipay_account", "invite_user_id", "role_id"); // TODO if (null != user) { Example.Criteria criteria = example.createCriteria(); // TODO String user_name = StringUtil.isEmpty(user.getUser_name()); if (null != user_name) { criteria.andLike("user_name", "%" + user_name + "%"); } // TODO String apikey = StringUtil.isEmpty(user.getApikey()); if (null != apikey) { criteria.andEqualTo("apikey", apikey); } // TODO String seckey = StringUtil.isEmpty(user.getSeckey()); if (null != seckey) { criteria.andEqualTo("seckey", seckey); } String invite_user_id = StringUtil.isEmpty(user.getInvite_user_id()); if (null != invite_user_id) { criteria.andEqualTo("invite_user_id", invite_user_id); } } PageHelper.startPage(page, rows); return selectByExample(example); }
@Override public Json updatePWD(YztUserinfo userinfo, String password_new, String password_re) { Json json = new Json(); if (userinfo.getPassword().isEmpty() || password_new.isEmpty() || password_re.isEmpty()) { json.setSuccess(false); json.setMsg(YztConstant.UP_PWD_ALLNULL); } else if (!password_new.equals(password_re)) { json.setSuccess(false); json.setMsg(YztConstant.UP_PWD_NOTEQUAL); } else { System.out.println("==1=" + userinfo.getId()); Example example = new Example(YztUserinfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("id", userinfo.getId()); criteria.andEqualTo("account", userinfo.getAccount()); criteria.andEqualTo("password", userinfo.getPassword()); List<YztUserinfo> list = selectByExample(example); if (list.size() == 1) { for (YztUserinfo user : list) { if (user.getStatus() != null && user.getStatus() == 1) { json.setSuccess(false); json.setMsg(YztConstant.LOGIN_ACCOUNT_BAN); } else { YztUserinfo user_ = new YztUserinfo(); user_.setId(user.getId()); user_.setAccount(user.getAccount()); user_.setPassword(password_new); updateNotNull(user_); json.setSuccess(true); json.setMsg(YztConstant.UP_PWD_SUCCESS); json.setObj(user); } } } else { json.setSuccess(false); json.setMsg(YztConstant.UP_PWD_PWDERR); } } return json; }
@Override public Json login(YztUserinfo userinfo) { Json json = new Json(); if (userinfo.getAccount().equals(null) || userinfo.getPassword().equals(null) || userinfo.getAccount().isEmpty() || userinfo.getPassword().isEmpty()) { json.setSuccess(false); json.setMsg(YztConstant.LOGIN_NOTNULL); } else if (YztUtil.isMobileNO(userinfo.getAccount())) { Example example = new Example(YztUserinfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("account", userinfo.getAccount()); List<YztUserinfo> list = selectByExample(example); if (list.size() == 1) { for (YztUserinfo user : list) { if (user.getStatus() != null && user.getStatus() == 1) { json.setSuccess(false); json.setMsg(YztConstant.LOGIN_ACCOUNT_BAN); } else { if (user.getPassword().equals(userinfo.getPassword())) { json.setSuccess(true); json.setMsg(YztConstant.LOGIN_SUCCESS); json.setObj(user); } else { json.setSuccess(false); json.setMsg(YztConstant.LOGIN_ERR); } } } } else { json.setSuccess(false); json.setMsg(YztConstant.LOGIN_ACCOUNT_NULL); } } else { json.setSuccess(false); json.setMsg(YztConstant.MSG_MOBILE_ERR); } return json; }
@Override public List<YztLearningcenterCommentObj> commentlist(String learningcenterId, int num) { Example example = new Example(YztLearningcenterComment.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("yztLearningcenterId", learningcenterId); example.setOrderByClause(" createtime desc limit 2"); // PageHelper.startPage(1, num); List<YztLearningcenterComment> lc = selectByExample(example); List<YztLearningcenterCommentObj> lcc = new ArrayList<YztLearningcenterCommentObj>(); for (YztLearningcenterComment lc_c : lc) { String jsonString = JSON.toJSONString(lc_c); YztLearningcenterCommentObj obj = JSON.parseObject(jsonString, YztLearningcenterCommentObj.class); obj.setPiclist(learningcenterCommentPicService.piclist(lc_c.getId())); lcc.add(obj); } return lcc; }
@Override public EasyuiDataGridJson datagrid(EasyuiDataGrid dg, String learningcenterId) { EasyuiDataGridJson listjson = new EasyuiDataGridJson(); Example example = new Example(YztLearningcenterComment.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("yztLearningcenterId", learningcenterId); // criteria.andEqualTo("parentid","0"); String filterRules = dg.getFilterRules(); if (filterRules != null && !"[]".equals(filterRules)) { List<FieldFilter> filtersr = JSON.parseArray(filterRules, FieldFilter.class); for (FieldFilter ft : filtersr) { // postparam.append(" and "+ft.getField()+" like '%"+ft.getValue().trim().replace(" ", // "%")+"%' "); criteria.andLike(ft.getField(), "%" + ft.getValue().trim().replaceAll(" ", "%") + "%"); } } // 加入排序 if (dg.getSort() != null && dg.getOrder() != null) { String orderby = ""; String[] order = dg.getSort().split(","); String[] sort = dg.getOrder().split(","); for (int i = 0; i < order.length; i++) { orderby += order[i] + " " + sort[i] + ","; } orderby = StringUtils.substringBeforeLast(orderby, ","); example.setOrderByClause(orderby); } else { example.setOrderByClause(" createtime desc "); } listjson.setTotal(selectCountByExample(example)); // 分页查询 PageHelper.startPage(dg.getPage(), dg.getRows()); listjson.setRows(selectByExample(example)); return listjson; }
@SuppressWarnings("unused") @Override public Json resetPWD(YztRegistor registor) { Json json = new Json(); if (!registor.getIsMobile().isEmpty() && !registor.getIsVerifyCode().isEmpty() && !registor.getIsPassword().isEmpty()) { Example example1 = new Example(YztUserinfo.class); Example.Criteria criteria1 = example1.createCriteria(); criteria1.andEqualTo("account", registor.getIsMobile()); // criteria1.andEqualTo("status",1);//0,非禁用 用户,1-禁用 List<YztUserinfo> list1 = selectByExample(example1); Example example = new Example(YztRegistor.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("isMobile", registor.getIsMobile()); // criteria.andEqualTo("isVerifyCode", registor.getIsVerifyCode()); List<YztRegistor> list = registService.selectByExample(example); for (YztUserinfo userinfo : list1) { if (userinfo.getStatus() != null && userinfo.getStatus() == 1) { json.setSuccess(false); json.setMsg(YztConstant.LOGIN_ACCOUNT_BAN); } else { if (list.size() > 0) { // 已经发送过验证码,对比过期时间,如果过期,重新发送验证码。如果没过期提示查看手机验证码 for (YztRegistor reg : list) { // reg.getOverdueTime(); if (reg.getStatus() != null && reg.getStatus() == 1) { // json.setSuccess(false); // json.setMsg(YztConstant.REGIST_SECOND); // }else{ Calendar cal = (GregorianCalendar) Calendar.getInstance(); cal.setTime(new Date()); GregorianCalendar endCalendar = (GregorianCalendar) Calendar.getInstance(); endCalendar.setTime(reg.getOverdueTime()); // if(cal.compareTo(endCalendar)>0){//时间已过期 if (1 > 2) { json.setSuccess(false); json.setMsg(YztConstant.MSG_VERFIYCODE_OVERDUE); } else { // 注册成功 // reg.setRegistTime(new Date()); // reg.setStatus(1); // registService.updateAll(reg); // 同时往用户表里插入 YztUserinfo user = new YztUserinfo(); user.setId(userinfo.getId()); // user.setAccount(reg.getIsMobile()); user.setPassword(registor.getIsPassword()); updateNotNull(user); json.setSuccess(true); json.setMsg(YztConstant.UP_PWD_SUCCESS); } } } } else { // 找不到用户,提示验证码错误 json.setSuccess(false); json.setMsg(YztConstant.MSG_MOBILE_VERFIYCODE_NOTEQUALL); } } } } else { json.setSuccess(false); json.setMsg(YztConstant.MSG_MOBILE_VERFIYCODE_NOTNULL); } return json; }
@Override public Json getVerifyCode(YztRegistor registor) { // LocalDateTime dateTime = LocalDateTime.now(); System.out.println("registor.getIsMobile()=" + registor.getIsMobile()); Json json = new Json(); if (registor.getIsMobile() != null && !registor.getIsMobile().isEmpty()) { if (YztUtil.isMobileNO(registor.getIsMobile())) { Example example = new Example(YztRegistor.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("isMobile", registor.getIsMobile()); Example example1 = new Example(YztUserinfo.class); Example.Criteria criteria1 = example1.createCriteria(); criteria1.andEqualTo("account", registor.getIsMobile()); criteria1.andEqualTo("status", 1); // 0,非禁用 用户,1-禁用 List<YztUserinfo> list1 = selectByExample(example1); if (list1.size() > 0) { json.setSuccess(false); json.setMsg(YztConstant.LOGIN_ACCOUNT_BAN); } else { List<YztRegistor> list = registService.selectByExample(example); if (list.size() > 0) { // 已经注册过,对比过期时间,如果过期,重新发送验证码。如果没过期提示查看手机验证码 // System.out.println("已经注册过"); for (YztRegistor reg : list) { if (reg.getStatus() != null && reg.getStatus() == 1) { // 已经是成功注册的用户,可以发送修改密码的验证 Calendar cal = (GregorianCalendar) Calendar.getInstance(); cal.setTime(new Date()); GregorianCalendar endCalendar = (GregorianCalendar) Calendar.getInstance(); endCalendar.setTime(reg.getOverdueTime()); if (cal.compareTo(endCalendar) > 0) { // 时间已过期 System.out.println("重新发送"); String smscontent = (int) ((Math.random() * 9) * 100000) + ""; Calendar c = Calendar.getInstance(); try { String sms_result = Demo_Client.sentContentTo(registor.getIsMobile(), smscontent); // String sms_result = "654321"; reg.setIsVerifyCode(smscontent); reg.setSmsId(sms_result); reg.setSendTime(c.getTime()); // 加一天 // c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MINUTE, 3); reg.setOverdueTime(c.getTime()); // reg.setRequestCount(reg.getRequestCount()+1); registService.updateNotNull(reg); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } json.setSuccess(true); json.setMsg(YztConstant.MSG_SUCCESS); json.setObj(reg); } else { // 在有效期内 // System.out.println(YztConstant.MSG_SECOND); json.setSuccess(false); json.setMsg(YztConstant.MSG_SECOND); } } else { json.setSuccess(false); json.setMsg(YztConstant.REGIST_MOBILE_NULL); } } // return ""; } else { json.setSuccess(false); json.setMsg(YztConstant.REGIST_MOBILE_NULL); } } } else { json.setSuccess(false); json.setMsg(YztConstant.MSG_MOBILE_ERR); } } else { json.setSuccess(false); json.setMsg(YztConstant.MSG_MOBILE_NULL); } return json; }