package vip.xiaonuo.money.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.money.entity.MoneyWriteOverdue;
import vip.xiaonuo.money.mapper.MoneyWriteOverdueMapper;
import vip.xiaonuo.money.param.MoneyBusinessPageParam;
import vip.xiaonuo.money.param.MoneyWriteOverdueAddParam;
import vip.xiaonuo.money.service.IMoneyWriteOverdueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 财务应收分析逾期填报 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-26
 */
@Service
public class MoneyWriteOverdueServiceImpl extends ServiceImpl<MoneyWriteOverdueMapper, MoneyWriteOverdue> implements IMoneyWriteOverdueService {

    @Autowired
    private MoneyWriteOverdueMapper writeOverdueMapper;

    @Override
    public CommonResult add(MoneyWriteOverdueAddParam param)  {
        MoneyWriteOverdue writeOverdue = new MoneyWriteOverdue();
        BeanUtil.copyProperties(param, writeOverdue);
        writeOverdue.setCreateTime(new Date());
        writeOverdueMapper.insert(writeOverdue);
        return CommonResult.ok();
    }

    @Override
    public Page<MoneyWriteOverdue> page(MoneyBusinessPageParam pageParam) {
        String orgId = pageParam.getOrgId();
        Integer pageNum = pageParam.getPageNum();
        Integer pageSize = pageParam.getPageSize();
        Page<MoneyWriteOverdue> page = new Page<>(pageNum, pageSize);
        QueryWrapper<MoneyWriteOverdue> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
        return writeOverdueMapper.selectPage(page, queryWrapper);
    }

    @Override
    public CommonResult edit(MoneyWriteOverdue writeOverdue) {
        writeOverdueMapper.updateById(writeOverdue);
        return CommonResult.ok();
    }

    @Override
    public CommonResult delete(Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        writeOverdueMapper.deleteById(id);
        return CommonResult.ok();
    }
}
