From 3bf4a89e8470abf09ca61db5a5e8e8e84f45455b Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Wed, 30 Sep 2020 14:12:56 +0800 Subject: [PATCH] 添加标识符 --- src/main/java/com/moral/service/impl/AccountServiceImpl.java | 481 ++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 345 insertions(+), 136 deletions(-) diff --git a/src/main/java/com/moral/service/impl/AccountServiceImpl.java b/src/main/java/com/moral/service/impl/AccountServiceImpl.java index c54317f..69752c4 100644 --- a/src/main/java/com/moral/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/moral/service/impl/AccountServiceImpl.java @@ -1,28 +1,34 @@ 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.ResourceUtil.getValue; -import static org.apache.commons.lang3.StringUtils.isNumeric; -import static org.springframework.util.ObjectUtils.isEmpty; - -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; 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.CollectionUtils; 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.Account; +import com.moral.entity.Menu; import com.moral.entity.Organization; +import com.moral.entity.Role; import com.moral.mapper.AccountMapper; import com.moral.mapper.OrganizationMapper; import com.moral.service.AccountService; @@ -31,147 +37,350 @@ import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example.Criteria; +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.ResourceUtil.getValue; +import static org.apache.commons.lang3.StringUtils.isNumeric; +import static org.springframework.util.ObjectUtils.isEmpty; + @Service public class AccountServiceImpl implements AccountService { @Resource - private BCryptPasswordEncoder encoder; - @Resource - private AccountMapper accountMapper; + private BCryptPasswordEncoder encoder; - @Resource - private OrganizationService organizationService; + @Resource + private AccountMapper accountMapper; - @Resource - private OrganizationMapper organizationMapper; + @Resource + private OrganizationService organizationService; - @Override - public Map<String, Object> screenLogin(Map<String, Object> parameters) { - Map<String, Object> result = new HashMap<String, Object>(); - Account account = new Account(); - account.setAccountName((String) parameters.get("account")); - String rawPassword = (String) parameters.get("password"); + @Resource + private OrganizationMapper organizationMapper; + + + + @Override + public Map<String, Object> getAccountInfoById(String accountId) { + Map<String, Object> result = new HashMap<String, Object>(); + Account account = new Account(); + account.setId(Integer.parseInt(accountId)); + account = accountMapper.selectOne(account); + if (ObjectUtils.isEmpty(account)) { + result.put("msg", "token������"); + result.put("accountId", -1); + } else { + result = judgeAccountInfo(account); + if (!String.valueOf(result.get("accountId")).equals("-1")) { + List<Menu> menuList = accountMapper.getScreenMenuListsByAccountName(account.getAccountName()); + result.put("msg", "���������������"); + result.put("accountId", account.getId()); + result.put("orgId", account.getOrganizationId()); + result.put("data", menuList); + setOrgIdsByAccount(result); + } + } + return result; + } + + @Override + public Map<String, Object> webLogin(Map<String, Object> parameters) { + Map<String, Object> result = new HashMap<String, Object>(); + Account account = new Account(); + account.setAccountName((String) parameters.get("account")); + String rawPassword = (String) parameters.get("password"); + account = accountMapper.selectOne(account); + boolean isValid = account == null ? false : encoder.matches(rawPassword, account.getPassword()); + if (!isValid) { + result.put("msg", "���������������������������������"); + result.put("accountId", -1); + } else { + result = judgeAccountInfo(account); + } + return result; + } + + + @Override + public Map<String, Object> screenLoginNew(Map<String, Object> parameters) { + Map<String, Object> result = new HashMap<String, Object>(); + 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 { - if (IS_DELETE_FALSE.equals(account.getIsDelete())) { - result.put("msg", "���������������"); - result.put("accountId", account.getId()); - result.put("orgId", account.getOrganizationId()); - } else { - result.put("msg","���������������������������������������������"); - } - } - return result; - } + account = accountMapper.selectOne(account); + Integer existRole = null; + List<Menu> menuList = new ArrayList<>(); + if (account != null) { + existRole = accountMapper.getScreenRoleByAccountName(account.getAccountName()); + menuList = accountMapper.getScreenMenuListsByAccountName(account.getAccountName()); + } + boolean isValid = account == null ? false : encoder.matches(rawPassword, account.getPassword()); + if (!isValid) { + result.put("msg", "���������������������������������"); + result.put("accountId", -1); + } else { + if (IS_DELETE_FALSE.equals(account.getIsDelete())) { + if (existRole != null) { + result.put("msg", "���������������"); + result.put("accountId", account.getId()); + result.put("orgId", account.getOrganizationId()); + result.put("data", menuList); + setOrgIdsByAccount(result); + } else { + result.put("msg", "���������������������"); + } + } else { + result.put("msg", "���������������������������������������������"); + } + } + return result; + } - @Override - public Account getAccountByAccountName(String accountName) { - Account account = new Account(); - account.setAccountName(accountName); - return accountMapper.selectOne(account); - } - @Override - public Account getAccountById(Integer id){ - return accountMapper.selectByPrimaryKey(id); - } - @Override - public void setOrgIdsByAccount(Map<String, Object> parameters) { - String accountId = (String) parameters.get("accountId"); - accountId = accountId.replaceFirst("-", ""); - if (!isNumeric((String) parameters.get("accountId"))) { - throw new BusinessException("accountId ������������������"); - } + @Override + public Map<String, Object> screenLogin(Map<String, Object> parameters) { + Map<String, Object> result = new HashMap<String, Object>(); + 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 { + 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", "���������������������������������������������"); + } + } + return result; + } - Account account = accountMapper.selectByPrimaryKey((Integer.valueOf(accountId))); - if (isEmpty(account) || IS_DELETE_TRUE.equals(account.getIsDelete())) { - throw new BusinessException(accountId + ":���������������������"); - } - Integer orgId = account.getOrganizationId(); - // ��������������������������������������������������������������� - - if (!(-1 == orgId || getValue("orgId").equals(orgId+""))) { - Set<Integer> orgIds = organizationService.getChildOrganizationIds(orgId); - parameters.put("orgIds", orgIds); - } - } + @Override + public Account getAccountByAccountName(String accountName) { + Account account = new Account(); + account.setAccountName(accountName); + return accountMapper.selectOne(account); + } - @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; - } - } - } - } + @Override + public Account getAccountById(Integer id) { + return accountMapper.selectByPrimaryKey(id); + } - return new PageBean<Account>(accounts); - } + @Override + public void setOrgIdsByAccount(Map<String, Object> parameters) { + String accountId = parameters.get("accountId").toString(); + accountId = accountId.replaceFirst("-", ""); + if (!isNumeric(accountId)) { + throw new BusinessException("accountId ������������������"); + } - @Override - @Transactional - public Integer saveOrUpdateAccount(Account account) { - 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); - } - } + Account account = accountMapper.selectByPrimaryKey((Integer.valueOf(accountId))); + if (isEmpty(account) || IS_DELETE_TRUE.equals(account.getIsDelete())) { + throw new BusinessException(accountId + ":���������������������"); + } + Integer orgId = account.getOrganizationId(); + // ��������������������������������������������������������������� - @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); - } + if (!(-1 == orgId || getValue("orgId").equals(orgId + ""))) { + Set<Integer> orgIds = organizationService.getChildOrganizationIds(orgId); + parameters.put("orgIds", orgIds); + } + } - @Override - public Integer getAccountCountByAccountName(String accountName) { - Account account = new Account(); - account.setAccountName(accountName); - return accountMapper.selectCount(account); - } + @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; + } + } + } + } - @Override - public Optional<Account> queryAccountByName(String accountName) { - Account account = accountMapper.getByAccountName(accountName); - return Optional.ofNullable(account); - } + 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; + } + + @Override + public Map<String, Object> getOrganizationIdByAccountId(String id) { + Integer accountId = Integer.parseInt(id); + Map<String, Object> map = accountMapper.getOrganizationIdByAccountId(accountId); + return map; + } + + @Override + public List<Role> getRolesByAccountName(String accountName) { + List<Role> roleList = accountMapper.getRolesByAccountName(accountName); + return roleList; + } + + @Override + public Map<String, Object> getMenuListsByAccountName(String accountName) { + List<Menu> menuList = accountMapper.getParentMenuListsByAccountName(accountName); + Integer organizationId = accountMapper.getByAccountName(accountName).getOrganizationId(); + Map<String, Object> organizationMap = new LinkedHashMap<>(); + organizationMap.put("organizationId", organizationId); + String email = accountMapper.getEmailByAccountName(accountName); + Map<String, Object> mapList = new LinkedHashMap<>(); + Map<String, Object> appMap = new LinkedHashMap<>(); + appMap.put("name", "������������������������"); + appMap.put("description", "������������������������������������������"); + mapList.put("app", appMap); + mapList.put("organization", organizationMap); + Map<String, Object> userMap = new LinkedHashMap<>(); + userMap.put("name", accountName); + userMap.put("avatar", "./assets/img/zorro.svg"); + userMap.put("email", email); + mapList.put("user", userMap); + Map<String, Object> navigationMap = new LinkedHashMap<>(); + Map<String, Object> navigationChildMap = new LinkedHashMap<>(); + navigationChildMap.put("text", "���������"); + navigationChildMap.put("link", "/dashboard/workplace"); + navigationChildMap.put("icon", "icon-speedometer"); + navigationChildMap.put("translate", "dashboard_workplace"); + List<Map> navigationChildList = new ArrayList<>(); + navigationChildList.add(navigationChildMap); + navigationMap.put("text", "���������"); + navigationMap.put("translate", "main_navigation"); + navigationMap.put("group", true); + navigationMap.put("children", navigationChildList); + Map<String, Object> systemMap = new LinkedHashMap<>(); + systemMap.put("text", "������������"); + systemMap.put("group", true); + List<Map> systemList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(menuList)) { + for (Menu m : menuList) { + Map<String, Object> systemChildMap = new LinkedHashMap<>(); + systemChildMap.put("text", m.getMenuName()); + systemChildMap.put("icon", m.getMenuIcon()); + List<Menu> childMenuLists = accountMapper.getChildMenuIdsByAccountName(accountName, m.getId()); + List<Map> systemSonList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(childMenuLists)) { + for (Menu childMenu : childMenuLists) { + Map<String, Object> systemSonMap = new LinkedHashMap<>(); + systemSonMap.put("text", childMenu.getMenuName()); + systemSonMap.put("link", childMenu.getMenuUrl()); + systemSonList.add(systemSonMap); + } + } + systemChildMap.put("children", systemSonList); + systemList.add(systemChildMap); + } + } + systemMap.put("children", systemList); + List<Map> list = new ArrayList<>(); + list.add(navigationMap); + list.add(systemMap); + mapList.put("menu", list); + return mapList; + } + + private Map<String, Object> judgeAccountInfo(Account account) { + Map<String, Object> result = new HashMap<String, Object>(); + Integer existRole = accountMapper.getScreenRoleByAccountName(account.getAccountName()); + if (!IS_DELETE_FALSE.equals(account.getIsDelete())) { + result.put("msg", "���������������������������������������������"); + result.put("accountId", -1); + } else if (ObjectUtils.isEmpty(existRole)) { + result.put("msg", "���������������������"); + result.put("accountId", -1); + } else { + result.put("msg", "���������������"); + result.put("accountId", account.getId()); + } + return result; + } + + } -- Gitblit v1.8.0