From 8bb0e02e8fd166f35782870983fd2140142df409 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Mon, 30 Nov 2020 15:52:12 +0800 Subject: [PATCH] 获取账户地图信息添加权限校验 --- src/main/java/com/moral/service/impl/AccountServiceImpl.java | 194 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 184 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/moral/service/impl/AccountServiceImpl.java b/src/main/java/com/moral/service/impl/AccountServiceImpl.java index 7d4b446..7bbcbe8 100644 --- a/src/main/java/com/moral/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/moral/service/impl/AccountServiceImpl.java @@ -10,13 +10,10 @@ import java.util.Optional; import java.util.Set; -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 javax.annotation.Resource; + +import com.moral.entity.*; +import com.moral.mapper.DictionaryDataMapper; import org.apache.commons.lang3.StringUtils; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -31,10 +28,6 @@ import com.moral.common.exception.BusinessException; 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; @@ -42,6 +35,12 @@ 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 { @@ -56,6 +55,88 @@ @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); + String regionCode = getRegionCodeByAccount(account); + if (!ObjectUtils.isEmpty(regionCode)) + result.put("regionCode", regionCode); + 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); + 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 Map<String, Object> screenLogin(Map<String, Object> parameters) { @@ -229,12 +310,16 @@ @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"); @@ -283,4 +368,93 @@ 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; + } + + @Resource + DictionaryDataMapper dictionaryDataMapper; + + @Override + public Map<String, Object> bsWebLogin(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; + } + + /** + * @Description: ������id������������������������������ + * @Param: [params] + * @return: java.util.Map<java.lang.String , java.lang.Object> + * @Author: ������������ + * @Date: 2020/11/25 + */ + private String getRegionCodeByAccount(Account account) { + Organization organization = new Organization(); + organization.setId(account.getOrganizationId()); + organization = organizationMapper.selectOne(organization); + Map<String, Object> regionCodeAndType = getRegionCodeAndTypeByOrg(organization); + if (ObjectUtils.isEmpty(regionCodeAndType)) + return null; + return (String) regionCodeAndType.get("regionCode"); + } + + public Map<String, Object> getRegionCodeAndTypeByOrg(Organization organization) { + Map<String, Object> result = new HashMap<>(); + String regionCode = ""; + String regionType = ""; + Long villageCode = organization.getVillageCode(); + Long townCode = organization.getTownCode(); + Integer areaCode = organization.getAreaCode(); + Integer cityCode = organization.getCityCode(); + Integer provinceCode = organization.getProvinceCode(); + + if (!ObjectUtils.isEmpty(villageCode)) { + regionCode = String.valueOf(villageCode); + regionType = "village"; + } else if (!ObjectUtils.isEmpty(townCode)) { + regionCode = String.valueOf(townCode); + regionType = "town"; + } else if (!ObjectUtils.isEmpty(areaCode)) { + regionCode = String.valueOf(areaCode); + regionType = "area"; + } else if (!ObjectUtils.isEmpty(cityCode)) { + regionCode = String.valueOf(cityCode); + regionType = "city"; + } else if (!ObjectUtils.isEmpty(provinceCode)) { + regionCode = String.valueOf(provinceCode); + regionType = "province"; + } else { + return null; + } + result.put("regionCode", regionCode); + result.put("regionType", regionType); + return result; + } } + + + -- Gitblit v1.8.0