| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.sun.org.apache.bcel.internal.generic.NEW; |
| | | import com.zy.asrs.entity.LocNormal; |
| | | import com.zy.asrs.entity.LocNormalLog; |
| | | import com.zy.asrs.entity.LocNormalReport; |
| | | import com.zy.asrs.entity.param.LocNormalParam; |
| | | import com.zy.asrs.service.LocNormalLogService; |
| | | import com.zy.asrs.service.LocNormalReportService; |
| | | import com.zy.asrs.service.LocNormalService; |
| | | import com.zy.asrs.utils.VersionUtils; |
| | | import com.zy.common.service.erp.ErpService; |
| | | import com.zy.common.service.erp.ErpSqlServer; |
| | | import com.zy.common.utils.excel.locNomal.LocNormalExcel; |
| | | import com.zy.common.utils.excel.locNomal.LocNormalExcelListener; |
| | | import com.zy.common.utils.excel.matcode.MatCodeExcel; |
| | | import com.zy.common.utils.excel.matcode.MatCodeExcelListener; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.text.MessageFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static jdk.nashorn.api.scripting.ScriptUtils.convert; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | public class LocNormalController extends BaseController{ |
| | | public class LocNormalController extends BaseController { |
| | | @Autowired |
| | | private LocNormalService locNormalService; |
| | | @Autowired |
| | | private LocNormalReportService locNormalReportService; |
| | | @Autowired |
| | | private ErpSqlServer erpSqlServer; |
| | | @Autowired |
| | | private LocNormalLogService locNormalLogService; |
| | | |
| | | @RequestMapping(value = "/locNomal/list/auth") |
| | | @ManagerAuth |
| | | public R list(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam(required = false)String condition, |
| | | @RequestParam Map<String, Object> param){ |
| | | public R list(@RequestParam(defaultValue = "1") Integer curr, |
| | | @RequestParam(defaultValue = "10") Integer limit, |
| | | @RequestParam(required = false) String orderByField, |
| | | @RequestParam(required = false) String orderByType, |
| | | @RequestParam(required = false) String condition, |
| | | @RequestParam Map<String, Object> param) { |
| | | excludeTrash(param); |
| | | EntityWrapper<LocNormal> wrapper = new EntityWrapper<>(); |
| | | convert(param, wrapper); |
| | | allLike(LocNormal.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | wrapper.eq("state", "1").or().eq("state", "2"); |
| | | if (!Cools.isEmpty(orderByField)) { |
| | | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); |
| | | } |
| | | if (Cools.isEmpty(param.get("state"))) { |
| | | wrapper.in("state", "1,2"); |
| | | } |
| | | return R.ok(locNormalService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper) { |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | String val = String.valueOf(entry.getValue()); |
| | | if (val.contains(RANGE_TIME_LINK)){ |
| | | if (val.contains(RANGE_TIME_LINK)) { |
| | | String[] dates = val.split(RANGE_TIME_LINK); |
| | | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); |
| | | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); |
| | |
| | | @ManagerAuth |
| | | public R query(@RequestBody JSONObject param) { |
| | | Wrapper<LocNormal> wrapper = new EntityWrapper<LocNormal>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); |
| | | if (null != locNormalService.selectOne(wrapper)){ |
| | | if (null != locNormalService.selectOne(wrapper)) { |
| | | return R.parse(BaseRes.REPEAT).add(getComment(LocNormal.class, String.valueOf(param.get("key")))); |
| | | } |
| | | return R.ok(); |
| | |
| | | public void updateLocNormal(LocNormal param) { |
| | | Long modiUser = getUserId(); |
| | | Date modiTime = new Date(); |
| | | locNormalService.updateLocNormal(param.getMatnr(), param.getAnfme(), modiUser, modiTime); |
| | | // 调整库存,修改,StockCheckRecord插入盘盈、盘亏数据 |
| | | LocNormal locNormalOld = locNormalService.selectOne(new EntityWrapper<LocNormal>().eq("matnr", param.getMatnr()).and().eq("warehouse", param.getWarehouse()).and().eq("supplier", param.getSupplier())); |
| | | BigDecimal erpCount = new BigDecimal(0); |
| | | if (param.getAnfme() == new BigDecimal(0)) { |
| | | erpCount = new BigDecimal(0).subtract(new BigDecimal(String.valueOf(locNormalOld.getAnfme()))); |
| | | } else { |
| | | erpCount = param.getAnfme().subtract(new BigDecimal(String.valueOf(locNormalOld.getAnfme()))); |
| | | } |
| | | // 调整库存,新增,StockCheckRecord插入盘盈数据 |
| | | String ErpSql = "insert into StockCheckRecord(Fnumber, CheckQty, Fflag_rw, Fflag_finish) values (''{0}'', {1,number,#}, 0, 0)"; |
| | | ErpSql = MessageFormat.format(ErpSql, param.getMatnr(), erpCount); |
| | | erpSqlServer.update(ErpSql); |
| | | locNormalService.updateLocNormal(param.getMatnr(), param.getAnfme(), modiUser, modiTime, param.getId()); |
| | | // 生成平仓出入库记录 |
| | | LocNormalLog locLog = new LocNormalLog(); |
| | | VersionUtils.setLocNormalLog(locLog, param); |
| | | locLog.setAnfme(erpCount.doubleValue()); |
| | | locLog.setIoType(3); // 修改 |
| | | locLog.setCreateTime(new Date()); |
| | | locLog.setCreateUser(modiUser); |
| | | if (!locNormalLogService.insert(locLog)) { |
| | | String logStr = JSON.toJSONString(locLog); |
| | | log.info("平仓修改库存记录插入失败,数据:" + logStr); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/locNormal/outLoc/auth") |
| | |
| | | public void outLocNormal(LocNormal param) { |
| | | Long modiUser = getUserId(); |
| | | Date modiTime = new Date(); |
| | | locNormalService.outLocNormal(param.getMatnr(), modiUser, modiTime); |
| | | locNormalService.outLocNormal(param.getMatnr(), modiUser, modiTime, param.getId()); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locNormal/removeLoc/auth") |
| | |
| | | public void removeLoc(LocNormal param) { |
| | | Long modiUser = getUserId(); |
| | | Date modiTime = new Date(); |
| | | locNormalService.removeLocNormal(param.getMatnr(), modiUser, modiTime); |
| | | locNormalService.removeLocNormal(param.getMatnr(), modiUser, modiTime, param.getId()); |
| | | } |
| | | |
| | | // 导入 |
| | | /* 导入 */ |
| | | @RequestMapping(value = "/locNormal/import/auth") |
| | | @ManagerAuth(memo = "平仓管理导入") |
| | | @Transactional |
| | | public R matCodeImport(MultipartFile file) throws IOException, InterruptedException { |
| | | public R locNormalImport(MultipartFile file) throws IOException, InterruptedException { |
| | | LocNormalExcelListener listener = new LocNormalExcelListener(getUserId()); |
| | | EasyExcel.read(file.getInputStream(), LocNormalExcel.class, listener).sheet().doRead(); |
| | | return R.ok("成功导入"+listener.getTotal()+"条物料信息"); |
| | | return R.ok("成功导入" + listener.getTotal() + "条物料信息"); |
| | | } |
| | | |
| | | /* 导出 */ |
| | | @RequestMapping(value = "/locNormal/export/auth") |
| | | @ManagerAuth(memo = "平仓管理导出") |
| | | public R export(@RequestBody JSONObject param){ |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | EntityWrapper<LocNormal> wrapper = new EntityWrapper<LocNormal>(); |
| | | wrapper.ne("state", "3"); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("exportData")); |
| | | convert(map, wrapper); |
| | | List<LocNormal> list = locNormalService.selectList(wrapper); |
| | | return R.ok(exportSupport(list, fields)); |
| | | } |
| | | |
| | | /* 平仓入库 成品 */ |
| | | @RequestMapping(value = "/locNormal/in") |
| | | @ManagerAuth(memo = "平仓入库") |
| | | @Transactional |
| | | public R locNormalIn(@RequestBody LocNormalParam param) { |
| | | Long userId = getUserId(); |
| | | Date timeNow = new Date(); |
| | | for (Integer i = 0; i < param.getNormalList().size(); i++) { |
| | | param.getNormalList().get(i).setAppeUser(userId); |
| | | param.getNormalList().get(i).setAppeTime(timeNow); |
| | | } |
| | | locNormalService.locNormalIn(param.getNormalList()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /* 平仓入库-原材料 */ |
| | | @RequestMapping(value = "/locNormal/in/source") |
| | | @ManagerAuth(memo = "平仓入库-原材料") |
| | | @Transactional |
| | | public R locNormalInSource(@RequestBody LocNormalParam param) { |
| | | Long userId = getUserId(); |
| | | Date timeNow = new Date(); |
| | | for (Integer i = 0; i < param.getNormalList().size(); i++) { |
| | | param.getNormalList().get(i).setAppeUser(userId); |
| | | param.getNormalList().get(i).setAppeTime(timeNow); |
| | | } |
| | | locNormalService.locNormalInSource(param.getNormalList()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /* pda入库 */ |
| | | @RequestMapping(value = "/locNormal/pda/in") |
| | | @ManagerAuth(memo = "平仓管理pda入库") |
| | | @Transactional |
| | | public R locNormalPdaIn(@RequestBody LocNormalParam param) { |
| | | Long userId = getUserId(); |
| | | Date timeNow = new Date(); |
| | | for (Integer i = 0; i < param.getNormalList().size(); i++) { |
| | | param.getNormalList().get(i).setAppeUser(userId); |
| | | param.getNormalList().get(i).setAppeTime(timeNow); |
| | | } |
| | | locNormalService.pdaLocNormalIn(param.getNormalList()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /* pda出库查询 */ |
| | | @RequestMapping(value = "/locNormal/pda/out/query") |
| | | @ManagerAuth(memo = "pda出库查询") |
| | | @Transactional |
| | | public R locNormalPdaOutQuery(String matnr, String warehouse, String billNo) { |
| | | List<LocNormal> list = new ArrayList<>(); |
| | | list = locNormalService.pdaLocNormalQuery(matnr, warehouse, billNo); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locNormal/pda/out") |
| | | @ManagerAuth(memo = "pda出库") |
| | | @Transactional |
| | | public R locNormalPdaOut(@RequestBody LocNormalParam param) { |
| | | Long userId = getUserId(); |
| | | Date timeNow = new Date(); |
| | | List<LocNormal> list = param.getNormalList(); |
| | | for (Integer i = 0; i < list.size(); i++) { |
| | | list.get(i).setModiUser(userId); |
| | | list.get(i).setModiTime(timeNow); |
| | | } |
| | | locNormalService.pdaLocNormalOut(list); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locNormal/pda/warehouseQuery") |
| | | @ManagerAuth(memo = "pda根据库区查询物料清单") |
| | | @Transactional |
| | | public R locNormalPdaWarehouseQuery(String warehouse, String matnr) { |
| | | List<LocNormal> list = locNormalService.pdaLocNormalWarehouseQuery(warehouse, matnr); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locNormal/pda/move") |
| | | @ManagerAuth(memo = "pda移库") |
| | | @Transactional |
| | | public R LocNormalPdaMove(@RequestBody LocNormalParam param) { |
| | | Long userId = getUserId(); |
| | | Date timeNow = new Date(); |
| | | List<LocNormal> list = param.getNormalList(); |
| | | for (Integer i = 0; i < list.size(); i++) { |
| | | list.get(i).setModiUser(userId); |
| | | list.get(i).setModiTime(timeNow); |
| | | } |
| | | locNormalService.pdaLocNormalMove(list); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locNomal/getInListByDay") |
| | | @ManagerAuth(memo = "平仓日出入库查询") |
| | | public R getInListByDay(@RequestParam(defaultValue = "1") Integer curr, |
| | | @RequestParam(defaultValue = "10") Integer limit, |
| | | @RequestParam(required = false) String orderByField, |
| | | @RequestParam(required = false) String orderByType, |
| | | @RequestParam(required = false) String condition, |
| | | @RequestParam Map<String, Object> param) { |
| | | excludeTrash(param); |
| | | EntityWrapper<LocNormalLog> wrapper = new EntityWrapper<>(); |
| | | String time1 = ""; |
| | | String time2 = ""; |
| | | if (!Cools.isEmpty(param.get("query_date"))) { |
| | | String timeRange = param.get("query_date").toString(); |
| | | time1 = timeRange.substring(0, 19); |
| | | time2 = timeRange.substring(21, timeRange.length()); |
| | | } |
| | | param.remove("query_date"); |
| | | convert(param, wrapper); |
| | | if (time1 != "" && time2 != "") { |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date dateTime1 = new Date(); |
| | | Date dateTime2 = new Date(); |
| | | try { |
| | | dateTime1 = formatter.parse(time1); |
| | | dateTime2 = formatter.parse(time2); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | wrapper.ge("create_time", dateTime1).and().le("create_time", dateTime2); |
| | | } |
| | | List<String> oderCol = new ArrayList<>(); |
| | | oderCol.add("create_time"); |
| | | wrapper.orderDesc(oderCol); |
| | | allLike(LocNormalLog.class, param.keySet(), wrapper, condition); |
| | | return R.ok(locNormalLogService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | //excel导出 |
| | | @RequestMapping("/locNomal/normalReportExport.action") |
| | | @ManagerAuth(memo = "日入库明细统计导出") |
| | | public R normalReportExport(@RequestBody JSONObject param){ |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | @SuppressWarnings("unchecked") |
| | | List<LocNormalReport> list = JSONObject.parseArray(param.getJSONArray("exportData").toJSONString(), LocNormalReport.class); |
| | | return R.ok(exportSupport(list, fields)); |
| | | } |
| | | } |