From a970b81177a41e1550012ff40446e143bbf9ef22 Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Tue, 02 Jan 2018 16:03:04 +0800
Subject: [PATCH] 账户 管理
---
src/main/java/com/moral/service/impl/AccountServiceImpl.java | 112 +++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 82 insertions(+), 30 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/AccountServiceImpl.java b/src/main/java/com/moral/service/impl/AccountServiceImpl.java
index 06808ff..53cfd53 100644
--- a/src/main/java/com/moral/service/impl/AccountServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/AccountServiceImpl.java
@@ -1,46 +1,61 @@
package com.moral.service.impl;
+import static com.moral.common.bean.Constants.IS_DELETE_FALSE;
+import static com.moral.common.bean.Constants.IS_DELETE_TRUE;
+import static com.moral.common.util.Crypto.md5;
+import static com.moral.common.util.ResourceUtil.getValue;
+import static org.apache.commons.lang3.StringUtils.isNumeric;
+import static org.springframework.util.ObjectUtils.isEmpty;
+
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
+import javax.annotation.Resource;
+
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.entity.Account;
-import com.moral.entity.AccountExample;
import com.moral.mapper.AccountMapper;
import com.moral.service.AccountService;
import com.moral.service.OrganizationService;
-import com.moral.util.BusinessException;
-import com.moral.util.Crypto;
-import com.moral.util.ResourceUtil;
+
+import tk.mybatis.mapper.entity.Example;
+import tk.mybatis.mapper.entity.Example.Criteria;
@Service
public class AccountServiceImpl implements AccountService {
- @Autowired
+
+ @Resource
private AccountMapper accountMapper;
- @Autowired
+ @Resource
private OrganizationService organizationService;
@Override
public Map<String, Object> screenLogin(Map<String, Object> parameters) {
Map<String, Object> result = new HashMap<String, Object>();
- AccountExample example = new AccountExample();
- String password = Crypto.md5((String) parameters.get("account"));
- example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password);
- List<Account> accounts = accountMapper.selectByExample(example);
- if (ObjectUtils.isEmpty(accounts) || accounts.size() != 1) {
+ Account account = new Account();
+ account.setAccountName((String) parameters.get("account"));
+ account.setPassword(md5((String) parameters.get("password")));
+ account = accountMapper.selectOne(account);
+ if (isEmpty(account)) {
result.put("msg", "���������������������������������");
} else {
- Account account = accounts.get(0);
- if ("1".equals(account.getIsDelete())) {
+ if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
result.put("msg", "���������������");
result.put("accountId", account.getId());
+ result.put("orgId", account.getOrganizationId());
} else {
result.put("msg","���������������������������������������������");
}
@@ -49,38 +64,75 @@
}
@Override
- public List<Account> getAccountLists(String accountName, String password) {
- AccountExample example = new AccountExample();
- example.or().andAccountNameEqualTo(accountName).andPasswordEqualTo(password);
- return accountMapper.selectByExample(example);
- }
-
- @Override
- public List<Account> getAccountList(String accountName) {
- AccountExample example = new AccountExample();
- example.or().andAccountNameEqualTo(accountName);
- return accountMapper.selectByExample(example);
+ public Account getAccountByAccountName(String accountName) {
+ Account account = new Account();
+ account.setAccountName(accountName);
+ return accountMapper.selectOne(account);
}
@Override
public void setOrgIdsByAccount(Map<String, Object> parameters) {
String accountId = (String) parameters.get("accountId");
accountId = accountId.replaceFirst("-", "");
- if (!StringUtils.isNumeric((String) parameters.get("accountId"))) {
+ if (!isNumeric((String) parameters.get("accountId"))) {
throw new BusinessException("accountId ������������������");
}
Account account = accountMapper.selectByPrimaryKey((Integer.valueOf(accountId)));
- if (ObjectUtils.isEmpty(account) || "1".equals(account.getIsDelete())) {
- throw new BusinessException(accountId + "���������������������");
+ if (isEmpty(account) || IS_DELETE_TRUE.equals(account.getIsDelete())) {
+ throw new BusinessException(accountId + ":���������������������");
}
Integer orgId = account.getOrganizationId();
// ���������������������������������������������������������������
- if (!("-1".equals(orgId) || ResourceUtil.getValue("orgId").equals(orgId))) {
+ if (!(-1 == orgId || getValue("orgId").equals(orgId+""))) {
Set<Integer> orgIds = organizationService.getChildOrganizationIds(orgId);
parameters.put("orgIds", orgIds);
}
}
+ @Override
+ public PageBean<Account> getAccountListByPage(Map<String, Object> parameters) {
+ Example example = new Example(Account.class);
+ Criteria criteria = example.createCriteria();
+ if (parameters.containsKey("accountName")) {
+ criteria.andLike("accountName", "%" + (String) parameters.get("accountName") + "%");
+ }
+ if (parameters.containsKey("mobile")) {
+ criteria.andLike("mobile", "%" + (String) parameters.get("mobile") + "%");
+ }
+ if (parameters.containsKey("isDelete")) {
+ criteria.andEqualTo("isDelete", parameters.get("isDelete"));
+ }
+ if (parameters.containsKey("sorter")) {
+ example.setOrderByClause((String) parameters.get("sorter"));
+ }
+ PageHelper.startPage(Integer.valueOf((String) parameters.get("pageIndex")), Integer.valueOf((String) parameters.get("pageSize")));
+ List<Account> accounts = accountMapper.selectByExample(example);
+ return new PageBean<Account>(accounts);
+ }
+
+ @Override
+ @Transactional
+ public Integer saveOrUpdateAccount(Account account) {
+ if (ObjectUtils.isEmpty(account.getId())) {
+ account.setIsDelete(Constants.IS_DELETE_FALSE);
+ account.setCreateTime(new Date());
+ account.setPassword(Crypto.md5(ResourceUtil.getValue("password")));
+ return accountMapper.insertSelective(account);
+ } else {
+ return accountMapper.updateByPrimaryKeySelective(account);
+ }
+ }
+
+ @Override
+ @Transactional
+ public Integer deleteAccountsByLogic(List<Integer> ids) {
+ Account account = new Account();
+ account.setIsDelete(Constants.IS_DELETE_TRUE);
+ Example example = new Example(Account.class);
+ example.or().andIn("id", ids);
+ return accountMapper.updateByExampleSelective(account, example);
+ }
+
}
--
Gitblit v1.8.0