package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.MallResource;
import com.iformall.mapper.MallResourceMapper;
import com.iformall.service.MallResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

@Service
public class MallResourceServiceImpl implements MallResourceService {
	
	@Autowired
    MallResourceMapper mallResourceMapper;


    @Override
    public PageInfo<MallResource> listAsPage(MallResource record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> mallResourceMapper.findList(record));
    }

    @Override
    public MallResource getById(Long id) {
        return mallResourceMapper.selectById(id);
    }

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

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