package com.elephant.framework.galaxy.aroad.module.zhjg.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.ZhjgDckhRw;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.ZhjgDckhRwFf;
import com.elephant.framework.galaxy.aroad.module.zhjg.mapper.ZhjgDckhRwFfMapper;
import com.elephant.framework.galaxy.aroad.module.zhjg.mapper.ZhjgDckhRwMapper;
import com.elephant.framework.galaxy.aroad.module.zhjg.service.ZhjgDckhRwService;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 督查情况任务表
 *
 * @author zyw
 * @date 2019-03-15 16:58:24
 */
@Service
public class ZhjgDckhRwServiceImpl extends ServiceImpl<ZhjgDckhRwMapper, ZhjgDckhRw> implements ZhjgDckhRwService {

    @Autowired
    private  ZhjgDckhRwFfMapper zhjgDckhRwFfMapper;

    @Override
    public IPage selectRwForPage(Page page,ZhjgDckhRw zhjgDckhRw,Integer loginDeptId) {

        return baseMapper.selectRwForPage(page,zhjgDckhRw,loginDeptId);
    }

    @Override
    public boolean downloadById(Integer id) {
        ZhjgDckhRw dckhRw = baseMapper.selectById(id);
        int rwnum=0;
        if (dckhRw!=null){
            dckhRw.setRwzt("1");
            dckhRw.setXfsj(LocalDateTime.now());
            rwnum =  baseMapper.updateById(dckhRw);
        }
        if(dckhRw.getCydw()!=null){
            String[] cydwmc = dckhRw.getCydw().split(",");
            for (int i = 0; i <cydwmc.length ; i++) {
                ZhjgDckhRwFf rwff = new ZhjgDckhRwFf();
                rwff.setRwid(id);
                rwff.setRwmc(cydwmc[i]);

                rwff.setZt("1");
                rwff.setCreateTime(LocalDateTime.now());
                zhjgDckhRwFfMapper.insert(rwff);
            }
        }


        if (rwnum>0){
            return true;
        }else {
            return false;
        }

    }
}
