package com.northglass.service.cutmanage;
|
|
import java.io.BufferedReader;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileWriter;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.io.StringReader;
|
import java.io.UnsupportedEncodingException;
|
import java.text.DecimalFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Stack;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
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 org.springframework.ui.Model;
|
|
import com.northglass.applicationListener.InitializeSystemApplicationListener;
|
import com.northglass.constants.ShelfTaskType;
|
import com.northglass.constants.StateConstants.LoadMachineTaskState;
|
import com.northglass.constants.StateConstants.RawPackageTxtState;
|
import com.northglass.constants.StateConstants.ShelfRankState;
|
import com.northglass.constants.StateConstants.ShelfTaskState;
|
import com.northglass.constants.StateConstants.TaskState;
|
import com.northglass.entity.CountMachineTask;
|
import com.northglass.entity.Cutting;
|
import com.northglass.entity.Glass;
|
import com.northglass.entity.GlassOrder;
|
import com.northglass.entity.Info;
|
import com.northglass.entity.LoadMachine;
|
import com.northglass.entity.LoadMachineRack;
|
import com.northglass.entity.LoadMachineTask;
|
import com.northglass.entity.OPattern;
|
import com.northglass.entity.OptPattern;
|
import com.northglass.entity.PrintMachine;
|
import com.northglass.entity.ProdLineState;
|
import com.northglass.entity.RawPackage;
|
import com.northglass.entity.RawPackageTxt;
|
import com.northglass.entity.ReportTask;
|
import com.northglass.entity.Shape;
|
import com.northglass.entity.ShelfRank;
|
import com.northglass.entity.ShelfTask;
|
import com.northglass.entity.SingalGlass;
|
import com.northglass.entity.Step;
|
import com.northglass.listener.GMMSPrinter;
|
import com.northglass.repository.CountMachineTaskDao;
|
import com.northglass.repository.GlassDao;
|
import com.northglass.repository.GlassOrderDao;
|
import com.northglass.repository.LoadMachineDao;
|
import com.northglass.repository.LoadMachineRackDao;
|
import com.northglass.repository.LoadMachineTaskDao;
|
import com.northglass.repository.OptPatternDao;
|
import com.northglass.repository.PrintMachineDao;
|
import com.northglass.repository.ProdLineStateDao;
|
import com.northglass.repository.RawPackageDao;
|
import com.northglass.repository.RawPackageTxtDao;
|
import com.northglass.repository.ReportTaskDao;
|
import com.northglass.repository.ShelfRankDao;
|
import com.northglass.repository.ShelfTaskDao;
|
import com.northglass.repository.SingalGlassDao;
|
import com.northglass.service.countmachine.CountMachineService;
|
import com.northglass.service.cutmachinemanage.GetTaskService;
|
import com.northglass.service.loadmachine.LoadMachineService;
|
import com.northglass.service.manage.ManageService;
|
|
@Component
|
@Transactional
|
public class CutManageService {
|
private static String WEB_ROOT_PATH;
|
private static String TEMP_PATH1;
|
private static String TEMP_PATH2;
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(CutManageService.class);
|
@Autowired
|
private LoadMachineTaskDao loadMachineTaskDao;
|
|
@Autowired
|
private OptPatternDao optPatternDao;
|
|
@Autowired
|
private ProdLineStateDao prodLineStateDao;
|
|
@Autowired
|
private RawPackageTxtDao rawPackageTxtDao;
|
|
@Autowired
|
private GetTaskService getTaskService;
|
|
@Autowired
|
private LoadMachineDao loadMachineDao;
|
|
@Autowired
|
private LoadMachineRackDao loadMachineRackDao;
|
|
@Autowired
|
private RawPackageDao rawPackageDao;
|
|
@Autowired
|
private ReportTaskDao reportTaskDao;
|
|
@Autowired
|
private ShelfRankDao shelfRankDao;
|
|
@Autowired
|
private GlassDao glassDao;
|
|
@Autowired
|
private ShelfTaskDao shelfTaskDao;
|
|
@Autowired
|
private CountMachineTaskDao countMachineTaskDao;
|
|
@Autowired
|
private PrintMachineDao printMachineDao;
|
|
@Autowired
|
private CountMachineService countMachineService;
|
|
@Autowired
|
private ManageService manageService;
|
|
@Autowired
|
private SingalGlassDao singalGlassDao;
|
|
@Autowired
|
private GlassOrderDao glassOrderDao;
|
|
@Autowired
|
private LoadMachineService loadMachineService;
|
|
/**
|
* 进入领取任务列表页面
|
*
|
* @return
|
*/
|
public String getTask(String prodLine, Model model) {
|
|
RawPackageTxt rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup(prodLine);// 当前产线是否有任务
|
|
// 没有任务
|
if (rawPackageTxt == null) {
|
List<RawPackageTxt> rawPackages = rawPackageTxtDao.findTasks();
|
List<RawPackageTxt> rawPackageTxts = rawPackageTxtDao.findInterruptTasks();
|
if (rawPackages.size() > 0) {
|
for (int i = 0; i < rawPackages.size(); i++) {
|
rawPackageTxts.add(rawPackages.get(i));
|
if (i == 1) {
|
break;
|
}
|
}
|
}
|
Map<String, Object> param1 = manageService.showMachineState();
|
model.addAttribute("allstatu", param1.get("allstatu"));
|
model.addAttribute("info", param1.get("info"));
|
model.addAttribute("rawPackageTxts", rawPackageTxts);
|
model.addAttribute("prodLine", prodLine);
|
return "cutmanage/gettaskY";
|
} else {// 有任务
|
// 当前产线的切割任务
|
model.addAttribute("line", prodLine);
|
List<LoadMachineTask> taskList = this.getTaskList(Long.parseLong(prodLine));
|
List<Integer> countPiece = this.countPiece(taskList);
|
model.addAttribute("taskhtml", this.getTasks(Long.parseLong(prodLine)));
|
model.addAttribute("patterns", this.gettas(Long.parseLong(prodLine)));
|
model.addAttribute("sumPiece", countPiece.get(0));
|
model.addAttribute("comPiece", countPiece.get(1));
|
Map<String, Object> param1 = manageService.showMachineState();
|
model.addAttribute("allstatu", param1.get("allstatu"));
|
model.addAttribute("info", param1.get("info"));
|
return "cutmanage/gottask";
|
}
|
}
|
|
/**
|
* 领取任务前校验是否已进入单机模式,是否该任务已被领取,该任务库存是否满足生产
|
*
|
* @return
|
*/
|
public String checktask(HttpServletRequest request) {
|
// 判断是否已经进入模式
|
String prodline = request.getParameter("prodline");// 获取生产线
|
String txtid = request.getParameter("txtid");// 获取opt文件的id(即rawpackagetxtid)
|
|
ProdLineState prodLine = prodLineStateDao.findById(Integer.parseInt(prodline));
|
|
if (prodLine.isStandalonestate() == false) {
|
RawPackageTxt rawPackageTxt = rawPackageTxtDao.findOne(Long.valueOf(txtid));
|
String status = rawPackageTxt.getStatus();
|
|
if (status.equals(RawPackageTxtState.SENDED) || status.equals(RawPackageTxtState.INTERRUPT)) {
|
// 查看此任务是否被另一条产线在操作
|
String operator = rawPackageTxt.getOperator();
|
if (operator != null) {
|
if (!prodline.equals(operator)) {
|
// 另一条产线在操作
|
return "operating";
|
}
|
} else {
|
// 没有被操作,先做标记
|
rawPackageTxt.setOperator(prodline);
|
rawPackageTxtDao.save(rawPackageTxt);
|
}
|
List<OptPattern> optPatterns = new ArrayList<OptPattern>();
|
List<OptPattern> optPatternes = optPatternDao.findOptPatternByBatchNumber(rawPackageTxt.getTxt_name());
|
if (optPatternes.size() > 0) {
|
for (OptPattern optPattern : optPatternes) {
|
if (optPatterns.size() > 0) {
|
for (int i = 0; i < optPatterns.size(); i++) {
|
OptPattern opt = optPatterns.get(i);
|
if (opt.getWidth() == optPattern.getWidth()
|
&& opt.getHeight() == optPattern.getHeight()
|
&& optPattern.getPieces()>=optPattern.getCompletedPieces()) {
|
opt.setPieces(opt.getPieces() + optPattern.getPieces()-optPattern.getCompletedPieces());
|
break;
|
}
|
if (i == optPatterns.size() - 1) {
|
optPatterns.add(new OptPattern(optPattern.getOptId(), optPattern.getGlassId(),
|
optPattern.getDescription(), optPattern.getGlassThickness(),
|
optPattern.getPieces()-optPattern.getCompletedPieces(), 0, optPattern.getWidth(), optPattern.getHeight(),
|
"等待中", optPattern.getColor(), optPattern.getContent(),
|
optPattern.getBatch(), optPattern.getGroups(),
|
optPattern.getRawPackageTxt()));
|
LOGGER.debug("optPattern.getPieces()-optPattern.getCompletedPieces()"+(optPattern.getPieces()-optPattern.getCompletedPieces()));
|
break;
|
}
|
}
|
|
} else {
|
if ( optPattern.getPieces()>optPattern.getCompletedPieces()) {
|
optPatterns.add(new OptPattern(optPattern.getOptId(), optPattern.getGlassId(),
|
optPattern.getDescription(), optPattern.getGlassThickness(), optPattern.getPieces()-optPattern.getCompletedPieces(),
|
0, optPattern.getWidth(), optPattern.getHeight(), "等待中", optPattern.getColor(),
|
optPattern.getContent(), optPattern.getBatch(), optPattern.getGroups(),
|
optPattern.getRawPackageTxt()));
|
LOGGER.debug("optPattern.getPieces()-optPattern.getCompletedPieces()"+(optPattern.getPieces()-optPattern.getCompletedPieces()));
|
}
|
}
|
}
|
}
|
List<ShelfRank> shelfRanks = shelfRankDao.findInWorkRankAndInWorkingRanks();
|
List<RawPackage> rawPackageLack = new ArrayList<RawPackage>();
|
LOGGER.debug("optPatterns.size"+optPatterns.size());
|
for (OptPattern opt : optPatterns) {
|
// 初始化这种规格剩余片数
|
|
int sum = 0;
|
// 初始化当前规格原片需要切割的片数
|
int pieces = opt.getPieces();
|
for (ShelfRank shelfRank : shelfRanks) {
|
LOGGER.debug("Shelf Rank:"+shelfRank.getId());
|
RawPackage shelfRankRawPackage = shelfRank.getRawPackage();
|
LOGGER.debug("getWidth:"+shelfRankRawPackage.getWidth());
|
LOGGER.debug("getHeight:"+shelfRankRawPackage.getHeight());
|
LOGGER.debug("getThickness:"+shelfRankRawPackage.getThickness());
|
LOGGER.debug("color:"+shelfRankRawPackage.getColor());
|
LOGGER.debug("getWidth111:"+opt.getWidth());
|
LOGGER.debug("getHeight111:"+opt.getHeight());
|
LOGGER.debug("getThickness111:"+opt.getGlassThickness());
|
LOGGER.debug("color111:"+opt.getColor());
|
if (shelfRankRawPackage.getWidth() == opt.getWidth()
|
&& shelfRankRawPackage.getHeight() == opt.getHeight()
|
&& shelfRankRawPackage.getThickness() == opt.getGlassThickness()
|
&& shelfRankRawPackage.getColor().equals(opt.getColor())) {
|
sum = sum + shelfRankRawPackage.getLeftPieces();
|
}
|
continue;
|
}
|
if (pieces > sum) {
|
rawPackageLack.add(new RawPackage(opt.getGlassId(), pieces - sum, opt.getWidth(),
|
opt.getHeight(), opt.getGlassThickness(), opt.getColor()));
|
}
|
}
|
if (rawPackageLack.size() > 0) {
|
String string = "";
|
for (RawPackage raw : rawPackageLack) {
|
string += raw.getThickness() + "mm" + raw.getColor() + "[" + raw.getWidth() + "*"
|
+ raw.getHeight() + "]" + raw.getPieces() + "片 ";
|
}
|
return "当前共有: " + rawPackageLack.size() + " 种原片规格缺失," + string;
|
} else {
|
return "ok";
|
}
|
} else {
|
return "invalidtask";// 无效任务,可能已被领取
|
}
|
} else {
|
return "startedstandalone";// 已进入单机模式
|
}
|
}
|
|
/**
|
* 领取任务统一调用接口
|
*
|
* @return
|
*/
|
public String getTaskInterface(HttpServletRequest request, HttpServletResponse response, Long line, Model model) {
|
// 领取任务,改变生产线的状态
|
// 判断生产线的状态是否有任务,如果有,就不经过这一步(由于领取完任务后的自动刷新切割列表时,会请求这个方法)
|
ProdLineState lineState = prodLineStateDao.findOne(line);
|
if (!lineState.isState()) {
|
// 调用领取任务的方法
|
this.drawList(request, response, line);
|
}
|
|
// 将领取的任务显示在前台
|
List<LoadMachineTask> taskList = this.getTaskList(line);
|
String name = taskList.get(0).getOptPattern().getRawPackageTxt().getTxt_name();
|
//生成总共的料架数量
|
if (name !=null) {
|
List<String> apartId = this.getApartId(name);
|
//生成下片队列
|
Install(apartId,name);
|
}
|
List<Integer> countPiece = this.countPiece(taskList);
|
model.addAttribute("taskhtml", this.getTasks(line));
|
model.addAttribute("patterns", this.gettas(line));
|
model.addAttribute("sumPiece", countPiece.get(0));
|
model.addAttribute("comPiece", countPiece.get(1));
|
Map<String, Object> param1 = manageService.showMachineState();
|
model.addAttribute("allstatu", param1.get("allstatu"));
|
model.addAttribute("info", param1.get("info"));
|
model.addAttribute("line", line);
|
return "cutmanage/gottask";
|
}
|
|
|
/***
|
*
|
* 2020年5月28日
|
* @author northglass
|
* 功能,给出下片需要的队列
|
*
|
* ***/
|
private void Install(List<String> apartId,String name) {
|
for (int i = 0; i < apartId.size(); i++) {
|
List<SingalGlass> singalGlasses = singalGlassDao.findByA(name , apartId.get(i));
|
GlassOrder glassOrder =null;
|
for (int j = 0; j < singalGlasses.size(); j++) {
|
SingalGlass singalGlass = singalGlasses.get(j);
|
int beishu = singalGlass.getOptPattern().getPieces();
|
if (j != 0) {
|
if (singalGlass.getLength() == glassOrder.getLength() &&
|
singalGlass.getWidth() == glassOrder.getWidth() &&
|
singalGlass.getSort() == glassOrder.getSort()) {//情况一样
|
glassOrder.setPieces(glassOrder.getPieces()+singalGlass.getPieces()*beishu);
|
}else {
|
glassOrder = new GlassOrder(singalGlass.getLength(),singalGlass.getWidth(),"待完成",singalGlass.getApart_id(),singalGlass.getManufacture_batch(),singalGlass.getSort(),singalGlass.getPieces()*beishu,0,0);
|
glassOrderDao.save(glassOrder);
|
}
|
}else {
|
glassOrder = new GlassOrder(singalGlass.getLength(),singalGlass.getWidth(),"待完成",singalGlass.getApart_id(),singalGlass.getManufacture_batch(),singalGlass.getSort(),singalGlass.getPieces()*beishu,0,0);
|
glassOrderDao.save(glassOrder);
|
}
|
}
|
}
|
}
|
|
private List<String> getApartId(String name) {
|
List<SingalGlass> glasses = singalGlassDao.findByBatch(name);
|
int number = 0;
|
List<String> apart = new ArrayList<String>();
|
for (int i = 0; i < glasses.size(); i++) {
|
if (i == 0){
|
apart.add(number, glasses.get(i).getApart_id());
|
number++;
|
}else {
|
for (int j = 0; j < apart.size(); j++) {
|
if (glasses.get(i).getApart_id().equals(apart.get(j))) {
|
break;
|
}
|
if (j == apart.size()-1) {
|
apart.add(number, glasses.get(i).getApart_id());
|
number++;
|
}
|
}
|
}
|
}
|
return apart;
|
}
|
|
/**
|
* 领取任务列表,生成单片任务表,放到loadmachinetask中,一条记录默认片数是1
|
*
|
* @param line
|
*
|
* @return
|
*/
|
public void drawList(HttpServletRequest request, HttpServletResponse response, Long line) {
|
// 获取选中的文件id
|
Long txtid = Long.valueOf(request.getParameter("txtid"));
|
// 根据txtid获取任务
|
RawPackageTxt rawPackageTxt = rawPackageTxtDao.findOne(txtid);
|
if (rawPackageTxt.getStatus().equals(RawPackageTxtState.INTERRUPT)
|
|| rawPackageTxt.getStatus().equals(RawPackageTxtState.SENDED)) {
|
// 获取数据库中选中的txt的所有pattern
|
List<OptPattern> OptPatterns = getTaskService.getOptPatterns(txtid);
|
|
// 排除pattern记录中pieces和completepiece相同的记录
|
for (int i = 0; i < OptPatterns.size(); i++) {
|
OptPattern optPattern = OptPatterns.get(i);
|
if (optPattern.getPieces() == optPattern.getCompletedPieces()) {
|
OptPatterns.remove(optPattern);
|
i--;
|
}
|
}
|
|
int number= 1;
|
// 拿到每一个pattern对象
|
for (OptPattern pattern : OptPatterns) {
|
String state = LoadMachineTaskState.WAITING;// 待开始
|
String batch = pattern.getBatch();
|
// 一个pattern对象含有多少片就生成多少条记录
|
for (int x = 1; x <= (pattern.getPieces() - pattern.getCompletedPieces()); x++) {
|
LoadMachine loadMachine = loadMachineDao.findOne(line);
|
LoadMachineTask loadMachineTask = new LoadMachineTask(loadMachine, null, pattern, state,
|
new Date());
|
loadMachineTask.setNumber(number++);
|
loadMachineTask.setDescription(batch);
|
loadMachineTaskDao.save(loadMachineTask);
|
}
|
}
|
}
|
|
// 将rawPackageTxt表中的group设置为1,状态设置为已领取
|
rawPackageTxt.setGroups(line.toString());
|
rawPackageTxt.setStatus(RawPackageTxtState.HAVE_ACCEPT);// 已领取
|
rawPackageTxtDao.save(rawPackageTxt);
|
|
// 将glass表中当前任务的group设置为1
|
List<Glass> glasses = glassDao.findGlassByManufactureBatch(rawPackageTxt.getTxt_name());
|
if (!glasses.isEmpty()) {
|
for (Glass glass : glasses) {
|
glass.setGroups(line.toString());
|
}
|
}
|
|
// 设置产线状态表中的当前产线状态为true
|
ProdLineState prodline = prodLineStateDao.findById(line.intValue());
|
prodline.setState(true);// 将该产线设置为有任务
|
prodLineStateDao.save(prodline);
|
|
try {
|
String fileName = this.downOptFile(request, line.toString(), response);
|
LOGGER.debug("line:"+line);
|
// 将文件名写入表中
|
loadMachineDao.findOne(line).setOpt_name(fileName);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
/**
|
* 显示任务列表
|
*
|
* @return
|
*/
|
public List<LoadMachineTask> getTaskList(Long line) {
|
RawPackageTxt rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup(line.toString());
|
List<LoadMachineTask> tasks = new ArrayList<LoadMachineTask>();
|
List<LoadMachineTask> oktasks = new ArrayList<LoadMachineTask>();
|
if (rawPackageTxt != null) {
|
String batch = rawPackageTxt.getTxt_name();
|
List<OptPattern> optPatterns = optPatternDao.findOptPatternByBatchNumber(batch);
|
List<LoadMachineTask> loadMachineTasks = null;
|
for (OptPattern opt : optPatterns) {
|
Long id = opt.getId();
|
loadMachineTasks = loadMachineTaskDao.findByOptId(id);
|
for (int i = 0; i < loadMachineTasks.size(); i++) {
|
LoadMachineTask loadMachineTask = loadMachineTasks.get(i);
|
if (loadMachineTask.getState().equals(TaskState.COMPLETED)) {
|
oktasks.add(loadMachineTask);
|
} else {
|
tasks.add(loadMachineTask);
|
}
|
|
}
|
}
|
tasks.addAll(oktasks);
|
}
|
|
return tasks;
|
|
}
|
|
/**
|
* 显示当前任务
|
*
|
* @return
|
*/
|
public LoadMachineTask gettas(Long line) {
|
LoadMachineTask task = loadMachineTaskDao.findInWorkTaskByLoadMachine(line);
|
if (task != null) {
|
return task;
|
}
|
List<LoadMachineTask> tasks = loadMachineTaskDao.findWarningTasksByLoadMachine(line);
|
if (tasks.size()>0) {
|
return tasks.get(0);
|
}
|
List<LoadMachineTask> comtasks = loadMachineTaskDao.findCompletedTasksByLoadMachine(line);
|
if (comtasks.size()>0) {
|
return comtasks.get(comtasks.size()-1);
|
}
|
return null;
|
}
|
/**
|
* 任务列表中具体的数值
|
*
|
* @param line
|
* @return
|
*/
|
public String getTasks(Long line) {
|
RawPackageTxt rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup(line.toString());
|
List<OptPattern> opts = new ArrayList<OptPattern>();
|
if (rawPackageTxt != null) {
|
String batch = rawPackageTxt.getTxt_name();
|
List<OptPattern> optPatterns = optPatternDao.findOptPatternByBatchNumber(batch);
|
for (OptPattern optPattern : optPatterns) {
|
if (opts.size() > 0) {
|
for (int i = 0; i < opts.size(); i++) {
|
OptPattern opt = opts.get(i);
|
if (opt.getWidth() == optPattern.getWidth() && opt.getHeight() == optPattern.getHeight()) {
|
opt.setPieces(opt.getPieces() + optPattern.getPieces() );
|
opt.setCompletedPieces(opt.getCompletedPieces() + optPattern.getCompletedPieces() );
|
break;
|
}
|
if (i == opts.size() - 1) {
|
opts.add(new OptPattern(optPattern.getOptId(), optPattern.getGlassId(),
|
optPattern.getDescription(), optPattern.getGlassThickness(),
|
optPattern.getPieces(), optPattern.getCompletedPieces(), optPattern.getWidth(),
|
optPattern.getHeight(), "等待中", optPattern.getColor(), optPattern.getContent(),
|
optPattern.getBatch(), optPattern.getGroups(), optPattern.getRawPackageTxt()));
|
break;
|
}
|
}
|
} else {
|
opts.add(new OptPattern(optPattern.getOptId(), optPattern.getGlassId(), optPattern.getDescription(),
|
optPattern.getGlassThickness(), optPattern.getPieces() , optPattern.getCompletedPieces(),
|
optPattern.getWidth(), optPattern.getHeight(), "等待中", optPattern.getColor(),
|
optPattern.getContent(), optPattern.getBatch(), optPattern.getGroups(),
|
optPattern.getRawPackageTxt()));
|
}
|
}
|
}
|
StringBuffer html = new StringBuffer();
|
|
// <td height="30px">${pattern.glassId}</td>
|
// <td height="30px">${pattern.batch}</td>
|
// <td height="30px">${pattern.width}</td>
|
// <td height="30px">${pattern.height}</td>
|
// <td height="30px">${pattern.glassThickness}</td>
|
// <td height="30px">${pattern.color}</td>
|
// <td height="30px">
|
// <div class="progress-group">
|
// <span class="progress-text">百分比</span> <span
|
// class="progress-number"><b>${pattern.completedPieces}</b>/${pattern.pieces}</span>
|
//
|
// <div class="progress sm">
|
// <div class="progress-bar progress-bar-aqua"
|
// style="width: ${pattern.completedPieces/pattern.pieces*100}%"></div>
|
// </div>
|
// </div> <%-- ${pattern.completedPieces} / ${pattern.pieces} --%>
|
// </td>
|
// </tr>
|
if (opts.size()>0) {
|
for (OptPattern opt : opts) {
|
html.append("<tr>");
|
html.append("<td height='30px'>").append(opt.getGlassId()).append("</td>");
|
html.append("<td height='30px'>").append(opt.getBatch()).append("</td>");
|
html.append("<td height='30px'>").append(opt.getWidth()).append("</td>");
|
html.append("<td height='30px'>").append(opt.getHeight()).append("</td>");
|
html.append("<td height='30px'>").append(opt.getGlassThickness()).append("</td>");
|
html.append("<td height='30px'>").append(opt.getColor()).append("</td>");
|
html.append("<td height='30px'>").append(this.getleftpieces(opt)).append("</td>");
|
html.append("<td height='30px'>").append("<div class='progress-group'><span class='progress-text'>百分比</span> ");
|
html.append("<span class='progress-number'><b>").append(opt.getCompletedPieces()).append("</b>/").append(opt.getPieces()).append("</span>");
|
html.append("<div class='progress sm'><div class='progress-bar progress-bar-aqua' style='width: ").append(opt.getCompletedPieces()/opt.getPieces()*100).append("%'></div></div>");
|
html.append("</td></tr>");
|
}
|
}
|
|
return html.toString();
|
|
}
|
|
private int getleftpieces(OptPattern opt) {
|
List<ShelfRank> ranks = shelfRankDao.findInWorkRankAndInWorkingRanks();
|
int sum = 0;
|
for (ShelfRank rank : ranks) {
|
RawPackage shelfRankRawPackage = rank.getRawPackage();
|
|
if (shelfRankRawPackage.getWidth() == opt.getWidth()
|
&& shelfRankRawPackage.getHeight() == opt.getHeight()
|
&& shelfRankRawPackage.getThickness() == opt.getGlassThickness()
|
&& shelfRankRawPackage.getColor().equals(opt.getColor())) {
|
sum = sum + shelfRankRawPackage.getLeftPieces();
|
}
|
continue;
|
}
|
if (opt.getPieces()-opt.getCompletedPieces()>sum) {
|
return opt.getPieces()-opt.getCompletedPieces()-sum;
|
}
|
return 0;
|
}
|
|
/**
|
* 计算当前完成片数,在前台显示
|
*
|
* @return
|
*/
|
|
public List<Integer> countPiece(List<LoadMachineTask> patterns) {
|
int sumPiece = 0;// 统计总片数
|
int comPiece = 0;// 统计完成片数
|
|
List<Integer> count = new ArrayList<Integer>();
|
|
if (patterns != null) {
|
for (LoadMachineTask load : patterns) {
|
String state = load.getState();
|
if (state.equals(LoadMachineTaskState.COMPLETED)) {
|
comPiece++;
|
}
|
}
|
sumPiece = patterns.size();
|
}
|
|
count.add(0, sumPiece);
|
count.add(1, comPiece);
|
|
return count;
|
|
}
|
|
/**
|
* 结束任务前校验
|
*/
|
public String checkEnd(String id) {
|
// 查看当前产线是否有任务存在(没有说明没有领取任务)
|
boolean prodState = prodLineStateDao.findOne(Long.parseLong(id)).isState();
|
|
if (!prodState)
|
return "notask";
|
return "ok";
|
}
|
|
/**
|
* 结束任务前校验(2号)
|
*/
|
public String checkEnd2() {
|
// 查看当前产线是否有任务存在(没有说明没有领取任务)
|
boolean prodState = prodLineStateDao.findOne((long) 2).isState();
|
|
if (!prodState)
|
return "notask";
|
return "ok";
|
}
|
|
/**
|
* 结束任务
|
*
|
* @param id
|
*/
|
public String endTask(String id, Model model) {
|
// 先判断当前产线上是否还有未切割完成的(是否是正常结束)
|
List<LoadMachineTask> notCompletedTasks = loadMachineTaskDao.findNotCutTask(Long.parseLong(id));
|
if (notCompletedTasks.size() == 0) {
|
RawPackageTxt txt = rawPackageTxtDao.findCutFinishByGroup(id);
|
if (txt != null) {
|
LOGGER.debug("下片没有结束,不能结束任务");
|
return "redirect:/cutmanage/gettask/" + id;// 表示正常结束任务
|
}
|
|
// 说明是正常结束
|
// 打印报表
|
// \\192.168.0.200\\完成计划\\完成计划 (192.168.0.200)
|
// countMachineService.exportAllGlass();
|
|
// 把玻璃全部退到库里面
|
// List<LoadMachineRack> racks =
|
// loadMachineRackDao.findLoadMachineRacksByLoadMachineId(1L);
|
// if (racks.size()>0) {
|
// for (LoadMachineRack rack : racks) {
|
// if (rack.getRawPackage() != null &&
|
// !rack.getState().equals("空闲中")) {
|
// ShelfRank rank =
|
// shelfRankDao.findRankByRawId(rack.getRawPackage().getId());
|
// ShelfTask task = new
|
// ShelfTask(ShelfTaskState.WAITING,ShelfTaskType.FROM_LOAD_MACHINE_RACK_TO_SHELF_RACK,
|
// new Date(),"1",rank,rack);
|
// shelfTaskDao.save(task);
|
// }
|
// }
|
// }
|
// 将表中的记录拿出放到统计表中
|
List<LoadMachineTask> loadMachineTasks = loadMachineTaskDao.findById(Long.parseLong(id));
|
if (loadMachineTasks.size() != 0) {
|
// 拿到批次号
|
String optName = loadMachineTasks.get(0).getDescription();
|
|
// 找到是否有相同批次的记录
|
List<String> optNames = reportTaskDao.findOptName(optName);
|
String newOptName = "";
|
if (optNames.size() == 0) {
|
// 没有记录过这种批次
|
newOptName = optName + "-1";// 第一次领取此批次
|
} else {
|
// 不是第一次领取过这个批次
|
// 找出最后那次领取的批次号
|
int temp = 0;
|
for (int l = 0; l < optNames.size(); l++) {
|
String name = optNames.get(l);
|
int startIndex = name.indexOf("-");// 找到分隔符的下标
|
|
int temp1 = Integer.valueOf(name.substring(startIndex + 1, name.length()));
|
|
if (temp < temp1) {
|
temp = temp1;
|
}
|
}
|
newOptName = optName + "-" + (temp + 1);
|
}
|
// 获取task对象,生成报告
|
for (int i = 0; i < loadMachineTasks.size(); i++) {
|
LoadMachineTask loadMachineTask = loadMachineTasks.get(i);
|
OptPattern optPattern = loadMachineTask.getOptPattern();
|
Date createTime = optPattern.getRawPackageTxt().getCreateTime();
|
String state = loadMachineTask.getState();
|
LoadMachine loadMachine = loadMachineTask.getLoadMachine();
|
DecimalFormat dFormat = new DecimalFormat("######0.00");
|
Double area = (double) (loadMachineTask.getOptPattern().getHeight() / 1000)
|
* (double) (loadMachineTask.getOptPattern().getWidth() / 1000);
|
area = Double.valueOf(dFormat.format(area));
|
ReportTask reportTask = new ReportTask(newOptName, 1, state, createTime, new Date(), null,
|
loadMachine, optPattern, area);
|
reportTaskDao.save(reportTask);
|
}
|
|
ProdLineState pro = prodLineStateDao.findById(Integer.parseInt(id));// 拿出第一条产线
|
pro.setState(false);// 将该产线设置为无任务
|
prodLineStateDao.save(pro);
|
|
LoadMachineTask loadMachineTask = loadMachineTasks.get(0);
|
RawPackageTxt rawPackageTxt = loadMachineTask.getOptPattern().getRawPackageTxt();
|
if (rawPackageTxt != null) {
|
// 发给派尔的使用小片完工报表
|
// countMachineService.exportAllGlass(rawPackageTxt.getTxt_name());
|
// 发给派尔的使用原片报表
|
// countMachineService.exportUseGlass(rawPackageTxt.getTxt_name());
|
// 将产线上的opt文件名清空
|
loadMachineDao.findOne((long) 1).setOpt_name(null);
|
rawPackageTxt.setStatus(RawPackageTxtState.COMPLETED);// "已完成"
|
rawPackageTxtDao.save(rawPackageTxt);
|
//删除glass order
|
List<GlassOrder> order = glassOrderDao.findByBatch(rawPackageTxt.getTxt_name());
|
for (int i = 0; i < order.size(); i++) {
|
glassOrderDao.delete(order.get(i));
|
}
|
}
|
|
// 清空当前产线上片位的缺片信息
|
List<LoadMachineRack> loadMachineRacks = loadMachineDao.findOne(Long.parseLong(id))
|
.getLoadMachineRacks();
|
for (LoadMachineRack rack : loadMachineRacks) {
|
String message = rack.getMessage();
|
if (message != null && !"".equals(message)) {
|
rack.setMessage(null);
|
}
|
}
|
|
// 清空当前任务的所有optpattern的状态
|
for (int i = 0; i < loadMachineTasks.size(); i++) {
|
String state = loadMachineTasks.get(i).getOptPattern().getState();
|
if (state != null && !"".equals(state)) {
|
// 设置为null
|
loadMachineTasks.get(i).getOptPattern().setState(null);
|
}
|
|
}
|
// List<LoadMachineTask> tasks = new
|
// ArrayList<LoadMachineTask>(); ;
|
// 导入数据包
|
// if (loadMachineTasks.size()>0) {
|
// for (int i = 0; i < loadMachineTasks.size(); i++) {
|
// //\\192.168.0.200\\完成计划\\完成计划 (192.168.0.200)
|
// LoadMachineTask tMachineTask = loadMachineTasks.get(i);
|
// if (tasks.size() == 0) {
|
// loadMachineTasks task = loadMachineTask
|
// }
|
// }
|
// }
|
// \\192.168.0.200\\完成计划\\完成计划 (192.168.0.200)
|
// 清空当前产线的切割任务
|
loadMachineTaskDao.deleteByLoadMachineId(Long.parseLong(id));
|
|
|
}
|
|
return "redirect:/cutmanage/gettask/" + id;// 表示正常结束任务
|
} else {
|
// 非正常结束
|
Map<String, Object> param1 = manageService.showMachineState();
|
model.addAttribute("allstatu", param1.get("allstatu"));
|
model.addAttribute("info", param1.get("info"));
|
model.addAttribute("id", id);
|
return "cutmanage/writereason";
|
}
|
|
}
|
|
/**
|
* 结束任务(2号)
|
*/
|
public String endTask2() {
|
// 先判断当前产线上是否还有未切割完成的(是否是正常结束)
|
List<LoadMachineTask> notCompletedTasks = loadMachineTaskDao.findNotCompletedTask((long) 2);
|
if (notCompletedTasks.size() == 0) {
|
// 说明是正常结束
|
// 将表中的记录拿出放到统计表中
|
List<LoadMachineTask> loadMachineTasks = loadMachineTaskDao.findById((long) 2);
|
if (loadMachineTasks.size() != 0) {
|
// 找到批次号
|
String optName = loadMachineTasks.get(0).getDescription();
|
|
// 找到是否有相同批次的记录
|
List<String> optNames = reportTaskDao.findOptName(optName);
|
String newOptName = "";
|
if (optNames.size() == 0) {
|
// 没有记录过这种批次
|
newOptName = optName + "-1";// 第一次领取此批次
|
} else {
|
// 不是第一次领取过这个批次
|
// 找出最后那次领取的批次号
|
int temp = 0;
|
for (int l = 0; l < optNames.size(); l++) {
|
String name = optNames.get(l);
|
int startIndex = name.indexOf("-");// 找到分隔符的下标
|
|
int temp1 = Integer.valueOf(name.substring(startIndex + 1, name.length()));
|
|
if (temp < temp1) {
|
temp = temp1;
|
}
|
}
|
newOptName = optName + "-" + (temp + 1);
|
}
|
// 获取task对象,处理
|
for (int i = 0; i < loadMachineTasks.size(); i++) {
|
LoadMachineTask loadMachineTask = loadMachineTasks.get(i);
|
OptPattern optPattern = loadMachineTask.getOptPattern();
|
Date createTime = optPattern.getRawPackageTxt().getCreateTime();
|
String state = loadMachineTask.getState();
|
LoadMachine loadMachine = loadMachineTask.getLoadMachine();
|
DecimalFormat dFormat = new DecimalFormat("######0.00");
|
Double area = (double) (loadMachineTask.getOptPattern().getHeight() / 1000)
|
* (double) (loadMachineTask.getOptPattern().getWidth() / 1000);
|
area = Double.valueOf(dFormat.format(area));
|
ReportTask reportTask = new ReportTask(newOptName, 1, state, createTime, new Date(), null,
|
loadMachine, optPattern, area);
|
reportTaskDao.save(reportTask);
|
}
|
|
ProdLineState pro = prodLineStateDao.findById(2);// 拿出第一条产线
|
pro.setState(false);// 将该产线设置为无任务
|
prodLineStateDao.save(pro);
|
|
LoadMachineTask loadMachineTask = loadMachineTasks.get(0);
|
RawPackageTxt rawPackageTxt = loadMachineTask.getOptPattern().getRawPackageTxt();
|
if (rawPackageTxt != null) {
|
// 将产线上的opt文件名清空
|
loadMachineDao.findOne((long) 2).setOpt_name(null);
|
|
rawPackageTxt.setStatus(RawPackageTxtState.COMPLETED);// "已完成"
|
rawPackageTxtDao.save(rawPackageTxt);
|
}
|
|
// 清空当前产线上片位的缺片信息
|
List<LoadMachineRack> loadMachineRacks = loadMachineDao.findOne((long) 2).getLoadMachineRacks();
|
for (LoadMachineRack rack : loadMachineRacks) {
|
String message = rack.getMessage();
|
if (message != null && !"".equals(message)) {
|
rack.setMessage(null);
|
}
|
}
|
|
// 清空当前任务的所有optpattern的状态
|
for (int i = 0; i < loadMachineTasks.size(); i++) {
|
String state = loadMachineTasks.get(i).getOptPattern().getState();
|
if (state != null && !"".equals(state)) {
|
// 设置为null
|
loadMachineTasks.get(i).getOptPattern().setState(null);
|
}
|
|
}
|
|
// 清空当前产线的切割任务
|
loadMachineTaskDao.deleteByLoadMachineId((long) 2);
|
|
}
|
|
return "redirect:/cutmanage/gettask2";// 表示正常结束任务
|
} else {
|
// 非正常结束
|
return "cutmanage/writereason2";// 填写原因页面
|
|
}
|
|
}
|
|
/**
|
* 异常结束任务处理(填写原因后)
|
*
|
* @throws UnsupportedEncodingException
|
*/
|
public void exceptionEndTask(HttpServletRequest request, String prodLine) throws UnsupportedEncodingException {
|
request.setCharacterEncoding("utf-8");// 设置编码防止中文乱码
|
String reson;
|
LOGGER.debug("prodLine:"+prodLine);
|
/// 把玻璃全部退到库里面
|
// List<LoadMachineRack> racks =
|
// loadMachineRackDao.findLoadMachineRacksByLoadMachineId(1L);
|
// if (racks.size()>0) {
|
// for (LoadMachineRack rack : racks) {
|
// if (rack.getRawPackage() != null && !rack.getState().equals("空闲中")) {
|
// ShelfRank rank =
|
// shelfRankDao.findRankByRawId(rack.getRawPackage().getId());
|
// ShelfTask task = new
|
// ShelfTask(ShelfTaskState.WAITING,ShelfTaskType.FROM_LOAD_MACHINE_RACK_TO_SHELF_RACK,
|
// new Date(),"1",rank,rack);
|
// shelfTaskDao.save(task);
|
// }
|
// }
|
// }
|
// //磨边机结束任务
|
// GaoliweiController.setButton("1");
|
// GaoliweiController.setButton1("1");
|
List<LoadMachineTask> loadMachineTasks = loadMachineTaskDao.findById(Long.valueOf(prodLine));
|
if (loadMachineTasks.size() != 0) {
|
// 拿到批次号
|
String optName = loadMachineTasks.get(0).getDescription();
|
|
// 找到是否有相同批次的记录
|
List<String> optNames = reportTaskDao.findOptName(optName);
|
String newOptName = "";
|
if (optNames.size() == 0) {
|
// 没有记录过这种批次
|
newOptName = optName + "-1";// 第一次领取此批次
|
} else {
|
// 不是第一次领取过这个批次
|
// 找出最后那次领取的批次号
|
int temp = 0;
|
for (int l = 0; l < optNames.size(); l++) {
|
String name = optNames.get(l);
|
int startIndex = name.indexOf("-");// 找到分隔符的下标
|
|
int temp1 = Integer.valueOf(name.substring(startIndex + 1, name.length()));
|
|
if (temp < temp1) {
|
temp = temp1;
|
}
|
}
|
newOptName = optName + "-" + (temp + 1);
|
}
|
// 获取task对象,处理
|
for (int i = 0; i < loadMachineTasks.size(); i++) {
|
LoadMachineTask loadMachineTask = loadMachineTasks.get(i);
|
OptPattern optPattern = loadMachineTask.getOptPattern();
|
Date createTime = optPattern.getRawPackageTxt().getCreateTime();
|
String state = loadMachineTask.getState();
|
if (!state.equals(LoadMachineTaskState.COMPLETED)) {
|
// 状态不是已完成的统统设置为‘未完成’
|
state = LoadMachineTaskState.NOT_COMPLETE;
|
reson = new String(request.getParameter("reson").getBytes("iso8859-1"), "utf-8");
|
} else {
|
reson = null;
|
}
|
LoadMachine loadMachine = loadMachineTask.getLoadMachine();
|
DecimalFormat dFormat = new DecimalFormat("######0.00");
|
Double area = (double) (loadMachineTask.getOptPattern().getHeight() / 1000)
|
* (double) (loadMachineTask.getOptPattern().getWidth() / 1000);
|
area = Double.valueOf(dFormat.format(area));
|
ReportTask reportTask = new ReportTask(newOptName, 1, state, createTime, new Date(), reson, loadMachine,
|
optPattern, area);
|
reportTaskDao.save(reportTask);
|
}
|
|
// 拿到正在工作的原片
|
LoadMachineTask workingGlass = loadMachineTaskDao.findWorkingGlass((long) 1);
|
if (workingGlass != null) {
|
|
// 找到正在工作的rawpackage
|
LoadMachineRack loadMachineRack = workingGlass.getLoadMachineRack();
|
if (loadMachineRack != null) {
|
RawPackage rawPackage = loadMachineRack.getRawPackage();
|
|
if (rawPackage != null && rawPackage.getLeftPieces() > 0) {
|
// 当没有收到上片完成时
|
rawPackage.setLeftPieces(rawPackage.getLeftPieces() - 1);// 设置片数
|
|
rawPackage.setState(ShelfRankState.IN_WORKING);// 备用
|
|
// 设置已用片数
|
String manufacturer = rawPackage.getManufacturer();
|
int manu = 0;
|
if (manufacturer != null && !"".equals(manufacturer)) {
|
manu = Integer.valueOf(manufacturer);
|
}
|
rawPackage.setManufacturer(String.valueOf(manu + 1));
|
|
// // 将正在工作的这一片设置成完成状态
|
// workingGlass.setState(LoadMachineTaskState.COMPLETED);
|
// // 将对应的pattern完成片数加1
|
// workingGlass.getOptPattern()
|
// .setCompletedPieces(workingGlass.getOptPattern().getCompletedPieces()
|
// + 1);
|
|
}
|
}
|
}
|
|
ProdLineState pro = prodLineStateDao.findById(Integer.valueOf(prodLine));// 拿出第一条产线
|
pro.setState(false);// 将该产线设置为无任务
|
prodLineStateDao.save(pro);
|
// 当前产线的领取任务
|
RawPackageTxt rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup(prodLine);
|
if (rawPackageTxt != null) {
|
// 清空产线opt文件名
|
loadMachineDao.findOne(Long.valueOf(prodLine)).setOpt_name(null);
|
|
rawPackageTxt.setStatus(RawPackageTxtState.INTERRUPT);// "中断"
|
rawPackageTxtDao.save(rawPackageTxt);
|
//删除glass order
|
List<GlassOrder> order = glassOrderDao.findByBatch(rawPackageTxt.getTxt_name());
|
for (int i = 0; i < order.size(); i++) {
|
glassOrderDao.delete(order.get(i));
|
}
|
}
|
// // 删除占用状态
|
// List<RawPackage> rawPackages =
|
// rawPackageDao.findByRawPackageTxtId(rawPackageTxt.getId());
|
// for (RawPackage rawPackage : rawPackages) {
|
// ShelfRank rank =
|
// shelfRankDao.findRankByRawId(rawPackage.getId());
|
// rank.setUsestatu(null);
|
// shelfRankDao.save(rank);
|
// }
|
// ShelfRank rank =
|
// shelfRankDao.findRankByRawId(rawPackageTxt.getId());
|
|
// 清空当前产线上片位的缺片信息
|
List<LoadMachineRack> loadMachineRacks = loadMachineDao.findOne(Long.valueOf(prodLine))
|
.getLoadMachineRacks();
|
for (LoadMachineRack rack : loadMachineRacks) {
|
String message = rack.getMessage();
|
if (message != null && !"".equals(message)) {
|
rack.setMessage(null);
|
}
|
}
|
|
// 清空当前任务的所有optpattern的状态
|
for (int i = 0; i < loadMachineTasks.size(); i++) {
|
String state = loadMachineTasks.get(i).getOptPattern().getState();
|
if (state != null && !"".equals(state)) {
|
// 设置为null
|
loadMachineTasks.get(i).getOptPattern().setState(null);
|
}
|
|
}
|
|
// 清空当前产线的切割任务
|
loadMachineTaskDao.deleteByLoadMachineId(Long.valueOf(prodLine));
|
|
}
|
}
|
|
/**
|
* 查看当前正在工作的玻璃
|
*
|
* @return
|
*/
|
|
public String workingGlass(HttpServletRequest request) {
|
String param = request.getParameter("id");
|
long id = Long.parseLong(param);
|
System.out.println("id:"+id);
|
String json = "";
|
// 拿到当前产线上状态为正在工作的对象
|
LoadMachineTask completeGlass = loadMachineTaskDao.findLastCompleted(id);
|
if (completeGlass != null) {
|
// 拿到工位
|
RawPackage rawPackage = completeGlass.getRawPackage();
|
if (rawPackage != null) {
|
// 正在使用
|
RawPackageTxt rawPackageTxt = rawPackage.getRawPackageTxt();
|
// 在自动创建的吊装任务是不分配批次的
|
if (rawPackageTxt != null) {
|
json = "切割 ---> 批次:" + rawPackageTxt.getTxt_name() + ",宽度:" + rawPackage.getWidth() + ",高度:"
|
+ rawPackage.getHeight() + ",厚度:" + rawPackage.getThickness() + ",膜系品种:"
|
+ rawPackage.getColor();
|
} else {
|
json = "切割 ---> 宽度:" + rawPackage.getWidth() + ",高度:" + rawPackage.getHeight() + ",厚度:"
|
+ rawPackage.getThickness() + ",膜系品种:" + rawPackage.getColor();
|
}
|
return json;
|
}
|
}
|
json = "当前无正在切割的玻璃";// 当前无正在切割的玻璃
|
return json;
|
|
}
|
|
/**
|
* 下载opt文件到服务器
|
*
|
* @return
|
* @throws IOException
|
*/
|
public String downOptFile(HttpServletRequest request, String loadmachineid, HttpServletResponse response)
|
throws IOException {
|
Long LoadMachineId = Long.valueOf(loadmachineid);
|
|
RawPackageTxt gotTask = rawPackageTxtDao.findAcceptedByGroup(String.valueOf(LoadMachineId));// 找到对应产线中状态为已领取的任务
|
if (gotTask == null) {
|
return "notask";
|
}
|
String batch = gotTask.getTxt_name();
|
// 先判断领取的任务是中断过的还是第一次领取的
|
List<ReportTask> reportTasks = reportTaskDao.findByOptNameLike(batch);
|
List<OptPattern> optPatterns = new ArrayList<OptPattern>();
|
if (reportTasks.size() == 0) {
|
// 说明是第一次领取该任务
|
optPatterns = new ArrayList<OptPattern>(gotTask.getOptPatternes());
|
|
} else {
|
// 该任务是中断过的
|
List<OptPattern> optpatterns = optPatternDao.findOptPatternByBatchNumber(batch);
|
|
if (optpatterns.size() != 0) {
|
for (int i = 0; i < optpatterns.size(); i++) {
|
OptPattern optPattern = optpatterns.get(i);
|
// 去除已经完成的pattern
|
if (optPattern.getPieces() == optPattern.getCompletedPieces()) {
|
optpatterns.remove(optPattern);
|
i--;
|
}
|
}
|
}
|
|
for (int j = 0; j < optpatterns.size(); j++) {
|
OptPattern optPatter = optpatterns.get(j);// 根据id拿到optpatter
|
|
// 根据optpattern对象将content字段内容中的片数做相应的修改
|
// 判断这个pattern是否已经部分片数完成了,如果完成就需要修改片数
|
int completedPieces = optPatter.getCompletedPieces();
|
if (completedPieces == 0) {
|
// 一片都没有完成,无需更改pieces
|
optPatterns.add(optPatter);
|
} else {
|
// 获取未完成片数
|
int notCompletePieces = optPatter.getPieces() - completedPieces;
|
|
// 设置content中接下来需要切割的片数
|
String content = optPatter.getContent();
|
int pieIndex = content.indexOf("Pieces");
|
int widthIndex = content.indexOf("Width");
|
String substring1 = content.substring(0, pieIndex);// 截取出pieces前段部分
|
String substring2 = content.substring(widthIndex, content.length());// 后半部分
|
|
// 替换掉中间的部分(例如Pieces=4)
|
content = substring1 + "Pieces=" + String.valueOf(notCompletePieces) + "\n" + substring2;
|
String optId = optPatter.getOptId();
|
String glassId = optPatter.getGlassId();
|
String glassDescription = optPatter.getGlassDescription();
|
double glassThickness = optPatter.getGlassThickness();
|
int pieces = optPatter.getPieces();
|
double width = optPatter.getWidth();
|
double height = optPatter.getHeight();
|
String state = optPatter.getState();
|
String color = optPatter.getColor();
|
String batch_name = optPatter.getBatch();
|
String groups = optPatter.getGroups();
|
RawPackageTxt rawPackageTxt = optPatter.getRawPackageTxt();
|
OptPattern pattern = new OptPattern(optId, glassId, glassDescription, glassThickness, pieces,
|
completedPieces, width, height, state, color, content, batch_name, groups, rawPackageTxt);
|
optPatterns.add(pattern);
|
}
|
}
|
}
|
|
SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
|
String fileName = "CUTMACHINE" + LoadMachineId.toString() + "_" + batch + "_" + timeFormat.format(new Date())
|
+ ".opt";
|
|
// 创建项目下载文件夹
|
this.initializeTempDir(request);
|
|
File file = null;
|
FileWriter writer = null;
|
|
if (LoadMachineId == 1) {
|
this.delFolder(TEMP_PATH1, request, response, loadmachineid);
|
file = new File(TEMP_PATH1 + File.separator + fileName);
|
}
|
|
if (LoadMachineId == 2) {
|
this.delFolder(TEMP_PATH2, request, response, loadmachineid);
|
file = new File(TEMP_PATH2 + File.separator + fileName);
|
}
|
|
try {
|
writer = new FileWriter(file);
|
|
// 打印头部信息
|
writer.write("[OPT_Header]\n");
|
writer.write("OPTCutVersion=1.0\n");
|
writer.write("Dimension=mm\n");
|
writer.write("Date=" + dateFormat.format(new Date()));
|
writer.write("\n\n");
|
writer.write("[OPT_Signature]\n");
|
writer.write("派尔www.glassoo.com\n");
|
writer.write("\n");
|
|
for (OptPattern optPattern : optPatterns) {
|
String string=optPattern.getContent();
|
writer.write(string);
|
}
|
writer.flush();
|
} catch (IOException e) {
|
// 打印异常
|
LOGGER.debug(e.getMessage());
|
e.printStackTrace();
|
return "false";
|
} finally {
|
if (writer != null) {
|
writer.close();
|
}
|
}
|
|
return fileName;
|
}
|
|
/**
|
* 删除项目中opt文件夹下的所有旧的opt
|
*
|
* @param folderPath
|
* @throws IOException
|
*/
|
public void delFolder(String folderPath, HttpServletRequest request, HttpServletResponse response,
|
String loadmachine) throws IOException {
|
try {
|
File file = new File(folderPath);
|
String[] filelist = file.list();
|
if (filelist != null) {
|
for (int i = 0; i < filelist.length; i++) {
|
File delfile = new File(folderPath + File.separator + filelist[i]);
|
delfile.delete();
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
/**
|
* 下载项目中的文件到本地
|
*
|
* @param url
|
* @param response
|
* @throws Exception
|
*/
|
public String downModelLoad(HttpServletRequest request, HttpServletResponse response, Long LoadMachineId) {
|
|
File file = null;
|
// String filePath = null;
|
|
// 将TEMP_PATH赋值
|
//this.initializeTempDir(request);
|
List<LoadMachineTask> tasks = loadMachineTaskDao.findNumberByLoadMachine(LoadMachineId);
|
// 取得文件的名称
|
if (LoadMachineId == 1) {
|
//file = new File(TEMP_PATH1);
|
file = new File("F:\\opt\\optFile1.opt");
|
//filePath = TEMP_PATH1 + File.separator + file.list()[0];
|
}
|
|
if (LoadMachineId == 2) {
|
//file = new File(TEMP_PATH2);
|
file = new File("F:\\opt\\optFile2.opt");
|
// filePath = TEMP_PATH2 + File.separator + file.list()[0];
|
// LOGGER.debug("filePath" + filePath);
|
}
|
|
FileWriter writer = null;
|
|
// OutputStream out = null;
|
// InputStream fis = null;
|
try {
|
writer = new FileWriter(file);
|
// 打印头部信息
|
writer.write("[OPT_Header]\n");
|
writer.write("OPTCutVersion=1.0\n");
|
writer.write("Dimension=mm\n");
|
writer.write("Date=" + new Date());
|
writer.write("\n\n");
|
writer.write("[OPT_Signature]\n");
|
writer.write("北玻www.northglass.com\n");
|
writer.write("\n");
|
// response.reset();
|
// // 转换格式
|
// response.setCharacterEncoding("UTF-8");
|
// response.setContentType("application/x-download");
|
// response.setHeader("Content-Disposition", "attachment;filename=" + file.list()[0]);
|
|
|
for (LoadMachineTask task : tasks) {
|
LOGGER.debug("ID:"+task.getOptPattern().getId());
|
String string = task.getOptPattern().getContent();
|
String tString ="Pieces="+task.getOptPattern().getPieces();
|
string = string.replaceAll(tString, "Pieces=1");
|
writer.write(string);
|
}
|
writer.flush();
|
|
// File newFile = new File(filePath);
|
//
|
// out = response.getOutputStream();
|
//
|
// fis = new FileInputStream(newFile);
|
//
|
// // 存储文件的buffer
|
// int len = 0;
|
// byte[] buffer = new byte[1024];
|
//
|
// // 将文件写出
|
// while ((len = fis.read(buffer)) != -1) {
|
// out.write(buffer, 0, len);
|
// }
|
//
|
// // 刷出流
|
// out.flush();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
LOGGER.error("【下载失败】" + e);
|
} finally {
|
try {
|
if (writer != null) {
|
writer.close();
|
}
|
// if (out != null) {
|
//
|
// out.close();
|
// }
|
// if (fis != null) {
|
//
|
// fis.close();
|
// }
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
|
}
|
return "redirect:/cutmanage/gettask/"+LoadMachineId;
|
}
|
|
// 创建项目文件夹
|
private void initializeTempDir(HttpServletRequest request) {
|
if (WEB_ROOT_PATH == null || WEB_ROOT_PATH.equals("")) {
|
WEB_ROOT_PATH = request.getSession().getServletContext().getRealPath("/");
|
LOGGER.debug("WEB_ROOT_PATH: " + WEB_ROOT_PATH);
|
|
TEMP_PATH1 = WEB_ROOT_PATH + File.separator + "static" + File.separator + "optFile1";
|
TEMP_PATH2 = WEB_ROOT_PATH + File.separator + "static" + File.separator + "optFile2";
|
|
LOGGER.debug("TEMP_PATH: " + TEMP_PATH1);
|
LOGGER.debug("TEMP_PATH: " + TEMP_PATH2);
|
|
File tempDir1 = new File(TEMP_PATH1);
|
if (tempDir1.exists()) {
|
tempDir1.delete();
|
}
|
if (!tempDir1.exists()) {
|
tempDir1.mkdirs();
|
}
|
File tempDir2 = new File(TEMP_PATH2);
|
if (tempDir2.exists()) {
|
tempDir2.delete();
|
}
|
if (!tempDir2.exists()) {
|
tempDir2.mkdirs();
|
}
|
|
}
|
}
|
|
public void manual() {
|
LoadMachineTask loadMachineTask = loadMachineTaskDao.findInWorkTaskByLoadMachine(1L);
|
List<LoadMachineRack> racks = loadMachineRackDao.findAll();
|
if (loadMachineTask != null) {
|
loadMachineTask.setState(LoadMachineTaskState.COMPLETED);
|
loadMachineTask.setCompleteTime(new Date());
|
loadMachineTaskDao.save(loadMachineTask);
|
if (racks.size() > 0) {
|
for (int i = 0; i < racks.size(); i++) {
|
LoadMachineRack rack = racks.get(i);
|
RawPackage rawPackage = rack.getRawPackage();
|
if (rawPackage != null && rawPackage.getLeftPieces() > 0) {
|
rawPackage.setState(ShelfRankState.START);
|
rawPackage.setLeftPieces(rawPackage.getLeftPieces() - 1);
|
rawPackageDao.save(rawPackage);
|
}
|
}
|
}
|
}
|
}
|
|
public void stoptask(String id) {
|
List<LoadMachineTask> loadMachineTasks = loadMachineTaskDao.findWaitingTasksByLoadMachine(Long.valueOf(id));
|
List<LoadMachineTask> tasks = loadMachineTaskDao.findStopTasksByLoadMachine(1L);
|
if (loadMachineTasks.size() > 0) {
|
for (LoadMachineTask loadMachineTask : loadMachineTasks) {
|
loadMachineTask.setState(LoadMachineTaskState.STOP_TASK);
|
loadMachineTaskDao.save(loadMachineTask);
|
}
|
} else {
|
for (LoadMachineTask loadMachineTask : tasks) {
|
loadMachineTask.setState(LoadMachineTaskState.WAITING);
|
loadMachineTaskDao.save(loadMachineTask);
|
}
|
}
|
}
|
|
/**
|
* 标签打印
|
*
|
* @param id
|
* 打印机号
|
*
|
*
|
*
|
**/
|
public void jbarprint(String id) {
|
PrintMachine printMachin = printMachineDao.findByLine(id);
|
RawPackageTxt txt = rawPackageTxtDao.findAcceptedByGroup(id);
|
if (txt != null) {
|
List<Glass> glasses = glassDao.findByBatch(txt.getTxt_name());
|
if (glasses.size() > 0) {
|
for (Glass glass : glasses) {
|
for (int i = 0; i < glass.getPieces(); i++) {
|
new GMMSPrinter(glass.getCustomer(), glass.getApplication(), glass.getProduction(),
|
glass.getFloor_number(), glass.getOrder_number(), glass.getWidth(), glass.getLength(),
|
glass.getApart_id(), glass.getPiece_sign(), glass.getRemark(), id, glass.getPieces(),
|
1L, printMachin.getName(), printMachin.getStatu(), glass.getArrangeStatu(),glass.getThingsout()).doPrint();
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 剩余标签打印
|
*
|
* @param id
|
* 打印机号
|
*
|
*
|
*
|
**/
|
public void print(String id) {
|
PrintMachine printMachin = printMachineDao.findByLine(id);
|
if (id.equals("1")) {
|
String s = "";
|
List<CountMachineTask> tasks = countMachineTaskDao.findByCountMachine(2L);
|
if (tasks.size() > 0) {
|
s = "2";
|
} else {
|
s = "1";
|
}
|
RawPackageTxt txt = rawPackageTxtDao.findAcceptedByGroup(s);
|
LOGGER.debug("打印剩余的玻璃标签!");
|
if (txt != null) {
|
List<Glass> glasses = glassDao.findByBatch(txt.getTxt_name());
|
if (glasses.size() > 0) {
|
for (Glass glass : glasses) {
|
if (glass.getPieces() > glass.getCompletePieces()) {
|
for (int i = 0; i < glass.getPieces() - glass.getCompletePieces(); i++) {
|
new GMMSPrinter(glass.getCustomer(), glass.getApplication(), glass.getProduction(),
|
glass.getFloor_number(), glass.getOrder_number(), glass.getWidth(),
|
glass.getLength(), glass.getApart_id(), glass.getPiece_sign(),
|
glass.getRemark(), s, glass.getPieces(), 1L, printMachin.getName(),
|
printMachin.getStatu(), glass.getArrangeStatu(),glass.getThingsout()).doPrint();
|
}
|
}
|
|
}
|
}
|
}
|
}
|
|
}
|
|
public String errordeal(String id) {
|
StringBuffer html = new StringBuffer();
|
|
RawPackageTxt txt = rawPackageTxtDao.findAcceptedByGroup(id);
|
if (txt != null) {
|
List<LoadMachineTask> tasks = loadMachineTaskDao.findSortTask(Long.valueOf(id));
|
if (tasks.size() > 0) {
|
for (LoadMachineTask task : tasks) {
|
html.append("<tr><td>").append(task.getId()).append("</td>");
|
html.append("<td>").append(task.getOptPattern().getGlassId()).append("</td>");
|
html.append("<td>").append(task.getOptPattern().getBatch()).append("</td>");
|
html.append("<td>").append(task.getOptPattern().getWidth()).append("</td>");
|
html.append("<td>").append(task.getOptPattern().getHeight()).append("</td>");
|
html.append("<td>").append(task.getOptPattern().getGlassThickness()).append("</td>");
|
html.append("<td>").append(task.getOptPattern().getColor()).append("</td>");
|
html.append("<td>").append(task.getState()).append("</td>");
|
if (task.getState().equals(LoadMachineTaskState.WAITING)) {
|
html.append("<td>").append("<a href='/gmms2/cutmanage/finishtask/").append(task.getId()).append("/").append(id)
|
.append("' class='btn btn-large btn-success' type='button'>设置完成</a>");
|
} else if (task.getState().equals(LoadMachineTaskState.COMPLETED) ||task.getState().equals(LoadMachineTaskState.CUT_FINISH)) {
|
html.append("<td>").append("<a href='/gmms2/cutmanage/againtask/").append(task.getId()).append("/").append(id)
|
.append("' class='btn btn-large btn-danger' type='button'>重新开始</a>");
|
} else if (task.getState().equals(LoadMachineTaskState.IN_WORK)) {
|
html.append("<td>").append("<a href='/gmms2/cutmanage/finishtask/").append(task.getId()).append("/").append(id)
|
.append("' class='btn btn-large btn-success' type='button'>设置完成</a>");
|
}
|
else {
|
html.append("<td>").append("<a href='#'class='btn btn-large btn-warning' type='button'>暂停等待</a>");
|
}
|
html.append("<a href='/gmms2/cutmanage/getsingalglass/").append(task.getOptPattern().getId()).append("/").append(id)
|
.append("' class='btn btn-large btn-success' type='button'>小片信息</a>");
|
html.append("<td>").append("<a href='/gmms2/cutmanage/getoneglass/").append(task.getId()).append("/").append(id)
|
.append("' class='btn btn-large btn-success' type='button'>切割下发</a>").append("</td>");
|
html.append("</tr>");
|
}
|
}
|
}
|
return html.toString();
|
}
|
|
public void finishtask(String id) {
|
LoadMachineTask task = loadMachineTaskDao.findOne(Long.valueOf(id));
|
if (task != null) {
|
task.setState(LoadMachineTaskState.COMPLETED);
|
loadMachineTaskDao.save(task);
|
OptPattern optPattern = task.getOptPattern();
|
LOGGER.debug("optPattern.compieces:"+optPattern.getCompletedPieces());
|
optPattern.setCompletedPieces(optPattern.getCompletedPieces() + 1);
|
LOGGER.debug("optPattern.compieces后:"+optPattern.getCompletedPieces());
|
optPatternDao.save(optPattern);
|
}
|
}
|
|
public void againtask(String id) {
|
LoadMachineTask task = loadMachineTaskDao.findOne(Long.valueOf(id));
|
if (task != null) {
|
task.setState(LoadMachineTaskState.WAITING);
|
loadMachineTaskDao.save(task);
|
OptPattern optPattern = task.getOptPattern();
|
optPattern.setCompletedPieces(optPattern.getCompletedPieces() - 1);
|
optPatternDao.save(optPattern);
|
}
|
}
|
|
public String exitTask(String id) {
|
// 把玻璃全部退到库里面
|
List<LoadMachineRack> racks = loadMachineRackDao.findLoadMachineRacksByLoadMachineId(Long.valueOf(id));
|
if (racks.size() > 0) {
|
for (LoadMachineRack rack : racks) {
|
if (rack.getRawPackage() != null && !rack.getState().equals("空闲中")) {
|
ShelfTask fromLoadMachineRackToShelfRack = shelfTaskDao.findShelfTaskFromLoadMachineRackToShelfRack(
|
rack.getId(), rack.getRawPackage().getShelfRank().getId());
|
if (fromLoadMachineRackToShelfRack == null) {
|
ShelfRank rank = shelfRankDao.findRankByRawId(rack.getRawPackage().getId());
|
ShelfTask task = new ShelfTask(ShelfTaskState.WAITING,
|
ShelfTaskType.FROM_LOAD_MACHINE_RACK_TO_SHELF_RACK, new Date(), id, rank, rack);
|
shelfTaskDao.save(task);
|
}
|
}
|
}
|
}
|
return "ok";
|
}
|
|
public String deletetask(HttpServletRequest request) {
|
String txtid = request.getParameter("txtid");// 获取opt文件的id(即rawpackagetxtid)
|
RawPackageTxt rawPackageTxt = rawPackageTxtDao.findOne(Long.valueOf(txtid));
|
if (rawPackageTxt != null) {
|
rawPackageTxt.setStatus(RawPackageTxtState.COMPLETED);
|
rawPackageTxtDao.save(rawPackageTxt);
|
// 删除玻璃小片的数据
|
String name = rawPackageTxt.getTxt_name();
|
List<Glass> glasses = glassDao.findByBatch(name);
|
for(Glass glass :glasses){
|
glassDao.delete(glass);
|
}
|
List<SingalGlass> singalGlasses = singalGlassDao.findByBatch(name);
|
if (singalGlasses.size()>0) {
|
for (SingalGlass singalGlass : singalGlasses) {
|
singalGlassDao.delete(singalGlass);
|
}
|
}
|
// 删除当前的opt文件
|
List<OptPattern> optPatterns = optPatternDao.findOptPatternByBatchNumber(name);
|
for(OptPattern optPattern :optPatterns){
|
List<ReportTask> reportTaskes = reportTaskDao.findByoptPatternId(optPattern.getId());
|
if (reportTaskes.size()>0) {
|
for (ReportTask reportTask :reportTaskes) {
|
reportTaskDao.delete(reportTask);
|
}
|
}
|
optPatternDao.delete(optPattern);
|
}
|
return "ok";
|
} else {
|
return "no";
|
}
|
}
|
|
public String getsingalglass(String id) {
|
StringBuffer html = new StringBuffer();
|
List<SingalGlass> glasses = singalGlassDao.findByOptPattern(Long.parseLong(id));
|
if (glasses.size()>0) {
|
for(SingalGlass glass : glasses){
|
html.append("<tr><td>").append(glass.getId()).append("</td>");
|
html.append("<td>").append(glass.getManufacture_batch()).append("</td>");
|
html.append("<td>").append(glass.getWidth()).append("</td>");
|
html.append("<td>").append(glass.getLength()).append("</td>");
|
html.append("<td>").append(glass.getThickness()).append("</td>");
|
html.append("<td>").append(glass.getColor()).append("</td>");
|
html.append("<td>").append(glass.getPieces()).append("</td>");
|
html.append("</tr>");
|
}
|
}
|
return html.toString();
|
}
|
|
public String getview(String id) throws IOException {
|
boolean enterCuttings = false;
|
boolean enterOptPattern = false;
|
boolean enterInfo = false;
|
boolean enterShape = false;
|
|
List<OPattern> optPatternList = new ArrayList<OPattern>();
|
OPattern oPattern = null;
|
Info info = null;
|
Shape shape = null;
|
LOGGER.debug("id:"+id);
|
List<LoadMachineTask> taskes = loadMachineTaskDao.findCutFinishByLoadMachine(Long.parseLong(id));
|
// List<OptPattern> optPatterns = optPatternDao.findOptPattern(id);
|
StringBuffer writer = new StringBuffer();
|
if (taskes.size()>0) {
|
OptPattern opt = taskes.get(taskes.size()-1).getOptPattern();//optPattern.getContent()
|
StringReader in2 = new StringReader(opt.getContent());
|
in2.reset();
|
BufferedReader reader = new BufferedReader(in2);
|
String line = reader.readLine();
|
while (line != null) {
|
if (line.equals("[OPT_Pattern]")) {
|
|
if (oPattern != null) {
|
optPatternList.add(oPattern);
|
}
|
|
enterOptPattern = true;
|
oPattern = new OPattern();
|
}
|
|
if (line.equals("[Cuttings]")) {
|
enterCuttings = true;
|
}
|
|
if (line.equals("[Info]")) {
|
enterInfo = true;
|
info = new Info();
|
}
|
|
if (line.equals("[Shape]")) {
|
enterShape = true;
|
shape = new Shape();
|
}
|
|
if (enterOptPattern && line.equals("")) {
|
enterOptPattern = false;
|
}
|
|
if (enterCuttings && line.equals("")) {
|
enterCuttings = false;
|
}
|
|
if (enterInfo && line.equals("")) {
|
oPattern.addInfo(info);
|
enterInfo = false;
|
}
|
|
if (enterShape && line.equals("")) {
|
oPattern.addShape(shape);
|
enterShape = false;
|
}
|
|
if (enterOptPattern) {
|
if(line.startsWith("Width")) {
|
String string=line.substring(line.indexOf("=")+1);
|
int width = (int)Double.parseDouble(string);
|
// int width = Integer.parseInt(line.substring(line.indexOf("=") + 1));
|
oPattern.setWidth(width);
|
}
|
|
if (line.startsWith("Height")) {
|
String string=line.substring(line.indexOf("=")+1);
|
int height = (int)Double.parseDouble(string);
|
// int height = Integer.parseInt(line.substring(line.indexOf("=") + 1));
|
oPattern.setHeight(height);
|
}
|
|
if (line.startsWith("TrimLeft")) {
|
String string=line.substring(line.indexOf("=")+1);
|
int trimLeft = (int)Double.parseDouble(string);
|
// int trimLeft = Integer.parseInt(line.substring(line.indexOf("=") + 1));
|
oPattern.setTrimLeft(trimLeft);
|
}
|
|
if (line.startsWith("TrimBottom")) {
|
String string=line.substring(line.indexOf("=")+1);
|
int trimBottom = (int)Double.parseDouble(string);
|
// int trimBottom = Integer.parseInt(line.substring(line.indexOf("=") + 1));
|
oPattern.setTrimBottom(trimBottom);
|
}
|
|
if (line.charAt(1) == '=') {
|
char axis = line.charAt(0);
|
|
if (line.contains("Shape") && line.contains("Info")) {
|
int value = (line.contains(".") ? (int)Double.parseDouble(line.substring(2, line.indexOf(" "))) : Integer.parseInt(line.substring(2, line.indexOf(" "))));
|
int shapeId = Integer.parseInt(line.substring(line.indexOf("=", 2) + 1, line.lastIndexOf(" ")));
|
int infoId = Integer.parseInt(line.substring(line.lastIndexOf("=") + 1));
|
|
oPattern.addStep(new Step(axis, value, shapeId, infoId));
|
}
|
else if (line.contains("Info")) {
|
int value = (line.contains(".") ? (int)Double.parseDouble(line.substring(2, line.indexOf(" "))) : Integer.parseInt(line.substring(2, line.indexOf(" "))));
|
int infoId = Integer.parseInt(line.substring(line.lastIndexOf("=") + 1));
|
|
oPattern.addStep(new Step(axis, value, infoId));
|
}
|
else {
|
int value = (line.contains(".") ? (int)Double.parseDouble(line.substring(2)) : Integer.parseInt(line.substring(2)));
|
oPattern.addStep(new Step(axis, value));
|
}
|
}
|
}
|
|
if (enterCuttings && line.startsWith("x=")) {
|
int start1 = line.indexOf("=");
|
int end1 = line.indexOf(".");
|
int x = Integer.parseInt(line.substring(start1 + 1, end1));
|
|
int start2 = line.indexOf("=", end1);
|
int end2 = line.indexOf(".", start2);
|
int y = Integer.parseInt(line.substring(start2 + 1, end2));
|
|
int start3 = line.indexOf("=", end2);
|
int end3 = line.indexOf(".", start3);
|
int X = Integer.parseInt(line.substring(start3 + 1, end3));
|
|
int start4 = line.indexOf("=", end3);
|
int end4 = line.indexOf(".", start4);
|
int Y = Integer.parseInt(line.substring(start4 + 1, end4));
|
|
oPattern.addCutting(new Cutting(x, y, X, Y));
|
}
|
|
if (enterInfo) {
|
if (line.startsWith("Id")) {
|
info.setId(Integer.parseInt(line.substring(3)));
|
}
|
|
// if (line.startsWith("OrderNo")) {
|
// int equalIndex = line.indexOf("=");
|
// int firstStarIndex = line.indexOf("*");
|
// int lastStarIndex = line.lastIndexOf("*");
|
//
|
// double width = Double.parseDouble(line.substring(equalIndex + 1, firstStarIndex));
|
// double height = Double.parseDouble(line.substring(firstStarIndex + 1, lastStarIndex));
|
// int count = Integer.parseInt(line.substring(lastStarIndex + 1));
|
//
|
// info.setWidth(width);
|
// info.setHeight(height);
|
// info.setCount(count);
|
// }
|
|
if (line.startsWith("SheetWidth")) {
|
info.setSheetWidth(
|
Integer.parseInt(line.substring(line.indexOf("=") + 1, line.indexOf("."))));
|
double width = Double.parseDouble(line.substring(line.indexOf("=") + 1, line.indexOf(".")));
|
info.setWidth(width);
|
}
|
|
if (line.startsWith("SheetHeight")) {
|
info.setSheetHeight(
|
Integer.parseInt(line.substring(line.indexOf("=") + 1, line.indexOf("."))));
|
double width = Double.parseDouble(line.substring(line.indexOf("=") + 1, line.indexOf(".")));
|
info.setHeight(width);
|
}
|
|
}
|
|
if (enterShape) {
|
if (line.startsWith("Id")) {
|
shape.setId(Integer.parseInt(line.substring(3)));
|
}
|
|
if (line.startsWith("x=")) {
|
int start1 = line.indexOf("=");
|
int end1 = line.indexOf(".");
|
int x = Integer.parseInt(line.substring(start1 + 1, end1));
|
|
int start2 = line.indexOf("=", end1);
|
int end2 = line.indexOf(".", start2);
|
int y = Integer.parseInt(line.substring(start2 + 1, end2));
|
|
int start3 = line.indexOf("=", end2);
|
int end3 = line.indexOf(".", start3);
|
int X = Integer.parseInt(line.substring(start3 + 1, end3));
|
|
int start4 = line.indexOf("=", end3);
|
int end4 = line.indexOf(".", start4);
|
int Y = Integer.parseInt(line.substring(start4 + 1, end4));
|
|
shape.addCutting(new Cutting(x, y, X, Y));
|
}
|
}
|
|
line = reader.readLine();
|
}
|
|
optPatternList.add(oPattern);
|
System.out.println(optPatternList.size());
|
for (int j = 0; j < optPatternList.size(); j++) {
|
OPattern pattern = optPatternList.get(j);
|
/* writer.append("<h1>" + opt.getBatch() + " " + j + "</h1>\n");
|
|
for (Step step : pattern.getSteps()) {
|
writer.append("<p>" + step.toString() + "</p>");
|
}
|
writer.append("\n");*/
|
writer.append("<svg preserveAspectRatio=\"xMinYMin meet\" viewBox=\"0 0 " + (pattern.getWidth() + 100) + " " + (pattern.getHeight() + 100) + "\">\n");
|
writer.append("<rect x=\"0\" y=\"0\" width=\"" + pattern.getWidth() + "\" height=\"" + pattern.getHeight() + "\" style=\"fill:transparent; stroke-width:1; stroke:black\"></rect>\n");
|
|
for (Cutting cutting : pattern.getCuttings()) {
|
writer.append("<path d=\"M " + cutting.getStartX() + " " + cutting.getStartY() + " L " + cutting.getEndX() + " " + cutting.getEndY() + "\" style=\"stroke-width: 1; stroke:black;\"></path>\n");
|
// writer.write("<text x=\"" + cutting.getStartX() + "\" y=\"" + cutting.getStartY() + "\" dy=\"19\">(" + cutting.getStartX() + ", " + cutting.getStartY() + ")</text>\n");
|
// writer.write("<text x=\"" + cutting.getEndX() + "\" y=\"" + cutting.getEndY() + "\" dy=\"19\">(" + cutting.getEndX() + ", " + cutting.getEndY() + ")</text>\n");
|
}
|
|
Stack<Integer> stackX = new Stack<Integer>();
|
Stack<Integer> stackY = new Stack<Integer>();
|
Stack<Integer> stackZ = new Stack<Integer>();
|
Stack<Integer> stackW = new Stack<Integer>();
|
Stack<Integer> stackV = new Stack<Integer>();
|
Stack<Integer> stackA = new Stack<Integer>();
|
|
int startX = pattern.getTrimLeft();
|
int startY = pattern.getTrimBottom();
|
|
stackX.push(startX);
|
stackY.push(startY);
|
stackZ.push(startX);
|
stackW.push(startY);
|
stackV.push(startX);
|
stackA.push(startY);
|
|
for (Step step : pattern.getSteps()) {
|
|
if (step.getInfoId() == 0) {
|
if (step.getAxis() == 'X') {
|
|
stackX.push(stackX.peek() + step.getValue());
|
|
stackY.clear();
|
stackY.push(pattern.getTrimBottom());
|
|
startY = 0;
|
}
|
else if (step.getAxis() == 'Y') {
|
|
stackY.push(stackY.peek() + step.getValue());
|
|
int top = stackX.pop();
|
startX = stackX.peek();
|
|
stackZ.clear();
|
stackZ.push(startX);
|
|
stackX.push(top);
|
}
|
else if (step.getAxis() == 'Z') {
|
|
startX = stackZ.peek();
|
stackZ.push(startX + step.getValue());
|
|
int topY = stackY.pop();
|
startY = stackY.peek();
|
|
stackW.clear();
|
stackW.push(startY);
|
|
stackY.push(topY);
|
|
}
|
else if (step.getAxis() == 'W') {
|
|
int topZ = stackZ.pop();
|
startX = stackZ.peek();
|
|
stackV.clear();
|
stackV.push(startX);
|
|
stackZ.push(topZ);
|
|
startY = stackW.peek();
|
stackW.push(startY + step.getValue());
|
}
|
else if (step.getAxis() == 'V') {
|
startX = stackV.peek();
|
stackV.push(startX + step.getValue());
|
|
int topW = stackW.pop();
|
startY = stackW.peek();
|
|
stackA.clear();
|
stackA.push(startY);
|
|
stackW.push(topW);
|
}
|
}
|
else {
|
String string= getInfoById(pattern, step.getInfoId()).toString();
|
String Stringid=string.split(":")[0];
|
String xString=string.split(":")[1].split("\\*")[0];
|
String yString=string.split(":")[1].split("\\*")[1];
|
if (step.getAxis() == 'Y') {
|
int width = stackX.pop() - stackX.peek();
|
int height = step.getValue();
|
|
startX = stackX.peek();
|
startY = stackY.peek();
|
|
writer.append("<rect x=\"" + startX + "\" y=\"" + startY + "\" "
|
+ "width=\"" + width + "\" height=\"" + height + "\" "
|
+ "style=\"fill:" + getRandomColor() + "; stroke-width:0; opacity:0.1\"/>\n");
|
|
/* writer.append("<text x=\"" + (startX + 50) + "\" y=\"" + (startY + height/2) + "\" style=\"font-size:48px\">"
|
+ getInfoById(pattern, step.getInfoId()).toString() + "</text>\n");*/
|
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/2) + "\" style=\"font-size:60px\">"
|
+ Stringid + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\">"
|
+ xString + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\" transform=\"rotate(90 "+ (startX+width/2) +","+(startY+height/2) +")\">"
|
+ yString + "</text>\n");
|
stackX.push(startX + width);
|
stackY.push(startY + height);
|
|
// System.out.println("======== Y ========");
|
// System.out.println("stackX: " + stackX);
|
// System.out.println("stackY: " + stackY);
|
}
|
else if (step.getAxis() == 'Z') {
|
int width = step.getValue();
|
int height = stackY.pop() - stackY.peek();
|
|
startX = stackZ.peek();
|
startY = stackY.peek();
|
|
if (step.getShapeId() != 0) {
|
Shape inShape = getShapeById(pattern, step.getShapeId());
|
|
writer.append("<rect x=\"" + startX + "\" y=\"" + startY + "\" "
|
+ "width=\"" + width + "\" height=\"" + height + "\" "
|
+ "style=\"fill:white; stroke-width:0; opacity:0\"/>\n");
|
|
writer.append("<polygon points=\"");
|
|
for (int k = 0; k < inShape.getCuttings().size(); k++) {
|
Cutting cutting = inShape.getCuttings().get(k);
|
writer.append((startX + cutting.getStartX() - pattern.getTrimLeft()) + "," + (startY + cutting.getStartY() - pattern.getTrimBottom()) + " ");
|
}
|
|
writer.append("\" style=\"fill:" + getRandomColor() + "; stroke-width:1; stroke:black; opacity:0.2\"/>\n");
|
|
}
|
else {
|
writer.append("<rect x=\"" + startX + "\" y=\"" + startY + "\" "
|
+ "width=\"" + width + "\" height=\"" + height + "\" "
|
+ "style=\"fill:" + getRandomColor() + "; stroke-width:0; opacity:0.1\"/>\n");
|
}
|
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/2) + "\" style=\"font-size:60px\">"
|
+ Stringid + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\">"
|
+ xString + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\" transform=\"rotate(90 "+ (startX+width/2) +","+(startY+height/2) +")\">"
|
+ yString + "</text>\n");
|
stackZ.push(startX + width);
|
stackY.push(startY + height);
|
|
// System.out.println("======== Z ========");
|
// System.out.println("stackX: " + stackX);
|
// System.out.println("stackY: " + stackY);
|
// System.out.println("stackZ: " + stackZ);
|
}
|
else if (step.getAxis() == 'W') {
|
int width = stackZ.pop() - stackZ.peek();
|
int height = step.getValue();
|
|
startX = stackZ.peek();
|
startY = stackW.peek();
|
|
writer.append("<rect x=\"" + startX + "\" y=\"" + startY + "\" "
|
+ "width=\"" + width + "\" height=\"" + height + "\" "
|
+ "style=\"fill:" + getRandomColor() + "; stroke-width:0; opacity:0.1\"/>\n");
|
|
System.out.println(step.getInfoId());
|
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/2) + "\" style=\"font-size:60px\">"
|
+ Stringid + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\">"
|
+ xString + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\" transform=\"rotate(90 "+ (startX+width/2) +","+(startY+height/2) +")\">"
|
+ yString + "</text>\n");
|
stackZ.push(startX + width);
|
stackW.push(startY + height);
|
|
// System.out.println("======== W ========");
|
// System.out.println("stackX: " + stackX);
|
// System.out.println("stackY: " + stackY);
|
// System.out.println("stackZ: " + stackZ);
|
System.out.println("stackW: " + stackW);
|
}
|
else if (step.getAxis() == 'V') {
|
int width = step.getValue();
|
int height = stackW.pop() - stackW.peek();
|
|
startX = stackV.peek();
|
startY = stackW.peek();
|
|
writer.append("<rect x=\"" + startX + "\" y=\"" + startY + "\" "
|
+ "width=\"" + width + "\" height=\"" + height + "\" "
|
+ "style=\"fill:" + getRandomColor() + "; stroke-width:0; opacity:0.1\"/>\n");
|
|
// writer.append("<text x=\"" + (startX + 50) + "\" y=\"" + (startY + height/2) + "\" style=\"font-size:60px\">"
|
// + Stringid + "</text>\n");
|
// writer.append("<text x=\"" + (startX + 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\">"
|
// + xString + "</text>\n");
|
// writer.append("<text x=\"" + (startX + 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\" transform=\"rotate(90 20,90)\">"
|
// + yString + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/2) + "\" style=\"font-size:60px\">"
|
+ Stringid + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\">"
|
+ xString + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\" transform=\"rotate(90 "+ (startX+width/2) +","+(startY+height/2) +")\">"
|
+ yString + "</text>\n");
|
stackV.push(startX + width);
|
stackW.push(startY + height);
|
|
// System.out.println("======== V ========");
|
// System.out.println("stackX: " + stackX);
|
// System.out.println("stackY: " + stackY);
|
// System.out.println("stackZ: " + stackZ);
|
// System.out.println("stackW: " + stackW);
|
// System.out.println("stackV: " + stackV);
|
}
|
else if (step.getAxis() == 'A') {
|
int width = stackV.pop() - stackV.peek();
|
int height = step.getValue();
|
|
startX = stackV.peek();
|
startY = stackA.peek();
|
|
writer.append("<rect x=\"" + startX + "\" y=\"" + startY + "\" "
|
+ "width=\"" + width + "\" height=\"" + height + "\" "
|
+ "style=\"fill:" + getRandomColor() + "; stroke-width:0; opacity:0.1\"/>\n");
|
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/2) + "\" style=\"font-size:60px\">"
|
+ Stringid + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\">"
|
+ xString + "</text>\n");
|
writer.append("<text x=\"" + (startX+width/2 - 50) + "\" y=\"" + (startY + height/8) + "\" style=\"font-size:60px\" transform=\"rotate(90 "+ (startX+width/2) +","+(startY+height/2) +")\">"
|
+ yString + "</text>\n");
|
stackV.push(startX + width);
|
stackA.push(startY + height);
|
|
// System.out.println("======== A ========");
|
// System.out.println("stackX: " + stackX);
|
// System.out.println("stackY: " + stackY);
|
// System.out.println("stackZ: " + stackZ);
|
// System.out.println("stackW: " + stackW);
|
// System.out.println("stackV: " + stackV);
|
// System.out.println("stackA: " + stackA);
|
}
|
}
|
}
|
|
writer.append("</svg>\n");
|
}
|
}
|
LOGGER.debug("集合内容:"+writer.toString());
|
return writer.toString();
|
}
|
private static int index = 0;
|
|
public String getRandomColor() {
|
if (index == 10) {
|
index = 0;
|
}
|
|
String[] colors = new String[]{"red", "blue", "yellow", "green", "pink", "purple", "navy", "maroon", "gold", "chocolate"};
|
return colors[index++];
|
}
|
|
public Info getInfoById(OPattern optPattern, int infoId) {
|
for (Info info : optPattern.getInfos()) {
|
if (info.getId() == infoId) {
|
return info;
|
}
|
}
|
|
return null;
|
}
|
|
|
public Shape getShapeById(OPattern optPattern, int shapeId) {
|
for (Shape shape : optPattern.getShapes()) {
|
if (shape.getId() == shapeId) {
|
return shape;
|
}
|
}
|
|
return null;
|
}
|
|
public void getglass(String id) {
|
RawPackageTxt txt = rawPackageTxtDao.findAcceptedByGroup(id);
|
if (txt != null) {
|
List<LoadMachineTask> taskes = loadMachineTaskDao.findAll();
|
if (taskes.size()>0) {
|
for (int i = 0; i < taskes.size(); i++) {
|
LoadMachineTask task = taskes.get(i);
|
loadMachineService.bcglass(task.getOptPattern().getId());
|
}
|
}
|
}
|
}
|
|
public void getoneglass(String id) {
|
LoadMachineTask task = loadMachineTaskDao.findOne(Long.parseLong(id));
|
if (task != null) {
|
task.setState("切割完成");
|
loadMachineTaskDao.save(task);
|
OptPattern optPattern = task.getOptPattern();
|
if (optPattern != null) {
|
loadMachineService.bcglass(optPattern.getId());
|
}
|
}
|
|
}
|
}
|