diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/controller/AftersalesOutOrderController.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/controller/AftersalesOutOrderController.java index 2394d827..3bb4f992 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/controller/AftersalesOutOrderController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/controller/AftersalesOutOrderController.java @@ -1,10 +1,13 @@ package com.ruoyi.aftersales.controller; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.List; import com.ruoyi.aftersales.domain.AftersalesOutOrderDetail; import com.ruoyi.aftersales.domain.vo.SelectShippingDeviceVO; import com.ruoyi.aftersales.service.IAftersalesOutOrderDetailService; +import lombok.SneakyThrows; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -221,24 +224,45 @@ public class AftersalesOutOrderController extends BaseController // // // - /** - * 售后第一次维护设备 成品添加出货设备信息 - */ - @GetMapping("/addShippingDevicesOne") - public String addShippingDevicesOne(@RequestParam("outOrderDetailId") Long outOrderDetailId, - @RequestParam("salesOrderCode") String salesOrderCode, - @RequestParam("makeNo") String makeNo, - @RequestParam("relatedOrderCode") String relatedOrderCode, - ModelMap mmap) - { - AftersalesOutOrderDetail aftersalesOutOrderDetail = aftersalesOutOrderDetailService.selectAftersalesOutOrderDetailById(outOrderDetailId); - mmap.put("salesOrderCode",salesOrderCode); - mmap.put("makeNo",makeNo); - mmap.put("relatedOrderCode",relatedOrderCode); - mmap.put("aftersalesOutOrderDetail", aftersalesOutOrderDetail); - return prefix + "/addShippingDevicesOne"; +@SneakyThrows +@GetMapping("/addShippingDevicesOne") +public String addShippingDevicesOne(@RequestParam("outOrderDetailId") Long outOrderDetailId, + @RequestParam(value = "salesOrderCode", required = false, defaultValue = "") String salesOrderCode, + @RequestParam(value = "makeNo", required = false, defaultValue = "") String makeNo, + @RequestParam(value = "relatedOrderCode", required = false, defaultValue = "") String relatedOrderCode, + @RequestParam(value = "outOrderCode", required = false, defaultValue = "") String outOrderCode, + ModelMap mmap) { + + AftersalesOutOrderDetail aftersalesOutOrderDetail = aftersalesOutOrderDetailService.selectAftersalesOutOrderDetailById(outOrderDetailId); + + + // 手动解码参数 + salesOrderCode = URLDecoder.decode(salesOrderCode, StandardCharsets.UTF_8.name()); + makeNo = URLDecoder.decode(makeNo, StandardCharsets.UTF_8.name()); + relatedOrderCode = URLDecoder.decode(relatedOrderCode, StandardCharsets.UTF_8.name()); + outOrderCode = URLDecoder.decode(outOrderCode, StandardCharsets.UTF_8.name()); + + // 非空检查并添加到 ModelMap + if (!"null".equalsIgnoreCase(salesOrderCode) && !salesOrderCode.isEmpty()) { + mmap.put("salesOrderCode", salesOrderCode); + } + if (!"null".equalsIgnoreCase(makeNo) && !makeNo.isEmpty()) { + mmap.put("makeNo", makeNo); + } + if (!"null".equalsIgnoreCase(relatedOrderCode) && !relatedOrderCode.isEmpty()) { + mmap.put("relatedOrderCode", relatedOrderCode); + } + if (!"null".equalsIgnoreCase(outOrderCode) && !outOrderCode.isEmpty()) { + mmap.put("outOrderCode", outOrderCode); } + // 无论是否为空,都添加 aftersalesOutOrderDetail + mmap.put("aftersalesOutOrderDetail", aftersalesOutOrderDetail); + + return prefix + "/addShippingDevicesOne"; +} + + @@ -272,17 +296,37 @@ public class AftersalesOutOrderController extends BaseController -// -// /** -// * 修改保存售后第一次维护设备 添加出货设备信息 -// */ -// @ResponseBody -// @PostMapping("/addShippingDevicesOne") -// public AjaxResult addShippingDevicesOneSave(@RequestBody WarehouseOutOrderDetail warehouseOutOrderDetail) -// { -// -// return toAjax(outOrderDetailService.addShippingDevicesOne(warehouseOutOrderDetail)); -// } + + /** + * 修改保存售后第一次维护设备 添加出货设备信息 + */ + @ResponseBody + @PostMapping("/addShippingDevicesOne") + public AjaxResult addShippingDevicesOneSave(@RequestBody AftersalesOutOrder aftersalesOutOrder) + { + + return toAjax(aftersalesOutOrderService.addShippingDevicesOne(aftersalesOutOrder)); + } + + + + + /** + * 展示第一次维护设备出库,已经添加了的出货设备 + */ + @ResponseBody + @PostMapping("/showAddShippingDevicesOne") + public TableDataInfo showAddShippingDevicesOne(AftersalesOutOrder aftersalesOutOrder) + { + startPage(); + List list = aftersalesOutOrderService.showAddShippingDevicesOne(aftersalesOutOrder); + return getDataTable(list); + } + + + + + // // // @@ -301,16 +345,16 @@ public class AftersalesOutOrderController extends BaseController // // // -// /** -// * 第一次维护设备删除物料信息出货设备信息 -// */ -// @Log(title = "售后维护设备出库", businessType = BusinessType.DELETE) -// @PostMapping("/deleteRow") -// @ResponseBody -// public AjaxResult deleteRow(String shippingDeviceId) -// { -// return toAjax(aftersalesOutOrderService.deleteAftersalesShippingDeviceById(shippingDeviceId)); -// } + /** + * 第一次维护设备删除物料信息出货设备信息 + */ + @Log(title = "售后维护设备出库", businessType = BusinessType.DELETE) + @PostMapping("/deleteRow") + @ResponseBody + public AjaxResult deleteRow(String shippingDeviceId) + { + return toAjax(aftersalesOutOrderService.deleteAftersalesShippingDeviceById(shippingDeviceId)); + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/AftersalesOutOrder.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/AftersalesOutOrder.java index 92adf0ca..3ed85986 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/AftersalesOutOrder.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/AftersalesOutOrder.java @@ -1,7 +1,10 @@ package com.ruoyi.aftersales.domain; import java.util.Date; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.aftersales.domain.vo.SelectShippingDeviceVO; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; @@ -132,6 +135,12 @@ public class AftersalesOutOrder extends BaseEntity @Excel(name = "收货电话") private String deliveryNumber; + + + /** 添加出货设备列表*/ + + private List selectShippingDeviceVOList; + public void setOutOrderId(Long outOrderId) { this.outOrderId = outOrderId; @@ -421,6 +430,14 @@ public class AftersalesOutOrder extends BaseEntity return deliveryNumber; } + public List getSelectShippingDeviceVOList() { + return selectShippingDeviceVOList; + } + + public void setSelectShippingDeviceVOList(List selectShippingDeviceVOList) { + this.selectShippingDeviceVOList = selectShippingDeviceVOList; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -461,6 +478,7 @@ public class AftersalesOutOrder extends BaseEntity .append("createTime", getCreateTime()) .append("updateBy", getUpdateBy()) .append("updateTime", getUpdateTime()) + .append("selectShippingDeviceVOList",getSelectShippingDeviceVOList()) .toString(); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/vo/SelectShippingDeviceVO.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/vo/SelectShippingDeviceVO.java index 06eeee72..2faee83a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/vo/SelectShippingDeviceVO.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/domain/vo/SelectShippingDeviceVO.java @@ -43,5 +43,7 @@ public class SelectShippingDeviceVO { /** 二次维修后部件质保时间 */ private Date componentGuaranteeDate; + /** 是否添加出货设备(0代表是 1代表否)*/ + private String addShippingDeviceFlag; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java index 65da4aa2..aeb0e7bd 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java @@ -141,4 +141,24 @@ public interface AfterSalesShippingDeviceMapper * 根据设备id批量查询出货设备信息列表 * */ List selectBatchShippingDeviceById(List otherShippingDeviceIds); + + /* + * 根据出库单号查询第一次维护设备已经添加的出货设备信息列表 + * */ + List selectShippingDeviceByOutOrderCode(String outOrderCode); + + /* + * 根据销售单号和物料号查询出货设备信息列表 + * */ + List selectShippingDeviceByOrderCodeAndMaterialNo(AfterSalesShippingDevice afterSalesShippingDevice); + + /* + * 根据物料号和出库单号查询已经添加了的出货设备信息列表 + * */ + List selectHasAddShippingDevice(AfterSalesShippingDevice tempShippingDevice); + + /* + * 根据物料号查询出货设备信息列表 + * */ + List selectShippingDevicesByMaterialNo(String materialNo); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/IAftersalesOutOrderService.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/IAftersalesOutOrderService.java index 633e2c53..e5f18c68 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/IAftersalesOutOrderService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/IAftersalesOutOrderService.java @@ -106,4 +106,19 @@ public interface IAftersalesOutOrderService * 售后第一次维护设备,添加出货设备信息,展示其他销售订单的出货设备信息 * */ List getOtherSalesOrderShippingDevices(AftersalesOutOrder aftersalesOutOrder); + + /** + * 售后第一次维护设备,添加出货设备信息 + * */ + int addShippingDevicesOne(AftersalesOutOrder aftersalesOutOrder); + + /** + * 展示第一次维护设备出库,已经添加了的出货设备 + * */ + List showAddShippingDevicesOne(AftersalesOutOrder aftersalesOutOrder); + + /** + * 逻辑删除出货设备(也就是取消关联) + * */ + int deleteAftersalesShippingDeviceById(String shippingDeviceId); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java index 6212f372..3e42771e 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java @@ -1,9 +1,6 @@ package com.ruoyi.aftersales.service.impl; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import com.ruoyi.aftersales.domain.AfterSalesShippingDevice; @@ -11,15 +8,22 @@ import com.ruoyi.aftersales.domain.AftersalesOutOrderDetail; import com.ruoyi.aftersales.domain.vo.SelectShippingDeviceVO; import com.ruoyi.aftersales.mapper.AfterSalesShippingDeviceMapper; import com.ruoyi.aftersales.mapper.AftersalesOutOrderDetailMapper; +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.domain.SysSalesShippingInform; +import com.ruoyi.system.mapper.SysSalesShippingInformMapper; +import com.ruoyi.warehouse.domain.WarehouseOutOrder; +import com.ruoyi.warehouse.mapper.WarehouseOutOrderMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.aftersales.mapper.AftersalesOutOrderMapper; import com.ruoyi.aftersales.domain.AftersalesOutOrder; import com.ruoyi.aftersales.service.IAftersalesOutOrderService; import com.ruoyi.common.core.text.Convert; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; /** * 售后维护设备出库Service业务层处理 @@ -39,6 +43,12 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService @Autowired private AfterSalesShippingDeviceMapper afterSalesShippingDeviceMapper; + @Autowired + private WarehouseOutOrderMapper warehouseOutOrderMapper; + + @Autowired + private SysSalesShippingInformMapper shippingInformMapper; + /** * 查询售后维护设备出库 * @@ -147,9 +157,109 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService * @param aftersalesOutOrder * @return */ + @Transactional(rollbackFor = Exception.class) @Override public int updateMaintenanceEquipmentOne(AftersalesOutOrder aftersalesOutOrder) { - return 0; + + String outOrderCode = aftersalesOutOrder.getOutOrderCode(); + + // 定义一个StringBuilder来收集所有缺少SN号的设备ID + StringBuilder missingSnIds = new StringBuilder(); + //物料信息主表的数据 + List needShippingDeviceMaterialsOne = this.getNeedShippingDeviceMaterialsOne(aftersalesOutOrder); + if (!CollectionUtils.isEmpty(needShippingDeviceMaterialsOne)){ + List selectShippingDeviceVOList = aftersalesOutOrder.getSelectShippingDeviceVOList(); + if (CollectionUtils.isEmpty(selectShippingDeviceVOList)){ + throw new BusinessException("请展开物料详情并添加要出货的设备"); + } + +// boolean anyNullSnCode = selectShippingDeviceVOList.stream().anyMatch(item -> item.getSnCode() == null); +// if (anyNullSnCode){ +// throw new BusinessException("请展开物料详情并填写每个设备的SN号"); +// } + + // 遍历 selectShippingDeviceVOList 列表 + selectShippingDeviceVOList.forEach(item -> { + // 检查 SnCode 是否为空 + if (item.getSnCode() == null) { + // 如果是第一次添加,不加前缀“、”,否则加上 + if (missingSnIds.length() > 0) { + missingSnIds.append("、"); + } + missingSnIds.append(item.getShippingDeviceId()); + } + }); + + // 检查是否有任何设备缺少SN号 + if (missingSnIds.length() > 0) { + throw new BusinessException(missingSnIds.toString() + " SN未维护,请维护"); + } + + /* 缺少校验规则,后续补充 + * 2.1、已选出货设备,是否可用(状态:可用,即未被其他出库单添加或报损),若不可用,则弹窗提示“CHSB20240808004、CHSB20240808005.不可用,请重新添加 + * */ + + for (SelectShippingDeviceVO selectShippingDeviceVO : selectShippingDeviceVOList) { + String shippingDeviceId = selectShippingDeviceVO.getShippingDeviceId(); + AfterSalesShippingDevice tempShippingDevice = new AfterSalesShippingDevice(); + tempShippingDevice.setShippingDeviceId(shippingDeviceId); + tempShippingDevice.setSnCode(selectShippingDeviceVO.getSnCode()); + + int updateShippingDeviceResult = afterSalesShippingDeviceMapper.updateAfterSalesShippingDevice(tempShippingDevice); + if (updateShippingDeviceResult <= 0){ + throw new BusinessException("更新设备数据失败"); + } + } + + } + //更新出库单 + WarehouseOutOrder warehouseOutOrder = new WarehouseOutOrder(); + //更改状态未待确认发货 + warehouseOutOrder.setOutOrderCode(outOrderCode); + warehouseOutOrder.setWarehouseOutStatus("2"); + int updateWarehouseResult = warehouseOutOrderMapper.updateWarehouseOutOrderByCode(warehouseOutOrder); + if (updateWarehouseResult <= 0){ + throw new BusinessException("更新销售售后通知单数据失败"); + } + + //更新销售出货通知单 + SysSalesShippingInform sysSalesShippingInform = new SysSalesShippingInform(); + sysSalesShippingInform.setOutOrderCode(outOrderCode); + sysSalesShippingInform.setWarehouseOutStatus("2"); + int updateShippingInformResult = shippingInformMapper.updateSysSalesShippingInformByOutOrderCode(sysSalesShippingInform); + if (updateShippingInformResult <= 0){ + throw new BusinessException("更新销售出货通知单数据失败"); + } + + + //更新售后维护设备出库单 + aftersalesOutOrder.setWarehouseOutStatus("2"); + int result = aftersalesOutOrderMapper.updateAftersalesOutOrder(aftersalesOutOrder); + + return result; + + } + + /** + * 售后第一次维护设备,添加出货设备信息 + * */ + @Override + public int addShippingDevicesOne(AftersalesOutOrder aftersalesOutOrder) { + String outOrderCode = aftersalesOutOrder.getOutOrderCode(); + int updateResult = 0; + List selectShippingDeviceVOList = aftersalesOutOrder.getSelectShippingDeviceVOList(); + for (SelectShippingDeviceVO selectShippingDeviceVO : selectShippingDeviceVOList) { + AfterSalesShippingDevice afterSalesShippingDevice = new AfterSalesShippingDevice(); + afterSalesShippingDevice.setShippingDeviceId(selectShippingDeviceVO.getShippingDeviceId()); + afterSalesShippingDevice.setAddShippingDeviceFlag("0"); + afterSalesShippingDevice.setOutOrderCode(outOrderCode); + updateResult = afterSalesShippingDeviceMapper.updateAfterSalesShippingDevice(afterSalesShippingDevice); + if (updateResult <= 0){ + throw new BusinessException("更新出货设备信息失败"); + } + } + + return updateResult; } /** @@ -187,22 +297,41 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService * */ @Override public List getThisSalesOrderShippingDevices(AftersalesOutOrder aftersalesOutOrder) { + // 输入验证 + if (aftersalesOutOrder == null || StringUtils.isEmpty(aftersalesOutOrder.getRelatedOrderCode()) && + StringUtils.isEmpty(aftersalesOutOrder.getSalesOrderCode())) { + return Collections.emptyList(); + } List selectShippingDeviceVOS = new ArrayList<>(); + String materialNo = aftersalesOutOrder.getMaterialNo(); - String relatedOrderCode = aftersalesOutOrder.getRelatedOrderCode(); - String salesOrderCode = aftersalesOutOrder.getSalesOrderCode(); - //优先使用销售订单号关联 - if (StringUtils.isNotEmpty(salesOrderCode)){ - List afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDeviceBySalesOrderCode(salesOrderCode); - convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); - }else { - // 关联订单号可能存在逗号分隔的情况 - String[] splitRelatedOrderCode = relatedOrderCode.split(","); - List afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectBatchShippingDeviceBySalesOrderCode(splitRelatedOrderCode); + // 优先使用销售订单号关联 + if (StringUtils.isNotEmpty(aftersalesOutOrder.getSalesOrderCode())) { + AfterSalesShippingDevice tempAfterSalesShippingDevice = new AfterSalesShippingDevice(); + tempAfterSalesShippingDevice.setMaterialNo(materialNo); + tempAfterSalesShippingDevice.setSalesOrderCode(aftersalesOutOrder.getSalesOrderCode()); + + List afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDeviceByOrderCodeAndMaterialNo(tempAfterSalesShippingDevice); convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); + + // 提前返回 + return selectShippingDeviceVOS; } + // 处理关联订单号 + String relatedOrderCode = aftersalesOutOrder.getRelatedOrderCode(); + Arrays.stream(relatedOrderCode.split(",")) + .map(String::trim) + .forEach(code -> { + AfterSalesShippingDevice tempAfterSalesShippingDevice = new AfterSalesShippingDevice(); + tempAfterSalesShippingDevice.setMaterialNo(materialNo); + tempAfterSalesShippingDevice.setSalesOrderCode(code); + + List afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDeviceByOrderCodeAndMaterialNo(tempAfterSalesShippingDevice); + convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); + }); + return selectShippingDeviceVOS; } @@ -214,18 +343,26 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService public List getOtherSalesOrderShippingDevices(AftersalesOutOrder aftersalesOutOrder) { List selectShippingDeviceVOS = new ArrayList<>(); - + String outOrderCode = aftersalesOutOrder.getOutOrderCode(); + String materialNo = aftersalesOutOrder.getMaterialNo(); List thisSalesOrderShippingDevices = this.getThisSalesOrderShippingDevices(aftersalesOutOrder); - //查找到当前销售订单的出货设备id集合 - List collectShippingDeviceId = thisSalesOrderShippingDevices.stream().map(SelectShippingDeviceVO::getShippingDeviceId).collect(Collectors.toList()); + // 查找到当前销售订单的出货设备ID集合 + List currentShippingDeviceIds = thisSalesOrderShippingDevices.stream() + .map(SelectShippingDeviceVO::getShippingDeviceId) + .collect(Collectors.toList()); //查找到所有出货设备id集合 - List afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectAllShippingDevices(); - List allShippingDeviceIds = afterSalesShippingDevices.stream().map(AfterSalesShippingDevice::getShippingDeviceId).collect(Collectors.toList()); - //筛选出所有出货设备id集合中,不在当前销售订单的出货设备id集合中的数据 - List otherShippingDeviceIds = allShippingDeviceIds.stream().filter(item -> !collectShippingDeviceId.contains(item)).collect(Collectors.toList()); - List list = afterSalesShippingDeviceMapper.selectBatchShippingDeviceById(otherShippingDeviceIds); + List afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDevicesByMaterialNo(materialNo); + + //保留是否添加出货设备等于1的,以及等于0且出库单号等于本单据的 + List filteredDevices = afterSalesShippingDevices.stream().filter(device -> "1".equals(device.getAddShippingDeviceFlag()) + || "0".equals(device.getAddShippingDeviceFlag()) && outOrderCode.equals(device.getOutOrderCode())).collect(Collectors.toList()); + + // 筛选出不在当前销售订单中的数据 + List otherDevices = filteredDevices.stream() + .filter(device -> !currentShippingDeviceIds.contains(device.getShippingDeviceId())) + .collect(Collectors.toList()); //转换成vo类 - this.convertToDeviceVOs(list, selectShippingDeviceVOS); + this.convertToDeviceVOs(otherDevices, selectShippingDeviceVOS); return selectShippingDeviceVOS; } @@ -238,7 +375,41 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService selectShippingDeviceVO.setDeviceModelCode(device.getDeviceModelCode()); selectShippingDeviceVO.setDeviceRunningNumber(device.getDeviceRunningNumber()); selectShippingDeviceVO.setMakePhotoUrl(device.getMakePhotourl()); + selectShippingDeviceVO.setAddShippingDeviceFlag(device.getAddShippingDeviceFlag()); selectShippingDeviceVOS.add(selectShippingDeviceVO); } } + + + /** + * 展示第一次维护设备出库,已经添加了的出货设备 + * */ + @Override + public List showAddShippingDevicesOne(AftersalesOutOrder aftersalesOutOrder) { + String outOrderCode = aftersalesOutOrder.getOutOrderCode(); + String materialNo = aftersalesOutOrder.getMaterialNo(); + List selectShippingDeviceVOS = new ArrayList<>(); + AfterSalesShippingDevice tempShippingDevice = new AfterSalesShippingDevice(); + tempShippingDevice.setMaterialNo(materialNo); + tempShippingDevice.setOutOrderCode(outOrderCode); + List afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectHasAddShippingDevice(tempShippingDevice); + convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); + + return selectShippingDeviceVOS; + } + + + /** + * 逻辑删除出货设备(也就是取消关联) + * */ + @Override + public int deleteAftersalesShippingDeviceById(String shippingDeviceId) { + + AfterSalesShippingDevice tempShippingDevice = new AfterSalesShippingDevice(); + tempShippingDevice.setAddShippingDeviceFlag("1"); + tempShippingDevice.setShippingDeviceId(shippingDeviceId); + tempShippingDevice.setOutOrderCode(""); + int updateAfterSalesShippingDevice = afterSalesShippingDeviceMapper.updateAfterSalesShippingDevice(tempShippingDevice); + return updateAfterSalesShippingDevice; + } } diff --git a/ruoyi-admin/src/main/resources/mapper/aftersales/AfterSalesShippingDeviceMapper.xml b/ruoyi-admin/src/main/resources/mapper/aftersales/AfterSalesShippingDeviceMapper.xml index 6ed26895..d3744d6e 100644 --- a/ruoyi-admin/src/main/resources/mapper/aftersales/AfterSalesShippingDeviceMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/aftersales/AfterSalesShippingDeviceMapper.xml @@ -154,6 +154,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + insert into aftersales_shipping_device diff --git a/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/addShippingDevicesOne.html b/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/addShippingDevicesOne.html index 659db9f9..7da460b2 100644 --- a/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/addShippingDevicesOne.html +++ b/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/addShippingDevicesOne.html @@ -109,6 +109,7 @@ var salesOrderCode = [[${salesOrderCode}]]; var makeNo = [[${makeNo}]]; var relatedOrderCode = [[${relatedOrderCode}]]; + var outOrderCode = [[${outOrderCode}]]; $("#form-addShippingDevicesOne-edit").validate({ focusCleanup: true @@ -123,35 +124,53 @@ obj[item.name] = item.value; return obj; }, {}); - // 获取bootstrap-table的数据,这里假设你使用bootstrap-table的API获取所有数据 - // var table = $('#table-shippingDevices').bootstrapTable('getData'); //获取选中复选框行的数据 - const selectedRows = $("#table-shippingDevices").bootstrapTable('getSelections'); - // 检查表格数据是否为空 - if (selectedRows.length===0){ - $.modal.alertWarning("请至少选择一条出货设备信息后再保存!"); + const selectedThisRows = $("#thisSalesOrderShippingDevice-table").bootstrapTable('getSelections'); + const selectedOtherRows = $("#otherSalesOrderShippingDevice-table").bootstrapTable('getSelections'); + //获取所有数据 + const allThisRows = $("#thisSalesOrderShippingDevice-table").bootstrapTable('getData'); + const allOtherRows = $("#otherSalesOrderShippingDevice-table").bootstrapTable('getData'); + // 将 outOrderCode 添加到 shippingDevicesData 对象中 + shippingDevicesData.outOrderCode = outOrderCode; + + // 检查是否有数据可以提交 + if (allThisRows.length === 0 && allOtherRows.length === 0) { + $.modal.alertWarning("没有数据可以提交!"); return; } - // 将表数据转换成与complaintNoticeData格式一致的数组 - var equipDetailDataList = selectedRows.map(function(item) { - // 根据实际字段名调整 - return { - "shippingDeviceId": item.shippingDeviceId, - "deviceModelCode": item.deviceModelCode, - "deviceRunningNumber": item.deviceRunningNumber, - "makePhotoUrl": item.makePhotoUrl - // ...其他字段 - }; - }); - - // 合并表单数据和表格数据 - const combinedData = Object.assign({}, shippingDevicesData, { selectShippingDeviceVOList: equipDetailDataList }); - - console.log(combinedData) - // 使用 JSON.stringify() 序列化数据 - const jsonData = JSON.stringify(combinedData); - // 发送 AJAX 请求到后端接口 - $.operate.saveJson(prefix + "/addShippingDevicesOne", jsonData); + // 检查表格数据是否为空 + if (selectedThisRows.length + selectedOtherRows.length === 0) { + $.modal.alertWarning("请至少选择一条出货设备后再保存!"); + return; + } + // 将表数据转换成一致的数组 + const equipDetailDataList = [ + ...selectedThisRows.map(item => ({ + "shippingDeviceId": item.shippingDeviceId, + "deviceModelCode": item.deviceModelCode, + "deviceRunningNumber": item.deviceRunningNumber, + "makePhotoUrl": item.makePhotoUrl + // ...其他字段 + })), + ...selectedOtherRows.map(item => ({ + "shippingDeviceId": item.shippingDeviceId, + "deviceModelCode": item.deviceModelCode, + "deviceRunningNumber": item.deviceRunningNumber, + "makePhotoUrl": item.makePhotoUrl + // ...其他字段 + })) + ]; + + + + // 合并表单数据和表格数据 + const combinedData = Object.assign({}, shippingDevicesData, { selectShippingDeviceVOList: equipDetailDataList }); + + console.log(combinedData) + // 使用 JSON.stringify() 序列化数据 + const jsonData = JSON.stringify(combinedData); + // 发送 AJAX 请求到后端接口 + $.operate.saveJson(prefix + "/addShippingDevicesOne", jsonData); } @@ -166,69 +185,6 @@ minView: "month", autoclose: true }); - // - // /*物料信息列表*/ - // $(function() { - // // 物料信息 - // $('#table-material').bootstrapTable('destroy'); - // var materialOptions = { - // id:"table-material", - // url: prefix + "/addShippingDevicesMaterial", - // modalName: "物料信息", - // showColumns: false, - // pagination: false, - // showToggle: false, - // showRefresh:false, - // showSearch:false, - // queryParams:queryParams, - // columns: [{ - // checkbox: true - // }, - // { title:'销售订单号', - // field:'quoteId', - // visible: false - // }, - // { - // title: '料号', - // field: 'materialCode', - // }, - // { - // title: '图片', - // field: 'photoUrl', - // }, - // { - // title: '物料名称', - // field: 'materialName', - // }, - // { - // title: '物料类型', - // field: 'materialType', - // }, - // { - // title: '单位', - // field: 'materialUnit', - // }, - // { - // title: '品牌', - // field: 'brand', - // }, - // { - // title: '描述', - // field: 'describe', - // }, - // ] - // }; - // $.table.init(materialOptions); - // - // }) - // function queryParams(params) { - // var curParams = { - // // 传递参数查询参数 - // quoteId: selectMaterialsVO.quoteId, - // materialCode: selectMaterialsVO.materialCode, - // }; - // return curParams; - // } //销售订单的出货设备 $(function(){ @@ -243,8 +199,15 @@ showColumns: false, queryParams:thisQueryParams, sidePagination: "client", - columns: [{ - checkbox: true + columns: [ { + checkbox : true, + formatter: function(value, row, index) { + if(row.addShippingDeviceFlag === "0"){//如果已经操作禁止选择 + return { disabled : true,} + }else{ + return { disabled : false,} + } + } }, { field: 'equipmentIndex', @@ -275,6 +238,12 @@ align: 'center', title: '生产图片', }, + { + field: 'addShippingDeviceFlag', + align: 'center', + title: '是否添加出货设备', + visible: false + }, ] }; @@ -288,7 +257,8 @@ materialNo: aftersalesOutOrderDetail.materialNo, salesOrderCode:salesOrderCode, makeNo:makeNo, - relatedOrderCode:relatedOrderCode + relatedOrderCode:relatedOrderCode, + outOrderCode:outOrderCode }; return curParams; } @@ -299,9 +269,7 @@ - //其他销售订单的出货设备 - $(function(){ - + $(function () { var options = { id: "otherSalesOrderShippingDevice-table", url: prefix + "/getOtherSalesOrderShippingDevices", @@ -310,46 +278,53 @@ showRefresh: false, showToggle: false, showColumns: false, - queryParams:otherQueryParams, + queryParams: otherQueryParams, sidePagination: "client", - columns: [{ - checkbox: true - }, + columns: [ { - field: 'equipmentIndex', - align: 'center', - title: "序号", - formatter: function (value, row, index) { - // 使用bootstrap-table的内置序号生成 - return index + 1; + checkbox : true, + formatter: function(value, row, index) { + if(row.addShippingDeviceFlag === "0"){//如果已经操作禁止选择 + return { disabled : true,} + }else{ + return { disabled : false,} + } } }, { - field: 'shippingDeviceId', - align: 'center', - title: '出货设备id', - }, - { - field: 'deviceModelCode', - align: 'center', - title: '设备型号', - }, - { - field: 'deviceRunningNumber', - align: 'center', - title: '追踪码', - }, - { - field: 'makePhotoUrl', - align: 'center', - title: '生产图片', - }, - - ] + field: 'equipmentIndex', + align: 'center', + title: "序号", + formatter: function (value, row, index) { + // 使用bootstrap-table的内置序号生成 + return index + 1; + } + }, { + field: 'shippingDeviceId', + align: 'center', + title: '出货设备id', + }, { + field: 'deviceModelCode', + align: 'center', + title: '设备型号', + }, { + field: 'deviceRunningNumber', + align: 'center', + title: '追踪码', + }, { + field: 'makePhotoUrl', + align: 'center', + title: '生产图片', + }, { + field: 'addShippingDeviceFlag', + align: 'center', + title: '是否添加出货设备', + visible: false + }] }; - $.table.init(options); - }) + $.table.init(options); + }); function otherQueryParams(params) { var curParams = { @@ -357,7 +332,8 @@ materialNo: aftersalesOutOrderDetail.materialNo, salesOrderCode:salesOrderCode, makeNo:makeNo, - relatedOrderCode:relatedOrderCode + relatedOrderCode:relatedOrderCode, + outOrderCode:outOrderCode }; return curParams; } diff --git a/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/maintenanceEquipmentOne.html b/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/maintenanceEquipmentOne.html index 6966c957..d3702299 100644 --- a/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/maintenanceEquipmentOne.html +++ b/ruoyi-admin/src/main/resources/templates/aftersales/aftersalesOutOrder/maintenanceEquipmentOne.html @@ -260,49 +260,76 @@ }) - // initChildTable = function(index, row, $detail) { - // var parentRow = row; - // var childTableId = 'child_table_'+index; - // $detail.html('
'); - // $('#'+childTableId).bootstrapTable({ - // url: prefix + "/showAftersalesShippingDeviceListOne", - // method: 'post', - // sidePagination: "server", - // contentType: "application/x-www-form-urlencoded", - // queryParams : { - // // salesOrderCode: aftersalesOutOrder.salesOrderCode, - // materialNo: parentRow.materialNo, - // salesOrderCode:aftersalesOutOrder.salesOrderCode, - // makeNo:aftersalesOutOrder.makeNo - // }, - // columns: [ - // { - // title: '出货设备ID', - // field: 'shippingDeviceId', - // }, - // { - // title: '设备型号', - // field: 'deviceModelCode', - // }, - // { - // title: '流水号', - // field: 'deviceRunningNumber', - // }, - // { - // title: '设备SN号', - // field: 'snCode', - // editable:true - // }, - // { - // title: '操作', - // align: 'center', - // formatter: function (value, row, index) { - // return '删除'; - // } - // } - // ], - // }); - // }; + initChildTable = function(index, row, $detail) { + var parentRow = row; + var childTableId = 'child_table_'+index; + $detail.html('
'); + $('#'+childTableId).bootstrapTable({ + url: prefix + "/showAddShippingDevicesOne", + method: 'post', + sidePagination: "server", + contentType: "application/x-www-form-urlencoded", + queryParams : { + outOrderCode: aftersalesOutOrder.outOrderCode, + materialNo: parentRow.materialNo, + // salesOrderCode:aftersalesOutOrder.salesOrderCode, + // makeNo:aftersalesOutOrder.makeNo + }, + columns: [ + { + title: '出货设备ID', + field: 'shippingDeviceId', + }, + { + title: '设备型号', + field: 'deviceModelCode', + }, + { + title: '追踪码', + field: 'deviceRunningNumber', + }, + { + title: '设备SN号', + field: 'snCode', + editable: { + validate: function(value) { + if ($.trim(value) === '') { + return '本次收货数不能为空'; + } + }, + }, + + + formatter: function (value, row) { + // 检查 snCode 是否存在 + if (row.snCode === undefined || row.snCode === null) { + return ""; + } + + // 根据 snCode 的值决定返回值 + if (row.snCode) { + return row.snCode; + } else { + return value; + } + } + + }, + + // { + // title: '售后图片', + // field: 'deviceRunningNumber', + // }, + { + title: '操作', + align: 'center', + formatter: function (value, row, index) { + return '删除'; + } + } + ], + }); + }; function queryParams(params) { @@ -393,51 +420,71 @@ - - // 获取所有子表数据的函数 // 获取所有子表数据的函数 function getAllSubTablesData() { var allSubData = []; - // 获取所有被展开的行 - var parentLength = $("#bootstrap-table").bootstrapTable("getData").length; - for (let i = 0; i < parentLength; i++) { - var sonData = $('#'+"child_table_" + i).bootstrapTable("getData"); - //循环获取子表中存在的行数据,每个行数据转换添加到allSubData数组中 - allSubData = allSubData.concat(sonData); + var parentData = $("#needShippingDevice-table").bootstrapTable("getData"); + var parentLength = parentData.length; + + if (parentLength !== 0) { + for (let i = 0; i < parentLength; i++) { + var sonData = $("#" + "child_table_" + i).bootstrapTable("getData"); + allSubData = allSubData.concat(sonData); + + // 获取主表的准备出库数 + var prepareOutOrderSum = parentData[i].prepareOutOrderSum; + var sonDataLength = sonData.length; + + // 比较主表的准备出库数和子表的长度 + if (sonDataLength < prepareOutOrderSum) { + + $.modal.alertWarning(`物料第 ${i + 1} 行的准备出库数为 ${prepareOutOrderSum},但已经添加出货设备为 ${sonDataLength},请添加出货设备`); + return; + }else if(sonDataLength > prepareOutOrderSum){ + $.modal.alertWarning(`物料第 ${i + 1} 行的准备出库数为 ${prepareOutOrderSum},但已经添加出货设备为 ${sonDataLength},请删除出货设备`); + return; + } + } } return allSubData; } - function deleteRow(shippingDeviceId) { + + function deleteRow(shippingDeviceId, index) { // 弹出确认框询问用户是否确定删除 - if (confirm("确定要删除这条记录吗?")) { - // 发送删除请求到服务器 - $.ajax({ - url: prefix + "/deleteRow", // 请根据实际API路径调整 - type: 'POST', - data: { - shippingDeviceId: shippingDeviceId, // 传递需要删除的记录的ID - }, - success: function(result) { - if (result.success) { // 假设result是一个对象,包含success属性来表示操作是否成功 - // 删除操作成功,从表格中移除这一行 - $('#child_table_' + index).bootstrapTable('remove', { - field: 'shippingDeviceId', - values: [shippingDeviceId] - }); - toastr.success("删除成功!"); // 显示成功提示信息,这里使用toastr作为示例,确保已引入相关库 - } else { - toastr.error("删除失败: " + result.message); // 显示失败原因,同样确保已引入toastr库 + $.modal.confirm("确定要删除这条记录吗?", function(confirmed) { + if (confirmed) { + // 发送删除请求到服务器 + $.ajax({ + url: prefix + "/deleteRow", // 请根据实际API路径调整 + type: 'POST', + data: { + shippingDeviceId: shippingDeviceId, // 传递需要删除的记录的ID + }, + success: function(result) { + handleDeleteResponse(result, shippingDeviceId, index); + }, + error: function(xhr, status, error) { + $.modal.msgError("发生错误,删除失败: " + xhr.responseText); } - }, - error: function() { - toastr.error("发生错误,删除失败!"); // 网络错误或后端错误处理 - } + }); + } + }); + } + + function handleDeleteResponse(result, shippingDeviceId, index) { + if (result.code === 0) { + // 删除操作成功,从表格中移除这一行 + $('#child_table_' + index).bootstrapTable('remove', { + field: 'shippingDeviceId', + values: [shippingDeviceId] }); + $.modal.msgSuccess("删除成功,请刷新表格"); + } else { + $.modal.msgError("删除失败: " + result.message); } - }; - + } /*添加出货设备*/ @@ -450,12 +497,17 @@ function addShippingDevicesOne(outOrderDetailId) { var salesOrderCode = [[${aftersalesOutOrder.salesOrderCode}]]; var relatedOrderCode = [[${aftersalesOutOrder.relatedOrderCode}]]; + var outOrderCode = [[${aftersalesOutOrder.outOrderCode}]]; var makeNo = [[${aftersalesOutOrder.makeNo}]]; var queryParams = new URLSearchParams(); queryParams.append('outOrderDetailId', outOrderDetailId); - queryParams.append('salesOrderCode', encodeURIComponent(salesOrderCode)); - queryParams.append('makeNo',encodeURIComponent(makeNo)); - queryParams.append('relatedOrderCode',encodeURIComponent(relatedOrderCode)); + + // 仅对需要编码的部分进行编码 + queryParams.append('salesOrderCode', salesOrderCode); + queryParams.append('makeNo', makeNo); + queryParams.append('relatedOrderCode', relatedOrderCode); + queryParams.append('outOrderCode', outOrderCode); + var url = prefix + '/addShippingDevicesOne?' + queryParams.toString(); $.modal.open("添加出货设备", url); }