package com.slcf.service.impl; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import com.slcf.bean.WorkMastCondition; import com.slcf.bean.WorkDetailCondition; import com.slcf.dao.LocationDao; import com.slcf.dao.MatCodeDao; import com.slcf.dao.StationDao; import com.slcf.dao.WaitPakInDao; import com.slcf.dao.WaitPakOutDao; import com.slcf.dao.WorkFileDao; import com.slcf.pojo.WorkMastBean; import com.slcf.service.WorkFileService; import com.slcf.pojo.LocationBean; import com.slcf.pojo.WorkDetailBean; /** * 工作主档接口实现 * @author admin * @date 2018年11月21日 */ @Service public class WorkFileServiceImpl implements WorkFileService { @Autowired WorkFileDao workFileDao; @Autowired MatCodeDao matCodeDao; @Autowired WaitPakInDao waitPakInDao; @Autowired LocationDao locationDao; @Autowired StationDao stationDao; @Autowired WaitPakOutDao waitPakOutDao; /** * 添加 */ public int insertWorkMast(WorkMastBean workMast) { int result=0; try { result=workFileDao.insertWorkMast(workMast); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } /** * 分页查询所有 */ public Map queryWorkMastList(WorkMastCondition workMastCon) { try { Map map=new HashMap(); List list=workFileDao.queryWorkMastList(workMastCon); int count =workFileDao.getWorkMastCount(workMastCon); map.put("rows", list); map.put("total", count); return map; }catch(Exception e) { System.out.println(e.getMessage()); return null; } } /** * 根据id查找 */ public WorkMastBean queryWorkMastById(int id) { WorkMastBean workMast = new WorkMastBean(); try { workMast = workFileDao.getWorkMastById(id); }catch(Exception e) { System.out.println(e.getMessage()); } return workMast; } //更新 public int upWorkMast(WorkMastBean workMast) { int result=0; try { result=workFileDao.upWorkMast(workMast); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } /** * 查询所有 * @return */ public List getWorkMastList() { try { return workFileDao.getWorkMastList(); }catch(Exception e) { System.out.println(e.getMessage()); return null; } } //查询站点是否有入库工作档资料 public int getStoreWorkCount(int dev_no) { int result = 1; try { result = workFileDao.getStoreWorkCount(dev_no); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } //------------------明细-------------------------- //插入明细档 public int insertWorkDetail(WorkDetailBean workDetail) { int result=0; try { result=workFileDao.insertWorkDetail(workDetail); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } //查询所有 public Map queryWorkDetailList(WorkDetailCondition workDetailCon){ try { Map map=new HashMap(); List list=workFileDao.queryWorkDetailList(workDetailCon); int count =workFileDao.getWorkDetailCount(workDetailCon); map.put("rows", list); map.put("total", count); return map; }catch(Exception e) { System.out.println(e.getMessage()); return null; } } /** * 转历史档 */ public int moveToLog(int wrk_no) { int result=0; try { result=workFileDao.insertLog(wrk_no); if(result>0) { result=workFileDao.delWorkFileById(wrk_no); } }catch(Exception e) { System.out.println(e.getMessage()); } return result; } /** * 取消工作档入出库数据 * 入库:更新库位状态为O,删除工作档,删除物料数据档 * 出库:更新库位状态为F,删除工作档 */ @Transactional public int deleteWorkFile(int wrk_no, String loc_no, String loc_sts, int type) throws Exception{ int result=0; try { LocationBean location = locationDao.getLocationById(loc_no); // location.setLoc_sts(loc_sts); // if(loc_sts.equals("O")) { // WorkDetailBean workDetail = workFileDao.getWorkDetlById(wrk_no); // if(workDetail!=null) { // String mat_no=workDetail.getMat_no(); // result = matCodeDao.delMatCodeById(mat_no); // } // }else if(loc_sts.equals("F")) { // result = waitPakOutDao.delWaitPakOutByLocNo(loc_no); // } result=workFileDao.delWorkFileById(wrk_no); location.setLoc_sts(loc_sts); result=locationDao.upLocation(location); }catch(Exception e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); System.out.println(e.getMessage()); } return result; } // //入出库作业 // @Transactional // public Map insertPakStoreIn(WorkMastBean workMast,String[] detls, // StationBean station,UserBean user) throws Exception{ // Map map=new HashMap(); // try { //// MatCodeBean mat = new MatCodeBean(); //// mat.setMat_no("123"); //// mat.setMat_name("asdasd"); //// int ret = matCodeDao.insertMatCode(mat); //// mat.setMat_no("456"); //// mat.setMat_name("456456"); //// ret = matCodeDao.insertMatCode(mat); ////// if(ret>=0) { //// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); ////// throw new RuntimeException("1111"); ////// } //// map.put("code", 1); //// map.put("msg", "测试数据"); //// if(1==1) return map; //// // //插入workDetail // if(detls!=null) { // for(String str : detls) { // String[] arr = str.split(";"); // if(arr!=null && arr.length>2) { // String sheet_no = arr[0]; // String mat_no = arr[1]; // int store_qty = Integer.parseInt(arr[2]); //// MatCodeBean matCode = new MatCodeBean(); //// matCode = matCodeService.queryMatCodeById(mat_no); // // WorkDetailBean workDetl = new WorkDetailBean(); // workDetl.setWrk_no(workMast.getWrk_no()); // workDetl.setMat_no(mat_no); // workDetl.setIo_time(workMast.getIo_time()); // workDetl.setQty(store_qty); // int result = workFileDao.insertWorkDetail(workDetl); // if(result>0) { // WaitPakInBean waitPakIn = waitPakInDao.getWaitPakInById(sheet_no, mat_no); // if(waitPakIn!=null) { // int in_qty = waitPakIn.getIn_qty() + store_qty; // waitPakIn.setIn_qty(in_qty); // if(in_qty>=waitPakIn.getQty()) { // waitPakIn.setIo_status("Y"); // } // result = waitPakInDao.upWaitPakIn(waitPakIn); // }else { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // map.put("code", 1); // map.put("msg", "查询通知档待入库资料失败:单号--" + sheet_no + "\n物料编号--" + mat_no); // return map; // } // }else { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // map.put("code", 1); // map.put("msg", "插入工作明细档失败:" + workDetl.getMat_no()); // return map; // } // }else { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // map.put("code", 1); // map.put("msg", "无入库明细数据"); // return map; // } // } // } // // //插入workMast // int result = workFileDao.insertWorkMast(workMast); // if(result>0) { // station.setWrk_no(workMast.getWrk_no()); // station.setIn_enable(station.getIn_enable()); // station.setOut_enable(station.getOut_enable()); // station.setBarcode(station.getBarcode()); // station.setDec_desc(station.getDec_desc()); // station.setModi_user(user.getUser_account()); // result = stationDao.upStation(station); // if(result<=0) { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // map.put("code", 1); // map.put("msg", "更新设备档失败:" + station.getDev_no()); // return map; // } // // LocationBean location = locationDao.getLocationById(workMast.getLoc_no()); // if(location!=null) { // if(location.getLoc_sts().equals("O")) { // location.setLoc_sts("S"); // location.setModi_user(user.getUser_account()); // result = locationDao.upLocation(location); // if(result<=0) { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // map.put("code", 1); // map.put("msg", "预约库位状态失败:" + workMast.getLoc_no()); // return map; // } // }else { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // map.put("code", 1); // map.put("msg", "预约库位状态失败,库位号不存在:" + workMast.getLoc_no()); // return map; // } // } // }else { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // map.put("code", 1); // map.put("msg", "插入工作主档失败"); // return map; // } // map.put("code", 0); // map.put("msg", "库位号:" + workMast.getLoc_no()); // return map; // }catch(Exception e) { // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // System.out.println(e.getMessage()); //// throw new RuntimeException("1111"); //// System.out.println(e.getMessage()); // map.put("code", 1); // map.put("msg", "启动入库失败--" + e.getMessage()); // } // return map; // } /** * 根据工作号、物料代号查询工作档明细 * @param wrk_no * @param matnr * @return */ public WorkDetailBean queryWorkDetlById(WorkDetailBean workDetl1) { WorkDetailBean workDetl = new WorkDetailBean(); try { workDetl = workFileDao.getWorkDetlById(workDetl1); }catch(Exception e) { System.out.println(e.getMessage()); } return workDetl; } /** * 更新实际拣料数量 * @param workDetl * @return */ public int upWorkDetl(WorkDetailBean workDetl) { int result=0; try { result=workFileDao.upWorkDetl(workDetl); }catch(Exception e) { System.out.println(e.getMessage()); } return result; } /** * 根据托盘码查询工作明细List * @return */ public List getWorkDetlList(String zpallet) { try { return workFileDao.getWorkDetlList(zpallet); }catch(Exception e) { System.out.println(e.getMessage()); return null; } } }