buhuazhen
2 天以前 28bc6d67f2f35e312fc1fa30095359cc8b3135a4
src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -16,6 +16,7 @@
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
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.ShippingInfoMapper;
@@ -50,25 +51,20 @@
    @Autowired
    private ShippingInfoService shippingInfoService;
    @Autowired
    private ShipmentApprovalMapper shipmentApprovalMapper;
    @Autowired
    private ISalesLedgerProductService salesLedgerProductService;
    @Autowired
    private TempFileServiceImpl tempFileService;
    @Autowired
    private CommonFileServiceImpl commonFileService;
    @Autowired
    private ApproveProcessServiceImpl approveProcessService;
    @Autowired
    private StockUtils stockUtils;
    @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);
    }
@@ -78,12 +74,19 @@
    @Log(title = "发货信息管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody ShippingInfoDto req) throws Exception {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH");
        String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH","shipping_no");
        // 发货审批
        ApproveProcessVO approveProcessVO = new ApproveProcessVO();
        approveProcessVO.setApproveType(7);
        approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId());
        approveProcessVO.setApproveReason(req.getType() + ":" +sh);
        // 审批原因格式:发货单号:{发货类型}:{发货车牌号}
        String approveReason = "发货单号:" + sh + "\n" + req.getType();
        if ("货车".equals(req.getType()) && req.getShippingCarNumber() != null) {
            approveReason += ":" + req.getShippingCarNumber();
        } else if ("快递".equals(req.getType()) && req.getExpressCompany() != null) {
            approveReason += ":" + req.getExpressCompany();
        }
        approveProcessVO.setApproveReason(approveReason);
        approveProcessVO.setApproveUserIds(req.getApproveUserIds());
        approveProcessVO.setApproveUser(loginUser.getUserId());
        approveProcessVO.setApproveTime(LocalDate.now().toString());
@@ -100,20 +103,7 @@
    @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.setStatus("已发货");
        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")
@@ -134,9 +124,8 @@
    @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
@@ -153,4 +142,35 @@
        util.exportExcel(response, list, "发货信息");
    }
    @GetMapping("/getByCustomerName")
    @ApiOperation("通过客户名称查询")
    public AjaxResult getByCustomerName(String customerName) {
        return AjaxResult.success(shippingInfoService.getShippingInfoByCustomerName(customerName));
    }
    /**
     * 一键发货 - 自动审批通过并出库
     */
    @PostMapping("/oneClickShipping")
    @ApiOperation("一键发货")
    @Transactional(rollbackFor = Exception.class)
    @Log(title = "发货信息管理", businessType = BusinessType.INSERT)
    public AjaxResult oneClickShipping(@RequestBody ShippingInfoDto req) throws IOException {
        return shippingInfoService.oneClickShipping(req) ? AjaxResult.success("发货成功") : AjaxResult.error("发货失败");
    }
    /**
     * 批量一键发货 - 将销售台账下所有未发货的产品全部发货
     */
    @PostMapping("/batchOneClickShipping")
    @ApiOperation("批量一键发货")
    @Transactional(rollbackFor = Exception.class)
    @Log(title = "发货信息管理", businessType = BusinessType.INSERT)
    public AjaxResult batchOneClickShipping(@RequestBody ShippingInfoDto req) throws IOException {
        if (req.getSalesLedgerId() == null) {
            return AjaxResult.error("销售台账ID不能为空");
        }
        return shippingInfoService.batchOneClickShipping(req.getSalesLedgerId(), req) ? AjaxResult.success("批量发货成功") : AjaxResult.error("批量发货失败");
    }
}