/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.gpsboot.service.maintain.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.tofly.gpsboot.common.system.MaterialEnum;
import com.tofly.gpsboot.util.WordUtil;
import com.tofly.pojo.maintain.vo.RepairgoodsVo;
import com.tofly.gpsboot.mapper.maintain.RepairgoodsMapper;
import com.tofly.gpsboot.service.maintain.RepairgoodsService;
import com.tofly.gpsboot.service.maintain.RepairmaterialService;
import com.tofly.pojo.maintain.Repairgoods;
import com.tofly.pojo.maintain.Repairmaterial;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * 抢维修耗材记录表
 *
 * @author admin
 * @date Tue Apr 06 00:00:00 CST 2021
 */
@Service("repairgoodsService")
public class RepairgoodsServiceImpl extends ServiceImpl<RepairgoodsMapper, Repairgoods> implements RepairgoodsService {
    @Autowired
    private RepairmaterialService repairmaterialService;

    @Override
    public List<RepairgoodsVo> viewConversion(List<Repairgoods> infoList) {
        List<RepairgoodsVo> infoVoList = new ArrayList<>();
        infoList.forEach(info ->{
            RepairgoodsVo baseInfo = JSONObject.parseObject(JSON.toJSONString(info),RepairgoodsVo.class);
            // 需要增加材料类型 转换材质
            Repairmaterial byId = repairmaterialService.getById(info.getMaterialType());
            if(null!=byId){
                baseInfo.setMaterialTypeName(WordUtil.transform(byId.getName()));
                baseInfo.setUnit(byId.getUnit());
                baseInfo.setSpecification(byId.getSpecification());
            }
            baseInfo.setBore(WordUtil.transform(info.getBore()));
            //baseInfo.setMaterial(MaterialEnum.getCodeForValue(info.getMaterial()));
            infoVoList.add(baseInfo);
        });
        return infoVoList;
    }
}
