package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.MallUserAction;
import com.iformall.domain.vo.MallUserActionVo;
import com.iformall.mapper.MallUserActionMapper;
import com.iformall.service.MallUserActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

import java.util.Date;

@Service
public class MallUserActionServiceImpl implements MallUserActionService {
	
	@Autowired
    MallUserActionMapper mallUserActionMapper;

    @Override
    public PageInfo<MallUserActionVo> listAsPage(MallUserActionVo record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> mallUserActionMapper.findListVo(record));
    }

    @Override
    public MallUserAction getById(Long id) {
        return mallUserActionMapper.selectById(id);
    }

    @Override
    public void saveOrUpdate(MallUserAction record) {
        if (record.getId() == null) {
            //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            final IdWorker idWorker = IdWorker.get();
        	record.setId(idWorker.nextId());
            mallUserActionMapper.insert(record);
        } else {
            mallUserActionMapper.updateById(record);
        }
    }

    @Override
    public void saveActionInfo(String tenantId, Integer actionType, String ipAddress, Long userId, String actionDesc) {
        MallUserAction record = new MallUserAction();
        final IdWorker idWorker = IdWorker.get();
        record.setId(idWorker.nextId());
        record.setTenantId(tenantId);
        record.setType(actionType);
        record.setIp(ipAddress);
        record.setUserId(userId);
        record.setActionDesc(actionDesc);
        record.setActionTime(new Date());
        mallUserActionMapper.insert(record);
    }

    @Override
    public void deleteById(Long id) {
        mallUserActionMapper.deleteById(id);
    }
    
    
    
    
    
    
    
    
}
