LinggangSchedulingServiceImpl.java 12.1 KB
package com.ruoyi.service.impl.scheduling;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ruoyi.domain.OrderEntity;
import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.mapper.scheduling.LinggangSchedulingMapper;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Service
/** Service实现类*/
public class LinggangSchedulingServiceImpl extends ServiceImpl<LinggangSchedulingMapper, LinggangScheduling> implements LinggangSchedulingService {
    @Autowired
    private LinggangSchedulingMapper linggangSchedulingMapper;

    /**
     * 分页查询
     */
    @Override
    public IPage<LinggangScheduling> pageList(Page<LinggangScheduling> page, LinggangScheduling entity, OrderEntity orderEntity) {
        LambdaQueryWrapper<LinggangScheduling> countWrapper = new LambdaQueryWrapper<>(entity);
        countWrapper.select(LinggangScheduling::getId);
        switchScheduleDate(countWrapper,entity);
        int count = count(countWrapper);

        List<LinggangScheduling> lists = Collections.emptyList();
        if (count > 0) {
            PageHelper.startPage((int) page.getCurrent(), (int) page.getSize(), false);
            LambdaQueryWrapper<LinggangScheduling> selectWrapper = new LambdaQueryWrapper<>(entity);
            switchScheduleDate(selectWrapper,entity);
            orderColumn(selectWrapper, orderEntity);
            lists = list(selectWrapper);
        }

        IPage<LinggangScheduling> returnPage = new Page<LinggangScheduling>();
        returnPage.setRecords(lists);
        returnPage.setPages(count % page.getSize() == 0 ? count / page.getSize() : count / page.getSize() + 1);
        returnPage.setCurrent(page.getCurrent());
        returnPage.setSize(page.getSize());
        returnPage.setTotal(count);

        return returnPage;
    }

    @Override
    public List<LinggangScheduling> list(LinggangScheduling entity) {
        return list(new LambdaQueryWrapper<>(entity));
    }

    @Override
    public List<LinggangScheduling> listByCZ(LinggangScheduling entity) {
      return linggangSchedulingMapper.listByCZ(entity);
    }
    // @Override
    // public List<LinggangScheduling> listOfSelect(LinggangScheduling entity) {
    //      LambdaQueryWrapper<LinggangScheduling> wrapper = new LambdaQueryWrapper<>(entity);
    //     wrapper.select(LinggangScheduling::, LinggangScheduling::);
    //      return list(wrapper);
    //  }

    // @Override
    // public List<LinggangScheduling> listOfIds(java.util.Collection<java.lang.Integer> ids) {
    //     if (org.springframework.util.CollectionUtils.isEmpty(ids)) {
    //         return java.util.Collections.emptyList();
    //    }
    //   LambdaQueryWrapper<LinggangScheduling> wrapper = new LambdaQueryWrapper<>();
    //   wrapper.select(LinggangScheduling::getId,LinggangScheduling::);
    //   wrapper.in(LinggangScheduling::getId, ids);
    //   return list(wrapper);
    // }

    @Override
    public LinggangScheduling getOne(LinggangScheduling entity) {
        return getOne(new LambdaQueryWrapper<>(entity));
    }

    @Override
    public Integer countId(LinggangScheduling entity) {
        LambdaQueryWrapper<LinggangScheduling> wrapper = new LambdaQueryWrapper<>(entity);
        switchScheduleDate(wrapper,entity);
        wrapper.select(LinggangScheduling::getId);
        return count(wrapper);
    }


    /**
     * 插入有值的列
     */
    @Override
    public int insertSelective(LinggangScheduling entity) {
        return linggangSchedulingMapper.insertSelective(entity);
    }

    /**
     * 插入数据
     */
    @Override
    public boolean insert(LinggangScheduling entity) {
        return save(entity);
    }

    /**
     * 根据主键修改数据
     */
    @Override
    public boolean updateByPrimaryKey(LinggangScheduling entity) {
        return updateById(entity);
    }

    /***根据主键删除数据*/
    @Override
    public boolean deleteById(Integer id) {
        return removeById(id);
    }


    public static void orderColumn(LambdaQueryWrapper<LinggangScheduling> wrapper, OrderEntity orderEntity) {
        if (org.apache.commons.lang3.StringUtils.equals("ascending", orderEntity.getOrder())) {
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "id")) {
                wrapper.orderByAsc(LinggangScheduling::getId);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "scheduleDate")) {
                wrapper.orderByAsc(LinggangScheduling::getScheduleDate);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "lineName")) {
                wrapper.orderByAsc(LinggangScheduling::getLineName);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "jobCode")) {
                wrapper.orderByAsc(LinggangScheduling::getJobCode);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "name")) {
                wrapper.orderByAsc(LinggangScheduling::getName);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "posts")) {
                wrapper.orderByAsc(LinggangScheduling::getPosts);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "lpName")) {
                wrapper.orderByAsc(LinggangScheduling::getLpName);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "nbbm")) {
                wrapper.orderByAsc(LinggangScheduling::getNbbm);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "bcType")) {
                wrapper.orderByAsc(LinggangScheduling::getBcType);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "fcsjT")) {
                wrapper.orderByAsc(LinggangScheduling::getFcsjT);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "zdsjT")) {
                wrapper.orderByAsc(LinggangScheduling::getZdsjT);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "signInId")) {
                wrapper.orderByAsc(LinggangScheduling::getSignInId);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "exType")) {
                wrapper.orderByAsc(LinggangScheduling::getExType);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "signTime")) {
                wrapper.orderByAsc(LinggangScheduling::getSignTime);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "signType")) {
                wrapper.orderByAsc(LinggangScheduling::getSignType);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "alcoholFlag")) {
                wrapper.orderByAsc(LinggangScheduling::getAlcoholFlag);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "alcoholIntake")) {
                wrapper.orderByAsc(LinggangScheduling::getAlcoholIntake);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "remark")) {
                wrapper.orderByAsc(LinggangScheduling::getRemark);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "keyInfoId")) {
                wrapper.orderByAsc(LinggangScheduling::getKeyInfoId);
            }
        } else if (org.apache.commons.lang3.StringUtils.equals("descending", orderEntity.getOrder())) {
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "id")) {
                wrapper.orderByDesc(LinggangScheduling::getId);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "scheduleDate")) {
                wrapper.orderByDesc(LinggangScheduling::getScheduleDate);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "lineName")) {
                wrapper.orderByDesc(LinggangScheduling::getLineName);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "jobCode")) {
                wrapper.orderByDesc(LinggangScheduling::getJobCode);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "name")) {
                wrapper.orderByDesc(LinggangScheduling::getName);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "posts")) {
                wrapper.orderByDesc(LinggangScheduling::getPosts);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "lpName")) {
                wrapper.orderByDesc(LinggangScheduling::getLpName);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "nbbm")) {
                wrapper.orderByDesc(LinggangScheduling::getNbbm);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "bcType")) {
                wrapper.orderByDesc(LinggangScheduling::getBcType);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "fcsjT")) {
                wrapper.orderByDesc(LinggangScheduling::getFcsjT);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "zdsjT")) {
                wrapper.orderByDesc(LinggangScheduling::getZdsjT);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "signInId")) {
                wrapper.orderByDesc(LinggangScheduling::getSignInId);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "exType")) {
                wrapper.orderByDesc(LinggangScheduling::getExType);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "signTime")) {
                wrapper.orderByDesc(LinggangScheduling::getSignTime);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "signType")) {
                wrapper.orderByDesc(LinggangScheduling::getSignType);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "alcoholFlag")) {
                wrapper.orderByDesc(LinggangScheduling::getAlcoholFlag);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "alcoholIntake")) {
                wrapper.orderByDesc(LinggangScheduling::getAlcoholIntake);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "remark")) {
                wrapper.orderByDesc(LinggangScheduling::getRemark);
            }
            if (org.apache.commons.lang3.StringUtils.equals(orderEntity.getProp(), "keyInfoId")) {
                wrapper.orderByDesc(LinggangScheduling::getKeyInfoId);
            }
        } else {
            wrapper.orderByDesc(LinggangScheduling::getId);
        }
    }

    private void switchScheduleDate(LambdaQueryWrapper<LinggangScheduling> wrapper,LinggangScheduling entity){
        if(Objects.nonNull(entity.getStartScheduleDate()) && Objects.nonNull(entity.getEndScheduleDate())){
            wrapper.between(LinggangScheduling::getScheduleDate,entity.getStartScheduleDate(),entity.getEndScheduleDate());
        }else if(Objects.nonNull(entity.getStartScheduleDate())){
            wrapper.ge(LinggangScheduling::getScheduleDate,entity.getStartScheduleDate());
        }else if(Objects.nonNull(entity.getEndScheduleDate())){
            wrapper.le(LinggangScheduling::getScheduleDate,entity.getEndScheduleDate());
        }
    }
}