| | |
| | | package com.ruoyi.sales.controller; |
| | | |
| | | // 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.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.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.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; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | // 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 io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | // import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private ShippingInfoService shippingInfoService; |
| | | |
| | | // @Autowired |
| | | // private CommonFileServiceImpl commonFileService; |
| | | |
| | | // @Autowired |
| | | // private ApproveProcessServiceImpl approveProcessService; |
| | | |
| | | // @Autowired |
| | | // private StockUtils stockUtils; |
| | | |
| | | @Autowired |
| | | private ISalesLedgerProductService salesLedgerProductService; |
| | | |
| | | @Autowired |
| | | private ISalesLedgerService salesLedgerService; |
| | | |
| | | |
| | | @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); |
| | | } |
| | | |
| | | @PostMapping("/add") |
| | | @ApiOperation("添加发货信息") |
| | | public AjaxResult add(@RequestBody ShippingInfo req) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Log(title = "发货信息管理", businessType = BusinessType.INSERT) |
| | | public AjaxResult add(@RequestBody ShippingInfoDto req) throws Exception { |
| | | // LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH"); |
| | | |
| | | /* // 原有的单产品发货及审批逻辑 |
| | | // 发货审批 |
| | | ApproveProcessVO approveProcessVO = new ApproveProcessVO(); |
| | | approveProcessVO.setApproveType(7); |
| | | approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId()); |
| | | approveProcessVO.setApproveReason(req.getType() + ":" +sh); |
| | | 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(); |
| | | */ |
| | | |
| | | // 按整个订单发货,不需审批 |
| | | if (req.getSalesLedgerId() == null) { |
| | | return AjaxResult.error("请选择发货订单"); |
| | | } |
| | | |
| | | // 获取该订单下的所有产品 |
| | | SalesLedgerProduct query = new SalesLedgerProduct(); |
| | | query.setSalesLedgerId(req.getSalesLedgerId()); |
| | | List<SalesLedgerProduct> productList = salesLedgerProductService.selectSalesLedgerProductList(query); |
| | | |
| | | if (CollectionUtils.isEmpty(productList)) { |
| | | return AjaxResult.error("该订单下无待发货产品"); |
| | | } |
| | | |
| | | // 为每个产品创建发货信息 |
| | | List<ShippingInfo> shippingInfoList = new ArrayList<>(); |
| | | for (SalesLedgerProduct product : productList) { |
| | | ShippingInfo shippingInfo = new ShippingInfo(); |
| | | shippingInfo.setSalesLedgerId(req.getSalesLedgerId()); |
| | | shippingInfo.setSalesLedgerProductId(product.getId()); |
| | | shippingInfo.setShippingNo(sh); |
| | | shippingInfo.setStatus("审核通过"); // 直接设为审核通过,跳过审批 |
| | | shippingInfo.setType(req.getType()); |
| | | shippingInfo.setExpressCompany(req.getExpressCompany()); |
| | | shippingInfo.setExpressNumber(req.getExpressNumber()); |
| | | shippingInfo.setShippingDate(req.getShippingDate()); |
| | | shippingInfo.setShippingCarNumber(req.getShippingCarNumber()); |
| | | shippingInfoList.add(shippingInfo); |
| | | } |
| | | |
| | | boolean save = shippingInfoService.saveBatch(shippingInfoList); |
| | | if (save) { |
| | | // 更新销售台账的发货状态为已发货 |
| | | SalesLedger salesLedger = new SalesLedger(); |
| | | salesLedger.setId(req.getSalesLedgerId()); |
| | | salesLedger.setDeliveryStatus(1); |
| | | salesLedgerService.updateById(salesLedger); |
| | | } |
| | | return save ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @ApiOperation("发货扣库存") |
| | | @PostMapping("/deductStock") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Log(title = "发货信息管理", businessType = BusinessType.UPDATE) |
| | | public AjaxResult deductStock(@RequestBody ShippingInfoDto req) throws IOException { |
| | | return shippingInfoService.deductStock( req) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @PostMapping("/update") |
| | | @ApiOperation("修改发货信息") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Log(title = "发货信息管理", businessType = BusinessType.UPDATE) |
| | | public AjaxResult update(@RequestBody ShippingInfo req) { |
| | | ShippingInfo byId = shippingInfoService.getById(req.getId()); |
| | | if (byId == null) { |
| | | return AjaxResult.error("发货信息不存在"); |
| | | } |
| | | Long userId = getLoginUser().getUserId(); |
| | | if(!userId.equals(Long.parseLong(byId.getCreateUser().toString()))){ |
| | | return AjaxResult.error("您没有权限修改此发货信息"); |
| | | } |
| | | boolean update = shippingInfoService.updateById(req); |
| | | return update ? AjaxResult.success() : AjaxResult.error(); |
| | |
| | | |
| | | @DeleteMapping("/delete") |
| | | @ApiOperation("删除发货信息") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Log(title = "发货信息管理", businessType = BusinessType.DELETE) |
| | | public AjaxResult delete(@RequestBody List<Long> ids) { |
| | | Long userId = getLoginUser().getUserId(); |
| | | ids.forEach(id -> { |
| | | ShippingInfo byId = shippingInfoService.getById(id); |
| | | if (byId == null) { |
| | | throw new RuntimeException("发货信息不存在"); |
| | | } |
| | | if(!userId.equals(Long.parseLong(byId.getCreateUser().toString()))){ |
| | | throw new RuntimeException("您没有权限删除此发货信息"); |
| | | } |
| | | }); |
| | | 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)); |
| | | } |
| | | } |