package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.PosOrder;
import com.iformall.mapper.PosOrderMapper;
import com.iformall.service.PosOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

@Service
public class PosOrderServiceImpl implements PosOrderService {
	
	@Autowired
    PosOrderMapper posOrderMapper;


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

    @Override
    public PosOrder getById(Long id) {
        return posOrderMapper.selectById(id);
    }

    @Override
    public void saveOrUpdate(PosOrder record) {
        if (record.getId() == null) {
            final IdWorker idWorker = IdWorker.get();
        	record.setId(idWorker.nextId());
        	record.setPosOrderNo(String.valueOf(record.getId()));
        	if (record.getPayment() != null) {
        	    record.setRemainAmount(record.getPayment());
            }
            posOrderMapper.insert(record);
        } else {
            posOrderMapper.updateById(record);
        }
    }

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