package com.zjrs.zwnw.rlzysc.blo.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.mohrss.leaf.core.framework.domain.blo.impl.BLOImpl;
import org.mohrss.leaf.core.framework.persistens.PageResult;
import org.mohrss.leaf.core.framework.persistens.PageUtil;
import org.mohrss.leaf.core.framework.web.exception.AppException;
import com.zjrs.zwnw.rlzysc.blo.SylbtpglBLO;
import com.zjrs.zwnw.rlzysc.dto.SylbtpglQueryDTO;
import com.zjrs.zwnw.rlzysc.dto.SylbtpglUDTO;
import com.zjrs.zwnw.rlzysc.dto.ZjDTO;
import com.zjrs.zwnw.rlzysc.dto.ZjQueryDTO;
import com.zjrs.zwnw.rlzysc.entity.VRsRlzyLbggMapper;
import com.zjrs.zwnw.rlzysc.po.VRsRlzyLbggPO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class SylbtpglBLOimpl extends BLOImpl implements SylbtpglBLO {

    @Resource
    private VRsRlzyLbggMapper vRsRlzyLbggMapper;

    @Override
    public PageResult getSylbtpglList(SylbtpglQueryDTO dto) {
        Page<Map<String, Object>> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<Map<String, Object>> pageResult = (Page) vRsRlzyLbggMapper.getSylbtpglList(page, dto);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
    }

    @Override
    public void updateSylbtpglZdzt(ZjDTO dto) {
        VRsRlzyLbggPO po = new VRsRlzyLbggPO();
        if (StringUtils.isNotBlank(dto.getZjlsh())) {
            po.setRsrlzylbgglsh(dto.getZjlsh().trim());
        }
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dataString = dateFormat.format(date);
        vRsRlzyLbggMapper.updateById(po);
    }

    @Override
    public void delSylbtpglXx(ZjDTO dto) {
        VRsRlzyLbggPO po = new VRsRlzyLbggPO();
        po.setTsyxbz("0");
        vRsRlzyLbggMapper.updateById(po);
    }

    @Override
    public Map getSylbtpglXx(ZjQueryDTO dto) {
        Map<String,Object> res = new HashMap<String,Object>();
        if (StringUtils.isNotBlank(dto.getFlag())){
            res = vRsRlzyLbggMapper.getSylbtpglXx(dto);
        } else {
            throw new AppException("flag参数不能为空");
        }
        return res;
    }

    @Override
    public String saveSylbtpglXx(SylbtpglUDTO dto) {
        VRsRlzyLbggPO po = new VRsRlzyLbggPO();
        BeanUtils.copyProperties(dto, po);
        if (StringUtils.isNotBlank(po.getRsrlzylbgglsh())){
            //修改
            vRsRlzyLbggMapper.updateById(po);
        }else{
            //新增
            vRsRlzyLbggMapper.insert(po);
        }
        return po.getRsrlzylbgglsh();
    }
}
