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.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.moral.common.bean.ResultBean; import com.moral.common.exception.BusinessException; import com.moral.common.util.Crypto; 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; @Service public class AccountServiceImpl implements AccountService { @Autowired private AccountMapper accountMapper; @Autowired private OrganizationService organizationService; @Override public Map screenLogin(Map parameters) { Map result = new HashMap(); AccountExample example = new AccountExample(); String password = md5((String) parameters.get("account")); example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password); List accounts = accountMapper.selectByExample(example); if (isEmpty(accounts) || accounts.size() != 1) { result.put("msg", "用户名及密码输入错误!"); } else { Account account = accounts.get(0); if (IS_DELETE_FALSE.equals(account.getIsDelete())) { result.put("msg", "登录成功!"); result.put("accountId", account.getId()); } else { result.put("msg","您的账号已禁用,请联系管理员!"); } } return result; } @Override public ResultBean screenLogin1(Map parameters) { ResultBean resultBean = new ResultBean(); AccountExample example = new AccountExample(); String password = Crypto.md5((String) parameters.get("password")); example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password); List 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; } @Override public List getAccountLists(String accountName, String password) { AccountExample example = new AccountExample(); example.or().andAccountNameEqualTo(accountName).andPasswordEqualTo(password); return accountMapper.selectByExample(example); } @Override public List getAccountList(String accountName) { AccountExample example = new AccountExample(); example.or().andAccountNameEqualTo(accountName); return accountMapper.selectByExample(example); } @Override public void setOrgIdsByAccount(Map parameters) { String accountId = (String) parameters.get("accountId"); accountId = accountId.replaceFirst("-", ""); if (!isNumeric((String) parameters.get("accountId"))) { throw new BusinessException("accountId 参数不合法!"); } 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 orgIds = organizationService.getChildOrganizationIds(orgId); parameters.put("orgIds", orgIds); } } }