package com.zbooksoft.gdmis.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruili.wcp.common.StringUtil; import com.ruili.wcp.data.entity.config.View; import com.ruili.wcp.data.entity.management.User; import com.ruili.wcp.engine.form.IFormData; import com.ruili.wcp.service.config.ModuleService; import com.ruili.wcp.service.config.ViewService; import com.ruili.wcp.web.model.AjaxResponse; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresUser; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Description * @Author fsr * @Date 2020/12/12 * 扫描枪分发 **/ @Controller @RequestMapping("/scanPrintController") public class ScanPrintController { private static final Logger logger = LoggerFactory.getLogger(ScanPrintController.class); @Autowired ModuleService moduleService; @Autowired IFormData iFormData; @Autowired JdbcTemplate jdbcTemplate; @Autowired ViewService viewService; /** * @Description 出库扫描 * @Date 2020/12/12 **/ @RequestMapping(value = "/outScanPrint") public ModelAndView outScanPrint(Long viewId) { ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("scanPrint/scanPrint"); modelAndView.addObject("viewId", viewId); modelAndView.addObject("printType", 1); return modelAndView; } /** * @Description 归还扫描 * @Date 2020/12/12 **/ @RequestMapping(value = "/returnScanPrint") public ModelAndView returnScanPrint(Long viewId) { ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("scanPrint/returnPrint"); modelAndView.addObject("viewId", viewId); modelAndView.addObject("printType", 2); return modelAndView; } /** * @Description 入库扫描 * @Date 2020/12/12 **/ @RequestMapping(value = "/inScanPrint") public ModelAndView inScanPrint(Long viewId) { ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("scanPrint/scanInPrint"); modelAndView.addObject("viewId", viewId); modelAndView.addObject("printType", 0); return modelAndView; //ARCHIVAL_TYPE } /** * @Description 保存扫描枪数据 * @Date 2020/12/12 * printType 扫描类型 1.出 0. 进 * operationType 操作类型 1 出入库 2 销毁 **/ @RequestMapping(value = "/saveScanPrintData") @RequiresUser @ResponseBody public Object saveScanPrintData(@RequestBody List> data, int printType, Long viewId, String boxNum) { Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); User user = (User) session.getAttribute("user"); try { View view = viewService.getViewById(viewId); String mainTableName = view.getMainTableName(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (data != null && data.size() > 0) { if (printType == 0) { //入库扫描 updateWarehousing(data, boxNum); } if (printType == 1) { //出库 outWarehousing(data); } if (printType == 2) { //归还 returnWarehousing(data); } } } catch (Exception e) { return new AjaxResponse(false); } return new AjaxResponse(true); } private Map getBusinessData(String tableName, String archivalCode) { String sql = "SELECT * FROM " + tableName + " WHERE ARCHIVAL_STATE = 3 AND ARCHIVAL_CODE='" + archivalCode + "'"; Map data = null; try { data = jdbcTemplate.queryForMap(sql); } catch (Exception e) { logger.error(e.getMessage()); } return data; } /** * @Description 入库 * @Date 2020/12/13 **/ private void updateWarehousing(List> data, String boxNum) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //更新出库状态 for (int i = 0; i < data.size(); i++) { String archivalCode = (String) data.get(i).get("archival_code"); String sqlSelect = "select * from BUS_PACKING_MANAGE where ITEM_NUM = '" + archivalCode + "'"; Map packingMap = jdbcTemplate.queryForMap(sqlSelect); long itemId = Long.parseLong(packingMap.get("ITEM_ID").toString()); String sql = "select * from BUS_WAREHOUSING where item_id =" + itemId + " and IN_STATUS_CODE =2"; List> mapList = jdbcTemplate.queryForList(sql); if (mapList.size() > 0) { Map map = mapList.get(0); Date date = new Date(); String format = sdf.format(date); HashMap mapData = new HashMap<>(); mapData.put("IN_STATUS_CODE", 3); mapData.put("OUT_STATUS", "已入库"); mapData.put("IN_TIME", format); iFormData.update(1972515952908148738L, mapData, Long.parseLong(map.get("ID").toString())); String sqlUpdateBox = "update BUS_PACKING_MANAGE SET BOX_NUMBER='" + boxNum + "', ITEM_STATE='已入库' WHERE ID=" + packingMap.get("ID"); jdbcTemplate.update(sqlUpdateBox); } } } /** * @Description 归还 * @Date 2020/12/13 **/ private void returnWarehousing(List> data) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //更新出库状态 for (int i = 0; i < data.size(); i++) { String archivalCode = (String) data.get(i).get("archival_code"); String sqlSelect = "select * from BUS_PACKING_MANAGE where ITEM_NUM = '" + archivalCode + "'"; Map packingMap = jdbcTemplate.queryForMap(sqlSelect); long itemId = Long.parseLong(packingMap.get("ITEM_ID").toString()); String sql = "select * from BUS_WAREHOUSING where item_id =" + itemId + " and IN_STATUS_CODE =1"; List> mapList = jdbcTemplate.queryForList(sql); if (mapList.size() > 0) { Map map = mapList.get(0); Date date = new Date(); String format = sdf.format(date); String sqlUpdate = "update BUS_WAREHOUSING SET IN_STATUS_CODE=2, OUT_STATUS='待入库', IN_TIME='" + format + "' WHERE ID=" + map.get("ID"); jdbcTemplate.update(sqlUpdate); String sqlUpdateBox = "update BUS_PACKING_MANAGE SET ITEM_STATE='已归还' WHERE ID=" + packingMap.get("ID"); jdbcTemplate.update(sqlUpdateBox); } } } /** * @Description 出库 * @Date 2020/12/13 **/ private void outWarehousing(List> data) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //更新出库状态 for (int i = 0; i < data.size(); i++) { String archivalCode = (String) data.get(i).get("archival_code"); String sqlSelect = "select * from BUS_PACKING_MANAGE where ITEM_NUM = '" + archivalCode + "'"; List> mapList1 = jdbcTemplate.queryForList(sqlSelect); Map packingMap = null; if (mapList1.size() > 0) { packingMap = mapList1.get(0); } long itemId = Long.parseLong(packingMap.get("ITEM_ID").toString()); String sql = "select * from BUS_WAREHOUSING where item_id =" + itemId + " and IN_STATUS_CODE =0"; List> mapList = jdbcTemplate.queryForList(sql); if (mapList.size() > 0) { Map map = mapList.get(0); String boxNumber = packingMap.get("BOX_NUMBER") == null ? "" : packingMap.get("BOX_NUMBER").toString(); String storageLocation = packingMap.get("STORAGE_LOCATION") == null ? "" : packingMap.get("STORAGE_LOCATION").toString(); Date date = new Date(); String format = sdf.format(date); HashMap mapData = new HashMap<>(); mapData.put("IN_STATUS_CODE", 1); mapData.put("OUT_STATUS", "已出库"); mapData.put("OUT_TIME", format); mapData.put("BOX_NUM", boxNumber); mapData.put("LOCATION_NUMBER", storageLocation); iFormData.update(1972515952908148738L, mapData, Long.parseLong(map.get("ID").toString())); String sqlUpdateBox = "update BUS_PACKING_MANAGE SET ITEM_STATE='借出' WHERE ID=" + packingMap.get("ID"); jdbcTemplate.update(sqlUpdateBox); } } } /** * @Description 保存到销毁库 * @Date 2020/12/13 **/ private void saveToDisposeForm(Map businessData) { } }