自动化立体仓库 - WMS系统
1
zhang
12 小时以前 be5373a650a8a40e808ab1664e59c60807809a7c
src/main/java/com/zy/asrs/controller/LocDetlController.java
@@ -13,14 +13,27 @@
import com.core.common.DateUtils;
import com.core.common.R;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.param.ProductCalibrationExcelParam;
import com.zy.asrs.importexcle.LocMat;
import com.zy.asrs.importexcle.LocMatListener;
import com.zy.asrs.importexcle.ProductCalibrationImportListener;
import com.zy.asrs.mapper.LocDetlMapper;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.MatService;
import com.zy.common.web.BaseController;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.Synchronized;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
@@ -31,10 +44,71 @@
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private LocDetlMapper locDetlMapper;
    @Autowired
    private MatService matService;
    @Resource
    private LocMastService locMastService;
    @Resource
    private SqlSessionFactory sqlSessionFactory;
    @PostMapping("/importLocData")
    @ManagerAuth(memo = "导入立库已有库存")
    public R importLocData(@RequestParam("file") MultipartFile multipartFile) {
        try {
            importLocData1(multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok("导入成功");
    }
    @PostMapping("/productCalibration")
    @ManagerAuth(memo = "产品校验导入excel方式")
    public R productCalibration(@RequestParam("file") MultipartFile multipartFile) {
        try {
            productCalibrationExcel(multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok("导入成功");
    }
    @PostMapping("/getLocDateByLocNo")
    @ManagerAuth(memo = "根据包装组号提取一整箱库存")
    public R getLocDateByLocNo(@RequestBody List<String> packageNoList) {
        List<LocDetl> locDetls = locDetlMapper.selectList(new EntityWrapper<LocDetl>().in("brand", packageNoList));
        return R.ok(locDetls);
    }
    @PostMapping("/getBoxLocDateByLocNo")
    @ManagerAuth(memo = "根据包装组号提取一整箱库存")
    public R getBoxLocDateByLocNo(@RequestBody List<String> packageNoList) {
        List<LocDetl> locDetls = locDetlMapper.selectList(new EntityWrapper<LocDetl>().in("loc_no", packageNoList));
        return R.ok(locDetls);
    }
    @Transactional(rollbackFor = Exception.class)
    public void importLocData1(MultipartFile multipartFile) throws IOException {
        EasyExcel.read(multipartFile.getInputStream(), LocMat.class,
                new LocMatListener(locMastService, locDetlMapper, getUserId())).sheet().doReadSync();
    }
    @Transactional(rollbackFor = Exception.class)
    public void productCalibrationExcel(MultipartFile multipartFile) throws IOException {
        EasyExcel.read(multipartFile.getInputStream(), ProductCalibrationExcelParam.class,
                new ProductCalibrationImportListener(sqlSessionFactory)).sheet().doReadSync();
    }
    @RequestMapping(value = "/locDetl/update")
    public R update1() {
@@ -52,7 +126,7 @@
    @RequestMapping(value = "/locDetl/auth")
    @ManagerAuth
    public R stockOutList(@RequestParam(value = "locNos[]") List<String> locNos){
    public R stockOutList(@RequestParam(value = "locNos[]") List<String> locNos) {
        if (!locNos.isEmpty()) {
            List<LocDetl> res = new ArrayList<>();
            for (String locNo : new HashSet<>(locNos)) {
@@ -68,10 +142,10 @@
    @RequestMapping(value = "/stock/out/list/auth")
    @ManagerAuth
    public R stockOutList(@RequestParam(defaultValue = "1")Integer curr,
                          @RequestParam(defaultValue = "10")Integer limit,
                          @RequestParam Map<String, Object> param){
        if (!Cools.isEmpty(param.get("modi_time"))){
    public R stockOutList(@RequestParam(defaultValue = "1") Integer curr,
                          @RequestParam(defaultValue = "10") Integer limit,
                          @RequestParam Map<String, Object> param) {
        if (!Cools.isEmpty(param.get("modi_time"))) {
            String val = String.valueOf(param.get("modi_time"));
            if (val.contains(RANGE_TIME_LINK)) {
                String[] dates = val.split(RANGE_TIME_LINK);
@@ -80,29 +154,73 @@
                param.remove("modi_time");
            }
        }
        return R.ok(locDetlService.getStockOut(toPage(curr, limit, param, LocDetl.class)));
        Page<LocDetl> stockOut = locDetlService.getStockOut(toPage(curr, limit, param, LocDetl.class));
        if (stockOut.getRecords().size() == 0) {
            stockOut = locDetlService.getStockOut(toPage(1, limit, param, LocDetl.class));
        }
        return R.ok(stockOut);
    }
    @RequestMapping(value = "/locDetl/list/auth")
    @RequestMapping(value = "/stock/boxOut/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){
        excludeTrash(param);
    public R boxOut(@RequestParam(defaultValue = "1") Integer curr,
                    @RequestParam(defaultValue = "10") Integer limit,
                    @RequestParam Map<String, Object> param) {
        if (!Cools.isEmpty(param.get("modi_time"))) {
            String val = String.valueOf(param.get("modi_time"));
            if (val.contains(RANGE_TIME_LINK)) {
                String[] dates = val.split(RANGE_TIME_LINK);
                param.put("startTime", DateUtils.convert(dates[0]));
                param.put("endTime", DateUtils.convert(dates[1]));
                param.remove("modi_time");
            }
        }
        param.put("matnr", "空箱");
        Page<LocDetl> stockOut = locDetlService.getStockOut(toPage(curr, limit, param, LocDetl.class));
        if (stockOut.getRecords().size() == 0) {
            stockOut = locDetlService.getStockOut(toPage(1, limit, param, LocDetl.class));
        }
        return R.ok(stockOut);
    }
    @RequestMapping(value = "/locDetl/list/auth")// /locDetl/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) {
//        String row = "";
        EntityWrapper<LocDetl> wrapper = new EntityWrapper<>();
//        if (param.get("row") != null) {
//            String chooseRow = (String) param.get("row");
//            if (chooseRow.length() == 1) {
//                row = "0" + chooseRow;
//                param.remove("row");
//            }else {
//                row = chooseRow;
//                param.remove("row");
//            }
//        }
        excludeTrash(param);
        convert(param, wrapper);
        allLike(LocDetl.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        if (!Cools.isEmpty(orderByField)) {
            wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));
        }
//        if (!row.equals("")){
//            wrapper.and()
//                    .where("loc_no like '" +row +"%'");
//        }
        return R.ok(locDetlService.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]));
@@ -127,10 +245,10 @@
        return R.ok();
    }
   @RequestMapping(value = "/locDetl/update/auth")
   @ManagerAuth(memo = "库位明细修改")
    public R update(LocDetl locDetl){
        if (Cools.isEmpty(locDetl) || null==locDetl.getMatnr()){
    @RequestMapping(value = "/locDetl/update/auth")
    @ManagerAuth(memo = "库位明细修改")
    public R update(LocDetl locDetl) {
        if (Cools.isEmpty(locDetl) || null == locDetl.getMatnr()) {
            return R.error();
        }
        locDetl.setModiUser(getUserId());
@@ -141,12 +259,12 @@
    @RequestMapping(value = "/locDetl/delete/auth")
    @ManagerAuth(memo = "库位明细删除")
    public R delete(@RequestParam String param){
    public R delete(@RequestParam String param) {
        List<LocDetl> list = JSONArray.parseArray(param, LocDetl.class);
        if (Cools.isEmpty(list)){
        if (Cools.isEmpty(list)) {
            return R.error();
        }
        for (LocDetl entity : list){
        for (LocDetl entity : list) {
            locDetlService.delete(new EntityWrapper<>(entity));
        }
        return R.ok();
@@ -154,11 +272,26 @@
    @RequestMapping(value = "/locDetl/export/auth")
    @ManagerAuth(memo = "库位明细导出")
    public R export(@RequestBody JSONObject param){
    public R export(@RequestBody JSONObject param) {
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        EntityWrapper<LocDetl> wrapper = new EntityWrapper<>();
        Map<String, Object> map = excludeTrash(param.getJSONObject("locDetl"));
        String row = "";
        if (map.get("row") != null) {
            String chooseRow = (String) map.get("row");
            if (chooseRow.length() == 1) {
                row = "0" + chooseRow;
                map.remove("row");
            } else {
                row = chooseRow;
                map.remove("row");
            }
        }
        convert(map, wrapper);
        if (!row.equals("")) {
            wrapper.and()
                    .where("loc_no like '" + row + "%'");
        }
        List<LocDetl> list = locDetlService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
@@ -170,7 +303,7 @@
        wrapper.like("matnr", condition);
        Page<LocDetl> page = locDetlService.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (LocDetl locDetl : page.getRecords()){
        for (LocDetl locDetl : page.getRecords()) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", locDetl.getMatnr());
            map.put("value", locDetl.getMatnr());
@@ -183,7 +316,7 @@
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<LocDetl> wrapper = new EntityWrapper<LocDetl>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != locDetlService.selectOne(wrapper)){
        if (null != locDetlService.selectOne(wrapper)) {
            return R.parse(BaseRes.REPEAT).add(getComment(LocDetl.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
@@ -191,8 +324,8 @@
    @RequestMapping(value = "/locDetl/statis/auth")
    @ManagerAuth
    public R statis(@RequestParam(defaultValue = "1")Integer curr,
                    @RequestParam(defaultValue = "10")Integer limit,
    public R statis(@RequestParam(defaultValue = "1") Integer curr,
                    @RequestParam(defaultValue = "10") Integer limit,
                    @RequestParam Map<String, Object> param) {
        Page<LocDetl> stockStatis = locDetlService.getStockStatis(toPage(curr, limit, param, LocDetl.class));
        for (LocDetl locDetl : stockStatis.getRecords()) {
@@ -206,6 +339,10 @@
    @Autowired
    private LocDetlMapper LocDetlMapper;
    @Autowired
    private ConfigService configService;
    @RequestMapping(value = "/locDetl/statis/export")
//    @ManagerAuth
@@ -227,4 +364,42 @@
                .doWrite(excel);
    }
    /**
     * 获取库存总数
     *
     * @return
     */
    @RequestMapping("/locDetl/count")
    public R getAllCount() {
        Integer sum = locDetlService.sum();
        return R.ok(sum);
    }
    @RequestMapping(value = "/locDetl/sync/auth")
    @ManagerAuth
    @Synchronized
    public R sync() {
        EntityWrapper<LocMast> locMastEntityWrapper = new EntityWrapper<>();
        int i = locMastService.selectCount(locMastEntityWrapper.in("loc_sts", "S", "R", "P", "Q"));
        if (i > 0) {
            return R.error("有" + i + "条数据处于出入库预约或盘点拣料中,无法同步库存");
        }
        Config config = configService.selectOne(new EntityWrapper<Config>().eq("code","sync"));
        if (config==null){
            config=new Config();
            config.setValue("1");
            config.setStatus((short) 1);
            config.setCode("sync");
            config.setType((short) 1);
            config.setName("同步期初数据MES");
        }else {
            if (config.getValue().equals("1")){
                return R.error("数据同步中,请勿重复点击");
            }
            config.setValue("1");
            configService.updateById(config);
        }
        return R.ok();
    }
}