package cn.superdesk.uniorder.service.accounting.unified.customer.impl;

import cn.superdesk.uniorder.common.exception.utils.AssertUtils;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.accounting.unified.customer.AccountingUnifiedCustomerOrderGoods;
import cn.superdesk.uniorder.dao.entity.accounting.unified.customer.AccountingUnifiedCustomerOrderGoodsExample;
import cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerOrderGoodsMapper;
import cn.superdesk.uniorder.service.accounting.unified.customer.AccountingUnifiedCustomerOrderGoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2021-01-06 17:46:38
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021-01-06 17:46:38
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class AccountingUnifiedCustomerOrderGoodsServiceImpl implements AccountingUnifiedCustomerOrderGoodsService {

    @Autowired
    private AccountingUnifiedCustomerOrderGoodsMapper accountingUnifiedCustomerOrderGoodsMapper;


    /****************************************** extends BaseService 部分 start ******************************************/

    @Override
    public int insertSelective(AccountingUnifiedCustomerOrderGoods entity) {
        return accountingUnifiedCustomerOrderGoodsMapper.insert(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(AccountingUnifiedCustomerOrderGoods entity) {
        return accountingUnifiedCustomerOrderGoodsMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void deleteObj(Long id) {
    }

    @Override
    public void deleteByAccountingUnifiedCustomerOrderId(Long accountingUnifiedCustomerOrderId) {

        AccountingUnifiedCustomerOrderGoodsExample deleteByExample = new AccountingUnifiedCustomerOrderGoodsExample();
        deleteByExample.createCriteria()
                .andDzOrderIdEqualTo(accountingUnifiedCustomerOrderId);
        accountingUnifiedCustomerOrderGoodsMapper.deleteByExample(deleteByExample);

    }

    @Override
    public AccountingUnifiedCustomerOrderGoods findById(Long id) {
        return accountingUnifiedCustomerOrderGoodsMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<AccountingUnifiedCustomerOrderGoods> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {
        return null;
    }

    @Override
    public List<AccountingUnifiedCustomerOrderGoods> findAll(Map<String, Object> queryMap) {
        return null;
    }

    /****************************************** extends BaseService 部分   end ******************************************/


    public void addAccountingUnifiedCustomerOrderGoods(AccountingUnifiedCustomerOrderGoods entity) {
        accountingUnifiedCustomerOrderGoodsMapper.insertSelective(entity);
    }

    public void updateAccountingUnifiedCustomerOrderGoods(AccountingUnifiedCustomerOrderGoods entity) {
        AccountingUnifiedCustomerOrderGoods originEntity = accountingUnifiedCustomerOrderGoodsMapper.selectByPrimaryKey(entity.getId());
        AssertUtils.notNull(originEntity);
        AnBeanUtils.copy(entity, originEntity);
        accountingUnifiedCustomerOrderGoodsMapper.updateByPrimaryKey(originEntity);
    }

    public void deleteAccountingUnifiedCustomerOrderGoods(Long id) {
        accountingUnifiedCustomerOrderGoodsMapper.deleteByPrimaryKey(id);
    }

    public AccountingUnifiedCustomerOrderGoods findAccountingUnifiedCustomerOrderGoodsById(Long id) {
        AccountingUnifiedCustomerOrderGoods entity = accountingUnifiedCustomerOrderGoodsMapper.selectByPrimaryKey(id);
        AssertUtils.notNull(entity);
        return entity;
    }

    public R<List<AccountingUnifiedCustomerOrderGoods>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {

        // 样例 保留
//		AccountingUnifiedCustomerOrderGoods accountingUnifiedCustomerOrderGoodsConditions = AnBeanUtils.mapToBean(conditions,AccountingUnifiedCustomerOrderGoods.class);

        AccountingUnifiedCustomerOrderGoodsExample          example  = new AccountingUnifiedCustomerOrderGoodsExample();
        AccountingUnifiedCustomerOrderGoodsExample.Criteria criteria = example.createCriteria();

        PageHelper.startPage(pageNun, pageSize);
        List<AccountingUnifiedCustomerOrderGoods>     resultList = accountingUnifiedCustomerOrderGoodsMapper.selectByExample(example);
        PageInfo<AccountingUnifiedCustomerOrderGoods> page       = new PageInfo<AccountingUnifiedCustomerOrderGoods>(resultList);
        PageHelper.clearPage();

        return new R<List<AccountingUnifiedCustomerOrderGoods>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), resultList);

    }

}