package cn.com.ty.lift.business.capital.service;

import cn.com.ty.lift.business.capital.dao.entity.CapitalRepairLiftRelevance;
import cn.com.ty.lift.business.capital.dao.entity.model.request.CapitalRepairRequest;
import cn.com.ty.lift.business.capital.dao.mapper.CapitalRepairLiftRelevanceMapper;
import cn.com.ty.lift.business.common.CommonRequest;
import cn.com.ty.lift.business.library.dao.entity.model.request.LiftExtensionRequest;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author bieao
 * @date 2020/4/15
 * @description 大修电梯业务层
 */
@Service
public class CapitalRepairLiftRelevanceService extends ServiceImpl<CapitalRepairLiftRelevanceMapper, CapitalRepairLiftRelevance> {

    /**
     * @param request 项目id，公司id，维保工id
     * @param liftId 电梯id
     * @return 是否成功
     * @description 新增大修项目和电梯关联
     * @date 2020/4/15 10:18 上午
     */
    public boolean save(LiftExtensionRequest request, long liftId) {
        //新增大修项目电梯关联表
        CapitalRepairLiftRelevance relevance = new CapitalRepairLiftRelevance();
        relevance.setProjectId(request.getProjectId());
        relevance.setLiftId(liftId);
        relevance.setWorkerId(request.getWorkerId());
        relevance.setMtCompanyId(request.getMtCompanyId());
        return save(relevance);
    }

    /**
     * @param request 项目id，项目电梯关联id列表
     * @return 1.成功, 0.失败, 消息描述
     * @description 批量移动电梯
     * @date 2020/1/7 7:57 下午
     */
    public boolean move(CapitalRepairRequest request) {
        List<CapitalRepairLiftRelevance> list = request.getList();
        list.forEach(entry -> entry.setProjectId(request.getProjectId()));
        return updateBatchById(list, list.size());
    }

    /**
     * @param list 项目电梯关联列表
     * @return 是否成功
     * @description 批量插入项目电梯关联表
     * @date 2020/5/9 10:36 上午
     */
    public boolean insertBatch(List<CapitalRepairLiftRelevance> list) {
        return saveBatch(list, list.size());
    }

    /**
     * @param mtCompanyId   公司id
     * @param projectStatus 项目状态
     * @return 条数
     * @description 根据公司id和项目状态查询电梯
     * @date 2020/4/23 3:44 下午
     */
    public int count(Long mtCompanyId, String projectStatus) {
        return baseMapper.count(mtCompanyId, projectStatus);
    }

    /**
     * @param request 公司id，用户id
     * @return 条数
     * @description 根据公司id和用户id查询大修项目数量
     * @date 2020/4/24 2:49 下午
     */
    public long countDoingByUser(CommonRequest request) {
        return baseMapper.countDoingByUser(request);
    }
}
