maven
5 天以前 e5e8464e8a6385683187b3459f8bfb5f9682a8ae
src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -3,11 +3,13 @@
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.common.enums.FileNameType;
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.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.other.service.impl.TempFileServiceImpl;
import com.ruoyi.sales.mapper.ShipmentApprovalMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
import com.ruoyi.sales.pojo.SalesLedger;
@@ -17,6 +19,7 @@
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;
@@ -25,6 +28,7 @@
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
@@ -43,6 +47,12 @@
    @Autowired
    private ISalesLedgerProductService salesLedgerProductService;
    @Autowired
    private TempFileServiceImpl tempFileService;
    @Autowired
    private CommonFileServiceImpl commonFileService;
    @GetMapping("/listPage")
    @ApiOperation("发货信息列表")
@@ -54,64 +64,38 @@
    @PostMapping("/add")
    @ApiOperation("添加发货信息")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(@RequestBody ShippingInfo req) {
        LambdaQueryWrapper<ShippingInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ShippingInfo::getSalesLedgerId, req.getSalesLedgerId());
        wrapper.eq(ShippingInfo::getSalesLedgerProductId, req.getSalesLedgerProductId());
        List<ShippingInfo> list = shippingInfoService.list(wrapper);
        if(!CollectionUtils.isEmpty(list)){
            return AjaxResult.error("发货信息已存在");
        }
    public AjaxResult add(@RequestBody ShippingInfo req) throws IOException {
        boolean save = shippingInfoService.save(req);
        if(save){
            ShippingInfo shippingInfo = shippingInfoService.getOne(wrapper);
            ShipmentApproval shipmentApproval = new ShipmentApproval();
            shipmentApproval.setSalesLedgerId(req.getSalesLedgerId());
            shipmentApproval.setSalesLedgerProductId(req.getSalesLedgerProductId());
            shipmentApproval.setApproveUserId(req.getApproverId());
            shipmentApproval.setApproveStatus(2);
            shipmentApproval.setShippingInfoId(shippingInfo.getId());
            shipmentApprovalMapper.insert(shipmentApproval);
            SalesLedgerProduct salesLedgerProduct = salesLedgerProductService.getById(req.getSalesLedgerProductId());
            if(salesLedgerProduct != null){
                salesLedgerProduct.setApproveStatus(2);
                salesLedgerProductService.updateById(salesLedgerProduct);
            }
        // 迁移文件
        if(CollectionUtils.isNotEmpty(req.getTempFileIds())){
            tempFileService.migrateTempFilesToFormal(req.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue());
        }
        return save ? AjaxResult.success() : AjaxResult.error();
    }
    @PostMapping("/update")
    @ApiOperation("修改发货信息")
    public AjaxResult update(@RequestBody ShippingInfo req) {
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult update(@RequestBody ShippingInfo req) throws IOException {
        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);
        if(CollectionUtils.isNotEmpty(req.getTempFileIds())){
            tempFileService.migrateTempFilesToFormal(req.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue());
        }
        return update ? AjaxResult.success() : AjaxResult.error();
    }
    @DeleteMapping("/delete")
    @ApiOperation("删除发货信息")
    @Transactional(rollbackFor = Exception.class)
    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("您没有权限删除此发货信息");
            }
        });
        if(CollectionUtils.isEmpty(ids)) return AjaxResult.error("请选择要删除的记录");
        boolean delete = shippingInfoService.removeBatchByIds(ids);
        // 删除附件
        commonFileService.deleteByBusinessIds(ids, FileNameType.SHIP.getValue());
        return delete ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }