From 3ea03e3c19eef31507bd075d36ae3466df5fee71 Mon Sep 17 00:00:00 2001 From: HashMap Date: Sun, 18 Jan 2026 14:57:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(module/feed):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=8E=9F=E6=96=99=E7=AE=A1=E7=90=86=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对前端原料管理页面的支持 --- .../Exception/MaterialExceptionHandler.java | 21 ++++++ .../feed/controller/SgMaterialController.java | 16 ++--- .../zhyc/module/feed/domain/SgMaterial.java | 65 +++++++++++++++++-- .../module/feed/mapper/SgMaterialMapper.java | 18 ++--- .../feed/service/ISgMaterialService.java | 30 ++++----- .../service/impl/SgMaterialServiceImpl.java | 34 ++++------ .../mapper/feed/SgMaterialMapper.xml | 20 +++--- 7 files changed, 135 insertions(+), 69 deletions(-) create mode 100644 zhyc-module/src/main/java/com/zhyc/module/feed/controller/Exception/MaterialExceptionHandler.java diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/Exception/MaterialExceptionHandler.java b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/Exception/MaterialExceptionHandler.java new file mode 100644 index 0000000..71bd09a --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/Exception/MaterialExceptionHandler.java @@ -0,0 +1,21 @@ +package com.zhyc.module.feed.controller.Exception; + +import com.zhyc.common.core.domain.AjaxResult; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import javax.servlet.http.HttpServletRequest; + +@ControllerAdvice +public class MaterialExceptionHandler { + + @ExceptionHandler({Exception.class, RuntimeException.class}) + public AjaxResult handleException(HttpServletRequest request, Exception ex) { + AjaxResult ajaxResult = new AjaxResult(); + ajaxResult.put("message", ex.getMessage()); + ajaxResult.put("url", request.getRequestURL().toString()); + ajaxResult.put("status", 500); + ajaxResult.put("error", "出现了一些错误"); + return ajaxResult; + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgMaterialController.java b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgMaterialController.java index b3e5ab0..69c51ac 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgMaterialController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/controller/SgMaterialController.java @@ -3,6 +3,7 @@ package com.zhyc.module.feed.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -22,19 +23,16 @@ import com.zhyc.common.core.page.TableDataInfo; /** * 原料Controller - * + * * @author HashMap - * @date 2025-08-11 + * @date 2026-01-16 */ @RestController @RequestMapping("/feed/material") public class SgMaterialController extends BaseController { - private final ISgMaterialService sgMaterialService; - - public SgMaterialController(ISgMaterialService sgMaterialService) { - this.sgMaterialService = sgMaterialService; - } + @Autowired + private ISgMaterialService sgMaterialService; /** * 查询原料列表 @@ -57,7 +55,7 @@ public class SgMaterialController extends BaseController public void export(HttpServletResponse response, SgMaterial sgMaterial) { List list = sgMaterialService.selectSgMaterialList(sgMaterial); - ExcelUtil util = new ExcelUtil<>(SgMaterial.class); + ExcelUtil util = new ExcelUtil(SgMaterial.class); util.exportExcel(response, list, "原料数据"); } @@ -98,7 +96,7 @@ public class SgMaterialController extends BaseController */ @PreAuthorize("@ss.hasPermi('feed:material:remove')") @Log(title = "原料", businessType = BusinessType.DELETE) - @DeleteMapping("/{materialIds}") + @DeleteMapping("/{materialIds}") public AjaxResult remove(@PathVariable String[] materialIds) { return toAjax(sgMaterialService.deleteSgMaterialByMaterialIds(materialIds)); diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgMaterial.java b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgMaterial.java index a9634be..316b999 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgMaterial.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/domain/SgMaterial.java @@ -1,15 +1,68 @@ package com.zhyc.module.feed.domain; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.zhyc.common.annotation.Excel; import com.zhyc.common.core.domain.BaseEntity; -import lombok.Getter; -import lombok.Setter; -@Setter -@Getter -public class SgMaterial extends BaseEntity { +/** + * 原料对象 sg_material + * + * @author HashMap + * @date 2026-01-16 + */ +public class SgMaterial extends BaseEntity +{ private static final long serialVersionUID = 1L; + /** 原料编码 */ + @Excel(name = "原料编码") private String materialId; + + /** 原料名称 */ + @Excel(name = "原料名称") private String materialName; - private String isGranular; + + /** 颗粒料 */ + @Excel(name = "颗粒料") + private Integer isGranular; + + public void setMaterialId(String materialId) + { + this.materialId = materialId; + } + + public String getMaterialId() + { + return materialId; + } + + public void setMaterialName(String materialName) + { + this.materialName = materialName; + } + + public String getMaterialName() + { + return materialName; + } + + public void setIsGranular(Integer isGranular) + { + this.isGranular = isGranular; + } + + public Integer getIsGranular() + { + return isGranular; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("materialId", getMaterialId()) + .append("materialName", getMaterialName()) + .append("isGranular", getIsGranular()) + .toString(); + } } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgMaterialMapper.java b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgMaterialMapper.java index a7a3d70..a466966 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgMaterialMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/mapper/SgMaterialMapper.java @@ -6,16 +6,16 @@ import org.apache.ibatis.annotations.Mapper; /** * 原料Mapper接口 - * + * * @author HashMap - * @date 2025-08-11 + * @date 2026-01-16 */ @Mapper -public interface SgMaterialMapper +public interface SgMaterialMapper { /** * 查询原料 - * + * * @param materialId 原料主键 * @return 原料 */ @@ -23,7 +23,7 @@ public interface SgMaterialMapper /** * 查询原料列表 - * + * * @param sgMaterial 原料 * @return 原料集合 */ @@ -31,7 +31,7 @@ public interface SgMaterialMapper /** * 新增原料 - * + * * @param sgMaterial 原料 * @return 结果 */ @@ -39,7 +39,7 @@ public interface SgMaterialMapper /** * 修改原料 - * + * * @param sgMaterial 原料 * @return 结果 */ @@ -47,7 +47,7 @@ public interface SgMaterialMapper /** * 删除原料 - * + * * @param materialId 原料主键 * @return 结果 */ @@ -55,7 +55,7 @@ public interface SgMaterialMapper /** * 批量删除原料 - * + * * @param materialIds 需要删除的数据主键集合 * @return 结果 */ diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgMaterialService.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgMaterialService.java index ba1e6ac..c402fe5 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgMaterialService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/ISgMaterialService.java @@ -5,57 +5,57 @@ import com.zhyc.module.feed.domain.SgMaterial; /** * 原料Service接口 - * + * * @author HashMap - * @date 2025-08-11 + * @date 2026-01-16 */ -public interface ISgMaterialService +public interface ISgMaterialService { /** * 查询原料 - * + * * @param materialId 原料主键 * @return 原料 */ - SgMaterial selectSgMaterialByMaterialId(String materialId); + public SgMaterial selectSgMaterialByMaterialId(String materialId); /** * 查询原料列表 - * + * * @param sgMaterial 原料 * @return 原料集合 */ - List selectSgMaterialList(SgMaterial sgMaterial); + public List selectSgMaterialList(SgMaterial sgMaterial); /** * 新增原料 - * + * * @param sgMaterial 原料 * @return 结果 */ - int insertSgMaterial(SgMaterial sgMaterial); + public int insertSgMaterial(SgMaterial sgMaterial); /** * 修改原料 - * + * * @param sgMaterial 原料 * @return 结果 */ - int updateSgMaterial(SgMaterial sgMaterial); + public int updateSgMaterial(SgMaterial sgMaterial); /** * 批量删除原料 - * + * * @param materialIds 需要删除的原料主键集合 * @return 结果 */ - int deleteSgMaterialByMaterialIds(String[] materialIds); + public int deleteSgMaterialByMaterialIds(String[] materialIds); /** * 删除原料信息 - * + * * @param materialId 原料主键 * @return 结果 */ - int deleteSgMaterialByMaterialId(String materialId); + public int deleteSgMaterialByMaterialId(String materialId); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgMaterialServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgMaterialServiceImpl.java index b858ae3..60c787b 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgMaterialServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/feed/service/impl/SgMaterialServiceImpl.java @@ -2,6 +2,7 @@ package com.zhyc.module.feed.service.impl; import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.zhyc.module.feed.mapper.SgMaterialMapper; import com.zhyc.module.feed.domain.SgMaterial; @@ -11,16 +12,12 @@ import com.zhyc.module.feed.service.ISgMaterialService; * 原料Service业务层处理 * * @author HashMap - * @date 2025-08-11 + * @date 2026-01-16 */ @Service -public class SgMaterialServiceImpl implements ISgMaterialService -{ - private final SgMaterialMapper sgMaterialMapper; - - public SgMaterialServiceImpl(SgMaterialMapper sgMaterialMapper) { - this.sgMaterialMapper = sgMaterialMapper; - } +public class SgMaterialServiceImpl implements ISgMaterialService { + @Autowired + private SgMaterialMapper sgMaterialMapper; /** * 查询原料 @@ -29,8 +26,7 @@ public class SgMaterialServiceImpl implements ISgMaterialService * @return 原料 */ @Override - public SgMaterial selectSgMaterialByMaterialId(String materialId) - { + public SgMaterial selectSgMaterialByMaterialId(String materialId) { return sgMaterialMapper.selectSgMaterialByMaterialId(materialId); } @@ -41,8 +37,7 @@ public class SgMaterialServiceImpl implements ISgMaterialService * @return 原料 */ @Override - public List selectSgMaterialList(SgMaterial sgMaterial) - { + public List selectSgMaterialList(SgMaterial sgMaterial) { return sgMaterialMapper.selectSgMaterialList(sgMaterial); } @@ -53,8 +48,10 @@ public class SgMaterialServiceImpl implements ISgMaterialService * @return 结果 */ @Override - public int insertSgMaterial(SgMaterial sgMaterial) - { + public int insertSgMaterial(SgMaterial sgMaterial) { + if (sgMaterialMapper.selectSgMaterialByMaterialId(sgMaterial.getMaterialId()) != null) { + throw new RuntimeException("重复的编码或名称"); + } return sgMaterialMapper.insertSgMaterial(sgMaterial); } @@ -65,8 +62,7 @@ public class SgMaterialServiceImpl implements ISgMaterialService * @return 结果 */ @Override - public int updateSgMaterial(SgMaterial sgMaterial) - { + public int updateSgMaterial(SgMaterial sgMaterial) { return sgMaterialMapper.updateSgMaterial(sgMaterial); } @@ -77,8 +73,7 @@ public class SgMaterialServiceImpl implements ISgMaterialService * @return 结果 */ @Override - public int deleteSgMaterialByMaterialIds(String[] materialIds) - { + public int deleteSgMaterialByMaterialIds(String[] materialIds) { return sgMaterialMapper.deleteSgMaterialByMaterialIds(materialIds); } @@ -89,8 +84,7 @@ public class SgMaterialServiceImpl implements ISgMaterialService * @return 结果 */ @Override - public int deleteSgMaterialByMaterialId(String materialId) - { + public int deleteSgMaterialByMaterialId(String materialId) { return sgMaterialMapper.deleteSgMaterialByMaterialId(materialId); } } diff --git a/zhyc-module/src/main/resources/mapper/feed/SgMaterialMapper.xml b/zhyc-module/src/main/resources/mapper/feed/SgMaterialMapper.xml index f4960c9..6129720 100644 --- a/zhyc-module/src/main/resources/mapper/feed/SgMaterialMapper.xml +++ b/zhyc-module/src/main/resources/mapper/feed/SgMaterialMapper.xml @@ -1,9 +1,9 @@ +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -16,13 +16,13 @@ - +