package com.slcf.controller;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Collections;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Random;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import com.slcf.pojo.UserBean;
|
import com.slcf.pojo.WorkMastBean;
|
import com.slcf.bean.LocDetailCondition;
|
import com.slcf.pojo.LocationBean;
|
import com.slcf.pojo.StationBean;
|
import com.slcf.pojo.SysLogBean;
|
import com.slcf.service.WaitPakInService;
|
import com.slcf.service.WorkFileService;
|
import com.slcf.service.WorkNoService;
|
import com.slcf.util.AuthorityCode;
|
import com.slcf.util.CommonMethod;
|
import com.slcf.util.DateTimeUtil;
|
import com.slcf.service.CrnService;
|
import com.slcf.service.LocDetailService;
|
import com.slcf.service.LocationService;
|
import com.slcf.service.MatCodeService;
|
import com.slcf.service.OperateService;
|
import com.slcf.service.RoleService;
|
import com.slcf.service.RowNoService;
|
import com.slcf.service.StaDescService;
|
import com.slcf.service.StationService;
|
import com.slcf.service.SysLogService;
|
|
/**
|
* 空托盘控制器层
|
* @author admin
|
* @date 2018年12月4日
|
*/
|
@Controller
|
@RequestMapping("/work")
|
public class EmptyController {
|
|
@Resource
|
WaitPakInService waitPakInService;
|
@Autowired
|
SysLogService sysLogService;
|
@Autowired
|
MatCodeService matCodeService;
|
@Autowired
|
StaDescService staDescService;
|
@Autowired
|
StationService stationService;
|
@Autowired
|
WorkNoService workNoService;
|
@Autowired
|
WorkFileService workFileService;
|
@Autowired
|
RowNoService rowNoService;
|
@Autowired
|
LocationService locationService;
|
@Autowired
|
CrnService crnService;
|
@Autowired
|
OperateService operateService;
|
@Autowired
|
LocDetailService locDetailService;
|
@Autowired
|
RoleService roleService;
|
|
@RequestMapping("/goEmptyIn.action")
|
public String goEmptyInPage(HttpServletRequest request){
|
try {
|
String rid = request.getSession().getAttribute("ROLEID").toString();
|
String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid),
|
AuthorityCode.EmptyInCode);
|
request.getSession().setAttribute("AUTHCODE",authCode);
|
// 插入日志
|
UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("goEmptyIn.action");
|
sysLog.setTts_keyname("访问空托盘入库");
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}catch (Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return "emptyIn";
|
}
|
|
@RequestMapping("/goEmptyOut.action")
|
public String goEmptyOutPage(HttpServletRequest request){
|
try {
|
String rid = request.getSession().getAttribute("ROLEID").toString();
|
String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid),
|
AuthorityCode.EmptyOutCode);
|
request.getSession().setAttribute("AUTHCODE",authCode);
|
// 插入日志
|
UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("goEmptyOut.action");
|
sysLog.setTts_keyname("访问空托盘出库");
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}catch (Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return "emptyOut";
|
}
|
|
@RequestMapping("/goLocMove.action")
|
public String goLocMovePage(HttpServletRequest request){
|
try {
|
String rid = request.getSession().getAttribute("ROLEID").toString();
|
String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid),
|
AuthorityCode.LocMoveCode);
|
request.getSession().setAttribute("AUTHCODE",authCode);
|
// 插入日志
|
UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("goLocMove.action");
|
sysLog.setTts_keyname("访问库位移转");
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}catch (Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return "locMove";
|
}
|
|
@RequestMapping("/goLocCheck.action")
|
public String goLocCheckPage(HttpServletRequest request){
|
try {
|
String rid = request.getSession().getAttribute("ROLEID").toString();
|
String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid),
|
AuthorityCode.LocCheckCode);
|
request.getSession().setAttribute("AUTHCODE",authCode);
|
// 插入日志
|
UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("goLocCheck.action");
|
sysLog.setTts_keyname("访问库存盘点");
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}catch (Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return "locCheck";
|
}
|
////////////////////////////////////////////////////////////////////////////
|
/**
|
* 空托盘入库启动
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/emptyStoreIn.action")
|
public Map<String,Object> emptyStoreIn(
|
@RequestParam("stn_no")int stn_no,HttpServletRequest request) throws Exception{
|
Map<String,Object> map=new HashMap<String, Object>();
|
try {
|
CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
|
stationService,locationService,rowNoService,staDescService);
|
|
UserBean user=(UserBean)request.getSession().getAttribute("USER");
|
WorkMastBean workMast = new WorkMastBean();
|
|
//判断站点是否正常
|
StationBean station = stationService.queryStationById(stn_no);
|
Map<String,Object> mapStation = commonMethod.checkStationStatus(station);
|
if((Integer)mapStation.get("code")==1) {
|
map.put("code", 1);
|
map.put("msg", mapStation.get("msg"));
|
return map;
|
}
|
|
int wrk_no = commonMethod.getNewWorkNo(workNoService.queryWorkNoById(0));
|
if(wrk_no<=0) {
|
map.put("code", 1);
|
map.put("msg", "生成工作号失败,请联系管理员");
|
return map;
|
}else {
|
WorkMastBean workFile = workFileService.queryWorkMastById(wrk_no);
|
if(workFile!=null) {
|
map.put("code", 1);
|
map.put("msg", "生成工作号" + wrk_no + "在工作档中已存在");
|
return map;
|
}
|
}
|
|
String loc_no = "";
|
loc_no = commonMethod.getLocNo(10, rowNoService.queryRowNoById(1), stn_no, station.getCtn_type());
|
if(loc_no.equals("")) {
|
map.put("code", 1);
|
map.put("msg", "查询可用库位失败,请检查堆垛机、设备状态");
|
return map;
|
}
|
int crn_no = Integer.parseInt(loc_no.substring(0,2));
|
crn_no = (crn_no+1) / 2;
|
int e_staNo = commonMethod.getIoStaNo(10, crn_no, stn_no);
|
if(e_staNo<=0) {
|
map.put("code", 1);
|
map.put("msg", "获取堆垛机站点失败");
|
return map;
|
}
|
String io_time = DateTimeUtil.getStringDateTime(19);
|
workMast.setWrk_no(wrk_no);
|
workMast.setIo_time(io_time);
|
workMast.setWrk_sts(1);
|
workMast.setIo_type(10);
|
workMast.setIo_pri(10);
|
workMast.setCrn_no(crn_no);
|
workMast.setSource_sta_no(stn_no);
|
workMast.setSta_no(e_staNo);
|
workMast.setLoc_no(loc_no);
|
workMast.setFull_plt("N");
|
workMast.setPicking("N");
|
workMast.setExit_mk("N");
|
workMast.setEmpty_mk("Y");
|
workMast.setLink_mis("N");
|
workMast.setModi_user(user.getUser_account());
|
|
map = operateService.insertEmptyStoreIn(workMast, station, user);
|
|
if((Integer)map.get("code")==0) {
|
// 插入日志
|
// UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("emptyStoreIn.action");
|
sysLog.setTts_keyname("启动空板入库:" + workMast.getWrk_no() + "-" + workMast.getLoc_no());
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}
|
}catch(RuntimeException e) {
|
System.out.println(e.getMessage());
|
}
|
return map;
|
}
|
|
/**
|
* 空托盘出库启动
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/emptyRetrieve.action")
|
public Map<String,Object> emptyRetrieve(@RequestParam("ids")String[] ids,
|
@RequestParam("stn_no")int stn_no,HttpServletRequest request) throws Exception{
|
Map<String,Object> map=new HashMap<String, Object>();
|
try {
|
CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
|
stationService,locationService,rowNoService,staDescService);
|
|
UserBean user=(UserBean)request.getSession().getAttribute("USER");
|
WorkMastBean workMast = new WorkMastBean();
|
|
// workMast.setWrk_no(wrk_no);
|
// workMast.setIo_time(io_time);
|
workMast.setWrk_sts(11);
|
workMast.setIo_type(110);
|
workMast.setIo_pri(13);
|
workMast.setSta_no(stn_no);
|
// workMast.setCrn_no(crn_no);
|
// workMast.setSource_sta_no(stn_no);
|
// workMast.setSta_no(e_staNo);
|
// workMast.setLoc_no(loc_no);
|
workMast.setFull_plt("N");
|
workMast.setPicking("N");
|
workMast.setExit_mk("N");
|
workMast.setEmpty_mk("Y");
|
workMast.setLink_mis("N");
|
workMast.setModi_user(user.getUser_account());
|
|
map = operateService.insertemptyRetrieve(workMast, ids, stn_no, user, commonMethod);
|
|
if((Integer)map.get("code")==0) {
|
// 插入日志
|
// UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("emptyRetrieve.action");
|
sysLog.setTts_keyname("启动空托盘出库:" + workMast.getWrk_no() + "-" + workMast.getLoc_no());
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}
|
}catch(RuntimeException e) {
|
System.out.println(e.getMessage());
|
}
|
return map;
|
}
|
|
//////////////////////库位移转///////////////////////////////////////////
|
@ResponseBody
|
@RequestMapping("/locDetlList.action")
|
public Map<String,Object> querylocDetlListByPages(LocDetailCondition locDetailCon){
|
Map<String,Object> map = new HashMap<String, Object>();
|
if(locDetailCon.getLoc_no()==null || locDetailCon.getLoc_no().equals("")) {
|
return map;
|
}
|
map=locDetailService.queryLocDetailList(locDetailCon);
|
return map;
|
}
|
|
/**
|
* 检查旧库位状态
|
* @param loc_no
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/checkOldLoc.action")
|
public Map<String,Object> checkOldLoc(@RequestParam("loc_no")String loc_no){
|
Map<String,Object> map=new HashMap<String, Object>();
|
try {
|
LocationBean location = locationService.queryLocationById(loc_no);
|
if(location!=null){
|
if(location.getLoc_sts().equals("F") || location.getLoc_sts().equals("D")) {
|
map.put("msg", "库位可用");
|
}else {
|
map.put("msg", "库位不是在库状态");
|
}
|
}else{
|
map.put("msg", "库位不存在");
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return map;
|
}
|
|
/**
|
* 检查旧库位状态
|
* @param loc_no
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/checkNewLoc.action")
|
public Map<String,Object> checkNewLoc(@RequestParam("loc_no")String loc_no){
|
Map<String,Object> map=new HashMap<String, Object>();
|
try {
|
LocationBean location = locationService.queryLocationById(loc_no);
|
if(location!=null){
|
if(location.getLoc_sts().equals("O")) {
|
map.put("msg", "库位可用");
|
}else {
|
map.put("msg", "库位不是空库位状态");
|
}
|
}else{
|
map.put("msg", "库位不存在");
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return map;
|
}
|
|
/**
|
* 库位移转
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/locMove.action")
|
public Map<String,Object> locMove(@RequestParam("old_loc_no")String old_loc_no,
|
@RequestParam("new_loc_no")String new_loc_no,HttpServletRequest request) throws Exception{
|
Map<String,Object> map=new HashMap<String, Object>();
|
try {
|
CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
|
stationService,locationService,rowNoService,staDescService);
|
|
UserBean user=(UserBean)request.getSession().getAttribute("USER");
|
WorkMastBean workMast = new WorkMastBean();
|
|
String emptyMk = "N";
|
LocationBean location = locationService.queryLocationById(old_loc_no);
|
if(location!=null) {
|
String loc_sts = location.getLoc_sts();
|
if(loc_sts.equals("D")) {
|
emptyMk="Y";
|
}
|
}
|
|
int wrk_no = commonMethod.getNewWorkNo(workNoService.queryWorkNoById(0));
|
if(wrk_no<=0) {
|
map.put("code", 1);
|
map.put("msg", "生成工作号失败,请联系管理员");
|
return map;
|
}else {
|
WorkMastBean workFile = workFileService.queryWorkMastById(wrk_no);
|
if(workFile!=null) {
|
map.put("code", 1);
|
map.put("msg", "生成工作号" + wrk_no + "在工作档中已存在");
|
return map;
|
}
|
}
|
|
int crn_no = Integer.parseInt(old_loc_no.substring(0,2));
|
crn_no = (crn_no+1)/2;
|
// int e_staNo = commonMethod.getIoStaNo(crn_no,"I",stn_no);
|
String io_time = DateTimeUtil.getStringDateTime(19);
|
workMast.setWrk_no(wrk_no);
|
workMast.setIo_time(io_time);
|
workMast.setWrk_sts(11);
|
workMast.setIo_type(11);
|
workMast.setIo_pri(10);
|
workMast.setCrn_no(crn_no);
|
// workMast.setSource_sta_no(stn_no);
|
// workMast.setSta_no(e_staNo);
|
workMast.setSource_loc_no(old_loc_no);
|
workMast.setLoc_no(new_loc_no);
|
workMast.setFull_plt("N");
|
workMast.setPicking("N");
|
workMast.setExit_mk("N");
|
workMast.setEmpty_mk(emptyMk);
|
workMast.setLink_mis("N");
|
workMast.setModi_user(user.getUser_account());
|
|
map = operateService.insertLocMove(workMast, old_loc_no, new_loc_no, user);
|
|
if((Integer)map.get("code")==0) {
|
// 插入日志
|
// UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("locMove.action");
|
sysLog.setTts_keyname("启动库位移转:" + workMast.getWrk_no() + "-" + workMast.getLoc_no());
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}
|
}catch(RuntimeException e) {
|
System.out.println(e.getMessage());
|
}
|
return map;
|
}
|
|
////////////////////////////////库存盘点//////////////////////////
|
/**
|
* 检查旧库位状态
|
* @param loc_no
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/checkChkLoc.action")
|
public Map<String,Object> checkChkLoc(@RequestParam("loc_no")String loc_no){
|
Map<String,Object> map=new HashMap<String, Object>();
|
try {
|
LocationBean location = locationService.queryLocationById(loc_no);
|
if(location!=null){
|
if(location.getLoc_sts().equals("F")) {
|
map.put("msg", "库位可用");
|
}else {
|
map.put("msg", "库位不是在库状态");
|
}
|
}else{
|
map.put("msg", "库位不存在");
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return map;
|
}
|
|
/**
|
* 盘点出库启动
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping("/locCheck.action")
|
public Map<String,Object> locCheck(@RequestParam("old_loc_no")String value,@RequestParam("chk_type")int chk_type,
|
@RequestParam("stn_no")int stn_no,HttpServletRequest request) throws Exception{
|
Map<String,Object> map=new HashMap<String, Object>();
|
try {
|
CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
|
stationService,locationService,rowNoService,staDescService);
|
|
UserBean user=(UserBean)request.getSession().getAttribute("USER");
|
String locs = "";
|
switch(chk_type) {
|
case 0: //指定库位
|
map = operateService.insertLocCheck(value, stn_no, user, commonMethod);
|
break;
|
case 1: //全盘
|
locs = locationService.getLocationListBySts("F");
|
List<String> listLoc = Arrays.asList(locs.split(","));
|
|
if(listLoc!=null && listLoc.size()>0) {
|
for(String loc_no : listLoc) {
|
map = operateService.insertLocCheck(loc_no, stn_no, user, commonMethod);
|
}
|
}else {
|
map.put("code", 1);
|
map.put("msg", "无在库资料");
|
return map;
|
}
|
break;
|
case 2: //百分比盘点
|
locs = locationService.getLocationListBySts("F");
|
String[] array = locs.split(",");
|
List<String> list = new ArrayList<String>(array.length);
|
Collections.addAll(list, array);
|
// list = Arrays.asList(locs.split(",")); //静态list不能做增删操作
|
|
int count = (list.size()*Integer.parseInt(value))/100;
|
List<String> arrayList = getListByQty(list,count);
|
if(arrayList!=null && arrayList.size()>0) {
|
for (String loc_no : arrayList) {
|
map = operateService.insertLocCheck(loc_no, stn_no, user, commonMethod);
|
}
|
}else {
|
map.put("code", 1);
|
map.put("msg", "无在库资料");
|
return map;
|
}
|
break;
|
}
|
|
if((Integer)map.get("code")==0) {
|
// 插入日志
|
// UserBean user = (UserBean) request.getSession().getAttribute("USER");
|
SysLogBean sysLog = new SysLogBean();
|
sysLog.setLogin_no(user.getUser_account());
|
sysLog.setMachine_ip(request.getRemoteAddr());
|
sysLog.setForm_no("locCheck.action");
|
sysLog.setTts_keyname("启动盘点出库");
|
sysLog.setModi_user(user.getUser_account());
|
sysLogService.insertSysLog(sysLog);
|
}
|
}catch(RuntimeException e) {
|
System.out.println(e.getMessage());
|
}
|
return map;
|
}
|
|
/**
|
* 从原list中随机获取指定数量元素的list
|
* @param list
|
* @param count
|
* @return
|
*/
|
private List<String> getListByQty(List<String> list, int count){
|
List<String> result = new ArrayList<String>();
|
try {
|
Random r = new Random();
|
int index = 0;
|
for (int i = 0; i < count; i++) {
|
index = r.nextInt(list.size() - i);
|
result.add(list.get(index));
|
list.remove(index);
|
}
|
}catch(Exception e) {
|
System.out.println(e.getMessage());
|
}
|
return result;
|
}
|
|
//测试代码
|
public static void main(String[] args) {
|
List<String> ids = new ArrayList<String>();
|
ids.add("aa");
|
ids.add("bb");
|
ids.add("cc");
|
ids.add("dd");
|
ids.add("ee");
|
ids.add("ff");
|
Random r = new Random();
|
List<String> ret = new ArrayList<String>();
|
int index = 0;
|
for (int i = 0; i < 2; i++) {
|
index = r.nextInt(ids.size() - i);
|
ret.add(ids.get(index));
|
ids.remove(index);
|
}
|
for (String str : ret) {
|
System.out.print(str + " ");
|
}
|
}
|
|
|
}
|