package cn.superdesk.uniorder.service.order._leaveover.impl;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.order.BankRecord;
import cn.superdesk.uniorder.dao.mapper.order.BankRecordMapper;
import cn.superdesk.uniorder.service.order._leaveover.BankRecordService;
import cn.superdesk.uniorder.service.setting.UnifiedSnConfigService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

@Service
public class BankRecordServiceImpl implements BankRecordService {

    @Autowired
    private BankRecordMapper bankRecordMapper;

    //	@Autowired
//	private SysConfigService sysConfigService;
    @Autowired
    private UnifiedSnConfigService unifiedSnConfigService;


    @Transactional
    @Override
    public int insertSelective(BankRecord t) {

//		Map<String, Object> codeMap = sysConfigService.getBanckNo();

//		t.setSn(codeMap.get("sn").toString());

        t.setSn(unifiedSnConfigService.getBankRecordSnBySnowflake());

        return bankRecordMapper.insert(t);

        // 更新账单号
//		SysConfig sysConfig = new SysConfig();
//
//		sysConfig.setCode(codeMap.get("key").toString());
//		sysConfig.setValueDate(new Date((Long) (codeMap.get("valueDate"))));
//		sysConfig.setValueInt(Integer.parseInt(codeMap.get("valueInt").toString()));
//
//		sysConfigService.updateSysConfig(sysConfig);
    }

    @Override
    public int updateByPrimaryKeySelective(BankRecord t) {
        return 0;

    }

    @Override
    public void deleteObj(Long id) {


    }

    @Override
    public BankRecord findById(Long id) {

        return null;
    }


    @Override
    public List<BankRecord> findAll(Map<String, Object> queryMap) {

        return bankRecordMapper.findAll(queryMap);
    }

    @Override
    public PageInfo<BankRecord> findByPaging(Map<String, Object> params, Integer pageNo, Integer pageSize) {

        return null;
    }

    @Override
    public R<List<BankRecord>> findAllByPage(Map<String, Object> params, int pageNo, int pageSize) {

        PageHelper.startPage(pageNo, pageSize);
        List<BankRecord>     ls   = bankRecordMapper.findAll(params);
        PageInfo<BankRecord> page = new PageInfo<BankRecord>(ls);
        PageHelper.clearPage();
        return new R<List<BankRecord>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), ls);
    }

    @Override
    public List<String> findBank() {

        return bankRecordMapper.findBank();
    }

}
