| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.approve.mapper.ApproveProcessMapper; |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | // import com.ruoyi.approve.mapper.ApproveProcessMapper; |
| | | // import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | // import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | // import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.approve.service.IApproveProcessService; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | // import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| | | // import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.other.service.impl.TempFileServiceImpl; |
| | | // import com.ruoyi.other.service.impl.TempFileServiceImpl; |
| | | // import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.sales.dto.ShippingInfoDto; |
| | | import com.ruoyi.sales.mapper.ShipmentApprovalMapper; |
| | | // import com.ruoyi.sales.mapper.ShipmentApprovalMapper; |
| | | import com.ruoyi.sales.mapper.ShippingInfoMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.pojo.ShipmentApproval; |
| | | // import com.ruoyi.sales.pojo.ShipmentApproval; |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.service.ISalesLedgerProductService; |
| | | import com.ruoyi.sales.service.ISalesLedgerService; |
| | | import com.ruoyi.sales.service.ShippingInfoService; |
| | | import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | | // import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | // import java.time.LocalDate; |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private ShippingInfoService shippingInfoService; |
| | | @Autowired |
| | | private ShipmentApprovalMapper shipmentApprovalMapper; |
| | | |
| | | // @Autowired |
| | | // private CommonFileServiceImpl commonFileService; |
| | | |
| | | @Autowired |
| | | private IApproveProcessService approveProcessService; |
| | | |
| | | // @Autowired |
| | | // private StockUtils stockUtils; |
| | | |
| | | @Autowired |
| | | private ISalesLedgerProductService salesLedgerProductService; |
| | | |
| | | @Autowired |
| | | private TempFileServiceImpl tempFileService; |
| | | private ISalesLedgerService salesLedgerService; |
| | | |
| | | @Autowired |
| | | private CommonFileServiceImpl commonFileService; |
| | | |
| | | @Autowired |
| | | private ApproveProcessServiceImpl approveProcessService; |
| | | private com.ruoyi.sales.mapper.SalesLedgerProductMapper salesLedgerProductMapper; |
| | | |
| | | |
| | | @GetMapping("/listPage") |
| | | @ApiOperation("发货信息列表") |
| | | public AjaxResult listPage(Page page, ShippingInfo req) { |
| | | IPage<ShippingInfo> listPage = shippingInfoService.listPage(page,req); |
| | | IPage<ShippingInfoDto> listPage = shippingInfoService.listPage(page,req); |
| | | return AjaxResult.success(listPage); |
| | | } |
| | | |
| | |
| | | @Log(title = "发货信息管理", businessType = BusinessType.INSERT) |
| | | public AjaxResult add(@RequestBody ShippingInfoDto req) throws Exception { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH"); |
| | | // 发货审批 |
| | | |
| | | if (req.getSalesLedgerId() == null) { |
| | | return AjaxResult.error("关联订单 ID 不能为空"); |
| | | } |
| | | |
| | | SalesLedger salesLedger = salesLedgerService.getById(req.getSalesLedgerId()); |
| | | if (salesLedger == null) { |
| | | return AjaxResult.error("关联订单不存在"); |
| | | } |
| | | |
| | | // 检查是否已经在审批中或已发货 |
| | | if (salesLedger.getDeliveryStatus() != null && salesLedger.getDeliveryStatus() >= 2 && !salesLedger.getDeliveryStatus().equals(3)) { |
| | | return AjaxResult.error("该订单已在审批中或已发货,无法重复发起"); |
| | | } |
| | | |
| | | String shNo = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH"); |
| | | |
| | | // 发起订审批 |
| | | ApproveProcessVO approveProcessVO = new ApproveProcessVO(); |
| | | approveProcessVO.setApproveType(7); |
| | | approveProcessVO.setApproveDeptId(loginUser.getTenantId()); |
| | | approveProcessVO.setApproveReason(req.getType() + ":" +sh); |
| | | approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId()); |
| | | // 审批理由包含合同号,用于后续审批通过后找回订单 |
| | | approveProcessVO.setApproveReason("发货审批:" + salesLedger.getSalesContractNo()); |
| | | approveProcessVO.setApproveUserIds(req.getApproveUserIds()); |
| | | approveProcessVO.setApproveUser(loginUser.getUserId()); |
| | | approveProcessVO.setApproveTime(LocalDate.now().toString()); |
| | | approveProcessService.addApprove(approveProcessVO); |
| | | // 添加发货消息 |
| | | req.setShippingNo(sh); |
| | | req.setStatus("待审核"); |
| | | boolean save = shippingInfoService.save(req); |
| | | return save ? AjaxResult.success() : AjaxResult.error(); |
| | | |
| | | // 更新销售台账状态为 2 (审批中) |
| | | salesLedger.setDeliveryStatus(2); |
| | | salesLedgerService.updateById(salesLedger); |
| | | |
| | | // 为订单下的每一个产品生成发货台账记录 (显示单个产品) |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId())); |
| | | |
| | | if (CollectionUtils.isNotEmpty(products)) { |
| | | for (SalesLedgerProduct product : products) { |
| | | ShippingInfo si = new ShippingInfo(); |
| | | si.setSalesLedgerId(salesLedger.getId()); |
| | | si.setSalesLedgerProductId(product.getId()); |
| | | si.setShippingNo(shNo); |
| | | si.setStatus("待审核"); |
| | | si.setType(req.getType()); // 来源/类型 |
| | | shippingInfoService.save(si); |
| | | } |
| | | } |
| | | |
| | | return AjaxResult.success("发货审批已发起"); |
| | | } |
| | | |
| | | @ApiOperation("发货扣库存") |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Log(title = "发货信息管理", businessType = BusinessType.UPDATE) |
| | | public AjaxResult deductStock(@RequestBody ShippingInfoDto req) throws IOException { |
| | | ShippingInfo byId = shippingInfoService.getById(req.getId()); |
| | | if (byId == null) { |
| | | return AjaxResult.error("发货信息不存在"); |
| | | } |
| | | byId.setExpressNumber(req.getExpressNumber()); |
| | | byId.setExpressCompany(req.getExpressCompany()); |
| | | byId.setShippingCarNumber(req.getShippingCarNumber()); |
| | | boolean update = shippingInfoService.updateById(req); |
| | | // 迁移文件 |
| | | if(CollectionUtils.isNotEmpty(req.getTempFileIds())){ |
| | | tempFileService.migrateTempFilesToFormal(req.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue()); |
| | | } |
| | | return update ? AjaxResult.success() : AjaxResult.error(); |
| | | return shippingInfoService.deductStock( req) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @PostMapping("/update") |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Log(title = "发货信息管理", businessType = BusinessType.DELETE) |
| | | public AjaxResult delete(@RequestBody List<Long> ids) { |
| | | commonFileService.deleteByBusinessIds(ids, FileNameType.SHIP.getValue()); |
| | | boolean delete = shippingInfoService.removeBatchByIds(ids); |
| | | return delete ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败"); |
| | | |
| | | return shippingInfoService.delete(ids) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败"); |
| | | } |
| | | |
| | | @Autowired |
| | |
| | | util.exportExcel(response, list, "发货信息"); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getByCustomerName") |
| | | @ApiOperation("通过客户名称查询") |
| | | public AjaxResult getByCustomerName(String customerName) { |
| | | return AjaxResult.success(shippingInfoService.getShippingInfoByCustomerName(customerName)); |
| | | } |
| | | } |