完成了配方配置

plp
86158 3 weeks ago
parent b58325c344
commit 0e562a9678

@ -90,8 +90,9 @@ public class MoldBrandController {
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<MoldBrandRespVO> list = moldBrandService.getMoldBrandPage(pageReqVO).getList();
List<MoldBrandRespVO> moldBrandRespVOS = BeanUtils.toBean(list, MoldBrandRespVO.class);
// 导出 Excel
ExcelUtils.write(response, "模具型号.xls", "数据", MoldBrandRespVO.class, list);
ExcelUtils.write(response, "模具型号.xls", "数据", MoldBrandRespVO.class, moldBrandRespVOS);
}
// ==================== 子表(模具) ====================

@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.erp.controller.admin.mold.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum OrgTypeStatusEnum {
zhijiang("zhijiang", "制浆"),
duidie("duidie", "堆叠"),
chengxing("chengxing", "成型"),
honggan("honggan", "烘干"),
zhuanyi("zhuanyi", "转移"),
jiashi("jiashi", "加湿"),
reya("reya", "热压"),
qiebian("qiebian", "切边"),
pinjian("pinjian", "品检"),
dabao("dabao", "打包"),
tiebiao("tiebiao", "贴标"),
sufeng("sufeng", "塑封"),
pinyin("pinyin", "品印");
private final String orgtype;
private final String description;
public static OrgTypeStatusEnum getByCode(String code) {
for (OrgTypeStatusEnum status : values()) {
if (status.getOrgtype().equals(code)) {
return status;
}
}
return null;
}
}

@ -53,4 +53,7 @@ public class MoldBrandPageReqVO extends PageParam {
@Schema(description = "工序", example = "你说的对")
private String orgType;
@Schema(description = "id集合导出用")
private String ids;
}

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
@ -11,6 +12,7 @@ import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 模具型号 Response VO")
@Data
@ExcelIgnoreUnannotated
@ -35,24 +37,24 @@ public class MoldBrandRespVO {
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
private Long productId;
@Schema(description = "产品", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
@ExcelProperty("产品")
// @ExcelProperty("产品")
private String productName;
@Schema(description = "预期寿命(小时)")
@ExcelProperty("预期寿命(小时)")
@Schema(description = "预期寿命/次")
@ExcelProperty("预期寿命/次")
private BigDecimal useTime;
@Schema(description = "维保模式", example = "2")
@ExcelProperty(value = "维保模式", converter = DictConvert.class)
// @ExcelProperty(value = "维保模式", converter = DictConvert.class)
@DictFormat("maintain_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Integer maintainType;
@Schema(description = "维保周期")
@ExcelProperty("维保周期")
// @ExcelProperty("维保周期")
private BigDecimal maintainTime;
@Schema(description = "模具系数", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("模具系数")
@Schema(description = "模数", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("模数")
private Long moldSize;
@Schema(description = "备注", example = "你说的对")
@ -60,14 +62,17 @@ public class MoldBrandRespVO {
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("是否启用")
// @ExcelProperty("是否启用")
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
@ColumnWidth(20)
private LocalDateTime createTime;
@Schema(description = "工序", example = "你说的对")
@DictFormat("mes_org_type")
@ExcelProperty(value = "工序")
private String orgType;
// , converter = OrgTypeConverter.class
}

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
@ -54,4 +55,10 @@ public class MoldPageReqVO extends PageParam {
@Schema(description = "型号id", example = "15258")
private Long brandId;
@Schema(description = "id集合导出用")
private String ids;
// @Schema(description = "机台名字")
// private String machineName;
}

@ -34,15 +34,15 @@ public class MoldRespVO {
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19527")
private Long unitId;
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "个")
@ExcelProperty("单位")
// @ExcelProperty("单位")
private String unitName;
@Schema(description = "机台ID", example = "24428")
@ExcelProperty("机台ID")
@Schema(description = "设备ID", example = "24428")
@ExcelProperty("使用设备")
private Long machineId;
@Schema(description = "使用时间(小时)")
@ExcelProperty("使用时间(小时)")
@Schema(description = "使用次数/次")
@ExcelProperty("使用次数/次")
private BigDecimal useTime;
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ -56,7 +56,7 @@ public class MoldRespVO {
private Integer status;
@Schema(description = "模具图片")
@ExcelProperty("模具图片")
// @ExcelProperty("模具图片")
private String images;
@Schema(description = "备注", example = "你猜")
@ -64,15 +64,19 @@ public class MoldRespVO {
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("是否启用")
// @ExcelProperty("是否启用")
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
// @ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "型号id", requiredMode = Schema.RequiredMode.REQUIRED, example = "15258")
@ExcelProperty("型号id")
private Long brandId;
@Schema(description = "附件地址")
@ExcelProperty("附件地址")
private String fileUrl;
}

@ -0,0 +1,86 @@
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
import cn.iocoder.yudao.module.erp.controller.admin.mold.enums.OrgTypeStatusEnum;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.springframework.stereotype.Component;
/**
*
*/
@Component
public class OrgTypeConverter implements Converter<String> { // 泛型改为 String对应英文字符串
/**
* ExcelExcel/ Java
*/
@Override
public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
String cellValue = cellData.getStringValue();
if (cellValue == null || cellValue.trim().isEmpty()) {
return null;
}
// 优先匹配中文 → 转换为对应的英文常量名
for (OrgTypeStatusEnum status : OrgTypeStatusEnum.values()) {
if (status.getDescription().equals(cellValue)) { // 注意枚举的描述方法是 getDesc
return status.name(); // 返回枚举的英文常量名(如 IN_USE
}
}
// 匹配英文 → 直接返回兼容Excel中填英文的场景
for (OrgTypeStatusEnum status : OrgTypeStatusEnum.values()) {
if (status.name().equals(cellValue)) {
return cellValue;
}
}
// 无匹配则抛出异常
throw new IllegalArgumentException("设备状态格式错误: " + cellValue + ",仅支持中文(在机/在库/维修中/保养中/报废或英文IN_USE/IN_STOCK/UNDER_REPAIR/UNDER_MAINTENANCE/SCRAPPED");
}
/**
* ExcelJava Excel
*/
@Override
public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (value == null || value.trim().isEmpty()) {
return new WriteCellData<>("");
}
// 根据英文常量名匹配枚举,转换为中文
OrgTypeStatusEnum status = null;
try {
status = OrgTypeStatusEnum.valueOf(value); // 通过英文名称获取枚举
} catch (IllegalArgumentException e) {
// 若英文匹配失败,尝试兜底匹配中文(兼容异常场景)
for (OrgTypeStatusEnum s : OrgTypeStatusEnum.values()) {
if (s.getDescription().equals(value)) {
status = s;
break;
}
}
}
String text = status != null ? status.getDescription() : "未知";
return new WriteCellData<>(text);
}
// 必须实现的接口方法指定转换的Java类型
@Override
public Class<?> supportJavaTypeKey() {
return String.class;
}
// 必须实现的接口方法指定Excel单元格类型
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
}

@ -5,9 +5,13 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.MoldBrandPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldBrandDO;
import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Mapper
@ -18,7 +22,23 @@ import java.util.List;
public interface MoldBrandMapper extends BaseMapperX<MoldBrandDO> {
default PageResult<MoldBrandDO> selectPage(MoldBrandPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MoldBrandDO>()
// return selectPage(reqVO, new LambdaQueryWrapperX<MoldBrandDO>()
// .eqIfPresent(MoldBrandDO::getCode, reqVO.getCode())
// .likeIfPresent(MoldBrandDO::getName, reqVO.getName())
// .eqIfPresent(MoldBrandDO::getMoldType, reqVO.getMoldType())
// .eqIfPresent(MoldBrandDO::getProductId, reqVO.getProductId())
// .eqIfPresent(MoldBrandDO::getUseTime, reqVO.getUseTime())
// .eqIfPresent(MoldBrandDO::getMaintainType, reqVO.getMaintainType())
// .eqIfPresent(MoldBrandDO::getMaintainTime, reqVO.getMaintainTime())
// .eqIfPresent(MoldBrandDO::getMoldSize, reqVO.getMoldSize())
// .eqIfPresent(MoldBrandDO::getRemark, reqVO.getRemark())
// .eqIfPresent(MoldBrandDO::getIsEnable, reqVO.getIsEnable())
// .eqIfPresent(MoldBrandDO::getOrgType, reqVO.getOrgType())
// .betweenIfPresent(MoldBrandDO::getCreateTime, reqVO.getCreateTime())
// .orderByDesc(MoldBrandDO::getId));
LambdaQueryWrapperX<MoldBrandDO> moldBrandDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
moldBrandDOLambdaQueryWrapperX
.eqIfPresent(MoldBrandDO::getCode, reqVO.getCode())
.likeIfPresent(MoldBrandDO::getName, reqVO.getName())
.eqIfPresent(MoldBrandDO::getMoldType, reqVO.getMoldType())
@ -29,8 +49,24 @@ public interface MoldBrandMapper extends BaseMapperX<MoldBrandDO> {
.eqIfPresent(MoldBrandDO::getMoldSize, reqVO.getMoldSize())
.eqIfPresent(MoldBrandDO::getRemark, reqVO.getRemark())
.eqIfPresent(MoldBrandDO::getIsEnable, reqVO.getIsEnable())
.eqIfPresent(MoldBrandDO::getOrgType, reqVO.getOrgType())
.betweenIfPresent(MoldBrandDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MoldBrandDO::getId));
.orderByDesc(MoldBrandDO::getId);
// 单独处理 ids 条件
if (StringUtils.isNotBlank(reqVO.getIds())) {
List<Long> idList = Arrays.stream(reqVO.getIds().split(","))
.map(String::trim)
.map(Long::valueOf)
.collect(Collectors.toList());
moldBrandDOLambdaQueryWrapperX.in(MoldBrandDO::getId, idList);
}
return selectPage(reqVO, moldBrandDOLambdaQueryWrapperX);
}
default List<MoldBrandDO> selectBy(MoldBrandPageReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<MoldBrandDO>()
@ -44,6 +80,7 @@ public interface MoldBrandMapper extends BaseMapperX<MoldBrandDO> {
.eqIfPresent(MoldBrandDO::getMoldSize, reqVO.getMoldSize())
.eqIfPresent(MoldBrandDO::getRemark, reqVO.getRemark())
.eqIfPresent(MoldBrandDO::getIsEnable, reqVO.getIsEnable())
.eqIfPresent(MoldBrandDO::getOrgType, reqVO.getOrgType())
.betweenIfPresent(MoldBrandDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MoldBrandDO::getId));
}

@ -91,11 +91,13 @@ public class MoldBrandServiceImpl implements MoldBrandService {
public List<MoldBrandDO> selectBy(MoldBrandPageReqVO reqVO){
return moldBrandMapper.selectBy(reqVO);
}
@Override
public PageResult<MoldBrandRespVO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) {
PageResult<MoldBrandDO> pageResult = moldBrandMapper.selectPage(pageReqVO);
return new PageResult<>(buildMoldBrandVOList(pageResult.getList()),pageResult.getTotal());
return new PageResult<>(buildMoldBrandVOList(pageResult.getList()), pageResult.getTotal());
}
private List<MoldBrandRespVO> buildMoldBrandVOList(List<MoldBrandDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();

Loading…
Cancel
Save