package com.qianhe.zqcz.zsrw.service.impl;

import com.qianhe.zqcz.jcdw.mapper.ZqczJcdwMapper;
import com.qianhe.zqcz.jcrw.mapper.ZqczJcrwMapper;
import com.qianhe.zqcz.zsrw.domain.ZqczZsrw;
import com.qianhe.zqcz.zsrw.domain.ZqczZsrwQuery;
import com.qianhe.zqcz.zsrw.domain.ZqczZsrwVo;
import com.qianhe.zqcz.zsrw.mapper.ZqczZsrwMapper;
import com.qianhe.zqcz.zsrw.service.ZqczZsrwService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class ZqczZsrwServiceImpl implements ZqczZsrwService {
    @Autowired
    private ZqczZsrwMapper zqczZsrwMapper;
    @Autowired
    private ZqczJcdwMapper zqczJcdwMapper;
    @Autowired
    private ZqczJcrwMapper zqczJcrwMapper;

    /**
     * 分页查询
     */
    @Override
    public List<ZqczZsrwVo> list(ZqczZsrwQuery zqczZsrwQuery) {
        List<ZqczZsrwVo> dataList = zqczZsrwMapper.list(zqczZsrwQuery);
        return dataList;
    }

    /**
     * 查询详情
     */
    @Override
    public ZqczZsrwVo info(Long zsrwid) {
        ZqczZsrwVo info = zqczZsrwMapper.info(zsrwid);
        return info;
    }

    /**
     * 新增
     */
    @Override
    public int add(ZqczZsrw zqczZsrw, String username) {
        zqczZsrw.setCreateBy(username);
        zqczZsrw.setCreateTime(new Date());
        zqczZsrw.setUpdateBy(username);
        return zqczZsrwMapper.add(zqczZsrw);
    }

    /**
     * 修改
     */
    @Override
    public int edit(ZqczZsrw zqczZsrw, String username) {
        zqczZsrw.setUpdateBy(username);
        return zqczZsrwMapper.edit(zqczZsrw);
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int delete(Long[] ids) {
        zqczZsrwMapper.delete(ids);  // 删除直属任务
        zqczJcdwMapper.deleteByZsrwids(ids);  // 删除基层单位
        zqczJcrwMapper.deleteByZsrwids(ids);  // 删除基层任务
        return 1;
    }
}
