Package com.eatle.service.system.systemdata.impl

Source Code of com.eatle.service.system.systemdata.impl.LoginLogServiceImpl

package com.eatle.service.system.systemdata.impl;

import com.eatle.common.Constants;
import com.eatle.persistent.mapper.CustomerMapper;
import com.eatle.persistent.mapper.LoginLogMapper;
import com.eatle.persistent.mapper.UserMapper;
import com.eatle.persistent.pojo.system.systemdata.LoginLog;
import com.eatle.persistent.pojo.system.systemdata.LoginLogCriteria.Criteria;
import com.eatle.persistent.pojo.system.systemdata.LoginLogCriteria;
import com.eatle.persistent.pojo.system.useradmin.User;
import com.eatle.service.system.systemdata.ILoginLogService;
import com.eatle.utils.Pagination;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("loginLogService")
public class LoginLogServiceImpl implements ILoginLogService
{
  @Resource
  private LoginLogMapper loginLogMapper;

  @Resource
  private UserMapper userMapper;
 
  @Resource
  private CustomerMapper customerMapper;
 
  @Resource
  private Map<String, String> identityStr;
 
  @Resource
  private Map<String, String> identityHtml;

  @Override
  public int add(LoginLog entity)
  {
    return loginLogMapper.insert(entity);
  }

  @Override
  public int delete(LoginLog entity)
  {
    return loginLogMapper.deleteByPrimaryKey(entity.getId());
  }

  @Override
  public int update(LoginLog entity)
  {
    return loginLogMapper.updateByPrimaryKeySelective(entity);
  }

  @Override
  public Pagination findPagination(Map<String, Object> queryMap,
      int currentPage, int pageSize) throws ParseException
  {
    LoginLogCriteria loginLogCriteria = new LoginLogCriteria();
    Criteria criteria = loginLogCriteria.createCriteria();
    // 设置搜索条件参数
    if (queryMap != null)
    {
      if (queryMap.containsKey("userName"))
      {
        User user = new User();
        user.setUserName((String) queryMap.get("userName"));
        user = userMapper.find(user);
        if(user != null)
        {
          criteria.andIdentifyIdEqualTo(user.getId());
        }
      }
      if (queryMap.containsKey("startTime"))
      {
        if(queryMap.containsKey("endTime"))
        {
          criteria.andLoginTimeBetween(
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) queryMap.get("startTime")),
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) queryMap.get("endTime")));
        }
        else
        {
          criteria.andLoginTimeBetween(
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) queryMap.get("startTime")),
            new Date());
        }
      }
      if(queryMap.containsKey("identifyType"))
      {
        criteria.andIdentifyTypeEqualTo(Short.parseShort((String) queryMap.get("identifyType")));
      }
    }
    // 设置分页参数
    loginLogCriteria.setPageSize(pageSize);
    loginLogCriteria.setStartIndex((currentPage - 1) * pageSize);
    List<LoginLog> items = loginLogMapper.selectByCriteria(loginLogCriteria);
    for(LoginLog loginLog : items)
    {
      // 登陆用户名
      if(loginLog.getIdentifyType() != Constants.Identity.IDENTITY_CUSTOMER)
        loginLog.setUserName(userMapper.selectByPrimaryKey(loginLog.getIdentifyId()).getUserName());
      else
        loginLog.setUserName(customerMapper.selectByPrimaryKey(loginLog.getIdentifyId()).getLoginEmail());
      // 登陆身份类型
      loginLog.setIdentifyTypeStr(identityHtml.get("" + loginLog.getIdentifyType()));
      // 登陆时间
      loginLog.setLoginTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(loginLog.getLoginTime()));
    }
    int totalCount = (int) loginLogMapper.selectCountByCriteria(loginLogCriteria);
    return new Pagination(pageSize, currentPage, totalCount, items);
  }

  @Override
  public LoginLog findById(long id)
  {
    return loginLogMapper.selectByPrimaryKey(id);
  }

  @Override
  public List<LoginLog> findAll()
  {
    return loginLogMapper.selectByCriteria(null);
  }

  @Override
  public List<LoginLog> findByCriteria(LoginLogCriteria criteria)
  {
    return loginLogMapper.selectByCriteria(criteria);
  }

  @SuppressWarnings("unchecked")
  @Override
  public LinkedHashMap<String, List> getExportData()
  {
    LinkedHashMap<String, List> map = new LinkedHashMap<String, List>();
    List<LoginLog> dataList = findAll();
    for(LoginLog loginLog : dataList)
    {
      // 登陆用户名
      if(loginLog.getIdentifyType() != Constants.Identity.IDENTITY_CUSTOMER)
        loginLog.setUserName(userMapper.selectByPrimaryKey(loginLog.getIdentifyId()).getUserName());
      else
        loginLog.setUserName(customerMapper.selectByPrimaryKey(loginLog.getIdentifyId()).getLoginEmail());
      // 登陆身份类型
      loginLog.setIdentifyTypeStr(identityStr.get("" + loginLog.getIdentifyType()));
      // 登陆时间
      loginLog.setLoginTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(loginLog.getLoginTime()));
    }
    map.put("登陆日志", dataList);
    return map;
  }
}
TOP

Related Classes of com.eatle.service.system.systemdata.impl.LoginLogServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.