From b419209310112939039b6e2935bee6c53cdf7a52 Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Thu, 25 Jul 2019 14:30:48 +0800
Subject: [PATCH] 新增无人机飞行轨迹地图页面
---
src/main/java/com/moral/service/impl/AccountServiceImpl.java | 192 +++++++++++++++++++++++++++++++++++-------------
1 files changed, 140 insertions(+), 52 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/AccountServiceImpl.java b/src/main/java/com/moral/service/impl/AccountServiceImpl.java
index aee503f..243ac98 100644
--- a/src/main/java/com/moral/service/impl/AccountServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/AccountServiceImpl.java
@@ -2,50 +2,67 @@
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.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
-import org.springframework.beans.factory.annotation.Autowired;
+import javax.annotation.Resource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
-import com.moral.common.bean.ResultBean;
+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.Account;
-import com.moral.entity.AccountExample;
+import com.moral.entity.Organization;
import com.moral.mapper.AccountMapper;
+import com.moral.mapper.OrganizationMapper;
import com.moral.service.AccountService;
import com.moral.service.OrganizationService;
+import tk.mybatis.mapper.entity.Example;
+import tk.mybatis.mapper.entity.Example.Criteria;
+
@Service
public class AccountServiceImpl implements AccountService {
- @Autowired
+ @Resource
+ private BCryptPasswordEncoder encoder;
+ @Resource
private AccountMapper accountMapper;
- @Autowired
+ @Resource
private OrganizationService organizationService;
+
+ @Resource
+ private OrganizationMapper organizationMapper;
@Override
public Map<String, Object> screenLogin(Map<String, Object> parameters) {
Map<String, Object> result = new HashMap<String, Object>();
- AccountExample example = new AccountExample();
- String password = md5((String) parameters.get("account"));
- example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password);
- List<Account> accounts = accountMapper.selectByExample(example);
- if (isEmpty(accounts) || accounts.size() != 1) {
+ Account account = new Account();
+ account.setAccountName((String) parameters.get("account"));
+ String rawPassword = (String) parameters.get("password");
+// account.setPassword(encoder.encode((String) parameters.get("password")));
+ account = accountMapper.selectOne(account);
+ boolean isValid = account == null ? false:encoder.matches(rawPassword,account.getPassword());
+ if (!isValid) {
result.put("msg", "���������������������������������");
} else {
- Account account = accounts.get(0);
if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
result.put("msg", "���������������");
result.put("accountId", account.getId());
+ result.put("orgId", account.getOrganizationId());
+ setOrgIdsByAccount(result);
} else {
result.put("msg","���������������������������������������������");
}
@@ -54,47 +71,20 @@
}
@Override
- public ResultBean<Account> screenLogin1(Map<String, Object> parameters) {
- ResultBean<Account> resultBean = new ResultBean<Account>();
- AccountExample example = new AccountExample();
- String password = Crypto.md5((String) parameters.get("password"));
- example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password);
- List<Account> accounts = accountMapper.selectByExample(example);
- if (isEmpty(accounts) || accounts.size() != 1) {
- resultBean.setMsg("���������������������������������");
- resultBean.setCode(ResultBean.FAIL);
- } else {
- Account account = accounts.get(0);
- if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
- resultBean.setData(account);
- } else {
- resultBean.setCode(ResultBean.NO_PERMISSION);
- resultBean.setMsg("���������������������������������������������");
- }
- }
- return resultBean;
+ public Account getAccountByAccountName(String accountName) {
+ Account account = new Account();
+ account.setAccountName(accountName);
+ return accountMapper.selectOne(account);
}
-
-
@Override
- public List<Account> getAccountLists(String accountName, String password) {
- AccountExample example = new AccountExample();
- example.or().andAccountNameEqualTo(accountName).andPasswordEqualTo(password);
- return accountMapper.selectByExample(example);
+ public Account getAccountById(Integer id){
+ return accountMapper.selectByPrimaryKey(id);
}
-
- @Override
- public List<Account> getAccountList(String accountName) {
- AccountExample example = new AccountExample();
- example.or().andAccountNameEqualTo(accountName);
- return accountMapper.selectByExample(example);
- }
-
@Override
public void setOrgIdsByAccount(Map<String, Object> parameters) {
- String accountId = (String) parameters.get("accountId");
+ String accountId = parameters.get("accountId").toString();
accountId = accountId.replaceFirst("-", "");
- if (!isNumeric((String) parameters.get("accountId"))) {
+ if (!isNumeric(accountId)) {
throw new BusinessException("accountId ������������������");
}
@@ -105,10 +95,108 @@
Integer orgId = account.getOrganizationId();
// ���������������������������������������������������������������
- if (!(-1 == orgId || 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);
+ Set<Integer> organizationIds = new HashSet<Integer>();
+ for (Account account : accounts) {
+ if (!ObjectUtils.isEmpty(account.getOrganizationId())) {
+ organizationIds.add(account.getOrganizationId());
+ }
+ }
+ if(!ObjectUtils.isEmpty(organizationIds)){
+ example = new Example(Organization.class);
+ example.or().andIn("id", organizationIds);
+ List<Organization> organizations = organizationMapper.selectByExample(example);
+ for (Account account : accounts) {
+ for (Organization organization : organizations) {
+ if (account.getOrganizationId() == organization.getId()) {
+ account.setOrganization(organization);
+ break;
+ }
+ }
+ }
+ }
+
+ return new PageBean<Account>(accounts);
+ }
+
+ @Override
+ @Transactional
+ public Integer saveOrUpdateAccount(Account account) {
+ // ������������
+ if(!StringUtils.isBlank(account.getPassword())){
+ account.setPassword(encoder.encode(account.getPassword()));
+ }
+ if (ObjectUtils.isEmpty(account.getId())) {
+ account.setIsDelete(Constants.IS_DELETE_FALSE);
+ account.setCreateTime(new Date());
+ account.setPassword(encoder.encode(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);
+ }
+
+ @Override
+ public Integer getAccountCountByAccountName(String accountName) {
+ Account account = new Account();
+ account.setAccountName(accountName);
+ return accountMapper.selectCount(account);
+ }
+
+ @Override
+ public Optional<Account> queryAccountByName(String accountName) {
+ Account account = accountMapper.getByAccountName(accountName);
+ return Optional.ofNullable(account);
+ }
+
+ @Override
+ public Account companyLogin(Map<String, Object> parameters) {
+ ValidateUtil.notNull(parameters.get("account"), "param.is.null");
+ ValidateUtil.notNull(parameters.get("password"), "param.is.null");
+ Account account = new Account();
+ account.setIsDelete(Constants.IS_DELETE_FALSE);
+ account.setAccountName(parameters.get("account").toString());
+ account = accountMapper.selectOne(account);
+ if (ObjectUtils.isEmpty(account)) {
+ throw new BusinessException("���������������������������������������");
+ }
+ if (!encoder.matches(parameters.get("password").toString(), account.getPassword())) {
+ throw new BusinessException("���������������������������������");
+ }
+ account.setPassword(parameters.get("password").toString());
+ return account;
+ }
}
--
Gitblit v1.8.0