package com.slcf.util;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import javax.sql.DataSource;
|
|
import org.apache.ibatis.datasource.pooled.PooledDataSource;
|
import org.apache.ibatis.mapping.Environment;
|
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
import org.apache.ibatis.transaction.TransactionFactory;
|
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
|
import com.slcf.dao.UserDao;
|
import com.slcf.pojo.CrnBean;
|
import com.slcf.pojo.LocationBean;
|
import com.slcf.pojo.RowNoBean;
|
import com.slcf.pojo.StaDescBean;
|
import com.slcf.pojo.StationBean;
|
import com.slcf.pojo.WorkMastBean;
|
import com.slcf.pojo.WorkNoBean;
|
import com.slcf.service.CrnService;
|
import com.slcf.service.LocationService;
|
import com.slcf.service.RowNoService;
|
import com.slcf.service.StaDescService;
|
import com.slcf.service.StationService;
|
import com.slcf.service.WorkFileService;
|
import com.slcf.service.WorkNoService;
|
|
/**
|
* 公共方法类
|
* @author admin
|
* @date 2018年11月6日
|
*/
|
public class CommonMethod {
|
private WorkFileService workFileService;
|
private WorkNoService workNoService;
|
private CrnService crnService;
|
private StationService stationService;
|
private LocationService locationService;
|
private RowNoService rowNoService;
|
private StaDescService staDescService;
|
|
public CommonMethod(WorkFileService workFileService,WorkNoService workNoService,
|
CrnService crnService,StationService stationService,LocationService locationService,
|
RowNoService rowNoService,StaDescService staDescService) {
|
this.workFileService = workFileService;
|
this.workNoService = workNoService;
|
this.crnService = crnService;
|
this.stationService = stationService;
|
this.locationService = locationService;
|
this.rowNoService = rowNoService;
|
this.staDescService = staDescService;
|
}
|
|
public SqlSession getSession(){
|
SqlSession session = null;
|
try {
|
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=AccessData";
|
String username="sa";
|
String password="sa4761516";
|
|
DataSource dataSource =new PooledDataSource(driver,url,username,password);
|
|
//创建事务
|
TransactionFactory transactionFactory = new JdbcTransactionFactory();
|
|
Environment environment = new Environment("development", transactionFactory, dataSource);
|
|
Configuration configuration = new Configuration(environment);
|
|
configuration.addMapper(UserDao.class);
|
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
|
System.out.println(sqlSessionFactory);
|
|
session = sqlSessionFactory.openSession();
|
}catch(Exception e) {
|
System.out.println(e);
|
}
|
return session;
|
}
|
|
/**
|
* 判断站点状态是否正常
|
* @param station
|
* @return
|
*/
|
public Map<String,Object> checkStationStatus(StationBean station) {
|
Map<String,Object> mapStation=new HashMap<String, Object>();
|
try {
|
if(station!=null) {
|
if(station.getAutoing()==null || !station.getAutoing().equals("Y")) {
|
mapStation.put("code", 1);
|
mapStation.put("msg", "入库站点不是自动状态");
|
return mapStation;
|
}
|
if(station.getLoading()==null || !station.getLoading().equals("Y")) {
|
mapStation.put("code", 1);
|
mapStation.put("msg", "入库站点无物");
|
return mapStation;
|
}
|
if(station.getWrk_no()>0) {
|
mapStation.put("code", 1);
|
mapStation.put("msg", "入库站点已有工作号");
|
return mapStation;
|
}
|
|
int count = workFileService.getStoreWorkCount(station.getDev_no());
|
if(count>0) {
|
mapStation.put("code", 1);
|
mapStation.put("msg", "同一站点不能同时生成两笔入库工作档");
|
return mapStation;
|
}
|
|
mapStation.put("code", 0);
|
}else {
|
mapStation.put("code", 1);
|
mapStation.put("msg", "入库站点不存在");
|
return mapStation;
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
mapStation.put("code", 1);
|
mapStation.put("msg", "站点异常!" + e.getMessage());
|
}
|
return mapStation;
|
}
|
|
/**
|
* 入出库作业生成新的工作号
|
* @return
|
*/
|
public int getNewWorkNo(WorkNoBean workNoBean) {
|
int wrk_no=0;
|
try {
|
if(workNoBean!=null) {
|
wrk_no = workNoBean.getWrk_no();
|
int s_no = workNoBean.getS_no();
|
int e_no = workNoBean.getE_no();
|
|
if(wrk_no>=e_no) {
|
wrk_no = s_no;
|
}else {
|
wrk_no++;
|
}
|
|
while(true) {
|
WorkMastBean workFile = workFileService.queryWorkMastById(wrk_no);
|
if(workFile!=null) {
|
wrk_no++;
|
if(wrk_no>=e_no) {
|
wrk_no = s_no;
|
}else {
|
wrk_no++;
|
}
|
}else {
|
break;
|
}
|
}
|
|
if(wrk_no>0) {
|
workNoBean.setWrk_no(wrk_no);
|
workNoService.upWorkNo(workNoBean);
|
}
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return wrk_no;
|
}
|
|
/**
|
* 入库作业寻找空库位号
|
* @return
|
*/
|
public String getLocNo(int type, RowNoBean rowNoBean, int stn_no, int loc_type) {
|
String loc_no = "";
|
try {
|
if(rowNoBean!=null) {
|
int cur_row = rowNoBean.getCurrent_row();
|
int min_row = rowNoBean.getS_row();
|
int max_row = rowNoBean.getE_row();
|
int crn_qty = rowNoBean.getCrn_qty();
|
|
int iii=1;
|
int max_row_1 = max_row - 1;
|
|
while(loc_no=="") {
|
if(cur_row==max_row) {
|
cur_row = min_row;
|
}else if(cur_row==max_row_1) {
|
cur_row = min_row + 1;
|
}else {
|
cur_row = cur_row + 2;
|
}
|
|
int crn_no = (cur_row+1)/2;
|
if("Y".equals(getCrnEnable(crn_no,"I"))) {
|
int e_staNo = getIoStaNo(type,crn_no,stn_no);
|
if(e_staNo==0) {
|
continue;
|
}
|
StationBean station = stationService.queryStationById(e_staNo);
|
if(station!=null) {
|
if("Y".equals(station.getIn_enable())
|
&& "Y".equals(station.getAutoing())
|
&& station.getIn_qty()<2) {
|
//查找库位
|
LocationBean location = locationService.getLocNoByRow(cur_row,loc_type);
|
if(location!=null) {
|
loc_no = location.getLoc_no();
|
break;
|
}
|
}
|
}
|
}
|
iii=iii+1;
|
if(iii>(crn_qty*2+1)) {
|
return loc_no;
|
}
|
}
|
|
if(loc_no!=null && !loc_no.equals("")) {
|
rowNoBean.setCurrent_row(cur_row);
|
rowNoService.upRowNo(rowNoBean);
|
}
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return loc_no;
|
}
|
|
/**
|
* 判断堆垛机入出库是否禁用
|
* @param crn_no
|
* @param type
|
* @return
|
*/
|
public String getCrnEnable(int crn_no,String type) {
|
String result="";
|
try {
|
CrnBean crn = crnService.queryCrnById(crn_no);
|
if(crn!=null) {
|
if(type.equals("I")) {
|
result = crn.getIn_enable();
|
}else {
|
result = crn.getOut_enable();
|
}
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return result;
|
}
|
|
/**
|
* 根据堆垛机编号,入库站得到堆垛机入库站
|
* @param type
|
* @param crn_no
|
* @param sta_no
|
* @return
|
*/
|
public int getIoStaNo(int type, int crn_no, int sta_no) {
|
int result=0;
|
try {
|
StationBean station = stationService.queryStationById(sta_no);
|
if(station!=null) {
|
StaDescBean staDesc = new StaDescBean();
|
staDesc.setType_no(type);
|
staDesc.setStn_no(sta_no);
|
staDesc.setCrn_no(crn_no);
|
result = staDescService.queryStnByTypeStnCrn(staDesc);
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return result;
|
}
|
|
}
|