7 changed files with 751 additions and 0 deletions
-
181src/main/java/com/xujie/sys/modules/erf/controller/ErfExpRawMaterialController.java
-
117src/main/java/com/xujie/sys/modules/erf/entity/ErfExpRawMaterial.java
-
50src/main/java/com/xujie/sys/modules/erf/mapper/ErfExpRawMaterialMapper.java
-
73src/main/java/com/xujie/sys/modules/erf/service/ErfExpRawMaterialService.java
-
254src/main/java/com/xujie/sys/modules/erf/service/impl/ErfExpRawMaterialServiceImpl.java
-
4src/main/java/com/xujie/sys/modules/sys/controller/AbstractController.java
-
72src/main/resources/mapper/erf/ErfExpRawMaterialMapper.xml
@ -0,0 +1,181 @@ |
|||||
|
package com.xujie.sys.modules.erf.controller; |
||||
|
|
||||
|
import com.xujie.sys.common.utils.R; |
||||
|
import com.xujie.sys.modules.erf.entity.ErfExpRawMaterial; |
||||
|
import com.xujie.sys.modules.erf.service.ErfExpRawMaterialService; |
||||
|
import com.xujie.sys.modules.sys.controller.AbstractController; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 工程实验申请单原材料清单控制器 |
||||
|
* |
||||
|
* <p><b>主要功能:</b></p> |
||||
|
* <ul> |
||||
|
* <li>查询指定申请单的原材料清单列表</li> |
||||
|
* <li>保存原材料记录(新增或修改)</li> |
||||
|
* <li>删除原材料记录</li> |
||||
|
* <li>根据物料编码查询物料描述(从part表)</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* @author System |
||||
|
* @since 2026-01-30 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@RequestMapping("/erf/rawMaterial") |
||||
|
public class ErfExpRawMaterialController extends AbstractController { |
||||
|
|
||||
|
@Autowired |
||||
|
private ErfExpRawMaterialService erfExpRawMaterialService; |
||||
|
|
||||
|
/** |
||||
|
* 根据申请单号查询原材料清单列表 |
||||
|
* |
||||
|
* @param params 包含applyNo的参数 |
||||
|
* @return 原材料清单列表 |
||||
|
*/ |
||||
|
@PostMapping("/getRawMaterialList") |
||||
|
@ResponseBody |
||||
|
public R getRawMaterialList(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
String applyNo = (String) params.get("applyNo"); |
||||
|
log.info("查询原材料清单列表,申请单号: {}", applyNo); |
||||
|
|
||||
|
List<ErfExpRawMaterial> list = erfExpRawMaterialService.getRawMaterialListByApplyNo(applyNo); |
||||
|
return R.ok().put("list", list); |
||||
|
} catch (Exception e) { |
||||
|
log.error("查询原材料清单列表失败: " + e.getMessage(), e); |
||||
|
return R.error("查询失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据ID查询单条原材料记录 |
||||
|
* |
||||
|
* @param params 包含id的参数 |
||||
|
* @return 原材料记录 |
||||
|
*/ |
||||
|
@PostMapping("/getRawMaterialById") |
||||
|
@ResponseBody |
||||
|
public R getRawMaterialById(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
Integer id = Integer.valueOf(params.get("id").toString()); |
||||
|
log.info("查询原材料记录,ID: {}", id); |
||||
|
|
||||
|
ErfExpRawMaterial rawMaterial = erfExpRawMaterialService.getRawMaterialById(id); |
||||
|
return R.ok().put("data", rawMaterial); |
||||
|
} catch (Exception e) { |
||||
|
log.error("查询原材料记录失败: " + e.getMessage(), e); |
||||
|
return R.error("查询失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存原材料记录(新增或修改) |
||||
|
* |
||||
|
* @param rawMaterial 原材料数据 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
@PostMapping("/saveRawMaterial") |
||||
|
@ResponseBody |
||||
|
public R saveRawMaterial(@RequestBody ErfExpRawMaterial rawMaterial) { |
||||
|
try { |
||||
|
log.info("保存原材料记录: {}", rawMaterial); |
||||
|
|
||||
|
Integer id = erfExpRawMaterialService.saveRawMaterial(rawMaterial); |
||||
|
return R.ok("保存成功").put("id", id); |
||||
|
} catch (Exception e) { |
||||
|
log.error("保存原材料记录失败: " + e.getMessage(), e); |
||||
|
return R.error("保存失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除原材料记录(逻辑删除) |
||||
|
* |
||||
|
* @param params 包含id的参数 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
@PostMapping("/deleteRawMaterial") |
||||
|
@ResponseBody |
||||
|
public R deleteRawMaterial(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
Integer id = Integer.valueOf(params.get("id").toString()); |
||||
|
String updatedBy = getUserName(); // 从AbstractController获取当前用户 |
||||
|
|
||||
|
log.info("删除原材料记录,ID: {}, 操作人: {}", id, updatedBy); |
||||
|
|
||||
|
boolean result = erfExpRawMaterialService.deleteRawMaterial(id, updatedBy); |
||||
|
if (result) { |
||||
|
return R.ok("删除成功"); |
||||
|
} else { |
||||
|
return R.error("删除失败"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.error("删除原材料记录失败: " + e.getMessage(), e); |
||||
|
return R.error("删除失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量删除原材料记录(逻辑删除) |
||||
|
* |
||||
|
* @param params 包含ids的参数 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
@PostMapping("/batchDeleteRawMaterial") |
||||
|
@ResponseBody |
||||
|
public R batchDeleteRawMaterial(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
@SuppressWarnings("unchecked") |
||||
|
List<Integer> ids = (List<Integer>) params.get("ids"); |
||||
|
String updatedBy = getUserName(); // 从AbstractController获取当前用户 |
||||
|
|
||||
|
log.info("批量删除原材料记录,ID列表: {}, 操作人: {}", ids, updatedBy); |
||||
|
|
||||
|
boolean result = erfExpRawMaterialService.batchDeleteRawMaterial(ids, updatedBy); |
||||
|
if (result) { |
||||
|
return R.ok("删除成功"); |
||||
|
} else { |
||||
|
return R.error("删除失败"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.error("批量删除原材料记录失败: " + e.getMessage(), e); |
||||
|
return R.error("删除失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据物料编码查询物料描述(从part表) |
||||
|
* |
||||
|
* @param params 包含partNo和site的参数 |
||||
|
* @return 物料描述 |
||||
|
*/ |
||||
|
@PostMapping("/getPartDescByPartNo") |
||||
|
@ResponseBody |
||||
|
public R getPartDescByPartNo(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
String partNo = (String) params.get("partNo"); |
||||
|
String site = (String) params.get("site"); |
||||
|
String buNo = (String) params.get("buNo"); |
||||
|
|
||||
|
log.info("查询物料描述,物料编码: {}, 工厂: {}", partNo, site); |
||||
|
|
||||
|
String partDesc = erfExpRawMaterialService.getPartDescByPartNo(partNo, site, buNo); |
||||
|
|
||||
|
if (partDesc != null) { |
||||
|
return R.ok().put("partDesc", partDesc); |
||||
|
} else { |
||||
|
return R.ok().put("partDesc", "").put("msg", "未找到该物料编码"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.error("查询物料描述失败: " + e.getMessage(), e); |
||||
|
return R.error("查询失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,117 @@ |
|||||
|
package com.xujie.sys.modules.erf.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 工程实验申请单原材料清单实体类 |
||||
|
* |
||||
|
* <p><b>核心字段说明:</b></p> |
||||
|
* <ul> |
||||
|
* <li><b>apply_no</b>:关联申请单号(外键关联erf_exp_apply.apply_no)</li> |
||||
|
* <li><b>part_no</b>:物料编码(允许为NULL,允许不存在于part表)</li> |
||||
|
* <li><b>part_desc</b>:物料描述(必填字段)</li> |
||||
|
* <li><b>quantity</b>:数量(必填字段,支持小数)</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* <p><b>业务规则:</b></p> |
||||
|
* <ul> |
||||
|
* <li>用户输入物料编码后失去焦点或按回车,自动查询part表带出物料描述</li> |
||||
|
* <li>如果物料编码不存在于part表,也允许保存(手动填写物料描述)</li> |
||||
|
* <li>物料描述为必填字段,数量为必填字段</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* @author System |
||||
|
* @since 2026-01-30 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName("erf_exp_raw_material") |
||||
|
public class ErfExpRawMaterial implements Serializable { |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 主键ID(自增) |
||||
|
*/ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private Integer id; |
||||
|
|
||||
|
/** |
||||
|
* 关联申请单号 |
||||
|
*/ |
||||
|
@TableField("apply_no") |
||||
|
private String applyNo; |
||||
|
|
||||
|
/** |
||||
|
* 工厂编码 |
||||
|
*/ |
||||
|
@TableField("site") |
||||
|
private String site; |
||||
|
|
||||
|
/** |
||||
|
* 物料编码(允许为NULL,允许不存在于part表) |
||||
|
*/ |
||||
|
@TableField("part_no") |
||||
|
private String partNo; |
||||
|
|
||||
|
/** |
||||
|
* 物料描述(必填字段) |
||||
|
*/ |
||||
|
@TableField("part_desc") |
||||
|
private String partDesc; |
||||
|
|
||||
|
/** |
||||
|
* 数量(必填字段,支持小数) |
||||
|
*/ |
||||
|
@TableField("quantity") |
||||
|
private BigDecimal quantity; |
||||
|
|
||||
|
/** |
||||
|
* 备注信息(可选) |
||||
|
*/ |
||||
|
@TableField("remark") |
||||
|
private String remark; |
||||
|
|
||||
|
/** |
||||
|
* 创建人 |
||||
|
*/ |
||||
|
@TableField(value = "created_by", fill = FieldFill.INSERT) |
||||
|
private String createdBy; |
||||
|
|
||||
|
/** |
||||
|
* 创建时间 |
||||
|
*/ |
||||
|
@TableField(value = "created_date", fill = FieldFill.INSERT) |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
|
private Date createdDate; |
||||
|
|
||||
|
/** |
||||
|
* 更新人 |
||||
|
*/ |
||||
|
@TableField(value = "updated_by", fill = FieldFill.UPDATE) |
||||
|
private String updatedBy; |
||||
|
|
||||
|
/** |
||||
|
* 更新时间 |
||||
|
*/ |
||||
|
@TableField(value = "updated_date", fill = FieldFill.UPDATE) |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
|
private Date updatedDate; |
||||
|
|
||||
|
/** |
||||
|
* 删除标记(0=未删除, 1=已删除) |
||||
|
*/ |
||||
|
@TableField("is_deleted") |
||||
|
private String isDeleted; |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
package com.xujie.sys.modules.erf.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.xujie.sys.modules.erf.entity.ErfExpRawMaterial; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 工程实验申请单原材料清单Mapper |
||||
|
* |
||||
|
* <p><b>主要功能:</b></p> |
||||
|
* <ul> |
||||
|
* <li>查询指定申请单的原材料清单列表</li> |
||||
|
* <li>根据ID查询单条原材料记录</li> |
||||
|
* <li>新增/修改/删除原材料记录</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* @author System |
||||
|
* @since 2026-01-30 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface ErfExpRawMaterialMapper extends BaseMapper<ErfExpRawMaterial> { |
||||
|
|
||||
|
/** |
||||
|
* 根据申请单号查询原材料清单列表 |
||||
|
* |
||||
|
* @param applyNo 申请单号 |
||||
|
* @return 原材料清单列表 |
||||
|
*/ |
||||
|
List<ErfExpRawMaterial> getRawMaterialListByApplyNo(@Param("applyNo") String applyNo); |
||||
|
|
||||
|
/** |
||||
|
* 根据ID查询单条原材料记录 |
||||
|
* |
||||
|
* @param id 主键ID |
||||
|
* @return 原材料记录 |
||||
|
*/ |
||||
|
ErfExpRawMaterial getRawMaterialById(@Param("id") Integer id); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除原材料记录(逻辑删除) |
||||
|
* |
||||
|
* @param ids ID列表 |
||||
|
* @param updatedBy 更新人 |
||||
|
* @return 影响行数 |
||||
|
*/ |
||||
|
int batchDeleteByIds(@Param("ids") List<Integer> ids, @Param("updatedBy") String updatedBy); |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
package com.xujie.sys.modules.erf.service; |
||||
|
|
||||
|
import com.xujie.sys.modules.erf.entity.ErfExpRawMaterial; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 工程实验申请单原材料清单服务接口 |
||||
|
* |
||||
|
* <p><b>主要功能:</b></p> |
||||
|
* <ul> |
||||
|
* <li>查询指定申请单的原材料清单列表</li> |
||||
|
* <li>保存原材料记录(新增或修改)</li> |
||||
|
* <li>删除原材料记录</li> |
||||
|
* <li>根据物料编码查询物料描述(从part表)</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* @author System |
||||
|
* @since 2026-01-30 |
||||
|
*/ |
||||
|
public interface ErfExpRawMaterialService { |
||||
|
|
||||
|
/** |
||||
|
* 根据申请单号查询原材料清单列表 |
||||
|
* |
||||
|
* @param applyNo 申请单号 |
||||
|
* @return 原材料清单列表 |
||||
|
*/ |
||||
|
List<ErfExpRawMaterial> getRawMaterialListByApplyNo(String applyNo); |
||||
|
|
||||
|
/** |
||||
|
* 根据ID查询单条原材料记录 |
||||
|
* |
||||
|
* @param id 主键ID |
||||
|
* @return 原材料记录 |
||||
|
*/ |
||||
|
ErfExpRawMaterial getRawMaterialById(Integer id); |
||||
|
|
||||
|
/** |
||||
|
* 保存原材料记录(新增或修改) |
||||
|
* |
||||
|
* @param rawMaterial 原材料数据 |
||||
|
* @return 操作结果(成功返回ID) |
||||
|
*/ |
||||
|
Integer saveRawMaterial(ErfExpRawMaterial rawMaterial); |
||||
|
|
||||
|
/** |
||||
|
* 删除原材料记录(逻辑删除) |
||||
|
* |
||||
|
* @param id 主键ID |
||||
|
* @param updatedBy 更新人 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean deleteRawMaterial(Integer id, String updatedBy); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除原材料记录(逻辑删除) |
||||
|
* |
||||
|
* @param ids ID列表 |
||||
|
* @param updatedBy 更新人 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean batchDeleteRawMaterial(List<Integer> ids, String updatedBy); |
||||
|
|
||||
|
/** |
||||
|
* 根据物料编码查询物料描述(从part表) |
||||
|
* |
||||
|
* @param partNo 物料编码 |
||||
|
* @param site 工厂编码 |
||||
|
* @return 物料描述(如果不存在返回null) |
||||
|
*/ |
||||
|
String getPartDescByPartNo(String partNo, String site,String buNo); |
||||
|
} |
||||
@ -0,0 +1,254 @@ |
|||||
|
package com.xujie.sys.modules.erf.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.xujie.sys.common.exception.XJException; |
||||
|
import com.xujie.sys.modules.erf.entity.ErfExpRawMaterial; |
||||
|
import com.xujie.sys.modules.erf.mapper.ErfExpRawMaterialMapper; |
||||
|
import com.xujie.sys.modules.erf.service.ErfExpRawMaterialService; |
||||
|
import com.xujie.sys.modules.part.entity.PartInformationEntity; |
||||
|
import com.xujie.sys.modules.part.mapper.PartInformationMapper; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import org.springframework.util.StringUtils; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 工程实验申请单原材料清单服务实现类 |
||||
|
* |
||||
|
* <p><b>主要功能:</b></p> |
||||
|
* <ul> |
||||
|
* <li>查询指定申请单的原材料清单列表</li> |
||||
|
* <li>保存原材料记录(新增或修改)</li> |
||||
|
* <li>删除原材料记录(逻辑删除)</li> |
||||
|
* <li>根据物料编码查询物料描述(从part表)</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* <p><b>业务规则:</b></p> |
||||
|
* <ul> |
||||
|
* <li>物料编码允许为NULL,允许不存在于part表</li> |
||||
|
* <li>物料描述为必填字段</li> |
||||
|
* <li>数量为必填字段,必须大于0</li> |
||||
|
* <li>删除操作为逻辑删除(is_deleted='1')</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* @author System |
||||
|
* @since 2026-01-30 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@Transactional |
||||
|
public class ErfExpRawMaterialServiceImpl implements ErfExpRawMaterialService { |
||||
|
|
||||
|
@Autowired |
||||
|
private ErfExpRawMaterialMapper erfExpRawMaterialMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private PartInformationMapper partInformationMapper; |
||||
|
|
||||
|
/** |
||||
|
* 根据申请单号查询原材料清单列表 |
||||
|
* |
||||
|
* @param applyNo 申请单号 |
||||
|
* @return 原材料清单列表 |
||||
|
*/ |
||||
|
@Override |
||||
|
public List<ErfExpRawMaterial> getRawMaterialListByApplyNo(String applyNo) { |
||||
|
log.info("查询原材料清单列表,申请单号: {}", applyNo); |
||||
|
|
||||
|
if (!StringUtils.hasText(applyNo)) { |
||||
|
throw new XJException("申请单号不能为空"); |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
List<ErfExpRawMaterial> list = erfExpRawMaterialMapper.getRawMaterialListByApplyNo(applyNo); |
||||
|
log.info("查询到 {} 条原材料记录", list != null ? list.size() : 0); |
||||
|
return list; |
||||
|
} catch (Exception e) { |
||||
|
log.error("查询原材料清单列表失败: " + e.getMessage(), e); |
||||
|
throw new XJException("查询原材料清单失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据ID查询单条原材料记录 |
||||
|
* |
||||
|
* @param id 主键ID |
||||
|
* @return 原材料记录 |
||||
|
*/ |
||||
|
@Override |
||||
|
public ErfExpRawMaterial getRawMaterialById(Integer id) { |
||||
|
log.info("查询原材料记录,ID: {}", id); |
||||
|
|
||||
|
if (id == null) { |
||||
|
throw new XJException("ID不能为空"); |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
return erfExpRawMaterialMapper.getRawMaterialById(id); |
||||
|
} catch (Exception e) { |
||||
|
log.error("查询原材料记录失败: " + e.getMessage(), e); |
||||
|
throw new XJException("查询原材料记录失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存原材料记录(新增或修改) |
||||
|
* |
||||
|
* @param rawMaterial 原材料数据 |
||||
|
* @return 操作结果(成功返回ID) |
||||
|
*/ |
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public Integer saveRawMaterial(ErfExpRawMaterial rawMaterial) { |
||||
|
log.info("保存原材料记录: {}", rawMaterial); |
||||
|
|
||||
|
// 数据验证 |
||||
|
validateRawMaterial(rawMaterial); |
||||
|
|
||||
|
try { |
||||
|
if (rawMaterial.getId() == null || rawMaterial.getId() == 0) { |
||||
|
// 新增 |
||||
|
log.info("新增原材料记录"); |
||||
|
rawMaterial.setIsDeleted("0"); |
||||
|
erfExpRawMaterialMapper.insert(rawMaterial); |
||||
|
log.info("新增原材料记录成功,ID: {}", rawMaterial.getId()); |
||||
|
} else { |
||||
|
// 修改 |
||||
|
log.info("修改原材料记录,ID: {}", rawMaterial.getId()); |
||||
|
rawMaterial.setUpdatedDate(new Date()); |
||||
|
erfExpRawMaterialMapper.updateById(rawMaterial); |
||||
|
log.info("修改原材料记录成功"); |
||||
|
} |
||||
|
|
||||
|
return rawMaterial.getId(); |
||||
|
} catch (Exception e) { |
||||
|
log.error("保存原材料记录失败: " + e.getMessage(), e); |
||||
|
throw new XJException("保存原材料记录失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除原材料记录(逻辑删除) |
||||
|
* |
||||
|
* @param id 主键ID |
||||
|
* @param updatedBy 更新人 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public boolean deleteRawMaterial(Integer id, String updatedBy) { |
||||
|
log.info("删除原材料记录,ID: {}, 操作人: {}", id, updatedBy); |
||||
|
|
||||
|
if (id == null) { |
||||
|
throw new XJException("ID不能为空"); |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
return batchDeleteRawMaterial(Arrays.asList(id), updatedBy); |
||||
|
} catch (Exception e) { |
||||
|
log.error("删除原材料记录失败: " + e.getMessage(), e); |
||||
|
throw new XJException("删除原材料记录失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量删除原材料记录(逻辑删除) |
||||
|
* |
||||
|
* @param ids ID列表 |
||||
|
* @param updatedBy 更新人 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public boolean batchDeleteRawMaterial(List<Integer> ids, String updatedBy) { |
||||
|
log.info("批量删除原材料记录,ID列表: {}, 操作人: {}", ids, updatedBy); |
||||
|
|
||||
|
if (ids == null || ids.isEmpty()) { |
||||
|
throw new XJException("ID列表不能为空"); |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
int rows = erfExpRawMaterialMapper.batchDeleteByIds(ids, updatedBy); |
||||
|
log.info("批量删除成功,影响行数: {}", rows); |
||||
|
return rows > 0; |
||||
|
} catch (Exception e) { |
||||
|
log.error("批量删除原材料记录失败: " + e.getMessage(), e); |
||||
|
throw new XJException("批量删除原材料记录失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据物料编码查询物料描述(从part表) |
||||
|
* |
||||
|
* @param partNo 物料编码 |
||||
|
* @param site 工厂编码 |
||||
|
* @return 物料描述(如果不存在返回null) |
||||
|
*/ |
||||
|
@Override |
||||
|
public String getPartDescByPartNo(String partNo, String site,String buNo) { |
||||
|
log.info("查询物料描述,物料编码: {}, 工厂: {}", partNo, site); |
||||
|
|
||||
|
if (!StringUtils.hasText(partNo)) { |
||||
|
log.warn("物料编码为空,无法查询"); |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
QueryWrapper<PartInformationEntity> queryWrapper = new QueryWrapper<>(); |
||||
|
queryWrapper.eq("part_no", partNo); |
||||
|
if (StringUtils.hasText(site)) { |
||||
|
queryWrapper.eq("site", site); |
||||
|
} |
||||
|
if (StringUtils.hasText(buNo)) { |
||||
|
queryWrapper.eq("sourceBu", buNo); |
||||
|
} |
||||
|
queryWrapper.eq("active", "Y"); // 只查询在用的物料 |
||||
|
|
||||
|
PartInformationEntity part = partInformationMapper.selectOne(queryWrapper); |
||||
|
|
||||
|
if (part != null) { |
||||
|
log.info("查询到物料描述: {}", part.getPartDesc()); |
||||
|
return part.getPartDesc(); |
||||
|
} else { |
||||
|
log.warn("未查询到物料编码: {} 对应的物料信息", partNo); |
||||
|
return null; |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.error("查询物料描述失败: " + e.getMessage(), e); |
||||
|
// 查询失败不抛异常,返回null即可 |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 验证原材料数据 |
||||
|
* |
||||
|
* @param rawMaterial 原材料数据 |
||||
|
*/ |
||||
|
private void validateRawMaterial(ErfExpRawMaterial rawMaterial) { |
||||
|
if (rawMaterial == null) { |
||||
|
throw new XJException("原材料数据不能为空"); |
||||
|
} |
||||
|
|
||||
|
if (!StringUtils.hasText(rawMaterial.getApplyNo())) { |
||||
|
throw new XJException("申请单号不能为空"); |
||||
|
} |
||||
|
|
||||
|
if (!StringUtils.hasText(rawMaterial.getSite())) { |
||||
|
throw new XJException("工厂编码不能为空"); |
||||
|
} |
||||
|
|
||||
|
if (!StringUtils.hasText(rawMaterial.getPartDesc())) { |
||||
|
throw new XJException("物料描述不能为空"); |
||||
|
} |
||||
|
|
||||
|
if (rawMaterial.getQuantity() == null || rawMaterial.getQuantity().doubleValue() <= 0) { |
||||
|
throw new XJException("数量必须大于0"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
|
||||
|
<mapper namespace="com.xujie.sys.modules.erf.mapper.ErfExpRawMaterialMapper"> |
||||
|
|
||||
|
<!-- 结果映射 --> |
||||
|
<resultMap id="ErfExpRawMaterialMap" type="com.xujie.sys.modules.erf.entity.ErfExpRawMaterial"> |
||||
|
<id property="id" column="id" /> |
||||
|
<result property="applyNo" column="apply_no" /> |
||||
|
<result property="site" column="site" /> |
||||
|
<result property="partNo" column="part_no" /> |
||||
|
<result property="partDesc" column="part_desc" /> |
||||
|
<result property="quantity" column="quantity" /> |
||||
|
<result property="remark" column="remark" /> |
||||
|
<result property="createdBy" column="created_by" /> |
||||
|
<result property="createdDate" column="created_date" /> |
||||
|
<result property="updatedBy" column="updated_by" /> |
||||
|
<result property="updatedDate" column="updated_date" /> |
||||
|
<result property="isDeleted" column="is_deleted" /> |
||||
|
</resultMap> |
||||
|
|
||||
|
<!-- 根据申请单号查询原材料清单列表 --> |
||||
|
<select id="getRawMaterialListByApplyNo" resultMap="ErfExpRawMaterialMap"> |
||||
|
SELECT |
||||
|
id, |
||||
|
apply_no, |
||||
|
site, |
||||
|
part_no, |
||||
|
part_desc, |
||||
|
quantity, |
||||
|
remark, |
||||
|
created_by, |
||||
|
created_date, |
||||
|
updated_by, |
||||
|
updated_date, |
||||
|
is_deleted |
||||
|
FROM erf_exp_raw_material |
||||
|
WHERE apply_no = #{applyNo} |
||||
|
AND is_deleted = '0' |
||||
|
ORDER BY id ASC |
||||
|
</select> |
||||
|
|
||||
|
<!-- 根据ID查询单条原材料记录 --> |
||||
|
<select id="getRawMaterialById" resultMap="ErfExpRawMaterialMap"> |
||||
|
SELECT |
||||
|
id, |
||||
|
apply_no, |
||||
|
site, |
||||
|
part_no, |
||||
|
part_desc, |
||||
|
quantity, |
||||
|
remark, |
||||
|
created_by, |
||||
|
created_date, |
||||
|
updated_by, |
||||
|
updated_date, |
||||
|
is_deleted |
||||
|
FROM erf_exp_raw_material |
||||
|
WHERE id = #{id} |
||||
|
AND is_deleted = '0' |
||||
|
</select> |
||||
|
|
||||
|
<!-- 批量删除原材料记录(逻辑删除) --> |
||||
|
<delete id="batchDeleteByIds"> |
||||
|
delete erf_exp_raw_material |
||||
|
WHERE id IN |
||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")"> |
||||
|
#{id} |
||||
|
</foreach> |
||||
|
</delete> |
||||
|
|
||||
|
</mapper> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue