wang..123
2022-03-10 dcd7fcf596005d0c7cf66558bee97edf6c3b03a0
src/main/java/com/zy/asrs/controller/LocNormalController.java
@@ -1,6 +1,7 @@
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;
@@ -11,14 +12,23 @@
import com.core.common.DateUtils;
import com.core.common.R;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.zy.asrs.entity.LocDetl;
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;
@@ -28,6 +38,9 @@
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;
@@ -35,10 +48,17 @@
import static jdk.nashorn.api.scripting.ScriptUtils.convert;
@Slf4j
@RestController
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
@@ -54,9 +74,11 @@
        allLike(LocNormal.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)) {
            wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));
        } else {
            wrapper.orderBy("appe_time", false);
        }
        if (Cools.isEmpty(param.get("state"))) {
            wrapper.eq("state", "1").or().eq("state", "2");
            wrapper.in("state", "1,2");
        }
        return R.ok(locNormalService.selectPage(new Page<>(curr, limit), wrapper));
    }
@@ -103,7 +125,30 @@
    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")
@@ -111,7 +156,19 @@
    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());
    }
    /**
     * 批量修改物料状态
     * @return
     */
    @RequestMapping(value = "/locNormal/getAllLocDetlData")
    @ManagerAuth(memo = "批量修改物料状态")
    public R getAllLocDetlData(@RequestBody JSONObject param) {
        List<LocNormal> list = JSONObject.parseArray(param.getJSONArray("list").toJSONString(), LocNormal.class);
        Integer result = locNormalService.getAllLocDetlData(list);
        return R.ok().add(result);
    }
    @RequestMapping(value = "/locNormal/removeLoc/auth")
@@ -119,7 +176,7 @@
    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());
    }
    /* 导入 */
@@ -132,7 +189,20 @@
        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
@@ -144,6 +214,21 @@
            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();
    }
@@ -166,9 +251,9 @@
    @RequestMapping(value = "/locNormal/pda/out/query")
    @ManagerAuth(memo = "pda出库查询")
    @Transactional
    public R locNormalPdaOutQuery(String matnr, String warehouse) {
    public R locNormalPdaOutQuery(String matnr, String warehouse, String billNo) {
        List<LocNormal> list = new ArrayList<>();
        list  = locNormalService.pdaLocNormalQuery(matnr, warehouse);
        list  = locNormalService.pdaLocNormalQuery(matnr, warehouse, billNo);
        return R.ok(list);
    }
@@ -186,4 +271,75 @@
        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<LocNormalLog> list = JSONObject.parseArray(param.getJSONArray("exportData").toJSONString(), LocNormalLog.class);
        return R.ok(exportSupport(list, fields));
    }
}