|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.excel.EasyExcel; | 
|---|
|  |  |  | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.MatExcel; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.WaitPakinExcel; | 
|---|
|  |  |  | import com.zy.asrs.common.utils.MatExcelListener; | 
|---|
|  |  |  | import com.zy.asrs.common.utils.WaitPakingExcelListener; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.Mat; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.WaitPakin; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.WaitPakinLog; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.WrkMast; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.OrderDetlService; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.WaitPakinService; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.WrkMastService; | 
|---|
|  |  |  | import com.zy.asrs.framework.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.R; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.framework.common.DateUtils; | 
|---|
|  |  |  | import com.zy.asrs.common.web.BaseController; | 
|---|
|  |  |  | 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.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WaitPakinService waitPakinService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WrkMastService wrkMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderDetlService orderDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/waitPakin/forBarcode/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R forBarcode(@RequestParam("barcode") String barcode) { | 
|---|
|  |  |  | List<WaitPakin> list = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getZpallet, barcode).eq(WaitPakin::getHostId, getHostId())); | 
|---|
|  |  |  | if (Cools.isEmpty(list)){ | 
|---|
|  |  |  | return R.error("未找到组托信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @RequestMapping(value = "/waitPakin/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R get(@PathVariable("id") String id) { | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestParam(required = false) String condition, | 
|---|
|  |  |  | @RequestParam(required = false) String timeRange, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | LambdaQueryWrapper<WaitPakin> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(WaitPakin::getHostId, getHostId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | wrapper.like(WaitPakin::getId, condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<WaitPakin> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("host_id", getHostId()); | 
|---|
|  |  |  | convert(param,wrapper); | 
|---|
|  |  |  | if (!Cools.isEmpty(timeRange)) { | 
|---|
|  |  |  | String[] range = timeRange.split(RANGE_TIME_LINK); | 
|---|
|  |  |  | wrapper.ge(WaitPakin::getAppeTime, DateUtils.convert(range[0])); | 
|---|
|  |  |  | wrapper.le(WaitPakin::getAppeTime, DateUtils.convert(range[1])); | 
|---|
|  |  |  | wrapper.ge("appe_time", DateUtils.convert(range[0])); | 
|---|
|  |  |  | wrapper.le("appe_time", DateUtils.convert(range[1])); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(waitPakinService.page(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, QueryWrapper<T> wrapper){ | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | if(Cools.eq(entry.getKey(),"curr") || Cools.eq(entry.getKey(),"limit")){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String val = String.valueOf(entry.getValue()); | 
|---|
|  |  |  | 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])); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (entry.getKey().equals("locNo")) { | 
|---|
|  |  |  | wrapper.eq("loc_no", String.valueOf(entry.getValue())); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.like(entry.getKey(), String.valueOf(entry.getValue())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    @RequestMapping(value = "/waitPakin/delete/auth") | 
|---|
|  |  |  | //    @ManagerAuth | 
|---|
|  |  |  | //    public R delete(@RequestParam(value="ids[]") Long[] ids){ | 
|---|
|  |  |  | //         for (Long id : ids){ | 
|---|
|  |  |  | //            waitPakinService.removeById(id); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return R.ok(); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/waitPakin/delete/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R delete(@RequestParam(value="ids[]") Long[] ids){ | 
|---|
|  |  |  | for (Long id : ids){ | 
|---|
|  |  |  | waitPakinService.removeById(id); | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R delete(@RequestParam String param){ | 
|---|
|  |  |  | List<WaitPakin> list = JSONArray.parseArray(param, WaitPakin.class); | 
|---|
|  |  |  | if (Cools.isEmpty(list)){ | 
|---|
|  |  |  | return R.error("数据为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (WaitPakin entity : list){ | 
|---|
|  |  |  | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>().eq("barcode", entity.getZpallet())); | 
|---|
|  |  |  | if(!Cools.isEmpty(wrkMasts) || wrkMasts.size() > 0){ | 
|---|
|  |  |  | return R.error("条码已生成入库工作档,禁止删除"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | waitPakinService.removeById(entity.getId()); | 
|---|
|  |  |  | //订单关联,修改订单作业数量 | 
|---|
|  |  |  | if (!Cools.isEmpty(entity.getOrderNo())) { | 
|---|
|  |  |  | if (!orderDetlService.decrease(entity.getOrderNo(),entity.getHostId(), entity.getMatnr(), entity.getBatch(), entity.getAnfme())) { | 
|---|
|  |  |  | return R.error("订单数据回滚失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok().add(vos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*************************************** 数据相关 ***********************************************/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * excel导入模板下载 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping(value = "/waitPakin/excel/import/mould") | 
|---|
|  |  |  | public void matExcelImportMould(HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | List<WaitPakinExcel> excels = new ArrayList<>(); | 
|---|
|  |  |  | response.setContentType("application/vnd.ms-excel"); | 
|---|
|  |  |  | response.setCharacterEncoding("utf-8"); | 
|---|
|  |  |  | String fileName = URLEncoder.encode("入库通知档Excel导入模板", "UTF-8"); | 
|---|
|  |  |  | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); | 
|---|
|  |  |  | EasyExcel.write(response.getOutputStream(), WaitPakinExcel.class) | 
|---|
|  |  |  | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) | 
|---|
|  |  |  | .sheet("sheet1") | 
|---|
|  |  |  | .doWrite(excels); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    // excel导入-------判断是否有重复物料 | 
|---|
|  |  |  | //    @PostMapping(value = "/mat/excel/import/check/auth") | 
|---|
|  |  |  | //    @ManagerAuth(memo = "商品档案数据导入") | 
|---|
|  |  |  | //    @Transactional | 
|---|
|  |  |  | //    public R matExcelImportCheck(MultipartFile file) throws IOException { | 
|---|
|  |  |  | //        MatExcelListener listener = new MatExcelListener(getUserId(), getHostId()); | 
|---|
|  |  |  | //        EasyExcel.read(file.getInputStream(), MatExcel.class, listener).sheet().doRead(); | 
|---|
|  |  |  | //        return R.ok("成功同步"+listener.getTotal()+"条商品数据"); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // excel导入 | 
|---|
|  |  |  | @PostMapping(value = "/waitPakin/excel/import/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "入库通知档档案数据导入") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R matExcelImport(MultipartFile file) throws IOException { | 
|---|
|  |  |  | WaitPakingExcelListener listener = new WaitPakingExcelListener(getUserId(), getHostId()); | 
|---|
|  |  |  | EasyExcel.read(file.getInputStream(), WaitPakinExcel.class, listener).sheet().doRead(); | 
|---|
|  |  |  | return R.ok("成功同步"+listener.getTotal()+"条商品数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/waitPakin/export/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "库位明细导出") | 
|---|
|  |  |  | public synchronized R export(@RequestBody JSONObject param){ | 
|---|
|  |  |  | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|---|
|  |  |  | QueryWrapper<WaitPakin> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | Map<String, Object> map = excludeTrash(param.getJSONObject("waitPakin")); | 
|---|
|  |  |  | 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<WaitPakin> list = waitPakinService.list(wrapper); | 
|---|
|  |  |  | return R.ok(exportSupport(list, fields)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|