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


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.util.CurrentUser;
import com.zjrs.zwnw.psam.blo.PsamAzjgwhBLO;
import com.zjrs.zwnw.psam.dto.PsamAzjgDTO;
import com.zjrs.zwnw.psam.dto.PsamQueryFjDTO;
import com.zjrs.zwnw.psam.entity.RsPsamAzjgxxMapper;
import com.zjrs.zwnw.psam.po.RsPsamAzjgxxPO;
import org.springframework.stereotype.Service;

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

/**
 *
 * @author liangxiudong
 * @since 2021-04-07
 */
@Service
public class PsamAzjgwhBLOImpl extends BLOImpl implements PsamAzjgwhBLO {
    @Resource
    private RsPsamAzjgxxMapper rsPsamAzjgxxMapper;
    @Override
    public PageResult getList(PsamAzjgDTO dto, int page, int rows) {
        Page<RsPsamAzjgxxPO> page1 = new Page<>(page, rows);
        Page<RsPsamAzjgxxPO> pageResult = (Page) rsPsamAzjgxxMapper.getList(page1, dto);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
    }

    @Override
    public RsPsamAzjgxxPO getInfo(PsamQueryFjDTO dto) {
        return rsPsamAzjgxxMapper.getInfo(dto);
    }

    @Override
    public void saveData(RsPsamAzjgxxPO rsPsamAzjgxxPO) {
        CurrentUser currentUser = getCurrentUser();
        String userid = currentUser.getUserid() == null ? "" : currentUser.getUserid().trim();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowDate = dateFormat.format(date);
        if (StringUtils.isNotBlank(rsPsamAzjgxxPO.getRsPsamAzjgxxLsh())) {
            //更新
            rsPsamAzjgxxPO.setZhxgsj(nowDate);
            UpdateWrapper<RsPsamAzjgxxPO> updateWrapper=new UpdateWrapper<>();
            updateWrapper.eq("RS_PSAM_AZJGXX_LSH",rsPsamAzjgxxPO.getRsPsamAzjgxxLsh());
            rsPsamAzjgxxMapper.update(rsPsamAzjgxxPO,updateWrapper);
        }else{
            rsPsamAzjgxxMapper.insert(rsPsamAzjgxxPO);
        }
    }
}
