liding
3 天以前 3b71cac369fb246ceafa59ffa3b775c2afc8add4
1.报工
已修改4个文件
136 ■■■■■ 文件已修改
src/main/java/com/ruoyi/production/controller/ProductionProductMainController.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/pojo/ProductionProductMain.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java 102 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/controller/ProductionProductMainController.java
@@ -3,13 +3,10 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.production.dto.ProductionProductMainDto;
import com.ruoyi.production.pojo.ProductionProductMain;
import com.ruoyi.production.service.ProductionProductMainService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RequestMapping("productionProductMain")
@RestController
@@ -19,13 +16,24 @@
    @Autowired
    private ProductionProductMainService productionProductMainService;
    /**
     * 报工查询
     * @param page
     * @param productionProductMainDto
     * @return
     */
    @GetMapping("listPage")
    public R page(Page<ProductionProductMainDto> page, ProductionProductMainDto productionProductMainDto) {
        return R.ok(productionProductMainService.listPageProductionProductMainDto(page, productionProductMainDto));
    }
    @GetMapping("addProductMain")
    public R addProductMain(ProductionProductMainDto productionProductMainDto) {
    /**
     * 报工新增更新
     * @param productionProductMainDto
     * @return
     */
    @PostMapping("addProductMain")
    public R addProductMain(@RequestBody ProductionProductMainDto productionProductMainDto) {
        return R.ok(productionProductMainService.addProductMain(productionProductMainDto));
    }
}
src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java
@@ -3,16 +3,14 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.production.dto.ProductOrderDto;
import com.ruoyi.production.dto.ProductionProductMainDto;
import com.ruoyi.production.pojo.ProductionProductMain;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import javax.annotation.ManagedBean;
import java.util.List;
@Mapper
public interface ProductionProductMainMapper extends BaseMapper<ProductionProductMain> {
    IPage<ProductionProductMainDto> listPageProductionProductMainDto(Page page, @Param("c") ProductionProductMainDto productionProductMainDto);
}
src/main/java/com/ruoyi/production/pojo/ProductionProductMain.java
@@ -23,15 +23,17 @@
    private Long userId;
    @ApiModelProperty(value = "报工人员")
    private Long userName;
    private String userName;
    @ApiModelProperty(value = "生产项目id")
    private Long productProcessRouteItemId;
    @ApiModelProperty(value = "工单id")
    private String productProcessRouteItemId;
    private Long workOrderId;
    @ApiModelProperty(value = "报工状态")
    private Integer status;
    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -6,36 +6,39 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.production.controller.ProductWorkOrderController;
import com.ruoyi.production.dto.ProcessRouteItemDto;
import com.ruoyi.production.dto.ProductOrderDto;
import com.ruoyi.production.dto.ProductionProductMainDto;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.pojo.ProductProcessRouteItem;
import com.ruoyi.production.pojo.ProductionProductMain;
import com.ruoyi.production.pojo.ProductionProductOutput;
import com.ruoyi.production.service.ProductionProductMainService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.production.mapper.ProductionProductMainMapper;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
@Service
@AllArgsConstructor
public class ProductionProductMainServiceImpl extends ServiceImpl<ProductionProductMainMapper, ProductionProductMain> implements ProductionProductMainService {
    @Autowired
    private ProductionProductMainMapper productionProductMainMapper;
    @Autowired
    private ProductWorkOrderController productWorkOrderController;
    @Autowired
    private ProductWorkOrderMapper productWorkOrderMapper;
    @Autowired
    private ProductProcessRouteItemMapper productProcessRouteItemMapper;
    @Autowired
    private ProductionProductOutputMapper productionProductOutputMapper;
    @Autowired
    private ProcessRouteItemMapper processRouteItemMapper;
    @Autowired
    private ProductModelMapper productModelMapper;
@@ -45,43 +48,86 @@
    }
    @Override
    public Boolean addProductMain(ProductionProductMainDto productionProductMainDto) {
    @Transactional(rollbackFor = Exception.class)
    public Boolean addProductMain(ProductionProductMainDto dto) {
        if (dto == null) {
            throw new RuntimeException("参数不能为空");
        }
        // 判断是新增还是更新
        if (dto.getId() != null) {
            // 更新逻辑 - 只更新数量
            QueryWrapper<ProductionProductOutput> outputWrapper = new QueryWrapper<>();
            outputWrapper.eq("product_main_id", dto.getId());
            ProductionProductOutput output = productionProductOutputMapper.selectOne(outputWrapper);
            if (output == null) {
                throw new RuntimeException("产出记录不存在");
            }
            // 只更新数量
            if (dto.getQuantity() != null) {
                output.setQuantity(dto.getQuantity());
                productionProductOutputMapper.updateById(output);
            }
            return true;
        }
        // 新增逻辑
        ProductionProductMain productionProductMain = new ProductionProductMain();
        ProductProcessRouteItem productProcessRouteItem = productProcessRouteItemMapper.selectById(productionProductMainDto.getProductProcessRouteItemId());
        ProductProcessRouteItem productProcessRouteItem = productProcessRouteItemMapper.selectById(dto.getProductProcessRouteItemId());
        if (productProcessRouteItem == null) {
            throw new RuntimeException("工艺路线项不存在");
        }
        String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        // 查询今日已存在的最大工单号
        QueryWrapper<ProductionProductMain> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("work_order_no", datePrefix)
                .orderByDesc("work_order_no")
                .last("LIMIT 1");
        queryWrapper.select("MAX(product_no) as maxNo")
                .likeRight("product_no", datePrefix);
        ProductionProductMain lastWorkOrder = productionProductMainMapper.selectOne(queryWrapper);
        // 修正:安全处理可能为空的查询结果
        List<Map<String, Object>> resultList = productionProductMainMapper.selectMaps(queryWrapper);
        int sequenceNumber = 1; // 默认序号
        if (lastWorkOrder != null && lastWorkOrder.getProductNo() != null) {
            String lastNo = lastWorkOrder.getProductNo().toString();
        int sequenceNumber = 1;
        if (resultList != null && !resultList.isEmpty()) {
            Map<String, Object> result = resultList.get(0);
            if (result != null) {
                Object maxNoObj = result.get("maxNo");
                if (maxNoObj != null) {
                    String lastNo = maxNoObj.toString();
                    System.out.println("lastNo: " + lastNo);
            if (lastNo.startsWith(datePrefix)) {
                String seqStr = lastNo.substring(datePrefix.length());
                try {
                            String seqStr = lastNo.substring(datePrefix.length());
                    sequenceNumber = Integer.parseInt(seqStr) + 1;
                } catch (NumberFormatException e) {
                    sequenceNumber = 1;
                }
            }
        }
        String workOrderNoStr = String.format("%s%03d", datePrefix, sequenceNumber);
        productionProductMain.setProductNo(workOrderNoStr);
        productionProductMain.setUserId(productionProductMainDto.getUserId());
        productionProductMain.setProductProcessRouteItemId(productionProductMainDto.getProductProcessRouteItemId());
            }
        }
        String productNo = String.format("%s%03d", datePrefix, sequenceNumber);
        productionProductMain.setProductNo(productNo);
        productionProductMain.setUserId(dto.getUserId());
        productionProductMain.setProductProcessRouteItemId(dto.getProductProcessRouteItemId());
        productionProductMain.setWorkOrderId(dto.getWorkOrderId());
        productionProductMain.setStatus(0);
        //添加报工主表
        productionProductMainMapper.insert(productionProductMain);
        // 添加产出
        ProductionProductOutput productionProductOutput = new ProductionProductOutput();
        productionProductOutput.setProductMainId(productionProductMain.getId());
        productionProductOutput.setProductModelId(productProcessRouteItem.getProductModelId());
        productionProductOutput.setQuantity(productionProductMainDto.getQuantity());
        //添加产出
        productionProductOutput.setQuantity(dto.getQuantity() != null ? dto.getQuantity() : BigDecimal.ZERO);
        productionProductOutputMapper.insert(productionProductOutput);
        return true;
    }
}