package com.sptg.estate.biz.service.impl;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.estate.api.dto.BillsDto;
import com.sptg.estate.api.entity.Bills;
import com.sptg.estate.api.entity.Car;
import com.sptg.estate.biz.mapper.BillsMapper;
import com.sptg.estate.biz.service.IBillsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lianghanqiang
 * @since 2021-01-19
 */
@Service
public class BillsServiceImpl extends ServiceImpl<BillsMapper, Bills> implements IBillsService {

    @Override
    public ResultBean<Page<Bills>> page(BillsDto dto) {
        Wrapper<Bills> wrapper = new EntityWrapper<>();
        if (dto.getOrgPosition()!=null){
            wrapper.like("org_position",dto.getOrgPosition(), SqlLike.DEFAULT);
        }
        //过滤删除
        wrapper.eq("is_del", 0);
        //社区
        wrapper.like(dto.getAgencyName() != null,"agency_name",dto.getAgencyName(), SqlLike.DEFAULT);
        //小区
        wrapper.like(dto.getResidentialName() != null,"residential_name",dto.getResidentialName(),SqlLike.DEFAULT);
        //楼栋
        wrapper.like(dto.getBuildingName() != null,"building_name",dto.getBuildingName(), SqlLike.DEFAULT);
        //单元
        wrapper.like(dto.getUnitName() != null,"unit_name",dto.getUnitName(), SqlLike.DEFAULT);
        //楼层
        wrapper.like(dto.getFloorName() != null,"floor_name",dto.getFloorName(),SqlLike.DEFAULT);
        //根据时间日期
        wrapper.eq(dto.getBillsDate() != null,"bills_date",dto.getBillsDate());
        //根据支付状态
        wrapper.eq(dto.getStatus() != null,"status",dto.getStatus());
        return new ResultBean<>(ResultEnum.SUCCESS,this.selectPage(dto.getPage(),wrapper));
    }

    @Override
    public ResultBean<Boolean> add(BillsDto billsDto) {
        return new ResultBean<>(ResultEnum.SUCCESS,this.insert(billsDto));
    }

    @Override
    public ResultBean<Boolean> edit(BillsDto billsDto) {
        return new ResultBean<>(ResultEnum.SUCCESS,this.updateById(billsDto));
    }

    @Override
    public ResultBean<Boolean> delete(BillsDto billsDto) {
        Bills bills = this.selectById(billsDto.getId());
        Assert.notNull(bills,"选择的账单不存在");
        bills.setIsDel(1);
        return new ResultBean<>(ResultEnum.SUCCESS,this.updateById(bills));
    }
}
