Newer
Older
huludao / src / main / java / com / newfiber / modules / inspection / service / impl / EquTechnologicalProcessInfoServiceImpl.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.EquRepairOrderDao;
import com.newfiber.modules.inspection.dao.EquTechnologicalProcessInfoDao;
import com.newfiber.modules.inspection.entity.EquRepairOrderEntity;
import com.newfiber.modules.inspection.entity.EquTechnologicalProcessInfoEntity;
import com.newfiber.modules.inspection.service.EquTechnologicalProcessInfoService;
import com.newfiber.modules.inspection.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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


@Service("equTechnologicalProcessInfoService")
public class EquTechnologicalProcessInfoServiceImpl extends ServiceImpl<EquTechnologicalProcessInfoDao, EquTechnologicalProcessInfoEntity> implements EquTechnologicalProcessInfoService {

    @Autowired
    private EquTechnologicalProcessInfoDao processInfoDao;

    @Autowired
    private EquRepairOrderDao repairOrderDao;

    @Autowired
    private FileUploadService fileUploadService;


    @Override
    public PageUtils queryInfo(Map<String, Object> params) {
        /**条件查询获取审批流程*/
        QueryWrapper<EquTechnologicalProcessInfoEntity> queryWrapper = new QueryWrapper<EquTechnologicalProcessInfoEntity>()
                .select("id", "repair_no", "approval_no", "approval_user", "fullname", "order_num", "pointer", "status", "remarks", "state", "create_time")
                .orderByDesc("order_num");

        Integer state = (Integer) params.get("state");
        if (state != null && state == 1) {
            queryWrapper.eq("state", 1);
            queryWrapper.eq("pointer", 0);
        } else {
            queryWrapper.eq("pointer", 1);
        }

        String username = (String) params.get("username");
        queryWrapper.eq(username != null, "approval_user", username);

        String repairNo = (String) params.get("repairNo");
        queryWrapper.eq(repairNo != null, "repair_no", repairNo);

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

        List<EquTechnologicalProcessInfoEntity> infoEntities = page.getRecords();

        /**获取审批对应的工单信息*/
        Map<String, Object> map = new HashMap<>();
        for (EquTechnologicalProcessInfoEntity entity : infoEntities) {
            EquRepairOrderEntity orderEntity = repairOrderDao.selectOne(new QueryWrapper<EquRepairOrderEntity>()
                    .select("id", "equ_no", "equ_name", "maintain_no", "repair_no", "repair_personnel", "fullname",
                            "work_order_status", "remarks", "repair_level ", "repair_state", "create_time")
                    .eq("repair_no", entity.getRepairNo()));

            map.put("relation_id", entity.getRepairNo());
            orderEntity.setFileUploadEntityList(fileUploadService.listByMap(map));

            entity.setOrderEntity(orderEntity);
        }

        return new PageUtils(page);
    }


    @Override
    @Transactional
    public void updateInfo(EquTechnologicalProcessInfoEntity processInfoEntity) {
        /**根据维修工单编号获取对应流程信息*/
        QueryWrapper<EquTechnologicalProcessInfoEntity> queryWrapper = new QueryWrapper<EquTechnologicalProcessInfoEntity>()
                .eq("repair_no", processInfoEntity.getRepairNo())
                .orderByAsc("order_num");
        List<EquTechnologicalProcessInfoEntity> entityList = processInfoDao.selectList(queryWrapper);

        /**获取审批对应的工单信息*/
        EquRepairOrderEntity equRepairOrder = repairOrderDao.selectOne(new QueryWrapper<EquRepairOrderEntity>()
                .select("id", "equ_no", "equ_name", "maintain_no", "repair_no", "repair_personnel", "fullname",
                        "work_order_status", "remarks", "repair_level ", "repair_state", "create_time")
                .eq("repair_no", processInfoEntity.getRepairNo()));

        Integer id = processInfoEntity.getId();
        /**审批未完成,修改审批的状态*/
        if (processInfoEntity.getStatus() == 2) {
            for (EquTechnologicalProcessInfoEntity infoEntity : entityList) {
                infoEntity.setState(0);
            }
            for (int i = 0; i < entityList.size(); i++) {
                if (id == entityList.get(i).getId()) {
                    entityList.set(i, processInfoEntity);
                }
            }
            equRepairOrder.setWorkOrderStatus(0);

        } else {
            /**审批通过,修改指针位置*/
            processInfoEntity.setPointer(0);

            for (int i = 0; i < entityList.size(); i++) {
                if (id == entityList.get(i).getId()) {
                    entityList.set(i, processInfoEntity);
                    if (i + 1 < entityList.size()) {
                        /**替换集合中的对象,指针下移*/
                        entityList.get(i + 1).setPointer(1);
                    } else {
                        /**审批已经最后一步*/
                        for (EquTechnologicalProcessInfoEntity infoEntity : entityList) {
                            infoEntity.setState(1);
                        }
                        equRepairOrder.setWorkOrderStatus(1);
                    }
                    break;
                }
            }
        }
        /**修改维修的工单性质*/
        repairOrderDao.updateById(equRepairOrder);

        /**修改审批流程*/
        this.updateBatchById(entityList);
    }

}