|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.excel.EasyExcel; | 
|---|
|  |  |  | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.plugins.Page; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.zy.asrs.entity.Pla; | 
|---|
|  |  |  | import com.zy.asrs.service.PlaService; | 
|---|
|  |  |  | import com.core.common.SnowflakeIdWorker; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.GlobleParameter; | 
|---|
|  |  |  | import com.zy.asrs.entity.result.KeyValueVo; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.PlaExcelListener; | 
|---|
|  |  |  | import com.zy.asrs.utils.SaasUtils; | 
|---|
|  |  |  | import com.zy.common.CodeRes; | 
|---|
|  |  |  | import com.zy.common.entity.PlaExcel; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.system.entity.OperateLog; | 
|---|
|  |  |  | import com.zy.system.service.OperateLogService; | 
|---|
|  |  |  | import lombok.Synchronized; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class PlaController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlaService plaService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlaQtyService plaQtyService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManPakOutService manPakOutService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderService orderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderDetlService orderDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlaLogService plaLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatService matService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SnowflakeIdWorker snowflakeIdWorker; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OperateLogService operateLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取下拉选择框值列表 | 
|---|
|  |  |  | @GetMapping(value = "/pla/dropdownValues/list") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R list() { | 
|---|
|  |  |  | List<DropdownValuesDto> list = plaService.getDropdownValues(); | 
|---|
|  |  |  | Map<String, List<String>> map = new HashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // owner 去重并加入 map | 
|---|
|  |  |  | List<String> owners = list.stream() | 
|---|
|  |  |  | .filter(dropdownValuesDto -> dropdownValuesDto.getType().equals("owner")) | 
|---|
|  |  |  | .map(DropdownValuesDto::getValue) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  | map.put("owner", owners); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // workshop 去重并加入 map | 
|---|
|  |  |  | List<String> workshops = list.stream() | 
|---|
|  |  |  | .filter(dropdownValuesDto -> dropdownValuesDto.getType().equals("workshop")) | 
|---|
|  |  |  | .map(DropdownValuesDto::getValue) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  | map.put("workshop", workshops); | 
|---|
|  |  |  | return R.ok(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1")Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10")Integer limit, | 
|---|
|  |  |  | @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 condition, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | EntityWrapper<Pla> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(param.get("brand"))) { | 
|---|
|  |  |  | wrapper.eq("brand", param.get("brand")); | 
|---|
|  |  |  | param.remove("brand"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 仓库精确匹配 | 
|---|
|  |  |  | if (!Cools.isEmpty(param.get("stash"))) { | 
|---|
|  |  |  | wrapper.eq("stash", param.get("stash")); | 
|---|
|  |  |  | param.remove("stash"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 没有选择的时候默认不显示已出库的物料 | 
|---|
|  |  |  | if (Cools.isEmpty(param.get("status"))) { | 
|---|
|  |  |  | wrapper.ne("status", "全部出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(param.get("batch")) && param.get("batch").toString().contains(",")) { | 
|---|
|  |  |  | String[] batchs = param.get("batch").toString().split(","); | 
|---|
|  |  |  | wrapper.in("batch", batchs); | 
|---|
|  |  |  | param.remove("batch"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | wrapper.orderBy("batch", true).orderBy("package_no", true); | 
|---|
|  |  |  | allLike(Pla.class, param.keySet(), wrapper, condition); | 
|---|
|  |  |  | return R.ok(plaService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/add/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R add(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | System.out.println(plas.toString()); | 
|---|
|  |  |  | log.info(plas.toString()); | 
|---|
|  |  |  | plas.forEach(pla -> { | 
|---|
|  |  |  | plaService.insert(pla); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R update(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | System.out.println(plas.toString()); | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | plas.forEach(pla -> { | 
|---|
|  |  |  | Pla plaSave = plaService.selectById(pla.getId()); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PlaLog plaLog = new PlaLog(); | 
|---|
|  |  |  | BeanUtils.copyProperties(plaSave, plaLog); | 
|---|
|  |  |  | plaLog.setId(null); | 
|---|
|  |  |  | plaLog.setCreateTime(date); | 
|---|
|  |  |  | plaLog.setModifyUser(getUser().getUsername()); | 
|---|
|  |  |  | plaLogService.insert(plaLog); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 记录操作日志 | 
|---|
|  |  |  | OperateLog operateLog = new OperateLog(); | 
|---|
|  |  |  | operateLog.setAction("聚乳酸库存明细修改"); | 
|---|
|  |  |  | operateLog.setUserId(getUserId()); | 
|---|
|  |  |  | operateLog.setIp(request.getRemoteAddr()); | 
|---|
|  |  |  | operateLog.setRequest(pla.toString()); | 
|---|
|  |  |  | operateLog.setResponse(plaSave.toString()); | 
|---|
|  |  |  | operateLog.setCreateTime(new Date()); | 
|---|
|  |  |  | operateLogService.insert(operateLog); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | @RequestMapping(value = "/pla/delete/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R delete(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | log.info(plas.toString()); | 
|---|
|  |  |  | plas.forEach(pla -> { | 
|---|
|  |  |  | if (!pla.getStatus().equals(GlobleParameter.PLA_STATUS_00) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_0) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_1)) { | 
|---|
|  |  |  | throw new CoolException("已入库的数据无法被删除"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Pla plaSave = plaService.selectById(pla.getId()); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | plaService.deleteById(pla.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PlaLog plaLog = new PlaLog(); | 
|---|
|  |  |  | BeanUtils.copyProperties(plaSave, plaLog); | 
|---|
|  |  |  | plaLog.setId(null); | 
|---|
|  |  |  | plaLog.setCreateTime(new Date()); | 
|---|
|  |  |  | plaLog.setModifyUser(getUser().getUsername()); | 
|---|
|  |  |  | plaLogService.insert(plaLog); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/delivery/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R delivery() { | 
|---|
|  |  |  | return R.ok(plaQtyService.getDeliveryDate()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/sellout/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "sellout") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | public R sellout(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String orderNo = plas.get(0).getOrderNo(); | 
|---|
|  |  |  | String maktx = plas.get(0).getBrand(); | 
|---|
|  |  |  | Double allOrderWeight = 0.0; | 
|---|
|  |  |  | Order order = orderService.selectByNo(orderNo); | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectByOrderNoAndMaktx(orderNo, maktx); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Pla pla : plas) { | 
|---|
|  |  |  | // 获取最新冻结状态 | 
|---|
|  |  |  | Pla pla1 = plaService.selectOne(new EntityWrapper<Pla>().setSqlSelect("stock_freeze as stockFreeze,stock_freeze_by as stockFreezeBy,stock_freeze_date as stockFreezeDate").eq("id", pla.getId())); | 
|---|
|  |  |  | pla.setStockFreeze(pla1.getStockFreeze()); | 
|---|
|  |  |  | pla.setStockFreezeBy(pla1.getStockFreezeBy()); | 
|---|
|  |  |  | pla.setStockFreezeDate(pla1.getStockFreezeDate()); | 
|---|
|  |  |  | if (pla.getStockFreeze() == 0) { | 
|---|
|  |  |  | //                throw new CoolException("库存已被冻结,请重新选择库存"); | 
|---|
|  |  |  | log.info("该库存已被其他用户冻结,请重新选择;{},{}", pla.getStockFreezeBy(), getUser().getUsername()); | 
|---|
|  |  |  | if (!Cools.eq(pla.getStockFreezeBy(), getUser().getUsername())) { | 
|---|
|  |  |  | throw new CoolException("该库存已被其他用户冻结,请重新选择"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | allOrderWeight += pla.getOrderWeight(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (pla.getWeightAnfme() - pla.getQtyAnfme() - pla.getOrderWeight() < 0) { | 
|---|
|  |  |  | throw new CoolException("批号:" + pla.getBatch() + ",包号:" + pla.getPackageNo() + " 剩余可出库重量不足,请调整出库重量"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Cools.isEmpty(pla.getMassState())){ | 
|---|
|  |  |  | throw new CoolException("质量指标为上传"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | pla.setQtyAnfme(pla.getQtyAnfme() + pla.getOrderWeight()); | 
|---|
|  |  |  | pla.setHandlerBy(getUser().getUsername()); | 
|---|
|  |  |  | pla.setStatus(GlobleParameter.PLA_STATUS_2); | 
|---|
|  |  |  | log.info("修改为待出库,地址:{},数据:{}","/pla/sellout/auth", pla); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | pla.setPakoutTime(pla.getPakoutTime().split("\\(")[0]); | 
|---|
|  |  |  | //生成此次作业信息 | 
|---|
|  |  |  | PlaQty plaQty = new PlaQty(); | 
|---|
|  |  |  | BeanUtils.copyProperties(pla, plaQty); | 
|---|
|  |  |  | plaQty.setCreateTime(new Date()); | 
|---|
|  |  |  | plaQty.setId(null); | 
|---|
|  |  |  | plaQty.setTransfer(order.getDocType$()); | 
|---|
|  |  |  | plaQty.setOrderDetlId(orderDetl.getId()); | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  | plaQtyService.insert(plaQty); | 
|---|
|  |  |  | //生成拣货单 | 
|---|
|  |  |  | addPakOUT(plaQty, getUserId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //修改单据信息 | 
|---|
|  |  |  | if (orderDetl.getAnfme() - orderDetl.getWorkQty() - allOrderWeight < 0) { | 
|---|
|  |  |  | throw new CoolException("该订单出库数量大于订单待出数量,请重新选择出库数量"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (order.getStatus() < 2) { | 
|---|
|  |  |  | orderService.updateSettle(order.getId(), 2L, getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderDetl.setWorkQty(orderDetl.getWorkQty() + allOrderWeight); | 
|---|
|  |  |  | orderDetlService.updateById(orderDetl); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/returned/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R returned(@RequestBody List<PlaQty> plaQties) { | 
|---|
|  |  |  | plaService.returned(plaQties, getUser()); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/viladate/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R viladate(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | plaService.viladate(plas, getUser()); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/rework/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R rework(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | plas.forEach(pla -> { | 
|---|
|  |  |  | Double anfme = pla.getWeightAnfme(); | 
|---|
|  |  |  | pla.setStatus("全部出库"); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | pla.setWeightAnfme(0.0); | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  | SaasUtils.insertLog(1, pla.getLocNo(), pla.getBrand(), anfme, getUser().getUsername(), | 
|---|
|  |  |  | null, pla.getBatch(), pla.getPackageNo(), pla.getOwner(), pla.getWorkshop(), null); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/updateStockFreeze") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | @ManagerAuth(memo = "库位冻结") | 
|---|
|  |  |  | public R updateStockFreeze(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | if (Cools.isEmpty(plas)) { | 
|---|
|  |  |  | return R.error("无数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Pla pla : plas) { | 
|---|
|  |  |  | if (pla.getStockFreeze() == 0) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | //                throw new CoolException("库存已被冻结!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | pla.setStockFreeze(0); | 
|---|
|  |  |  | pla.setStockFreezeBy(getUser().getUsername()); | 
|---|
|  |  |  | pla.setStockFreezeDate(new Date()); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("冻结成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/updateStockDisFreeze") | 
|---|
|  |  |  | @ManagerAuth(memo = "库位解冻") | 
|---|
|  |  |  | public R updateStockDisFreeze(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | if (Cools.isEmpty(plas)) { | 
|---|
|  |  |  | return R.error("无数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Pla pla : plas) { | 
|---|
|  |  |  | if (pla.getStockFreeze() == 1) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | //                throw new CoolException("库位未冻结,无需解冻"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.eq(pla.getStockFreezeBy(), getUser().getUsername())) { | 
|---|
|  |  |  | throw new CoolException("无法解冻其他用户冻结的库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | pla.setStockFreeze(1); | 
|---|
|  |  |  | pla.setStockFreezeBy(getUser().getUsername()); | 
|---|
|  |  |  | pla.setStockFreezeDate(new Date()); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("解除冻结成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/matMaktxQuery/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R queryMat(String condition) { | 
|---|
|  |  |  | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.like("maktx", condition); | 
|---|
|  |  |  | Page<Mat> page = matService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (Mat mat : page.getRecords()) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("id", mat.getMaktx()); | 
|---|
|  |  |  | map.put("value", mat.getMaktx()); | 
|---|
|  |  |  | result.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/pla/statis/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R statis(@RequestParam(defaultValue = "1") Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10") Integer limit, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Page<Pla> stockStatis = plaService.getStockStatisAll(toPage(curr, limit, param, Pla.class)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok().add(stockStatis); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * excel导入模板下载 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping(value = "/pla/excel/import/mould") | 
|---|
|  |  |  | public void plaExcelImportMould(HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | List<PlaExcel> 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(), PlaExcel.class) | 
|---|
|  |  |  | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) | 
|---|
|  |  |  | .sheet("sheet1") | 
|---|
|  |  |  | .doWrite(excels); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // excel导入 | 
|---|
|  |  |  | @PostMapping(value = "/pla/excel/import/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "pla档案数据导入") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R matExcelImport(MultipartFile file) throws IOException { | 
|---|
|  |  |  | PlaExcelListener listener = new PlaExcelListener(getUserId()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | EasyExcel.read(file.getInputStream(), PlaExcel.class, listener).sheet().doRead(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | int index = listener.getIndex() - 1; | 
|---|
|  |  |  | throw new CoolException("导入的数据格式错误,原因:" + e.getMessage() + ",第" + index + ",数据格式不对"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("导入修改信息输出:" + listener.getRecordLog()); | 
|---|
|  |  |  | return R.ok("成功同步" + listener.getTotal() + "条pla物料数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 打印 | 
|---|
|  |  |  | @RequestMapping(value = "/pla/print/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "pla编码打印") | 
|---|
|  |  |  | public R matCodePrint(@RequestBody List<Pla> plas) { | 
|---|
|  |  |  | if (Cools.isEmpty(plas)) { | 
|---|
|  |  |  | return R.parse(CodeRes.EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Pla> res = new ArrayList<>(); | 
|---|
|  |  |  | for (Pla pla : plas) { | 
|---|
|  |  |  | res.add(pla); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*************************************** xm-select ***********************************************/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // xm-select 搜索批号 | 
|---|
|  |  |  | @RequestMapping("/pla/batch/all/get/kv") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R getMatDataKV(@RequestParam(required = false) String condition) { | 
|---|
|  |  |  | Wrapper<Pla> wrapper = new EntityWrapper<Pla>().setSqlSelect("batch") | 
|---|
|  |  |  | .andNew().like("batch", condition) | 
|---|
|  |  |  | .groupBy("batch") | 
|---|
|  |  |  | .orderBy("batch", false); | 
|---|
|  |  |  | Page<Pla> plaPage = new Page<>(1, 30); | 
|---|
|  |  |  | plaPage.setSearchCount(false); | 
|---|
|  |  |  | Page<Pla> plaPage1 = plaService.selectPage(plaPage, wrapper); | 
|---|
|  |  |  | // 重新查询然后给page设置Total | 
|---|
|  |  |  | plaPage.setTotal(this.plaService.selectCount(new EntityWrapper<Pla>().setSqlSelect("batch") | 
|---|
|  |  |  | .andNew().like("batch", condition))); | 
|---|
|  |  |  | List<KeyValueVo> valueVos = new ArrayList<>(); | 
|---|
|  |  |  | for (Pla pla : plaPage1.getRecords()) { | 
|---|
|  |  |  | KeyValueVo vo = new KeyValueVo(); | 
|---|
|  |  |  | vo.setName(pla.getBatch()); | 
|---|
|  |  |  | vo.setValue(pla.getBatch()); | 
|---|
|  |  |  | valueVos.add(vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(valueVos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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])); | 
|---|
|  |  |  | } else if (entry.getKey().contains("Min")) { | 
|---|
|  |  |  | wrapper.ge(entry.getKey().substring(0, entry.getKey().length() - 3), val); | 
|---|
|  |  |  | } else if (entry.getKey().contains("Max")) { | 
|---|
|  |  |  | wrapper.le(entry.getKey().substring(0, entry.getKey().length() - 3), val); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.like(entry.getKey(), val); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | private R addPakOUT(PlaQty plaQty, Long userId) { | 
|---|
|  |  |  | ManPakOut manPakOut = new ManPakOut(); | 
|---|
|  |  |  | manPakOut.setWrkNo(plaQty.getOrderNo() + "-" + String.valueOf(snowflakeIdWorker.nextId())); | 
|---|
|  |  |  | manPakOut.setWrkSts((long) 1); | 
|---|
|  |  |  | manPakOut.setAnfme(plaQty.getOrderWeight()); | 
|---|
|  |  |  | manPakOut.setMaktx(plaQty.getBrand()); | 
|---|
|  |  |  | manPakOut.setLocNo(plaQty.getLocNo()); | 
|---|
|  |  |  | manPakOut.setBatch(plaQty.getBatch()); | 
|---|
|  |  |  | manPakOut.setBarcode(plaQty.getPackageNo() + ""); | 
|---|
|  |  |  | manPakOut.setUuid(String.valueOf(System.currentTimeMillis())); | 
|---|
|  |  |  | manPakOut.setCreateTime(new Date()); | 
|---|
|  |  |  | manPakOut.setUpdateTime(new Date()); | 
|---|
|  |  |  | manPakOut.setCount(0.0); | 
|---|
|  |  |  | manPakOut.setDocNum(plaQty.getOrderNo()); | 
|---|
|  |  |  | manPakOut.setStatus(0); | 
|---|
|  |  |  | manPakOut.setDocId(plaQty.getOrderDetlId()); | 
|---|
|  |  |  | manPakOut.setNodeId(plaQty.getId()); | 
|---|
|  |  |  | manPakOut.setCustName(plaQty.getCustomer()); | 
|---|
|  |  |  | manPakOut.setCreateBy(userId); | 
|---|
|  |  |  | //预计发货时间 | 
|---|
|  |  |  | manPakOut.setSpecs(plaQty.getPakoutTime()); | 
|---|
|  |  |  | //manPakOut.setNodeId(plaQty.getOrderDetlId()); | 
|---|
|  |  |  | manPakOutService.insert(manPakOut); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|