| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.Order; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.param.InitOrderParam; |
| | | import com.zy.asrs.service.OrderDetlService; |
| | | import com.zy.asrs.service.OrderService; |
| | | import com.core.common.*; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.AgvMobileStartPakin; |
| | | import com.zy.asrs.entity.param.OrderDomainParam; |
| | | import com.zy.asrs.entity.result.WrkTraceVo; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.Synchronized; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.DataFormatter; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | 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 java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | public class OrderController extends BaseController { |
| | | |
| | |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private DocTypeService docTypeService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkMastLogService wrkMastLogService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private AgvLocDetlService agvLocDetlService; |
| | | @Autowired |
| | | private FlowLogService flowLogService; |
| | | |
| | | @GetMapping("/doc/type/list") |
| | | @Transactional |
| | | @ManagerAuth(memo = "入库单据类型") |
| | | @Synchronized |
| | | public R docTypeList(){ |
| | | List<DocType> result = new ArrayList<>(); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakin", 1)); |
| | | List<Long> unDocIds = new ArrayList<>(); |
| | | unDocIds.add(19L); |
| | | unDocIds.add(30L); |
| | | unDocIds.add(32L); |
| | | unDocIds.add(36L); |
| | | for (DocType pakin : pakins) { |
| | | if (!unDocIds.contains(pakin.getDocId())) { |
| | | result.add(pakin); |
| | | } |
| | | } |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | @GetMapping("/doc/type/out/list") |
| | | @Transactional |
| | | @ManagerAuth(memo = "出库单据类型") |
| | | @Synchronized |
| | | public R docTypeOutList(){ |
| | | List<DocType> result = new ArrayList<>(); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakout", 1)); |
| | | List<Long> unDocIds = new ArrayList<>(); |
| | | unDocIds.add(18L); |
| | | unDocIds.add(31L); |
| | | unDocIds.add(33L); |
| | | unDocIds.add(34L); |
| | | unDocIds.add(35L); |
| | | unDocIds.add(37L); |
| | | for (DocType pakin : pakins) { |
| | | if (!unDocIds.contains(pakin.getDocId())) { |
| | | result.add(pakin); |
| | | } |
| | | } |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/nav/list/auth") |
| | | @ManagerAuth |
| | | public R navList(@RequestParam(required = false) String orderNo){ |
| | | EntityWrapper<Order> wrapper = new EntityWrapper<>(); |
| | | if (!Cools.isEmpty(orderNo)) { |
| | | wrapper.like("order_no", orderNo); |
| | | } |
| | | wrapper.le("settle", 2).eq("status", 1); |
| | | wrapper.orderBy("create_time", false); |
| | | List<Order> orders = orderService.selectList(wrapper); |
| | | // 保留出库单 |
| | | if (!Cools.isEmpty(orders)) { |
| | | Iterator<Order> iterator = orders.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Order order = iterator.next(); |
| | | if (order.getDocType() != null) { |
| | | DocType docType = docTypeService.selectById(order.getDocType()); |
| | | if (docType != null) { |
| | | if (docType.getPakout() == 0) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok().add(orders); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/head/page/auth") |
| | | @ManagerAuth |
| | |
| | | EntityWrapper<Order> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} else { |
| | | wrapper.orderBy("settle").orderBy("create_time", false); |
| | | } |
| | | wrapper.eq("status", 1); |
| | | return R.ok(orderService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | // 所有入库订单 |
| | | @RequestMapping(value = "/order/detls/in/page/auth") |
| | | @ManagerAuth |
| | | public R orderIn(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10000")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<Order> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} else { |
| | | wrapper.orderBy("settle").orderBy("create_time", false); |
| | | } |
| | | wrapper.eq("status", 1); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakin", 1)); |
| | | List<Long> docIds = new ArrayList<>(); |
| | | for (DocType pakin : pakins) { |
| | | docIds.add(pakin.getDocId()); |
| | | } |
| | | wrapper.in("doc_type",docIds); |
| | | return R.ok(orderService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | // 所有入库订单明细 |
| | | @RequestMapping(value = "/order/detls/pakin/page/auth") |
| | | @ManagerAuth |
| | | public R orderDetls(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "100")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | // return R.ok(orderDetlService.getPakoutPage(toPage(curr, limit, param, OrderDetl.class))); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakin", 1)); |
| | | List<Long> docIds = new ArrayList<>(); |
| | | for (DocType pakin : pakins) { |
| | | if (pakin.getDocId() != 32) { |
| | | docIds.add(pakin.getDocId()); |
| | | } |
| | | } |
| | | wrapper.in("source",docIds); |
| | | return R.ok(orderDetlService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | // EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>(); |
| | | // excludeTrash(param); |
| | | // convert(param, wrapper); |
| | | // if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} else { |
| | | // wrapper.orderBy("create_time", false); |
| | | // } |
| | | // List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakin", 1)); |
| | | // List<Long> docIds = new ArrayList<>(); |
| | | // for (DocType pakin : pakins) { |
| | | // docIds.add(pakin.getDocId()); |
| | | // } |
| | | // EntityWrapper<Order> orderEntityWrapper = new EntityWrapper<>(); |
| | | // List<Order> orders = orderService.selectList(orderEntityWrapper.in("doc_type",docIds)); |
| | | // List<String> orderNos = new ArrayList<>(); |
| | | // for (Order order : orders) { |
| | | // orderNos.add(order.getOrderNo()); |
| | | // } |
| | | // wrapper.in("order_no",orderNos); |
| | | // return R.ok(orderDetlService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/detls/pakin") |
| | | @ManagerAuth |
| | | public R orderDetlsIn(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "100")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam(required = false)Long docType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>(); |
| | | param.remove("docType"); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | // return R.ok(orderDetlService.getPakoutPage(toPage(curr, limit, param, OrderDetl.class))); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakin", 1)); |
| | | List<Long> docIds = new ArrayList<>(); |
| | | List<Long> unDocIds = new ArrayList<>(); |
| | | unDocIds.add(19L); |
| | | unDocIds.add(30L); |
| | | unDocIds.add(32L); |
| | | unDocIds.add(36L); |
| | | for (DocType pakin : pakins) { |
| | | if (!unDocIds.contains(pakin.getDocId())) { |
| | | docIds.add(pakin.getDocId()); |
| | | } |
| | | } |
| | | |
| | | if (docIds.size() > 0) { |
| | | if (docType > 0) { |
| | | wrapper.in("source",docType); |
| | | } else { |
| | | wrapper.in("source",docIds); |
| | | } |
| | | |
| | | } else { |
| | | wrapper.in("source",0); |
| | | } |
| | | |
| | | return R.ok(orderDetlService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/wait/detls/pakin/page/auth") |
| | | @ManagerAuth |
| | | public R waitOrderDetls(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "100")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | // return R.ok(orderDetlService.getPakoutPage(toPage(curr, limit, param, OrderDetl.class))); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakin", 1)); |
| | | List<Long> docIds = new ArrayList<>(); |
| | | for (DocType pakin : pakins) { |
| | | if (pakin.getDocId() == 36) { |
| | | docIds.add(pakin.getDocId()); |
| | | } |
| | | } |
| | | wrapper.in("source",docIds); |
| | | return R.ok(orderDetlService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | // 所有入库订单明细 |
| | | @RequestMapping(value = "/order/bcp/detls/pakin/page/auth") |
| | | @ManagerAuth |
| | | public R bcpOrderDetls(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "100")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | // return R.ok(orderDetlService.getPakoutPage(toPage(curr, limit, param, OrderDetl.class))); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakin", 1)); |
| | | List<Long> docIds = new ArrayList<>(); |
| | | for (DocType pakin : pakins) { |
| | | if (pakin.getDocId() == 32) { |
| | | docIds.add(pakin.getDocId()); |
| | | } |
| | | } |
| | | wrapper.in("source",docIds); |
| | | return R.ok(orderDetlService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/bcpDb/detls/pakin/page/auth") |
| | | @ManagerAuth |
| | | public R bcpDbOrderDetls(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "100")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | // return R.ok(orderDetlService.getPakoutPage(toPage(curr, limit, param, OrderDetl.class))); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakout", 1)); |
| | | List<Long> docIds = new ArrayList<>(); |
| | | for (DocType pakin : pakins) { |
| | | if (pakin.getDocId() == 33) { |
| | | docIds.add(pakin.getDocId()); |
| | | } |
| | | } |
| | | wrapper.in("source",docIds); |
| | | Page<OrderDetl> page = orderDetlService.selectPage(new Page<>(curr, limit), wrapper); |
| | | for (OrderDetl record : page.getRecords()) { |
| | | Double sumAnfme = agvLocDetlService.getSumAnfmeDb(record.getMatnr(), record.getThreeCode(),1); |
| | | record.setStock(sumAnfme == null ? 0 : sumAnfme); |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | @RequestMapping(value = "/order/backStocks/detls/pakin/page/auth") |
| | | @ManagerAuth |
| | | public R backStocksOrderDetls(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "100")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<OrderDetl> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | // return R.ok(orderDetlService.getPakoutPage(toPage(curr, limit, param, OrderDetl.class))); |
| | | List<DocType> pakins = docTypeService.selectList(new EntityWrapper<DocType>().eq("pakout", 1)); |
| | | List<Long> docIds = new ArrayList<>(); |
| | | for (DocType pakin : pakins) { |
| | | if (pakin.getDocId() == 36) { |
| | | docIds.add(pakin.getDocId()); |
| | | } |
| | | } |
| | | wrapper.in("source",docIds); |
| | | Page<OrderDetl> page = orderDetlService.selectPage(new Page<>(curr, limit), wrapper); |
| | | for (OrderDetl record : page.getRecords()) { |
| | | Double sumAnfme = agvLocDetlService.getSumAnfmeback(record.getMatnr(), record.getThreeCode(),1); |
| | | record.setStock(sumAnfme == null ? 0 : sumAnfme); |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/detl/all/auth") |
| | |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/form/add/auth") |
| | | @ManagerAuth |
| | | public R formAdd(@RequestBody InitOrderParam param){ |
| | | System.out.println(JSON.toJSONString(param)); |
| | | return R.ok(); |
| | | @ManagerAuth(memo = "手动添加订单") |
| | | @Transactional |
| | | public R formAdd(@RequestBody OrderDomainParam param){ |
| | | Order order = orderService.selectByNo(param.getOrderNo()); |
| | | long flowId = snowflakeIdWorker.nextId(); |
| | | if (order != null) { |
| | | return R.error("单据编号已存在"); |
| | | } |
| | | Date now = new Date(); |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | param.getOrderNo(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | param.getDocType(), // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | getUserId(), // 添加人员 |
| | | now, // 添加时间 |
| | | getUserId(), // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("保存订单主档失败"); |
| | | } |
| | | List<DetlDto> list = new ArrayList<>(); |
| | | Boolean flag = false; |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | if (Cools.isEmpty(orderDetl.getProcessSts())) { |
| | | orderDetl.setProcessSts(3); |
| | | } |
| | | if (orderDetl.getProcessSts() == 1) { |
| | | flag = true; |
| | | } |
| | | if (param.getDocType() != 32) { |
| | | orderDetl.setProcessSts(3); |
| | | } |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | if (DetlDto.has(list, dto)) { |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getThreeCode(),orderDetl.getDeadTime()); |
| | | Double anfme = item.getAnfme(); |
| | | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); |
| | | if (!orderDetlService.updateById(item)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | | } |
| | | // 流水 -- 新增订单明细 |
| | | // FlowLog flowLog = new FlowLog(); |
| | | // flowLog.setFid(String.valueOf(flowId)); |
| | | // flowLog.setOpType(2L); |
| | | // flowLog.setOrderNo(param.getOrderNo()); |
| | | // flowLog.setThreeCode(orderDetl.getThreeCode()); |
| | | // flowLog.setMatnr(orderDetl.getMatnr()); |
| | | // flowLog.setMaktx(orderDetl.getMaktx()); |
| | | // flowLog.setOrderPrevious(anfme); |
| | | // flowLog.setOrderCurrent(anfme + orderDetl.getAnfme()); |
| | | // flowLog.setOrderChanged(orderDetl.getAnfme()); |
| | | // flowLog.setQtyPrevious(orderDetl.getQty()); |
| | | // flowLog.setQtyCurrent(orderDetl.getQty()); |
| | | // flowLog.setQtyChanged(0.0D); |
| | | // flowLog.setUserId(getUserId()); |
| | | // flowLog.setAppeTime(now); |
| | | // if (!flowLogService.insert(flowLog)) { |
| | | // throw new CoolException("同步半成品调拨单流水记录失败"); |
| | | // } |
| | | } else { |
| | | list.add(dto); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(param.getDocType().intValue()); |
| | | orderDetl.setCreateBy(getUserId()); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(getUserId()); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | | } |
| | | // // 流水 -- 新增订单明细 |
| | | // FlowLog flowLog = new FlowLog(); |
| | | // flowLog.setFid(String.valueOf(flowId)); |
| | | // flowLog.setOpType(1L); |
| | | // flowLog.setOrderNo(param.getOrderNo()); |
| | | // flowLog.setThreeCode(orderDetl.getThreeCode()); |
| | | // flowLog.setMatnr(orderDetl.getMatnr()); |
| | | // flowLog.setMaktx(orderDetl.getMaktx()); |
| | | // flowLog.setOrderPrevious(0.0D); |
| | | // flowLog.setOrderCurrent(orderDetl.getAnfme()); |
| | | // flowLog.setOrderChanged(orderDetl.getAnfme()); |
| | | // flowLog.setQtyPrevious(0.0D); |
| | | // flowLog.setQtyCurrent(0.0D); |
| | | // flowLog.setQtyChanged(0.0D); |
| | | // flowLog.setUserId(getUserId()); |
| | | // flowLog.setAppeTime(now); |
| | | // if (!flowLogService.insert(flowLog)) { |
| | | // throw new CoolException("同步半成品调拨单流水记录失败"); |
| | | // } |
| | | } |
| | | } |
| | | if (param.getDocType().intValue() == 32) { |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | "DB" + param.getOrderNo(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | 33L, // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | getUserId(), // 添加人员 |
| | | now, // 添加时间 |
| | | getUserId(), // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("生成半成品调拨单失败"); |
| | | } |
| | | List<DetlDto> dbList = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | if (DetlDto.has(dbList, dto)) { |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getThreeCode(),orderDetl.getDeadTime()); |
| | | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); |
| | | if (!orderDetlService.updateById(item)) { |
| | | throw new CoolException("生成半成品调拨单明细档失败"); |
| | | } |
| | | } else { |
| | | dbList.add(dto); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(33); |
| | | orderDetl.setCreateBy(getUserId()); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(getUserId()); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成半成品调拨单明细档失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | // 工序为1:待加工 生成加工单 |
| | | if (flag) { |
| | | if (param.getDocType().intValue() == 32) { |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | "JG" + param.getOrderNo(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | 35L, // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | getUserId(), // 添加人员 |
| | | now, // 添加时间 |
| | | getUserId(), // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("生成半成品调拨单失败"); |
| | | } |
| | | List<DetlDto> dbList = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | if (orderDetl.getProcessSts() != 1) continue; |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | if (DetlDto.has(dbList, dto)) { |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getThreeCode(),orderDetl.getDeadTime()); |
| | | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); |
| | | if (!orderDetlService.updateById(item)) { |
| | | throw new CoolException("生成半成品调拨单明细档失败"); |
| | | } |
| | | } else { |
| | | dbList.add(dto); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(35); |
| | | orderDetl.setCreateBy(getUserId()); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(getUserId()); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成半成品调拨单明细档失败"); |
| | | } |
| | | // // 流水 -- 新增订单明细 |
| | | // FlowLog flowLog = new FlowLog(); |
| | | // flowLog.setFid(String.valueOf(flowId)); |
| | | // flowLog.setOpType(1L); |
| | | // flowLog.setOrderNo(param.getOrderNo()); |
| | | // flowLog.setThreeCode(orderDetl.getThreeCode()); |
| | | // flowLog.setMatnr(orderDetl.getMatnr()); |
| | | // flowLog.setMaktx(orderDetl.getMaktx()); |
| | | // flowLog.setOrderPrevious(0.0D); |
| | | // flowLog.setOrderCurrent(orderDetl.getAnfme()); |
| | | // flowLog.setOrderChanged(orderDetl.getAnfme()); |
| | | // flowLog.setQtyPrevious(0.0D); |
| | | // flowLog.setQtyCurrent(0.0D); |
| | | // flowLog.setQtyChanged(0.0D); |
| | | // flowLog.setUserId(getUserId()); |
| | | // flowLog.setAppeTime(now); |
| | | // if (!flowLogService.insert(flowLog)) { |
| | | // throw new CoolException("同步半成品调拨单流水记录失败"); |
| | | // } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | return R.ok("订单添加成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/form/modify/auth") |
| | | @ManagerAuth |
| | | public R formModify(@RequestBody InitOrderParam param){ |
| | | System.out.println(JSON.toJSONString(param)); |
| | | return R.ok(); |
| | | @ManagerAuth(memo = "手动修改订单") |
| | | @Transactional |
| | | public R formModify(@RequestBody OrderDomainParam param){ |
| | | Order order = orderService.selectById(param.getOrderId()); |
| | | long flowId = snowflakeIdWorker.nextId(); |
| | | int docType = param.getDocType().intValue(); |
| | | if (order == null || order.getStatus() == 0) { |
| | | return R.error("订单不存在"); |
| | | } |
| | | Date now = new Date(); |
| | | Long userId = getUserId(); |
| | | // 修改主档 |
| | | if (!param.getDocType().equals(order.getDocType())) { |
| | | order.setDocType(param.getDocType()); |
| | | order.setUpdateBy(userId); |
| | | order.setUpdateTime(now); |
| | | if (!orderService.updateById(order)) { |
| | | throw new CoolException("修改订单类型失败"); |
| | | } |
| | | } |
| | | // 修改明细档 |
| | | // List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId()); |
| | | // 1.清空明细档 |
| | | if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()))) { |
| | | throw new CoolException("清空订单明细失败"); |
| | | } |
| | | // 2.重组数据 |
| | | List<DetlDto> list = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getAnfme(), orderDetl.getProcessSts()); |
| | | if (DetlDto.has(list, dto)) { |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getThreeCode(),orderDetl.getDeadTime()); |
| | | Double anfme = item.getAnfme(); |
| | | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); |
| | | if (!orderDetlService.updateById(item)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | | } |
| | | // // 流水 -- 新增订单明细 |
| | | // FlowLog flowLog = new FlowLog(); |
| | | // flowLog.setFid(String.valueOf(flowId)); |
| | | // flowLog.setOpType(2L); |
| | | // flowLog.setOrderNo(param.getOrderNo()); |
| | | // flowLog.setThreeCode(orderDetl.getThreeCode()); |
| | | // flowLog.setMatnr(orderDetl.getMatnr()); |
| | | // flowLog.setMaktx(orderDetl.getMaktx()); |
| | | // flowLog.setOrderPrevious(anfme); |
| | | // flowLog.setOrderCurrent(anfme + orderDetl.getAnfme()); |
| | | // flowLog.setOrderChanged(orderDetl.getAnfme()); |
| | | // flowLog.setQtyPrevious(orderDetl.getQty()); |
| | | // flowLog.setQtyCurrent(orderDetl.getQty()); |
| | | // flowLog.setQtyChanged(0.0D); |
| | | // flowLog.setUserId(getUserId()); |
| | | // flowLog.setAppeTime(now); |
| | | // if (!flowLogService.insert(flowLog)) { |
| | | // throw new CoolException("同步半成品调拨单流水记录失败"); |
| | | // } |
| | | } else { |
| | | if (docType == 35 && orderDetl.getProcessSts() == 1) { |
| | | List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>() |
| | | .eq("matnr", orderDetl.getMatnr()) |
| | | .eq("order_no", orderDetl.getOrderNo()) |
| | | .eq("process_sts", 3)); |
| | | for (AgvLocDetl agvLocDetl : agvLocDetls) { |
| | | agvLocDetl.setProcessSts(1); |
| | | agvLocDetlService.updateById(agvLocDetl); |
| | | } |
| | | } |
| | | list.add(dto); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setSource(docType); |
| | | orderDetl.setCreateBy(getUserId()); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(getUserId()); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | | } |
| | | // 流水 -- 新增订单明细 |
| | | // FlowLog flowLog = new FlowLog(); |
| | | // flowLog.setFid(String.valueOf(flowId)); |
| | | // flowLog.setOpType(2L); |
| | | // flowLog.setOrderNo(param.getOrderNo()); |
| | | // flowLog.setThreeCode(orderDetl.getThreeCode()); |
| | | // flowLog.setMatnr(orderDetl.getMatnr()); |
| | | // flowLog.setMaktx(orderDetl.getMaktx()); |
| | | // flowLog.setOrderPrevious(0.0D); |
| | | // flowLog.setOrderCurrent(orderDetl.getAnfme()); |
| | | // flowLog.setOrderChanged(orderDetl.getAnfme()); |
| | | // flowLog.setQtyPrevious(orderDetl.getQty()); |
| | | // flowLog.setQtyCurrent(orderDetl.getQty()); |
| | | // flowLog.setQtyChanged(0.0D); |
| | | // flowLog.setUserId(getUserId()); |
| | | // flowLog.setAppeTime(now); |
| | | // if (!flowLogService.insert(flowLog)) { |
| | | // throw new CoolException("同步半成品调拨单流水记录失败"); |
| | | // } |
| | | } |
| | | } |
| | | return R.ok("订单修改成功"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping(value = "/order/wrk/trace/auth") |
| | | @ManagerAuth |
| | | public R orderWrkTrace(@RequestParam("orderId") Long orderId) { |
| | | Order order = orderService.selectById(orderId); |
| | | if (null == order) { |
| | | return R.error("单据不存在"); |
| | | } |
| | | // 数量统计 |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(orderId); |
| | | double totalQty = 0; |
| | | double wrkQty = 0; |
| | | double lackQty = 0; |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | totalQty = totalQty + orderDetl.getAnfme(); |
| | | wrkQty = wrkQty + orderDetl.getQty(); |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty()).orElse(0.0D); |
| | | if (issued > 0.0) { |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getOrigin(), null); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | issued = issued - locDetl.getAnfme(); |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (issued > 0.0) { |
| | | lackQty = lackQty + issued; |
| | | } |
| | | } |
| | | // 任务追溯 |
| | | List<WrkTraceVo> wrkTraceVos = new ArrayList<>(); |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectAndLogByOrderNoGroupByMatnrOfSum(order.getOrderNo()); |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkDetl.getWrkNo()).eq("io_time", wrkDetl.getIoTime())); |
| | | if (wrkMast == null) { |
| | | WrkMastLog wrkMastLog = wrkMastLogService.selectOne(new EntityWrapper<WrkMastLog>().eq("wrk_no", wrkDetl.getWrkNo()).eq("io_time", wrkDetl.getIoTime())); |
| | | if (wrkMastLog != null) { |
| | | wrkMast = new WrkMast(); |
| | | BeanUtils.copyProperties(wrkMastLog, wrkMast); |
| | | } else { |
| | | continue; |
| | | } |
| | | } |
| | | boolean exist = false; |
| | | for (WrkTraceVo vo : wrkTraceVos) { |
| | | if (vo.getWrkNo().equals(wrkMast.getWrkNo()) && vo.getIoTimeStr().equals(DateUtils.convert(wrkMast.getIoTime()))) { |
| | | vo.getWrkDetls().add(wrkDetl); |
| | | exist = true; |
| | | } |
| | | } |
| | | if (!exist) { |
| | | WrkTraceVo vo = new WrkTraceVo(wrkMast.getWrkNo(), DateUtils.convert(wrkMast.getIoTime()), wrkMast, wrkDetl); |
| | | wrkTraceVos.add(vo); |
| | | } |
| | | } |
| | | if (!Cools.isEmpty(wrkTraceVos) && wrkTraceVos.size() > 1) { |
| | | wrkTraceVos.sort((o1, o2) -> (int) (o2.getWrkMast().getIoTime().getTime() - o1.getWrkMast().getIoTime().getTime())); |
| | | } |
| | | return R.ok().add(Cools |
| | | .add("list", wrkTraceVos) |
| | | .add("orderNo", order.getOrderNo()) |
| | | .add("totalQty", totalQty) |
| | | .add("wrkQty", wrkQty) |
| | | .add("lackQty", lackQty) |
| | | ); |
| | | } |
| | | |
| | | |
| | | // ------------------------------------------------------------------------------------------------ |
| | |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/add/auth") |
| | | @RequestMapping(value = "/order/update/auth") |
| | | @ManagerAuth |
| | | public R add(Order order) { |
| | | orderService.insert(order); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/update/auth") |
| | | @ManagerAuth |
| | | public R update(Order order){ |
| | | if (Cools.isEmpty(order) || null==order.getId()){ |
| | | if (Cools.isEmpty(order) || null == order.getId()){ |
| | | return R.error(); |
| | | } |
| | | orderService.updateById(order); |
| | | order.setUpdateBy(getUserId()); |
| | | order.setUpdateTime(new Date()); |
| | | if (!orderService.updateById(order)) { |
| | | throw new CoolException("修改订单失败"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(@RequestParam(value="ids[]") Long[] ids){ |
| | | for (Long id : ids){ |
| | | orderService.deleteById(id); |
| | | } |
| | | @ManagerAuth(memo = "手动删除订单") |
| | | @Transactional |
| | | public R delete(@RequestParam Long orderId){ |
| | | orderService.remove(orderId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/report/auth") |
| | | @ManagerAuth(memo = "手动上传订单") |
| | | @Transactional |
| | | public R report(@RequestParam Long orderId){ |
| | | orderService.report(orderId,getUser().getUsername()); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | for (Order order : page.getRecords()){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", order.getId()); |
| | | map.put("value", order.getId()); |
| | | map.put("value", order.getOrderNo()); |
| | | result.add(map); |
| | | } |
| | | return R.ok(result); |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /*************************************** 数据相关 ***********************************************/ |
| | | |
| | | /** |
| | | * excel导入 |
| | | */ |
| | | @PostMapping(value = "/order/excel/import/auth") |
| | | @ManagerAuth(memo = "销售单Excel导入") |
| | | @Transactional |
| | | public R cstmrExcelImport(MultipartFile file) throws IOException { |
| | | InputStream inStream = file.getInputStream(); |
| | | String fileMime = file.getContentType(); |
| | | int excelVersion = 2007; |
| | | if ("application/vnd.ms-excel".equals(fileMime)) { |
| | | excelVersion = 2003; |
| | | } |
| | | Workbook book = null; |
| | | try { |
| | | if (excelVersion == 2003) { |
| | | book = new HSSFWorkbook(inStream); |
| | | } |
| | | else { // 当 excel 是 2007 时 |
| | | book = new XSSFWorkbook(inStream); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | return R.error("导入文件格式错误,请使用xls后缀的文件!"); |
| | | } |
| | | |
| | | Sheet sheet = book.getSheetAt(0); |
| | | int totalRows = sheet.getLastRowNum() + 1; // 总 |
| | | Long userId = getUserId(); |
| | | Date now = new Date(); |
| | | DataFormatter dataFormatter = new DataFormatter(); |
| | | for (int i = 1; i < totalRows; i++) { |
| | | Integer proSts = 0; |
| | | Row row = sheet.getRow(i); |
| | | //单据类型 |
| | | String docName = dataFormatter.formatCellValue(row.getCell(0)).trim(); |
| | | //单据编号 |
| | | String uuid = dataFormatter.formatCellValue(row.getCell(1)).trim(); |
| | | //物料号 |
| | | String matnr = dataFormatter.formatCellValue(row.getCell(2)).trim(); |
| | | //销售单号 |
| | | String csocode = dataFormatter.formatCellValue(row.getCell(3)).trim(); |
| | | //自由项 |
| | | String isocode = dataFormatter.formatCellValue(row.getCell(4)).trim(); |
| | | // 数量 |
| | | if(Cools.isEmpty(dataFormatter.formatCellValue(row.getCell(5)))){ |
| | | continue; |
| | | } |
| | | Double anfme = Double.parseDouble(dataFormatter.formatCellValue(row.getCell(5))); |
| | | |
| | | Mat mat = matService.selectByMatnr(matnr); |
| | | if (null == mat) { |
| | | throw new CoolException(matnr + "商品编码的商品不存在,请重新导入!"); |
| | | } |
| | | |
| | | //String timeStr = DateUtils.convert(new Date()); |
| | | |
| | | DocType docType = docTypeService.selectOne(new EntityWrapper<DocType>().eq("doc_name", docName)); |
| | | |
| | | // 单据类型为 半成品入库单才有工序 |
| | | if (docType.getDocId().intValue() == 32) { |
| | | //工序 |
| | | if (Cools.isEmpty(dataFormatter.formatCellValue(row.getCell(6)))) { |
| | | // 工序为空,默认为无需加工 |
| | | proSts = 3; |
| | | } else { |
| | | String processSts = dataFormatter.formatCellValue(row.getCell(6)); |
| | | //1: 待加工 2:已加工 3:无需加工 |
| | | if ("待加工".equals(processSts)) { |
| | | proSts = 1; |
| | | } else if ("已加工".equals(processSts)) { |
| | | proSts = 2; |
| | | } else { |
| | | proSts = 3; |
| | | } |
| | | } |
| | | } else { |
| | | proSts = 3; |
| | | } |
| | | |
| | | String odNo = uuid; |
| | | if(docType.getPakin() == 1){ |
| | | odNo += "_I"; |
| | | }else { |
| | | odNo += "_O"; |
| | | } |
| | | |
| | | Order order = orderService.selectByNo(odNo); |
| | | if (null == order) { |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | odNo, // 订单编号 |
| | | null, // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | userId, // 添加人员 |
| | | now, // 添加时间 |
| | | userId, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("生成单据主档失败,请重新导入!"); |
| | | } |
| | | }else { |
| | | // 有原订单在的情况 |
| | | DocType orderType = docTypeService.selectById(order.getDocType()); |
| | | if (!orderType.getDocName().equals(docName)) { |
| | | throw new CoolException("新订单:" + uuid + " 与系统内的订单号相同,单据类型不同。请确认新订单单据类型!"); |
| | | } |
| | | order.setSettle(order.getSettle() == 1L ? 1L : 2L ); |
| | | orderService.updateById(order); |
| | | } |
| | | |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), matnr, null,csocode,isocode); |
| | | if (orderDetl == null) { |
| | | orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setSource(docType.getDocId().intValue()); |
| | | orderDetl.setBatch(null); |
| | | orderDetl.setAnfme(anfme); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setCreateBy(userId); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(userId); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setThreeCode(csocode); |
| | | orderDetl.setDeadTime(isocode); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | orderDetl.setProcessSts(proSts); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } else { |
| | | if (anfme < 0) { |
| | | throw new CoolException("订单数量不允许为负数!"); |
| | | } |
| | | if(!orderDetlService.increaseAnfme(order.getId(), matnr, null, anfme,csocode,isocode)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } |
| | | // 生成调拨单 |
| | | if (docType.getDocId().intValue() == 32) { |
| | | String dbUuid = "DB" + odNo; |
| | | Order order2 = orderService.selectByNo(dbUuid); |
| | | if (null == order2) { |
| | | order2 = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | dbUuid, // 订单编号 |
| | | null, // 单据日期 |
| | | 33L, // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | userId, // 添加人员 |
| | | now, // 添加时间 |
| | | userId, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order2)) { |
| | | throw new CoolException("生成单据主档失败,请重新导入!"); |
| | | } |
| | | }else { |
| | | order2.setSettle(order.getSettle() == 1L ? 1L : 2L ); |
| | | orderService.updateById(order2); |
| | | } |
| | | |
| | | OrderDetl orderDetl2 = orderDetlService.selectItem(order2.getId(), matnr, null,csocode,isocode); |
| | | if (orderDetl2 == null) { |
| | | orderDetl2 = new OrderDetl(); |
| | | orderDetl2.sync(mat); |
| | | orderDetl2.setSource(33); |
| | | orderDetl2.setBatch(null); |
| | | orderDetl2.setAnfme(anfme); |
| | | orderDetl2.setOrderId(order2.getId()); |
| | | orderDetl2.setOrderNo(order2.getOrderNo()); |
| | | orderDetl2.setCreateBy(userId); |
| | | orderDetl2.setCreateTime(now); |
| | | orderDetl2.setUpdateBy(userId); |
| | | orderDetl2.setUpdateTime(now); |
| | | orderDetl2.setThreeCode(csocode); |
| | | orderDetl2.setDeadTime(isocode); |
| | | orderDetl2.setStatus(1); |
| | | orderDetl2.setQty(0.0D); |
| | | orderDetl2.setProcessSts(proSts); |
| | | if (!orderDetlService.insert(orderDetl2)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } else { |
| | | if(!orderDetlService.increaseAnfme(order2.getId(), matnr, null, anfme,csocode,isocode)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 工序为1:待加工 生成加工单 |
| | | if (proSts == 1) { |
| | | if (docType.getDocId().intValue() == 32) { |
| | | String dbUuid = "JG" + odNo; |
| | | Order order3 = orderService.selectByNo(dbUuid); |
| | | if (null == order3) { |
| | | order3 = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | dbUuid, // 订单编号 |
| | | null, // 单据日期 |
| | | 35L, // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | userId, // 添加人员 |
| | | now, // 添加时间 |
| | | userId, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order3)) { |
| | | throw new CoolException("生成单据主档失败,请重新导入!"); |
| | | } |
| | | }else { |
| | | order3.setSettle(order.getSettle() == 1L ? 1L : 2L ); |
| | | orderService.updateById(order3); |
| | | } |
| | | |
| | | OrderDetl orderDetl3 = orderDetlService.selectItem(order3.getId(), matnr, null,csocode,isocode); |
| | | if (orderDetl3 == null) { |
| | | orderDetl3 = new OrderDetl(); |
| | | orderDetl3.sync(mat); |
| | | orderDetl3.setSource(35); |
| | | orderDetl3.setBatch(null); |
| | | orderDetl3.setAnfme(anfme); |
| | | orderDetl3.setOrderId(order3.getId()); |
| | | orderDetl3.setOrderNo(order3.getOrderNo()); |
| | | orderDetl3.setCreateBy(userId); |
| | | orderDetl3.setCreateTime(now); |
| | | orderDetl3.setUpdateBy(userId); |
| | | orderDetl3.setUpdateTime(now); |
| | | orderDetl3.setThreeCode(csocode); |
| | | orderDetl3.setDeadTime(isocode); |
| | | orderDetl3.setStatus(1); |
| | | orderDetl3.setQty(0.0D); |
| | | orderDetl3.setProcessSts(proSts); |
| | | if (!orderDetlService.insert(orderDetl3)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } else { |
| | | if(!orderDetlService.increaseAnfme(order3.getId(), matnr, null, anfme,csocode,isocode)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | return R.ok("导入成功"); |
| | | } |
| | | |
| | | /** |
| | | * excel导入 |
| | | */ |
| | | @PostMapping(value = "/order/excel/import2/auth") |
| | | @ManagerAuth(memo = "销售单Excel导入") |
| | | @Transactional |
| | | public R cstmrExcelImport2(MultipartFile file) throws IOException { |
| | | InputStream inStream = file.getInputStream(); |
| | | String fileMime = file.getContentType(); |
| | | int excelVersion = 2007; |
| | | if ("application/vnd.ms-excel".equals(fileMime)) { |
| | | excelVersion = 2003; |
| | | } |
| | | Workbook book = null; |
| | | try { |
| | | if (excelVersion == 2003) { |
| | | book = new HSSFWorkbook(inStream); |
| | | } |
| | | else { // 当 excel 是 2007 时 |
| | | book = new XSSFWorkbook(inStream); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | return R.error("导入文件格式错误,请使用xls后缀的文件!"); |
| | | } |
| | | |
| | | Sheet sheet = book.getSheetAt(0); |
| | | int totalRows = sheet.getLastRowNum() + 1; // 总 |
| | | DataFormatter dataFormatter = new DataFormatter(); |
| | | List<String> strs = new ArrayList<>(); |
| | | for (int i = 1; i < totalRows; i++) { |
| | | Row row = sheet.getRow(i); |
| | | //单据类型 |
| | | String docName = dataFormatter.formatCellValue(row.getCell(0)); |
| | | //单据编号 |
| | | String uuid = dataFormatter.formatCellValue(row.getCell(1)); |
| | | //物料号 |
| | | String matnr = dataFormatter.formatCellValue(row.getCell(2)); |
| | | Mat mat = matService.selectByMatnr(matnr); |
| | | if (null == mat) { |
| | | strs.add(matnr); |
| | | // throw new CoolException(matnr + "商品编码的商品不存在,请检查!"); |
| | | } |
| | | } |
| | | return R.ok("导入成功").add(strs); |
| | | } |
| | | |
| | | } |