| | |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.web.BaseController; |
| | | 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.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | public class OrderController extends BaseController { |
| | | |
| | |
| | | private WrkMastLogService wrkMastLogService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | @RequestMapping(value = "/order/nav/list/auth") |
| | | @ManagerAuth |
| | |
| | | @Transactional |
| | | public R delete(@RequestParam Long orderId){ |
| | | orderService.remove(orderId); |
| | | // Order order = orderService.selectById(orderId); |
| | | // if (order != null) { |
| | | // order.setStatus(0); |
| | | // } |
| | | // if (!orderService.updateById(order)) { |
| | | // throw new CoolException("删除订单失败"); |
| | | // } |
| | | // orderDetlService.modifyStatus(orderId, 0); |
| | | 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(); |
| | | } |
| | | |
| | |
| | | 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++) { |
| | | Row row = sheet.getRow(i); |
| | | // 订单编号 |
| | | String uuid = dataFormatter.formatCellValue(row.getCell(0)); |
| | | // 物料号 |
| | | String maktx = dataFormatter.formatCellValue(row.getCell(1)); |
| | | // 物料号 |
| | | String matnr = dataFormatter.formatCellValue(row.getCell(2)); |
| | | // 数量 |
| | | Double anfme = Double.parseDouble(dataFormatter.formatCellValue(row.getCell(3))); |
| | | // 下单时间 |
| | | String timeStr = dataFormatter.formatCellValue(row.getCell(4)); |
| | | Date time = null; |
| | | try { |
| | | time = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss_F); |
| | | } catch (Exception e) { |
| | | throw new CoolException("第" + i + "行下的那时间解析失败,请重新导入!"); |
| | | } |
| | | // 商品系列 |
| | | String tagName = dataFormatter.formatCellValue(row.getCell(5)); |
| | | // 规格 |
| | | String specs = dataFormatter.formatCellValue(row.getCell(6)); |
| | | |
| | | Mat mat = matService.selectByMatnr(matnr); |
| | | if (null == mat) { |
| | | throw new CoolException(matnr + "商品编码的商品不存在,请重新导入!"); |
| | | } |
| | | |
| | | Order order = orderService.selectByNo(uuid); |
| | | if (null == order) { |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | uuid, // 订单编号 |
| | | timeStr, // 单据日期 |
| | | 14L, // 单据类型 |
| | | 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("生成单据主档失败,请重新导入!"); |
| | | } |
| | | } |
| | | |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), matnr, null); |
| | | if (orderDetl == null) { |
| | | orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | 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.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } else { |
| | | if(!orderDetlService.increaseAnfme(order.getId(), matnr, null, anfme)) { |
| | | throw new CoolException("生成单据明细失败,请重新导入!"); |
| | | } |
| | | } |
| | | } |
| | | return R.ok("导入成功"); |
| | | } |
| | | |
| | | } |