6 changed files with 485 additions and 0 deletions
-
33src/main/java/com/gaotao/modules/factory/dao/PartAttributeMapper.java
-
59src/main/java/com/gaotao/modules/factory/entity/PartAttribute.java
-
40src/main/java/com/gaotao/modules/factory/entity/dto/PartAttributeQueryDto.java
-
50src/main/java/com/gaotao/modules/factory/service/PartAttributeService.java
-
246src/main/java/com/gaotao/modules/factory/service/impl/PartAttributeServiceImpl.java
-
57src/main/resources/mapper/factory/PartAttributeMapper.xml
@ -0,0 +1,33 @@ |
|||||
|
package com.gaotao.modules.factory.dao; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.gaotao.modules.factory.entity.PartAttribute; |
||||
|
import com.gaotao.modules.factory.entity.dto.PartAttributeQueryDto; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 料件属性Mapper接口 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface PartAttributeMapper extends BaseMapper<PartAttribute> { |
||||
|
|
||||
|
/** |
||||
|
* 分页查询料件属性列表 |
||||
|
*/ |
||||
|
IPage<PartAttribute> getPartAttributeList(Page<PartAttribute> page, @Param("params") PartAttributeQueryDto queryDto); |
||||
|
|
||||
|
/** |
||||
|
* 查询料件属性列表(不分页) |
||||
|
*/ |
||||
|
List<PartAttribute> getPartAttributeList(@Param("params") PartAttributeQueryDto queryDto); |
||||
|
|
||||
|
/** |
||||
|
* 根据站点和料号查询料件属性 |
||||
|
*/ |
||||
|
PartAttribute getPartAttributeByKey(@Param("site") String site, @Param("partNo") String partNo); |
||||
|
} |
||||
@ -0,0 +1,59 @@ |
|||||
|
package com.gaotao.modules.factory.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* 料件属性实体类 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName("part_attribute") |
||||
|
public class PartAttribute { |
||||
|
|
||||
|
/** |
||||
|
* 工厂/站点 |
||||
|
*/ |
||||
|
private String site; |
||||
|
|
||||
|
/** |
||||
|
* 料号 |
||||
|
*/ |
||||
|
private String partNo; |
||||
|
|
||||
|
/** |
||||
|
* 是否进立库 (Y/N) |
||||
|
*/ |
||||
|
private String isInWh; |
||||
|
|
||||
|
/** |
||||
|
* 是否机械手臂拣选 (Y/N) |
||||
|
*/ |
||||
|
private String isRobotPick; |
||||
|
|
||||
|
/** |
||||
|
* 重量 (kg) |
||||
|
*/ |
||||
|
private BigDecimal weight; |
||||
|
|
||||
|
/** |
||||
|
* 长度 (mm) |
||||
|
*/ |
||||
|
private BigDecimal length; |
||||
|
|
||||
|
/** |
||||
|
* 宽度 (mm) |
||||
|
*/ |
||||
|
private BigDecimal width; |
||||
|
|
||||
|
/** |
||||
|
* 高度 (mm) |
||||
|
*/ |
||||
|
private BigDecimal height; |
||||
|
|
||||
|
/** |
||||
|
* 直径 (mm) |
||||
|
*/ |
||||
|
private BigDecimal diameter; |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
package com.gaotao.modules.factory.entity.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* 料件属性查询DTO |
||||
|
*/ |
||||
|
@Data |
||||
|
public class PartAttributeQueryDto { |
||||
|
|
||||
|
/** |
||||
|
* 当前页 |
||||
|
*/ |
||||
|
private int page = 1; |
||||
|
|
||||
|
/** |
||||
|
* 每页显示条数 |
||||
|
*/ |
||||
|
private int size = 10; |
||||
|
|
||||
|
/** |
||||
|
* 工厂/站点 |
||||
|
*/ |
||||
|
private String site; |
||||
|
|
||||
|
/** |
||||
|
* 料号(支持模糊查询) |
||||
|
*/ |
||||
|
private String partNo; |
||||
|
|
||||
|
/** |
||||
|
* 是否进立库 (Y/N) |
||||
|
*/ |
||||
|
private String isInWh; |
||||
|
|
||||
|
/** |
||||
|
* 是否机械手臂拣选 (Y/N) |
||||
|
*/ |
||||
|
private String isRobotPick; |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
package com.gaotao.modules.factory.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.gaotao.common.utils.PageUtils; |
||||
|
import com.gaotao.common.utils.R; |
||||
|
import com.gaotao.modules.factory.entity.PartAttribute; |
||||
|
import com.gaotao.modules.factory.entity.dto.PartAttributeQueryDto; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 料件属性服务接口 |
||||
|
*/ |
||||
|
public interface PartAttributeService extends IService<PartAttribute> { |
||||
|
|
||||
|
/** |
||||
|
* 分页查询料件属性列表 |
||||
|
*/ |
||||
|
PageUtils getPartAttributeList(PartAttributeQueryDto queryDto); |
||||
|
|
||||
|
/** |
||||
|
* 根据站点和料号查询料件属性 |
||||
|
*/ |
||||
|
PartAttribute getPartAttributeByKey(String site, String partNo); |
||||
|
|
||||
|
/** |
||||
|
* 新增料件属性 |
||||
|
*/ |
||||
|
R savePartAttribute(PartAttribute partAttribute); |
||||
|
|
||||
|
/** |
||||
|
* 修改料件属性 |
||||
|
*/ |
||||
|
R updatePartAttribute(PartAttribute partAttribute); |
||||
|
|
||||
|
/** |
||||
|
* 删除料件属性 |
||||
|
*/ |
||||
|
R deletePartAttribute(String site, String partNo); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除料件属性 |
||||
|
*/ |
||||
|
R batchDeletePartAttribute(List<PartAttribute> partAttributes); |
||||
|
|
||||
|
/** |
||||
|
* 验证料件属性数据 |
||||
|
*/ |
||||
|
R validatePartAttribute(PartAttribute partAttribute); |
||||
|
} |
||||
@ -0,0 +1,246 @@ |
|||||
|
package com.gaotao.modules.factory.service.impl; |
||||
|
|
||||
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.gaotao.common.exception.XJException; |
||||
|
import com.gaotao.common.utils.PageUtils; |
||||
|
import com.gaotao.common.utils.R; |
||||
|
import com.gaotao.modules.factory.dao.PartAttributeMapper; |
||||
|
import com.gaotao.modules.factory.entity.PartAttribute; |
||||
|
import com.gaotao.modules.factory.entity.dto.PartAttributeQueryDto; |
||||
|
import com.gaotao.modules.factory.service.PartAttributeService; |
||||
|
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.List; |
||||
|
|
||||
|
/** |
||||
|
* 料件属性服务实现类 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
public class PartAttributeServiceImpl extends ServiceImpl<PartAttributeMapper, PartAttribute> implements PartAttributeService { |
||||
|
|
||||
|
@Autowired |
||||
|
private PartAttributeMapper partAttributeMapper; |
||||
|
|
||||
|
@Override |
||||
|
public PageUtils getPartAttributeList(PartAttributeQueryDto queryDto) { |
||||
|
IPage<PartAttribute> page = partAttributeMapper.getPartAttributeList( |
||||
|
new Page<>(queryDto.getPage(), queryDto.getSize()), queryDto); |
||||
|
return new PageUtils(page); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public PartAttribute getPartAttributeByKey(String site, String partNo) { |
||||
|
return partAttributeMapper.getPartAttributeByKey(site, partNo); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional |
||||
|
public R savePartAttribute(PartAttribute partAttribute) { |
||||
|
try { |
||||
|
// 数据验证 |
||||
|
R validateResult = validatePartAttribute(partAttribute); |
||||
|
if ((int)validateResult.get("code") != 0) { |
||||
|
return validateResult; |
||||
|
} |
||||
|
|
||||
|
// 检查是否已存在 |
||||
|
PartAttribute existing = getPartAttributeByKey(partAttribute.getSite(), partAttribute.getPartNo()); |
||||
|
if (existing != null) { |
||||
|
return R.error("料件属性已存在,请使用修改功能"); |
||||
|
} |
||||
|
|
||||
|
// 设置默认值 |
||||
|
if (!StringUtils.hasText(partAttribute.getIsInWh())) { |
||||
|
partAttribute.setIsInWh("N"); |
||||
|
} |
||||
|
if (!StringUtils.hasText(partAttribute.getIsRobotPick())) { |
||||
|
partAttribute.setIsRobotPick("N"); |
||||
|
} |
||||
|
|
||||
|
// 保存 |
||||
|
this.save(partAttribute); |
||||
|
|
||||
|
return R.ok("新增料件属性成功"); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("新增料件属性失败: {}", e.getMessage(), e); |
||||
|
throw new XJException("新增料件属性失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional |
||||
|
public R updatePartAttribute(PartAttribute partAttribute) { |
||||
|
try { |
||||
|
// 数据验证 |
||||
|
R validateResult = validatePartAttribute(partAttribute); |
||||
|
if ((int)validateResult.get("code") != 0) { |
||||
|
return validateResult; |
||||
|
} |
||||
|
|
||||
|
// 检查记录是否存在 |
||||
|
PartAttribute existing = getPartAttributeByKey(partAttribute.getSite(), partAttribute.getPartNo()); |
||||
|
if (existing == null) { |
||||
|
return R.error("料件属性不存在"); |
||||
|
} |
||||
|
|
||||
|
// 构建更新条件 |
||||
|
LambdaQueryWrapper<PartAttribute> wrapper = new LambdaQueryWrapper<>(); |
||||
|
wrapper.eq(PartAttribute::getSite, partAttribute.getSite()) |
||||
|
.eq(PartAttribute::getPartNo, partAttribute.getPartNo()); |
||||
|
|
||||
|
// 更新 |
||||
|
this.update(partAttribute, wrapper); |
||||
|
|
||||
|
return R.ok("修改料件属性成功"); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("修改料件属性失败: {}", e.getMessage(), e); |
||||
|
throw new XJException("修改料件属性失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional |
||||
|
public R deletePartAttribute(String site, String partNo) { |
||||
|
try { |
||||
|
// 检查记录是否存在 |
||||
|
PartAttribute existing = getPartAttributeByKey(site, partNo); |
||||
|
if (existing == null) { |
||||
|
return R.error("料件属性不存在"); |
||||
|
} |
||||
|
|
||||
|
// 构建删除条件 |
||||
|
LambdaQueryWrapper<PartAttribute> wrapper = new LambdaQueryWrapper<>(); |
||||
|
wrapper.eq(PartAttribute::getSite, site) |
||||
|
.eq(PartAttribute::getPartNo, partNo); |
||||
|
|
||||
|
// 删除 |
||||
|
this.remove(wrapper); |
||||
|
|
||||
|
return R.ok("删除料件属性成功"); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("删除料件属性失败: {}", e.getMessage(), e); |
||||
|
throw new XJException("删除料件属性失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional |
||||
|
public R batchDeletePartAttribute(List<PartAttribute> partAttributes) { |
||||
|
try { |
||||
|
if (partAttributes == null || partAttributes.isEmpty()) { |
||||
|
return R.error("删除列表不能为空"); |
||||
|
} |
||||
|
|
||||
|
int successCount = 0; |
||||
|
int failCount = 0; |
||||
|
StringBuilder errorMsg = new StringBuilder(); |
||||
|
|
||||
|
for (PartAttribute partAttribute : partAttributes) { |
||||
|
try { |
||||
|
R result = deletePartAttribute(partAttribute.getSite(), partAttribute.getPartNo()); |
||||
|
if ((int)result.get("code") == 0) { |
||||
|
successCount++; |
||||
|
} else { |
||||
|
failCount++; |
||||
|
errorMsg.append("料号").append(partAttribute.getPartNo()).append("删除失败: ") |
||||
|
.append(result.get("msg")).append("; "); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
failCount++; |
||||
|
errorMsg.append("料号").append(partAttribute.getPartNo()).append("删除异常: ") |
||||
|
.append(e.getMessage()).append("; "); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
String resultMsg = String.format("批量删除完成,成功%d条,失败%d条", successCount, failCount); |
||||
|
if (failCount > 0) { |
||||
|
resultMsg += "。失败原因: " + errorMsg.toString(); |
||||
|
} |
||||
|
|
||||
|
if (failCount == 0) { |
||||
|
return R.ok(resultMsg); |
||||
|
} else if (successCount > 0) { |
||||
|
return R.ok(resultMsg).put("hasError", true); |
||||
|
} else { |
||||
|
return R.error(resultMsg); |
||||
|
} |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("批量删除料件属性失败: {}", e.getMessage(), e); |
||||
|
throw new XJException("批量删除料件属性失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public R validatePartAttribute(PartAttribute partAttribute) { |
||||
|
if (partAttribute == null) { |
||||
|
return R.error("料件属性数据不能为空"); |
||||
|
} |
||||
|
|
||||
|
if (!StringUtils.hasText(partAttribute.getSite())) { |
||||
|
return R.error("工厂/站点不能为空"); |
||||
|
} |
||||
|
|
||||
|
if (!StringUtils.hasText(partAttribute.getPartNo())) { |
||||
|
return R.error("料号不能为空"); |
||||
|
} |
||||
|
|
||||
|
// 验证工厂/站点长度 |
||||
|
if (partAttribute.getSite().length() > 50) { |
||||
|
return R.error("工厂/站点长度不能超过50个字符"); |
||||
|
} |
||||
|
|
||||
|
// 验证料号长度 |
||||
|
if (partAttribute.getPartNo().length() > 100) { |
||||
|
return R.error("料号长度不能超过100个字符"); |
||||
|
} |
||||
|
|
||||
|
// 验证是否进立库字段 |
||||
|
if (StringUtils.hasText(partAttribute.getIsInWh())) { |
||||
|
if (!"Y".equals(partAttribute.getIsInWh()) && !"N".equals(partAttribute.getIsInWh())) { |
||||
|
return R.error("是否进立库只能填写Y或N"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证是否机械手臂拣选字段 |
||||
|
if (StringUtils.hasText(partAttribute.getIsRobotPick())) { |
||||
|
if (!"Y".equals(partAttribute.getIsRobotPick()) && !"N".equals(partAttribute.getIsRobotPick())) { |
||||
|
return R.error("是否机械手臂拣选只能填写Y或N"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证数值字段不能为负数 |
||||
|
if (partAttribute.getWeight() != null && partAttribute.getWeight().signum() < 0) { |
||||
|
return R.error("重量不能为负数"); |
||||
|
} |
||||
|
|
||||
|
if (partAttribute.getLength() != null && partAttribute.getLength().signum() < 0) { |
||||
|
return R.error("长度不能为负数"); |
||||
|
} |
||||
|
|
||||
|
if (partAttribute.getWidth() != null && partAttribute.getWidth().signum() < 0) { |
||||
|
return R.error("宽度不能为负数"); |
||||
|
} |
||||
|
|
||||
|
if (partAttribute.getHeight() != null && partAttribute.getHeight().signum() < 0) { |
||||
|
return R.error("高度不能为负数"); |
||||
|
} |
||||
|
|
||||
|
if (partAttribute.getDiameter() != null && partAttribute.getDiameter().signum() < 0) { |
||||
|
return R.error("直径不能为负数"); |
||||
|
} |
||||
|
|
||||
|
return R.ok(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
<?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.gaotao.modules.factory.dao.PartAttributeMapper"> |
||||
|
|
||||
|
<!-- 结果映射 --> |
||||
|
<resultMap id="PartAttributeResult" type="com.gaotao.modules.factory.entity.PartAttribute"> |
||||
|
<id property="site" column="site"/> |
||||
|
<id property="partNo" column="part_no"/> |
||||
|
<result property="isInWh" column="is_in_wh"/> |
||||
|
<result property="isRobotPick" column="is_robot_pick"/> |
||||
|
<result property="weight" column="weight"/> |
||||
|
<result property="length" column="length"/> |
||||
|
<result property="width" column="width"/> |
||||
|
<result property="height" column="height"/> |
||||
|
<result property="diameter" column="diameter"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<!-- 基础查询SQL --> |
||||
|
<sql id="selectPartAttributeVo"> |
||||
|
SELECT site, part_no, is_in_wh, is_robot_pick, weight, length, width, height, diameter |
||||
|
FROM part_attribute |
||||
|
</sql> |
||||
|
|
||||
|
<!-- 查询条件 --> |
||||
|
<sql id="whereCondition"> |
||||
|
<where> |
||||
|
<if test="params.site != null and params.site != ''"> |
||||
|
AND site = #{params.site} |
||||
|
</if> |
||||
|
<if test="params.partNo != null and params.partNo != ''"> |
||||
|
AND part_no LIKE CONCAT('%', #{params.partNo}, '%') |
||||
|
</if> |
||||
|
<if test="params.isInWh != null and params.isInWh != ''"> |
||||
|
AND is_in_wh = #{params.isInWh} |
||||
|
</if> |
||||
|
<if test="params.isRobotPick != null and params.isRobotPick != ''"> |
||||
|
AND is_robot_pick = #{params.isRobotPick} |
||||
|
</if> |
||||
|
</where> |
||||
|
</sql> |
||||
|
|
||||
|
<!-- 分页查询料件属性列表 --> |
||||
|
<select id="getPartAttributeList" parameterType="com.gaotao.modules.factory.entity.dto.PartAttributeQueryDto" |
||||
|
resultMap="PartAttributeResult"> |
||||
|
<include refid="selectPartAttributeVo"/> |
||||
|
<include refid="whereCondition"/> |
||||
|
ORDER BY site, part_no |
||||
|
</select> |
||||
|
|
||||
|
<!-- 根据站点和料号查询料件属性 --> |
||||
|
<select id="getPartAttributeByKey" resultMap="PartAttributeResult"> |
||||
|
<include refid="selectPartAttributeVo"/> |
||||
|
WHERE site = #{site} AND part_no = #{partNo} |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue