package zy.cloud.wms.manager.controller; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.core.annotations.ManagerAuth; import com.core.common.*; import lombok.extern.slf4j.Slf4j; 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 zy.cloud.wms.common.model.DeliveryPrintDetlVo; import zy.cloud.wms.common.model.DeliveryPrintVo; import zy.cloud.wms.common.utils.NumToCN; import zy.cloud.wms.common.web.BaseController; import zy.cloud.wms.manager.entity.Cstmr; import zy.cloud.wms.manager.entity.Order; import zy.cloud.wms.manager.entity.OrderDetl; import zy.cloud.wms.manager.service.CstmrService; import zy.cloud.wms.manager.service.OrderDetlService; import zy.cloud.wms.manager.service.OrderService; import java.util.*; /** * Created by vincent on 2021/9/2 */ @Slf4j @RestController public class DeliveryController extends BaseController { @Autowired private OrderService orderService; @Autowired private OrderDetlService orderDetlService; @Autowired private CstmrService cstmrService; @RequestMapping(value = "/delivery/head/page/auth") @ManagerAuth public R headPage(@RequestParam(defaultValue = "1")Integer curr, @RequestParam(defaultValue = "10")Integer limit, @RequestParam Map param){ if (!Cools.isEmpty(param.get("create_time"))){ String val = String.valueOf(param.get("create_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("create_time"); } } Long hostId = getHostId(); if (hostId != null) { param.put("host_id", hostId); } return R.ok(orderService.getPage(toPage(curr, limit, param, Order.class))); } @RequestMapping(value = "/delivery/print/info/auth") @ManagerAuth public R printInfo(@RequestParam Long orderId, @RequestParam(required = false) Integer length){ Order order = orderService.selectById(orderId); if (order == null) { return R.parse(BaseRes.EMPTY); } List orderDetls = orderDetlService.selectByOrderNo(order.getOrderNo(), getHostId()); if (Cools.isEmpty(orderDetls)) { return R.parse(BaseRes.EMPTY); } // 客户信息 Cstmr cstmr = null; if (order.getCstmr() != null) { cstmr = cstmrService.selectById(order.getCstmr()); } Date now = new Date(); // 返回视图对象 List> vos = new ArrayList<>(); length = Optional.ofNullable(length).orElse(10); int times = getTimes(orderDetls.size(), length); for (int i=0;i map = new HashMap<>(); DeliveryPrintVo vo = new DeliveryPrintVo(); Map map1 = new HashMap<>(); map1.put("vo", vo); map.put("vo", map1); vos.add(map); if (cstmr != null) { vo.setCstmrName(cstmr.getName()); vo.setCstmrTel(cstmr.getTel()); vo.setCstmrContacts(cstmr.getContacts()); vo.setCstmrAddr(cstmr.getAddr()); } vo.setCompany("浙江中扬立库技术有限公司"); vo.setOrderId(orderId); vo.setOrderNo(order.getOrderNo()); vo.setTime(DateUtils.convert(now, DateUtils.yyyyMMdd_F)); // 单据明细 double totalFee = 0.0D; double totalAnfme = 0.0D; int size = (i + 1) * length; int more = 0; if (size > orderDetls.size()) { more = size - orderDetls.size(); size = orderDetls.size(); } int no = 1; for (int j=i*length;j 0 && detlVo.getAnfme() > 0) { detlVo.setFee(Arith.multiplys(2, detlVo.getAnfme(), detlVo.getPrice())); } else { detlVo.setFee(0.0D); } detlVo.setMemo(orderDetl.getMemo()); vo.getList().add(detlVo); totalFee += detlVo.getFee(); // 合计金额 totalAnfme += detlVo.getAnfme(); // 合计数量 } if (more > 0) { for (int k=0;k orderDetls = orderDetlService.selectByOrderNo(orderNo, getHostId()); for (OrderDetl orderDetl : orderDetls) { orderDetl.setUnitPrice(Optional.ofNullable(orderDetl.getUnitPrice()).orElse(0.0D)); } return R.ok().add(orderDetls); } @RequestMapping(value = "/delivery/orderDetl/price/update/auth") @ManagerAuth public R orderDetlPriceUpdate(@RequestBody List orderDetls){ for (OrderDetl orderDetl : orderDetls) { if (!orderDetlService.updateById(orderDetl)) { log.error("修改订单明细失败:{}", JSON.toJSON(orderDetl)); } } return R.ok(); } private static int getTimes(int total, int len){ double divides = Arith.divides(1, total, len); int i = (int)divides; if (i == divides) { return i; } else { return i + 1; } } }