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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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 com.zjrs.zwnw.dbgl.blo.DbrwclPLO;
import com.zjrs.zwnw.dbgl.blo.GzqdglPLO;
import com.zjrs.zwnw.dbgl.dto.*;
import com.zjrs.zwnw.dbgl.entity.DbxmGzqdMapper;
import com.zjrs.zwnw.dbgl.entity.DbxmMapper;
import com.zjrs.zwnw.dbgl.entity.GzqdMapper;
import com.zjrs.zwnw.dbgl.po.RsdbgldbxmgzqdPO;
import com.zjrs.zwnw.dbgl.po.RsdbglgzqdPO;
import com.zjrs.zwnw.portal.blo.CommonBLO;
import com.zjrs.zwnw.portal.entity.VSSgOrgMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.Map;


/**
 * @Author chenzhibiao
 * @create 2022/6/30 8:43
 */
@Service
public class GzqdglimplPLO extends BLOImpl implements GzqdglPLO {
    @Resource
    private GzqdMapper gzqdMapper;
    @Resource
    private CommonBLO commonBLO;
    @Resource
    private DbrwclPLO dbrwclPLO;
    @Resource
    private VSSgOrgMapper vSSgOrgMapper;
    @Resource
    private DbxmMapper dbxmMapper;
    @Resource
    private DbxmGzqdMapper dbxmGzqdMapper;



    @Override
    public PageResult getGzqdglList(DbrwglGzqdglQueryDTO dto, Integer pagenum, Integer pagesize){
        Page<Map<String, Object>> page = new Page<>(dto.getPagenum(), dto.getPagesize());

        Page<Map<String, Object>> pageResult = (Page) gzqdMapper.getGzqdglList(page,dto);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
    }

    @Override
    public RsdbglgzqdPO getGzqdById(DbrwglCommDTO dto){
        return this.gzqdMapper.selectById(dto.getIds());
    }
    @Override
    public String saveGzqd(DbrwglGzqdUDTO dto){
        RsdbglgzqdPO po = new RsdbglgzqdPO();
        BeanUtils.copyProperties(dto, po);
        if(StringUtils.isBlank(dto.getRsdbglgzqdlsh())){//新增
            this.gzqdMapper.insert(po);
            System.out.println("insert----"+po.getRsdbglgzqdlsh());
            //2023-01-03变更、新增时自动选择该工作清单
            DbrwglDbrwclGzqdxzDTO dbrwglDbrwclGzqdxzDTO = new DbrwglDbrwclGzqdxzDTO();
            dbrwglDbrwclGzqdxzDTO.setRsdbglgzqdlsh(po.getRsdbglgzqdlsh());
            dbrwclPLO.updateGzqdXz(dbrwglDbrwclGzqdxzDTO);
        }else{
            po.setShzt("0");//修改时置为未审核
            this.gzqdMapper.updateById(po);
        }
        return po.getRsdbglgzqdlsh();

    }

    @Override
    public void delGzqd(DbrwglCommDTO dto){
        //若该工作清单已关联督办项目，则不允许删除，提示“该工作清单已关联督办项目，不允许删除。”。
        QueryWrapper<RsdbgldbxmgzqdPO> queryWrapper = new QueryWrapper<RsdbgldbxmgzqdPO>();
        RsdbglgzqdPO po = new RsdbglgzqdPO();
        po.setTsyxbz("0");
        this.gzqdMapper.updateById(po);
    }
    @Override
    public PageResult getDbrwListByGzqdid(DbrwglCommQueryDTO dto, Integer pagenum, Integer pagesize){
        Page<Map<String, Object>> page = new Page<>(pagenum, pagesize);
        Page<Map<String, Object>> pageResult = (Page) gzqdMapper.getDbrwListByGzqdid(page,dto);
        PageResult result = PageUtil.PageResult(pageResult);
        return result;
    }

}
