Newer
Older
huludao / src / main / java / com / newfiber / modules / inspection / service / impl / EquMaintenanceHandleServiceImpl.java
package com.newfiber.modules.inspection.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newfiber.common.utils.PageUtils;
import com.newfiber.common.utils.Query;
import com.newfiber.modules.inspection.dao.EquMaintenanceHandleDao;
import com.newfiber.modules.inspection.entity.EquMaintenanceHandleEntity;
import com.newfiber.modules.inspection.service.EquMaintenanceHandleService;
import com.newfiber.modules.inspection.service.FileUploadService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("equMaintenanceHandleService")
public class EquMaintenanceHandleServiceImpl extends ServiceImpl<EquMaintenanceHandleDao, EquMaintenanceHandleEntity> implements EquMaintenanceHandleService {

    @Autowired
    private FileUploadService fileUploadService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<EquMaintenanceHandleEntity> queryWrapper = new QueryWrapper<>();
        String username = (String) params.get("username");

        String pumpNo = (String) params.get("pumpNo");
        queryWrapper.eq(StringUtils.isNotBlank(pumpNo), "pump_no", pumpNo);

        Integer handleType = Integer.parseInt(params.get("handleType") + "");
        queryWrapper.eq("handle_type", handleType);

        if (handleType == 0) {
            queryWrapper.eq(StringUtils.isNotBlank(username), "handle_personnel", username);
        }
        if (handleType == 1) {
            queryWrapper.eq(StringUtils.isNotBlank(username), "acceptance_personnel", username);
        }
        if (handleType == 2) {
            queryWrapper.and(Wrapper -> Wrapper
                    .eq(StringUtils.isNotBlank(username), "handle_personnel", username)
                    .or()
                    .eq(StringUtils.isNotBlank(username), "acceptance_personnel", username));

        }

        IPage<EquMaintenanceHandleEntity> page = this.page(
                new Query<EquMaintenanceHandleEntity>().getPage(params), queryWrapper);

        List<EquMaintenanceHandleEntity> records = page.getRecords();
        Map<String, Object> map = new HashMap<>();
        for (EquMaintenanceHandleEntity record : records) {
            /**获取上传的文件信息*/
            map.put("relation_id", record.getHandleNo());
            record.setFileUploadEntityList(fileUploadService.listByMap(map));
        }

        return new PageUtils(page);
    }

}