|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.*; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.DocType; | 
|---|
|  |  |  | import com.zy.asrs.entity.Order; | 
|---|
|  |  |  | import com.zy.asrs.entity.OrderDetl; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.DefinedExcelExportParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.OrderDomainParam; | 
|---|
|  |  |  | import com.zy.asrs.service.DocTypeService; | 
|---|
|  |  |  | import com.zy.asrs.service.OrderDetlService; | 
|---|
|  |  |  | import com.zy.asrs.service.OrderService; | 
|---|
|  |  |  | import com.zy.asrs.entity.result.OrderDetlVo; | 
|---|
|  |  |  | import com.zy.asrs.mapper.OrderDetlMapper; | 
|---|
|  |  |  | 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.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderDetlMapper orderDetlMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/nav/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R navList(@RequestParam(required = false) String orderNo){ | 
|---|
|  |  |  | public R navList(@RequestParam(required = false) String orderNo) { | 
|---|
|  |  |  | EntityWrapper<Order> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderNo)) { | 
|---|
|  |  |  | wrapper.like("order_no", orderNo); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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>().eq("username", 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));} else { | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)) { | 
|---|
|  |  |  | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.orderBy("settle").orderBy("create_time", false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrapper.eq("status", 1); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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(memo = "手动添加订单") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R formAdd(@RequestBody OrderDomainParam param){ | 
|---|
|  |  |  | 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(),    // 单据类型 | 
|---|
|  |  |  | null,    // 项目编号 | 
|---|
|  |  |  | null,    // | 
|---|
|  |  |  | itemId,    // 项目编号 | 
|---|
|  |  |  | param.getItemName(),    // | 
|---|
|  |  |  | null,    // 调拨项目编号 | 
|---|
|  |  |  | null,    // 初始票据号 | 
|---|
|  |  |  | null,    // 票据号 | 
|---|
|  |  |  | null,    // 客户编号 | 
|---|
|  |  |  | null,    // 客户 | 
|---|
|  |  |  | null,    // 联系方式 | 
|---|
|  |  |  | null,    // 操作人员 | 
|---|
|  |  |  | param.getNumber(),    // 票据号 | 
|---|
|  |  |  | param.getCstmr(),    // 客户编号 | 
|---|
|  |  |  | param.getCstmrName(),    // 客户 | 
|---|
|  |  |  | param.getTel(),    // 联系方式 | 
|---|
|  |  |  | getUser().getUsername(),    // 操作人员 | 
|---|
|  |  |  | null,    // 合计金额 | 
|---|
|  |  |  | null,    // 优惠率 | 
|---|
|  |  |  | null,    // 优惠金额 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | 
|---|
|  |  |  | orderDetl.setUpdateTime(now); | 
|---|
|  |  |  | orderDetl.setStatus(1); | 
|---|
|  |  |  | orderDetl.setQty(0.0D); | 
|---|
|  |  |  | orderDetl.setUuid(String.valueOf(System.currentTimeMillis())); | 
|---|
|  |  |  | if (!orderDetlService.insert(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存订单明细档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/form/modify/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "手动修改订单") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R formModify(@RequestBody OrderDomainParam param){ | 
|---|
|  |  |  | 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())) { | 
|---|
|  |  |  | 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("修改订单类型失败"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // ------------------------------------------------------------------------------------------------ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/{id}/auth") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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])); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.like(entry.getKey(), val); | 
|---|
|  |  |  | wrapper.eq(entry.getKey(), val); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //订单完结前,判断是否存在作业中数据,存在则不能完结 | 
|---|
|  |  |  | 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)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/delete/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "手动删除订单") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R delete(@RequestParam Long orderId){ | 
|---|
|  |  |  | Order order = orderService.selectById(orderId); | 
|---|
|  |  |  | if (order != null) { | 
|---|
|  |  |  | order.setStatus(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!orderService.updateById(order)) { | 
|---|
|  |  |  | throw new CoolException("删除订单失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderDetlService.modifyStatus(orderId, 0); | 
|---|
|  |  |  | 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.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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping (value = "/order/definedExcelExport/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public void export(HttpServletResponse response, @RequestBody DefinedExcelExportParam definedExcelExportParam) throws IOException { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | EntityWrapper<OrderDetl> orderDetlEntityWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if ("all".equals(definedExcelExportParam.getType())) { | 
|---|
|  |  |  | DefinedExcelExportParam.QueryWhere queryWhere = definedExcelExportParam.getQueryWhere(); | 
|---|
|  |  |  | EntityWrapper<Order> orderEntityWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 限制销售角色只能看自己创建的单子(销售角色id固定21,不能随意修改) | 
|---|
|  |  |  | User user = getUser(); | 
|---|
|  |  |  | if (user.getRoleId() != 2 && user.getRoleId() != 24) { | 
|---|
|  |  |  | orderEntityWrapper.eq("create_by", user.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 操作人:订单表只存了操作人id,所以操作人姓名查询,只能从姓名先去找id, | 
|---|
|  |  |  | Object userName = queryWhere.getOper_memb(); | 
|---|
|  |  |  | if (userName != null && user.getRoleId() != 21) { | 
|---|
|  |  |  | List<User> users = userService.selectList(new EntityWrapper<User>().eq("username", queryWhere.getOper_memb())); | 
|---|
|  |  |  | if (users.size() > 0) { | 
|---|
|  |  |  | orderEntityWrapper.in("create_by", users.stream().map(User::getId).collect(Collectors.toList())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 订单编号 | 
|---|
|  |  |  | if (!Cools.isEmpty(queryWhere.getOrder_no())) { | 
|---|
|  |  |  | orderEntityWrapper.eq("order_no", queryWhere.getOrder_no()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 创建时间 | 
|---|
|  |  |  | if (queryWhere.getCreate_time().contains(RANGE_TIME_LINK)) { | 
|---|
|  |  |  | String[] dates = queryWhere.getCreate_time().split(RANGE_TIME_LINK); | 
|---|
|  |  |  | orderEntityWrapper.ge("create_time", DateUtils.convert(dates[0])); | 
|---|
|  |  |  | orderEntityWrapper.le("create_time", DateUtils.convert(dates[1])); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 单据类型 | 
|---|
|  |  |  | if (!Cools.isEmpty(queryWhere.getDoc_type())) { | 
|---|
|  |  |  | orderEntityWrapper.eq("doc_type", queryWhere.getDoc_type()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 单据状态 | 
|---|
|  |  |  | if (!Cools.isEmpty(queryWhere.getSettle())) { | 
|---|
|  |  |  | orderEntityWrapper.eq("settle", queryWhere.getSettle()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 客户名称 | 
|---|
|  |  |  | if (!Cools.isEmpty(queryWhere.getCstmr_name())) { | 
|---|
|  |  |  | orderEntityWrapper.eq("cstmr_name", queryWhere.getCstmr_name()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 未删除 | 
|---|
|  |  |  | orderEntityWrapper.eq("status", 1); | 
|---|
|  |  |  | orderEntityWrapper.setSqlSelect("order_no as orderNo"); | 
|---|
|  |  |  | List<Order> orderList = orderService.selectList(orderEntityWrapper); | 
|---|
|  |  |  | orderDetlEntityWrapper.in("order_no", orderList.stream().map(Order::getOrderNo).collect(Collectors.toList())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | orderDetlEntityWrapper.in("order_no", definedExcelExportParam.getOrderNoList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<OrderDetl> list = orderDetlService.selectList(orderDetlEntityWrapper); | 
|---|
|  |  |  | List<OrderDetlExcelVo> orderDetlExcelVoList = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (OrderDetl orderDetl : list) { | 
|---|
|  |  |  | OrderDetlExcelVo orderDetlExcelVo = new OrderDetlExcelVo(); | 
|---|
|  |  |  | BeanUtils.copyProperties(orderDetl,orderDetlExcelVo); | 
|---|
|  |  |  | orderDetlExcelVoList.add(orderDetlExcelVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | response.setContentType("application/vnd.ms-excel"); | 
|---|
|  |  |  | response.setCharacterEncoding("utf-8"); | 
|---|
|  |  |  | String fileName = URLEncoder.encode("单据", "UTF-8"); | 
|---|
|  |  |  | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); | 
|---|
|  |  |  | EasyExcel.write(response.getOutputStream(), OrderDetlExcelVo.class) | 
|---|
|  |  |  | .sheet("表1") | 
|---|
|  |  |  | .doWrite(orderDetlExcelVoList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|