package cn.superdesk.uniorder.service.thirdpart.szhtxx.electronicInvoice.impl;

import cn.superdesk.uniorder.common.enums.common.CommonSoftDeleteEnum;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxx;
import cn.superdesk.uniorder.dao.entity.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxExample;
import cn.superdesk.uniorder.dao.mapper.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxMapper;
import cn.superdesk.uniorder.dao.mapper.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxMapperEx;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxQueryCriteria;
import cn.superdesk.uniorder.dto.vo.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxListItemVo;
import cn.superdesk.uniorder.service.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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: 2022-01-24 11:50:43
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022-01-24 11:50:43
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class SzhtxxElectronicInvoiceFptxxXmxxServiceImpl implements SzhtxxElectronicInvoiceFptxxXmxxService {

    @Autowired
    private SzhtxxElectronicInvoiceFptxxXmxxMapper   szhtxxElectronicInvoiceFptxxXmxxMapper;
    @Autowired
    private SzhtxxElectronicInvoiceFptxxXmxxMapperEx szhtxxElectronicInvoiceFptxxXmxxMapperEx;


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

    @Override
    public int insertSelective(SzhtxxElectronicInvoiceFptxxXmxx entity) {
        return szhtxxElectronicInvoiceFptxxXmxxMapper.insertSelective(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(SzhtxxElectronicInvoiceFptxxXmxx entity) {
        return szhtxxElectronicInvoiceFptxxXmxxMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void deleteObj(Long id) {
    }

    public int opUpdateLogicalTemp2Normal(String batchId, String fpqqlsh, LoginSysUser loginSysUser) {

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

        criteria
                .andBatchIdEqualTo(batchId)
                .andFpqqlshEqualTo(fpqqlsh)
                .andDeletedEqualTo(CommonSoftDeleteEnum.临时.getKey());

        return szhtxxElectronicInvoiceFptxxXmxxMapper.updateByExampleSelective(
                SzhtxxElectronicInvoiceFptxxXmxx
                        .builder()
                        .deleted(CommonSoftDeleteEnum.正常.getKey())
                        .build(),
                example
        );

    }

    public int opLogicalDelete(String batchId, String fpqqlsh, LoginSysUser loginSysUser) {

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

        criteria
                .andFpqqlshEqualTo(fpqqlsh)
                .andDeletedEqualTo(CommonSoftDeleteEnum.正常.getKey())
                .andBatchIdNotEqualTo(batchId);

        return szhtxxElectronicInvoiceFptxxXmxxMapper.updateByExampleSelective(
                SzhtxxElectronicInvoiceFptxxXmxx.builder().deleted(CommonSoftDeleteEnum.删除.getKey()).build(),
                example
        );

    }

    @Override
    public SzhtxxElectronicInvoiceFptxxXmxx findById(Long id) {
        return szhtxxElectronicInvoiceFptxxXmxxMapper.selectByPrimaryKey(id);
    }

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

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

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


    public void addSzhtxxElectronicInvoiceFptxxXmxx(SzhtxxElectronicInvoiceFptxxXmxx entity) {
        szhtxxElectronicInvoiceFptxxXmxxMapper.insertSelective(entity);
    }

    public int insertBatch(List<SzhtxxElectronicInvoiceFptxxXmxx> processList) {
        return szhtxxElectronicInvoiceFptxxXmxxMapperEx.insertBatch(processList);
    }

    public void updateSzhtxxElectronicInvoiceFptxxXmxx(SzhtxxElectronicInvoiceFptxxXmxx entity) {
        SzhtxxElectronicInvoiceFptxxXmxx originEntity = szhtxxElectronicInvoiceFptxxXmxxMapper.selectByPrimaryKey(entity.getId());
//		AssertUtil.notNull(originEntity);
        AnBeanUtils.copy(entity, originEntity);
        szhtxxElectronicInvoiceFptxxXmxxMapper.updateByPrimaryKey(originEntity);
    }

    public void deleteSzhtxxElectronicInvoiceFptxxXmxx(Long id) {
        szhtxxElectronicInvoiceFptxxXmxxMapper.deleteByPrimaryKey(id);
    }

    public SzhtxxElectronicInvoiceFptxxXmxx findSzhtxxElectronicInvoiceFptxxXmxxById(Long id) {
        SzhtxxElectronicInvoiceFptxxXmxx entity = szhtxxElectronicInvoiceFptxxXmxxMapper.selectByPrimaryKey(id);
//		AssertUtil.notNull(entity);
        return entity;
    }

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

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

        // TODO 喜欢用Map 还是 Bean 自己喜欢... 后期添加 转 SzhtxxElectronicInvoiceFptxxXmxxExample.Criteria
        // SzhtxxElectronicInvoiceFptxxXmxx szhtxxElectronicInvoiceFptxxXmxxConditions = BeanUtils.mapToBean(conditions,SzhtxxElectronicInvoiceFptxxXmxx.class);

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

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

    }

    public R<List<SzhtxxElectronicInvoiceFptxxXmxx>> pageQueryGenericParam(SzhtxxElectronicInvoiceFptxxXmxxQueryCriteria queryCriteria) {

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

        // TODO 添加条件... 后期添加 queryCriteria 转 SzhtxxElectronicInvoiceFptxxXmxxExample.Criteria

        PageHelper.startPage(queryCriteria.getPageNumber(), queryCriteria.getPageSize());
        List<SzhtxxElectronicInvoiceFptxxXmxx>     resultList = szhtxxElectronicInvoiceFptxxXmxxMapper.selectByExample(example);
        PageInfo<SzhtxxElectronicInvoiceFptxxXmxx> page       = new PageInfo<SzhtxxElectronicInvoiceFptxxXmxx>(resultList);
        PageHelper.clearPage();

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

    }

    public List<SzhtxxElectronicInvoiceFptxxXmxxListItemVo> queryGenericParam(SzhtxxElectronicInvoiceFptxxXmxxQueryCriteria queryCriteria, LoginSysUser loginSysUser) {

        List<SzhtxxElectronicInvoiceFptxxXmxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxXmxxMapperEx.queryGenericParam(queryCriteria);
        return resultList;
    }
}
