package com.northglass.service.identifymachine; import java.sql.ResultSet; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.swing.text.html.HTML; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import com.northglass.Globel.mes; import com.northglass.SqlHelper.DBSession; import com.northglass.constants.StateConstants.ConnectState; import com.northglass.constants.StateConstants.GaoliweiMachineState; import com.northglass.constants.StateConstants.GlassArrangeState; import com.northglass.constants.StateConstants.GlassState; import com.northglass.constants.StateConstants.sendGlassState; import com.northglass.entity.GalssTask; import com.northglass.entity.IdentifyError; import com.northglass.entity.LoadRack; import com.northglass.entity.Password; import com.northglass.entity.PatternTask; import com.northglass.entity.PreprocessingGlass; import com.northglass.entity.Rank; import com.northglass.entity.RawPackage; import com.northglass.entity.ShelfRack; import com.northglass.entity.ShelfTask; import com.northglass.entity.Slicecage; import com.northglass.entity.SlicecagePattern; import com.northglass.repository.GalssTaskDao; import com.northglass.repository.IdentifyErrorDao; import com.northglass.repository.PasswordDao; import com.northglass.repository.PatternTaskDao; import com.northglass.repository.PreprocessingGlassDao; @Component @Transactional public class IdentifyMachineService { @Autowired private GalssTaskDao galssTaskDao; @Autowired private PatternTaskDao patternTaskDao; @Autowired private PasswordDao passwordDao; @Autowired private IdentifyErrorDao identifyErrorDao; @Autowired private PreprocessingGlassDao preprocessingGlassDao; private static final Logger LOGGER = LoggerFactory.getLogger(IdentifyMachineService.class); public Map getCeliangManageData(String groups) { // Long machineId = Long.valueOf(groups); PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups)); Map param = new HashMap(); if(preprocessingGlass!=null){ param.put("actuallength", preprocessingGlass.getActualLength()); param.put("actualwidth", preprocessingGlass.getActualWidth()); param.put("color", preprocessingGlass.getColor()); param.put("thickness", preprocessingGlass.getThickness()); param.put("status", preprocessingGlass.getStatu()); if (preprocessingGlass.getGlassId() != 0) { param.put("width", preprocessingGlass.getWidth()); param.put("length", preprocessingGlass.getLength()); param.put("glassid", preprocessingGlass.getGlassId()); } if (preprocessingGlass.getStatu().equals("匹配失败")) { param.put("img", "quxiao.png"); param.put("mesgess", "玻璃匹配失败"); }else if(preprocessingGlass.getStatu().equals("匹配失败1")){ param.put("img", "quxiao.png"); param.put("mesgess", "玻璃摆放不正确"); }else if(preprocessingGlass.getStatu().equals("多数据匹配")){ param.put("img", "quxiao.png"); param.put("mesgess", "玻璃多数据匹配失败"); }else { param.put("img", "zhengque.png"); } /*int totalPieces = 0; int completePieces = 0; if (preprocessingGlass.getRawPackageTxt()!=null) { List glasses = glassDao.findByRaw(preprocessingGlass.getRawPackageTxt().getId()); if (glasses.size()>0) { for (Glass glass : glasses) { completePieces = completePieces + glass.getCompletePieces(); totalPieces = totalPieces + glass.getPieces(); } } } param.put("totalPieces", totalPieces); param.put("completePieces", completePieces); param.put("leftPieces", totalPieces - completePieces); param.put("progress", ((double) completePieces / (double) totalPieces * 100) + "%");*/ // 测量结果显示。 // - 若找到匹配玻璃,则显示结果为匹配成功,不需要人工处理,自动执行送片; // - 若没有找到识别玻璃,则显示两个按钮 // - 一个是重新匹配,允许用户校正并重新测量; // - 另一个是匹配失败,需要用户自己将玻璃移除,并确认; StringBuffer html = new StringBuffer(); param.put("identifyResultHtml", html.toString()); } return param; } public List getGlass(Long groups) { PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(String.valueOf(groups))); if(preprocessingGlass.getStatu().equals("多数据匹配")){ IdentifyError identifyError=identifyErrorDao.findBygroup(Integer.parseInt(String.valueOf(groups))); List glass=new ArrayList(); double minwidth=preprocessingGlass.getActualWidth()-identifyError.getHeigtherror(); double maxwidth=preprocessingGlass.getActualWidth()+identifyError.getHeigtherror(); double minheigth=preprocessingGlass.getActualLength()-identifyError.getWidtherror(); double maxheigth=preprocessingGlass.getActualLength()+identifyError.getWidtherror(); glass=galssTaskDao.findByidentify2(groups,minwidth,maxwidth,minheigth,maxheigth); return glass; }else{ List glass=new ArrayList(); glass=galssTaskDao.findByidentify1(groups,preprocessingGlass.getMinwidths()); return glass; } } public List getGlass2(Long groups) { PatternTask patternTask =patternTaskDao.findbygroups2(groups); PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(String.valueOf(groups))); List glass; if(patternTask!=null){ glass=galssTaskDao.findpattern2(groups,preprocessingGlass.getMinwidths()); /*glass=galssTaskDao.findByidentify1(groups);*/ glass.addAll(galssTaskDao.findpattern1(patternTask.getId(),preprocessingGlass.getMinwidths())); }else if(preprocessingGlass.getStatu().equals("多数据匹配")){ IdentifyError identifyError=identifyErrorDao.findBygroup(Integer.parseInt(String.valueOf(groups))); double minwidth=preprocessingGlass.getActualWidth()-identifyError.getHeigtherror(); double maxwidth=preprocessingGlass.getActualWidth()+identifyError.getHeigtherror(); double minheigth=preprocessingGlass.getActualLength()-identifyError.getWidtherror(); double maxheigth=preprocessingGlass.getActualLength()+identifyError.getWidtherror(); glass=galssTaskDao.findByidentify2(groups,minwidth,maxwidth,minheigth,maxheigth); return glass; }else{ glass=galssTaskDao.findByidentify1(groups,preprocessingGlass.getMinwidths()); } return glass; } public String rankhtml(Long groups){ /*PatternTask patternTask =patternTaskDao.findbygroups2(groups); if(patternTask!=null){ return patternTask.getRank().toString(); }else{ return ""; }*/ /* Long galssTask=galssTaskDao.findBypatternTask(groups); List g=galssTaskDao.findBypatternTask(groups,galssTask); System.out.println(galssTask+":"+g.size());*/ try { DBSession sn=mes.getMesDBHelper().createSession(false); sn.createSql("select * from y_Len_CeLiang where Mode_State=1 and groups=? limit 0,1"); ResultSet r= sn.query(groups).getCurrentResult(); String minpattern=""; while (r.next()) { minpattern=r.getString("minpattern"); } sn.createSql(minpattern); ResultSet r2= sn.query(groups).getCurrentResult(); while (r2.next()) { return r2.getString(1); } } catch (Exception e) { // TODO: handle exception } return ""; } public String buttonhmtl(int groups){ StringBuffer html = new StringBuffer(); PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(groups); if (preprocessingGlass.getMarking()==1){ html.append("  "); html.append(""); }else if (preprocessingGlass.getMarking()==0){ html.append("  "); html.append(""); } return html.toString(); } public String buttonhmtl2(Long groups){ StringBuffer html = new StringBuffer(); List patternTask =patternTaskDao.findbygroups3(groups); if (patternTask.size()>0){ html.append("  "); } return html.toString(); } public String buttonhmthtml(Long groups){ StringBuffer html = new StringBuffer(); PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(groups+"")); try { DBSession sn=mes.getMesDBHelper().createSession(false); sn.createSql("select * from y_Len_CeLiang where Mode_State=1 and groups=? limit 0,1"); ResultSet r= sn.query(groups).getCurrentResult(); String Fx_Content=""; while (r.next()) { Fx_Content=r.getString("Fx_Content"); } sn.createSql(Fx_Content); ResultSet r2= sn.query(groups).getCurrentResult(); while (r2.next()) { String work_procedure=r2.getString("work_procedure"); String work_state=r2.getString("work_state"); Long id=Long.valueOf(r2.getString("id")); String width=r2.getString("width"); String height=r2.getString("height"); String edgwidth=r2.getString("edg_width"); String edgheight=r2.getString("edg_height"); if("测量".equals(work_procedure)){ if(Double.parseDouble(width)"+width+"x"+height+""); }else if("破损".equals(work_state) ){ html.append(""); }else{ html.append(""); } }else{ html.append(""); } } } catch (Exception e) { // TODO: handle exception System.out.println("异常:冷加工测量 - 线路:"+groups); } return html.toString(); } /* public String buttonhmthtml(Long groups){ StringBuffer html = new StringBuffer(); PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(groups+"")); PatternTask patternTask =patternTaskDao.findbygroups2(groups); if(patternTask!=null){ if(patternTask.getRank()!=0){ List galssTasklist=galssTaskDao.findpattern(patternTask.getId()); if(galssTasklist!=null){ for (GalssTask galssTask : galssTasklist) { if(galssTask.getWorkProcedure().equals("测量")){ if(galssTask.getWidth()"+galssTask.getWidth()+"x"+galssTask.getHeight()+""); }else if(galssTask.getWorkState().equals("破损") ){ html.append(""); }else{ html.append(""); } }else{ html.append(""); } } } } } return html.toString(); }*/ public void Deleteglalls(String groups, String glassid) { //破损 PreprocessingGlass gs = preprocessingGlassDao.findBygroup(Integer.parseInt(groups)); if(gs.getFlag()==0){ GalssTask glass=galssTaskDao.findOne(Integer.valueOf(glassid).longValue()); gs.setFlag(3); glass.setWorkState("破损"); preprocessingGlassDao.save(gs); galssTaskDao.save(glass); } } public void updatestate(Long id) { GalssTask glass=galssTaskDao.findOne(id); glass.setWorkState("破损"); galssTaskDao.save(glass); } public void updatepatternstate(Long groups,String id) { if(id.equals("上")){ PatternTask patternTask = patternTaskDao.findbygroupsfalg(groups); if(patternTask!=null){ patternTask.setFlag(0); patternTaskDao.save(patternTask); } }else if(id.equals("下")){ PatternTask patternTask = patternTaskDao.findbygroups2(groups); if(patternTask!=null){ patternTask.setFlag(1); patternTaskDao.save(patternTask); } } } public void updatepatternstates(Long groups) { List patternTask = patternTaskDao.findIdGroup(groups); for (PatternTask patternTask2 : patternTask) { if(patternTask2!=null){ patternTask2.setFlag(1); patternTaskDao.save(patternTask2); } } } public void yichu(String groups) { //移除 PreprocessingGlass gs = preprocessingGlassDao.findBygroup(Integer.parseInt(groups)); gs.setFlag(-1); preprocessingGlassDao.save(gs); } public void modify(String groups, String glassid) { PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups)); //找出当前的玻璃,并修改指认 if(preprocessingGlass.getFlag()==0){ preprocessingGlass.setFlag(Long.parseLong(glassid)); preprocessingGlassDao.save(preprocessingGlass); } } public void updatemarking(String type,int groups) { PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(groups); preprocessingGlass.setMarking(Integer.parseInt(type)); preprocessingGlassDao.save(preprocessingGlass); } public IdentifyError getfloor(String groups) { return identifyErrorDao.findBygroup(Integer.parseInt(groups)); } public double getminwidth(String groups) { PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups)); return preprocessingGlass.getMinwidths(); } public void modifyErrorRange(String groups, String floor, String ceiling) { IdentifyError identifyError = identifyErrorDao.findBygroup(Integer.parseInt(groups)); if (identifyError != null) { identifyError.setWidtherror(Double.parseDouble(floor)); identifyError.setHeigtherror(Double.parseDouble(ceiling)); identifyErrorDao.save(identifyError); } } public void modifyErrorRange2(String groups, String floor) { PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups)); if (preprocessingGlass != null) { preprocessingGlass.setMinwidths(Double.parseDouble(floor)); preprocessingGlassDao.save(preprocessingGlass); } } public String BupianForHtml() { StringBuffer html = new StringBuffer(); List glassLists=galssTaskDao.findByidentify(); for (GalssTask glass : glassLists) { html.append("").append(glass.getId()).append(""); html.append("").append(glass.getHeight()).append(""); html.append("").append(glass.getWidth()).append(""); html.append("").append(glass.getThickness()).append(""); html.append("").append(glass.getColor()).append(""); html.append("").append(glass.getWorkState()).append(""); html.append(""); } return html.toString(); } public void addgalsstask(HttpServletRequest request) { GalssTask galssTask=new GalssTask(); galssTask.setGalssId(Long.valueOf(request.getParameter("galssid"))); galssTask.setWidth(Double.valueOf(request.getParameter("width"))); galssTask.setHeight(Double.valueOf(request.getParameter("heigth"))); galssTask.setThickness(Double.valueOf(request.getParameter("thickness"))); galssTask.setColor(request.getParameter("color")); galssTask.setEdgHeight(request.getParameter("edgwidth")); galssTask.setEdgWidth(request.getParameter("edgheight")); galssTask.setEdgSpeed1(request.getParameter("edgspeed1")); galssTask.setEdgSpeed2(request.getParameter("edgspeed2")); galssTask.setDropFrame(request.getParameter("dropframe")); galssTask.setFineThrowing(Integer.parseInt(request.getParameter("finethrowing"))); galssTask.setWorkProcedure(request.getParameter("workprocedure")); galssTask.setWorkState(request.getParameter("workstart")); galssTask.setSlicecageFlag("0"); galssTask.setStartTime(new Date()); galssTaskDao.save(galssTask); } public boolean modifypassword(String password1,String password2) { System.out.println(password2); Password password =passwordDao.findpassword(password1); if(password!=null){ password.setPassword(password2); passwordDao.save(password); return true; }else{ return false; } } }