| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | |
|
| | | 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 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) {
|
| | |
| | | @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");
|
| | |
| | | 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;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|