From 9b33e93fccddea356c3d686684fc58ceb176ff39 Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Fri, 30 Mar 2018 15:01:26 +0800
Subject: [PATCH] 增加 省市区 查询条件

---
 src/main/java/com/moral/service/impl/OperateUserServiceImpl.java |   97 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 86 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java b/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java
index f574667..9ef3df8 100644
--- a/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java
@@ -1,49 +1,70 @@
 package com.moral.service.impl;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 import javax.annotation.Resource;
 
+import com.moral.common.util.MyBatisBaseMapUtil;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 
+import com.github.pagehelper.PageHelper;
+import com.moral.common.bean.Constants;
+import com.moral.common.bean.PageBean;
 import com.moral.common.exception.BusinessException;
 import com.moral.common.util.Crypto;
+import com.moral.common.util.ResourceUtil;
+import com.moral.common.util.ValidateUtil;
 import com.moral.entity.OperateUser;
 import com.moral.mapper.OperateUserMapper;
 import com.moral.service.OperateUserService;
 
 import tk.mybatis.mapper.entity.Example;
+import tk.mybatis.mapper.entity.Example.Criteria;
 
 @Service
 public class OperateUserServiceImpl implements OperateUserService {
-
+    private static Class ENTITY_CLASS = OperateUser.class;
 	@Resource
 	private OperateUserMapper operateUserMapper;
-
 	@Override
-	public List<OperateUser> getUserList(String mobile) {
-		Example example = new Example(OperateUser.class);
-		example.or().andEqualTo("mobile", mobile);
-		return operateUserMapper.selectByExample(example);
+	public boolean isUniqueProperty(String propertyName, Object value){
+		Example example = new Example(ENTITY_CLASS);
+		example.or().andEqualTo(propertyName,value);
+		return operateUserMapper.selectCountByExample(example)==0;
+	}
+	@Override
+	public OperateUser getOperateUserByMobile(String mobile) {
+		OperateUser operateUser = new OperateUser();
+		operateUser.setMobile(mobile);
+		return operateUserMapper.selectOne(operateUser);
 	}
 
 	@Override
 	public OperateUser mobileLogin(String mobile, String password) {
-		Example example = new Example(OperateUser.class);
-		example.or().andEqualTo("mobile", mobile).andEqualTo("password", Crypto.md5(password));
-		List<OperateUser> operateUsers = operateUserMapper.selectByExample(example);
-		if (ObjectUtils.isEmpty(operateUsers) || operateUsers.size() > 1) {
+		ValidateUtil.notEmpty(mobile, "param.is.null");
+		ValidateUtil.notEmpty(password, "param.is.null");
+		OperateUser operateUser = new OperateUser();
+		operateUser.setMobile(mobile);
+		operateUser.setPassword(Crypto.md5(password));
+		operateUser = operateUserMapper.selectOne(operateUser);
+		if (ObjectUtils.isEmpty(operateUser)) {
 			throw new BusinessException("������������������������,���������������");
 		}else {
-			OperateUser operateUser = operateUsers.get(0);
 			operateUser.setPassword(password);
 			return operateUser;
 		}
 	}
 
 	@Override
+	@Transactional
 	public OperateUser updatePassword(Integer uid, String password, String newPassword) {
+		ValidateUtil.notNull(uid, "param.is.null");
+		ValidateUtil.notEmpty(password, "param.is.null");
+		ValidateUtil.notEmpty(newPassword, "param.is.null");
 		OperateUser operateUser = operateUserMapper.selectByPrimaryKey(uid);
 		if (ObjectUtils.isEmpty(operateUser) || !Crypto.md5(password).equals(operateUser.getPassword())) {
 			throw new BusinessException("���������������,���������������������");
@@ -55,4 +76,58 @@
 		}
 	}
 
+	@Override
+	public PageBean<OperateUser> getOperateUserList(Map<String, Object> parameters) {
+		Example example = new Example(OperateUser.class);
+		Criteria criteria = example.createCriteria();
+		if (parameters.containsKey("u_name")) {
+			criteria.andLike("name", "%" + (String) parameters.get("u_name") + "%");
+		}
+		if (parameters.containsKey("u_mobile")) {
+			criteria.andLike("mobile", "%" + (String) parameters.get("u_mobile") + "%");
+		}
+		if (parameters.containsKey("sorter")) {
+			example.setOrderByClause((String) parameters.get("sorter"));
+		}
+		criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
+		PageHelper.startPage(Integer.valueOf((String) parameters.get("pi")), Integer.valueOf((String) parameters.get("ps")));
+		List<OperateUser> operateUsers = operateUserMapper.selectByExample(example);
+		return new PageBean<OperateUser>(operateUsers);
+	}
+
+	@Override
+	@Transactional
+	public Integer saveOrUpdateOperateUser(OperateUser operateUser) {
+		if (ObjectUtils.isEmpty(operateUser.getId())) {
+			operateUser.setIsDelete(Constants.IS_DELETE_FALSE);
+			operateUser.setCreateTime(new Date());
+			operateUser.setPassword(Crypto.md5(ResourceUtil.getValue("password")));
+			return operateUserMapper.insertSelective(operateUser);
+		}else {
+			return operateUserMapper.updateByPrimaryKeySelective(operateUser);
+		}
+	}
+
+
+	@Override
+	@Transactional
+	public Integer deleteOperateUserByLogic(OperateUser operateUser) {
+		operateUser.setIsDelete(Constants.IS_DELETE_TRUE);
+		return operateUserMapper.updateByPrimaryKey(operateUser);
+	}
+
+	@Override
+	@Transactional
+	public Integer deleteOperateUsersByLogic(List<Integer> ids) {
+		OperateUser operateUser = new OperateUser();
+		operateUser.setIsDelete(Constants.IS_DELETE_TRUE);
+		Example example = new Example(OperateUser.class);
+		example.or().andIn("id", ids);
+		return operateUserMapper.updateByExampleSelective(operateUser, example);
+	}
+
+	@Override
+	public PageBean queryByPageBean(PageBean pageBean) {
+		return MyBatisBaseMapUtil.queryPage(operateUserMapper,pageBean,ENTITY_CLASS);
+	}
 }

--
Gitblit v1.8.0