严智鑫
2024-03-22 ecde4b864d846fb68ecbfd562aa22286abfad9c4
springboot-vue3/src/main/java/com/example/springboot/service/StorageCageService.java
@@ -5,11 +5,13 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.springboot.common.Result;
import com.example.springboot.component.PLCAutoMes;
import com.example.springboot.component.Plchome;
import com.example.springboot.component.S7control;
import com.example.springboot.entity.FlowCard;
@@ -17,7 +19,9 @@
import com.example.springboot.entity.Queue;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.StorageTask;
import com.example.springboot.entity.device.PlcParameterObject;
import com.example.springboot.mapper.HomeMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
@Service
public class StorageCageService {
@@ -256,7 +260,6 @@
        return Result.success(map);
    }
    //查询玻璃信息
    public Result SelectGlassInfo(String width,String height,String thickness,String films) {
        List<GlassInfo> glassInfoList = homeMapper.SelectGlassInfo(width,height,thickness,films);
@@ -309,10 +312,82 @@
    //修改测量信息
    public Result UpdateQueue(GlassInfo glassInfo) {
        homeMapper.UpdateQueue(glassInfo.getFlowcard(),glassInfo.getWidth(),glassInfo.getHeight(),glassInfo.getGlasstype());
        homeMapper.UpdateQueue(glassInfo.getFlowcard(), glassInfo.getWidth(), glassInfo.getHeight(),
                glassInfo.getGlasstype());
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
    // 人工拿走
    public Result ManualTake(String glassInfo) {
        // 读取DB105区文件
        PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
        // 移除
        // S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(),
        // (short) 3);
        // plcmes.getPlcParameter("GaToMES").setValue("3");
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
    // 重新测量
    public Result AnewMeasure(String glassInfo) {
        // 读取DB105区文件
        PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
        // 重新测量
        // S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(),
        // (short) 2);
        // plcmes.getPlcParameter("GaToMES").setValue("2");
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
    // 添加小片信息
    public Result AddGlassinfo(List<Map> IportDataStr) {
        // 筛选处理数据 1.去除无用数据 2.计算配片ID 3.计算ID 4. 计算总层数
        List<Map> TypeDatas = homeMapper.SelectType();
        Map<String, String> TypeData = new HashMap<String, String>();// 得到处理完后所有的类型
        List<Map> RemoveErrorData = IportDataStr.stream()
                .filter(item -> (item.get("order") != null && item.get("glasstype") != null && item.get("tier") != null
                        &&
                        item.get("films") != null && item.get("base") != null && item.get("height") != null
                        && item.get("thickness") != null && item.get("quantity") != null))
                .collect(Collectors.toList());
        // 取出RemoveErrorData 里面的列当作TypeData的key
        TypeDatas.forEach(item -> {
            TypeData.put(item.get("type").toString(), item.get("glasstype").toString());
        });
        System.out.println(RemoveErrorData.size());
        // 处理完成 添加数据库
        for (Map map : RemoveErrorData) {
            // GlassInfo glassInfo = mapper.convertValue(map, GlassInfo.class);
            String key=map.get("base").toString()+"_"+map.get("height").toString()+"_"+map.get("thickness").toString()+"_"+map.get("films").toString();
            String value=TypeData.get(key);
            Integer glasstype;
            if (TypeData.get(key)==null) {
                glasstype=homeMapper.SelectMaxType();
            }else{
                glasstype=Integer.valueOf(value);
            }
            homeMapper.AddGlassinfo(map.get("order").toString(), glasstype,
                    Integer.parseInt(map.get("glasstype").toString()) // 需要计算 配片ID
                    , map.get("glasstype").toString() // 需要计算 玻璃ID
                    , Integer.parseInt(map.get("tier").toString()), map.get("films").toString(),
                    Double.parseDouble(map.get("base").toString()), Double.parseDouble(map.get("height").toString()),
                    Double.parseDouble(map.get("thickness").toString()),
                    Integer.parseInt(map.get("quantity").toString()), 1);// 需要计算总层数
        }
        Map<String, Object> ResultCode = new HashMap<>();
        ResultCode.put("message", "200");
        return Result.success(ResultCode);
    }
}