|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.excel.EasyExcel; | 
|---|
|  |  |  | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; | 
|---|
|  |  |  | 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.OrderDomainParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.result.OrderDetlVo; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.common.CodeRes; | 
|---|
|  |  |  | import com.zy.common.model.DetlDto; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.system.entity.User; | 
|---|
|  |  |  | import com.zy.system.service.UserService; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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 WaitPakinService waitPakinService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocOwnerService locOwnerService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderLogService orderLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private UserService userService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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 | 
|---|
|  |  |  | public R head(@RequestParam(defaultValue = "1")Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10")Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | public R head(@RequestParam(defaultValue = "1") Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10") Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | EntityWrapper<Order> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | // 限制销售角色只能看自己创建的单子(销售角色id固定21,不能随意修改) | 
|---|
|  |  |  | User user = getUser(); | 
|---|
|  |  |  | if (user.getRoleId() != 2 && user.getRoleId() != 24) { | 
|---|
|  |  |  | wrapper.eq("create_by", user.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 订单表只存了操作人id,所以操作人姓名查询,只能从姓名先去找id, | 
|---|
|  |  |  | Object userName = param.get("oper_memb"); | 
|---|
|  |  |  | if (userName != null && user.getRoleId() != 21) { | 
|---|
|  |  |  | List<User> users = userService.selectList(new EntityWrapper<User>().like("username", (String) param.get("oper_memb"))); | 
|---|
|  |  |  | if (users.size() > 0) { | 
|---|
|  |  |  | wrapper.in("create_by", users.stream().map(User::getId).collect(Collectors.toList())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 上述已自定义搜索,移除操作人姓名搜索 | 
|---|
|  |  |  | param.remove("oper_memb"); | 
|---|
|  |  |  | 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/detl/all/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R head(@RequestParam Long orderId){ | 
|---|
|  |  |  | return R.ok().add(orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_id", orderId))); | 
|---|
|  |  |  | public R head(@RequestParam Long orderId) { | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_id", orderId)); | 
|---|
|  |  |  | List<OrderDetl> orderDetls1 = new ArrayList<>(); | 
|---|
|  |  |  | for (OrderDetl orderDetl : orderDetls) { | 
|---|
|  |  |  | double v = orderDetl.getAnfme() - orderDetl.getWorkQty(); | 
|---|
|  |  |  | double v1 = new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
|---|
|  |  |  | if (v1 != 0.0) { | 
|---|
|  |  |  | orderDetls1.add(orderDetl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(orderDetls1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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) { | 
|---|
|  |  |  | String prefix = ""; | 
|---|
|  |  |  | DocType docType = docTypeService.selectById(param.getDocType()); | 
|---|
|  |  |  | if (!Cools.isEmpty(docType)) { | 
|---|
|  |  |  | prefix = docType.getPakin() == 1 ? "RK" : "CK"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Cools.isEmpty(param.getOrderNo())) { | 
|---|
|  |  |  | param.setOrderNo(prefix + snowflakeIdWorker.nextId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Order order = orderService.selectByNo(param.getOrderNo()); | 
|---|
|  |  |  | OrderLog orderLog = orderLogService.selectByNo(param.getOrderNo()); | 
|---|
|  |  |  | if (order != null) { | 
|---|
|  |  |  | return R.error("单据编号已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (orderLog != null) { | 
|---|
|  |  |  | return R.error("单据编号在历史档中已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | Long itemId = null; | 
|---|
|  |  |  | if (param.getDocType() == 16 || param.getDocType() == 19) { | 
|---|
|  |  |  | itemId = 1L; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | order = new Order( | 
|---|
|  |  |  | String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空] | 
|---|
|  |  |  | param.getOrderNo(),    // 订单编号 | 
|---|
|  |  |  | DateUtils.convert(now),    // 单据日期 | 
|---|
|  |  |  | param.getDocType(),    // 单据类型 | 
|---|
|  |  |  | itemId,    // 项目编号 | 
|---|
|  |  |  | param.getItemName(),    // | 
|---|
|  |  |  | null,    // 调拨项目编号 | 
|---|
|  |  |  | null,    // 初始票据号 | 
|---|
|  |  |  | param.getNumber(),    // 票据号 | 
|---|
|  |  |  | param.getCstmr(),    // 客户编号 | 
|---|
|  |  |  | param.getCstmrName(),    // 客户 | 
|---|
|  |  |  | param.getTel(),    // 联系方式 | 
|---|
|  |  |  | getUser().getUsername(),    // 操作人员 | 
|---|
|  |  |  | null,    // 合计金额 | 
|---|
|  |  |  | null,    // 优惠率 | 
|---|
|  |  |  | null,    // 优惠金额 | 
|---|
|  |  |  | null,    // 销售或采购费用合计 | 
|---|
|  |  |  | null,    // 实付金额 | 
|---|
|  |  |  | null,    // 付款类型 | 
|---|
|  |  |  | null,    // 业务员 | 
|---|
|  |  |  | null,    // 结算天数 | 
|---|
|  |  |  | null,    // 邮费支付类型 | 
|---|
|  |  |  | null,    // 邮费 | 
|---|
|  |  |  | null,    // 付款时间 | 
|---|
|  |  |  | null,    // 发货时间 | 
|---|
|  |  |  | null,    // 物流名称 | 
|---|
|  |  |  | null,    // 物流单号 | 
|---|
|  |  |  | 1L,    // 订单状态 | 
|---|
|  |  |  | 1,    // 状态 | 
|---|
|  |  |  | getUserId(),    // 添加人员 | 
|---|
|  |  |  | now,    // 添加时间 | 
|---|
|  |  |  | getUserId(),    // 修改人员 | 
|---|
|  |  |  | now,    // 修改时间 | 
|---|
|  |  |  | null    // 备注 | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | order.setOperMemb(getUser().getUsername()); | 
|---|
|  |  |  | if (!orderService.insert(order)) { | 
|---|
|  |  |  | throw new CoolException("保存订单主档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<DetlDto> list = new ArrayList<>(); | 
|---|
|  |  |  | for (OrderDetl orderDetl : param.getOrderDetlList()) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (orderDetl.getBatch() == null) { | 
|---|
|  |  |  | orderDetl.setBatch(""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch()); | 
|---|
|  |  |  | if (DetlDto.has(list, dto)) { | 
|---|
|  |  |  | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch()); | 
|---|
|  |  |  | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); | 
|---|
|  |  |  | if (!orderDetlService.updateById(item)) { | 
|---|
|  |  |  | throw new CoolException("保存订单明细档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | list.add(dto); | 
|---|
|  |  |  | orderDetl.setOrderId(order.getId()); | 
|---|
|  |  |  | orderDetl.setOrderNo(order.getOrderNo()); | 
|---|
|  |  |  | orderDetl.setCreateBy(getUserId()); | 
|---|
|  |  |  | orderDetl.setCreateTime(now); | 
|---|
|  |  |  | orderDetl.setUpdateBy(getUserId()); | 
|---|
|  |  |  | orderDetl.setUpdateTime(now); | 
|---|
|  |  |  | orderDetl.setStatus(1); | 
|---|
|  |  |  | orderDetl.setQty(0.0D); | 
|---|
|  |  |  | orderDetl.setUuid(String.valueOf(System.currentTimeMillis())); | 
|---|
|  |  |  | if (!orderDetlService.insert(orderDetl)) { | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | if (order == null || order.getStatus() == 0) { | 
|---|
|  |  |  | return R.error("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | Long userId = getUserId(); | 
|---|
|  |  |  | // 修改主档 | 
|---|
|  |  |  | if (!param.getDocType().equals(order.getDocType()) || param.getCstmrName() != order.getCstmrName() || !Cools.eq(param.getItemName(), order.getItemName())) { | 
|---|
|  |  |  | order.setDocType(param.getDocType()); | 
|---|
|  |  |  | order.setUpdateBy(userId); | 
|---|
|  |  |  | order.setCstmr(param.getCstmr()); | 
|---|
|  |  |  | order.setCstmrName(param.getCstmrName()); | 
|---|
|  |  |  | order.setTel(param.getTel()); | 
|---|
|  |  |  | order.setNumber(param.getNumber()); | 
|---|
|  |  |  | order.setItemName(param.getItemName()); | 
|---|
|  |  |  | 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.getBatch()); | 
|---|
|  |  |  | if (DetlDto.has(list, dto)) { | 
|---|
|  |  |  | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch()); | 
|---|
|  |  |  | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); | 
|---|
|  |  |  | if (!orderDetlService.updateById(item)) { | 
|---|
|  |  |  | throw new CoolException("保存订单明细档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | list.add(dto); | 
|---|
|  |  |  | orderDetl.setOrderId(order.getId()); | 
|---|
|  |  |  | orderDetl.setOrderNo(order.getOrderNo()); | 
|---|
|  |  |  | 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("保存订单明细档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("订单修改成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // ------------------------------------------------------------------------------------------------ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1")Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10")Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1") Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10") 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));} | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)) { | 
|---|
|  |  |  | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(orderService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | 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])); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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()){ | 
|---|
|  |  |  | public R update(Order order) { | 
|---|
|  |  |  | if (Cools.isEmpty(order) || null == order.getId()) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderService.updateById(order); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //订单完结前,判断是否存在作业中数据,存在则不能完结 | 
|---|
|  |  |  | if (order.getSettle() == 4) { | 
|---|
|  |  |  | int wrkCount = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("order_no", order.getOrderNo())); | 
|---|
|  |  |  | int pakinCount = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("order_no", order.getOrderNo())); | 
|---|
|  |  |  | if (wrkCount > 0 || pakinCount > 0) { | 
|---|
|  |  |  | throw new CoolException("存在作业中数据,不能完结。请检查入库通知档和工作档"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | //        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/export/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param){ | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param) { | 
|---|
|  |  |  | EntityWrapper<Order> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|---|
|  |  |  | Map<String, Object> map = excludeTrash(param.getJSONObject("order")); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/orderQuery/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | //    @ManagerAuth | 
|---|
|  |  |  | public R query(String condition) { | 
|---|
|  |  |  | EntityWrapper<Order> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.like("id", condition); | 
|---|
|  |  |  | wrapper.like("order_no", condition); | 
|---|
|  |  |  | wrapper.le("settle", 3); | 
|---|
|  |  |  | Page<Order> page = orderService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (Order order : page.getRecords()){ | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | map.put("customer", order.getCstmrName()); | 
|---|
|  |  |  | map.put("phone", order.getTel()); | 
|---|
|  |  |  | map.put("addr", order.getNumber()); | 
|---|
|  |  |  | map.put("allocate", order.getItemName()); | 
|---|
|  |  |  | map.put("type", "order"); | 
|---|
|  |  |  | result.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R query(@RequestBody JSONObject param) { | 
|---|
|  |  |  | Wrapper<Order> wrapper = new EntityWrapper<Order>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); | 
|---|
|  |  |  | if (null != orderService.selectOne(wrapper)){ | 
|---|
|  |  |  | if (null != orderService.selectOne(wrapper)) { | 
|---|
|  |  |  | return R.parse(BaseRes.REPEAT).add(getComment(Order.class, String.valueOf(param.get("key")))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/print/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "订单编码打印") | 
|---|
|  |  |  | public R orderPrint(@RequestParam(value = "param[]") String[] param) { | 
|---|
|  |  |  | if (Cools.isEmpty(param)) { | 
|---|
|  |  |  | return R.parse(CodeRes.EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<OrderDetl> res = new ArrayList<>(); | 
|---|
|  |  |  | for (String orderNo : param) { | 
|---|
|  |  |  | res = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/order/in") | 
|---|
|  |  |  | public R in(@RequestBody JSONObject param) { | 
|---|
|  |  |  | System.out.println("111 = " + 111); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/printExport/auth") | 
|---|
|  |  |  | //   @ManagerAuth(memo = "盘点单导出") | 
|---|
|  |  |  | public void export(HttpServletResponse response, @RequestParam String orderNo) throws IOException { | 
|---|
|  |  |  | //从数据库查询数据 | 
|---|
|  |  |  | EntityWrapper<OrderDetl> locCheckEntityWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | locCheckEntityWrapper.eq("order_no", orderNo); | 
|---|
|  |  |  | List<OrderDetl> list = orderDetlService.selectList(locCheckEntityWrapper); | 
|---|
|  |  |  | List<OrderDetlVo> orderDetlVos = new ArrayList<>(); | 
|---|
|  |  |  | OrderDetlVo orderDetlVo = new OrderDetlVo(); | 
|---|
|  |  |  | for (OrderDetl o : | 
|---|
|  |  |  | list) { | 
|---|
|  |  |  | orderDetlVo.setOrderNo(o.getOrderNo()); | 
|---|
|  |  |  | orderDetlVo.setMatnr(o.getMatnr()); | 
|---|
|  |  |  | orderDetlVo.setMaktx(o.getMaktx()); | 
|---|
|  |  |  | orderDetlVo.setSpecs(o.getSpecs()); | 
|---|
|  |  |  | orderDetlVo.setOwner(o.getOwner$()); | 
|---|
|  |  |  | orderDetlVo.setPayment(o.getPayment$()); | 
|---|
|  |  |  | orderDetlVo.setAnfme(o.getAnfme()); | 
|---|
|  |  |  | orderDetlVo.setQty(o.getQty()); | 
|---|
|  |  |  | orderDetlVo.setWorkQty(o.getWorkQty()); | 
|---|
|  |  |  | orderDetlVo.setWeight(o.getWeight()); | 
|---|
|  |  |  | orderDetlVos.add(orderDetlVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | response.setContentType("application/vnd.ms-excel"); | 
|---|
|  |  |  | response.setCharacterEncoding("utf-8"); | 
|---|
|  |  |  | String fileName = URLEncoder.encode("单据", "UTF-8"); | 
|---|
|  |  |  | response.setHeader("Content-disposition", "attachment;filename=" + fileName + orderNo + ".xlsx"); | 
|---|
|  |  |  | Set<String> includeColumnFiledNames = new HashSet<String>(); | 
|---|
|  |  |  | includeColumnFiledNames.add("orderNo"); | 
|---|
|  |  |  | includeColumnFiledNames.add("matnr"); | 
|---|
|  |  |  | includeColumnFiledNames.add("maktx"); | 
|---|
|  |  |  | includeColumnFiledNames.add("specs"); | 
|---|
|  |  |  | includeColumnFiledNames.add("owner"); | 
|---|
|  |  |  | includeColumnFiledNames.add("payment"); | 
|---|
|  |  |  | includeColumnFiledNames.add("anfme"); | 
|---|
|  |  |  | includeColumnFiledNames.add("qty"); | 
|---|
|  |  |  | includeColumnFiledNames.add("workQty"); | 
|---|
|  |  |  | includeColumnFiledNames.add("weight"); | 
|---|
|  |  |  | EasyExcel.write(response.getOutputStream(), OrderDetlVo.class) | 
|---|
|  |  |  | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) | 
|---|
|  |  |  | .includeColumnFiledNames(includeColumnFiledNames) | 
|---|
|  |  |  | .sheet("表1") | 
|---|
|  |  |  | .doWrite(orderDetlVos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/list/all") | 
|---|
|  |  |  | public R orderList() { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(orderService.selectAllorderNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //订单组托2 | 
|---|
|  |  |  | @RequestMapping(value = "/order/list/orderNo") | 
|---|
|  |  |  | public R orderListorderNo(@RequestParam String orderNo) { | 
|---|
|  |  |  | //数量修改成为完成数量 | 
|---|
|  |  |  | List<OrderDetl> orderDetl1 = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); | 
|---|
|  |  |  | List<OrderDetl> orderDetls = new ArrayList<OrderDetl>(); | 
|---|
|  |  |  | for (OrderDetl o : orderDetl1) { | 
|---|
|  |  |  | o.setAnfme(o.getAnfme() - o.getWorkQty()); | 
|---|
|  |  |  | BigDecimal c1 = new BigDecimal(o.getAnfme()).setScale(2, BigDecimal.ROUND_HALF_UP); | 
|---|
|  |  |  | o.setAnfme(c1.doubleValue()); | 
|---|
|  |  |  | orderDetls.add(o); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(orderDetls); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|