Browse Source
feat(srm): 添加供应商管理和分组功能
feat(srm): 添加供应商管理和分组功能
- 添加了供应商实体类SrmSupplier,包含税率、多个电话邮箱和联系方式字段 - 实现了供应商分组实体SrmGroup和对应的数据库映射 - 创建了供应商货币实体SrmCurrency用于币种管理 - 在供应商控制器中添加了新增、更新和删除供应商的API接口 - 扩展了供应商数据类以支持货币和分组描述信息 - 实现了供应商服务层的完整CRUD操作和业务逻辑验证 - 添加了供应商分组的数据库映射文件和查询功能 - 更新了开发环境数据库配置文件以使用正确的数据库名master
4 changed files with 304 additions and 0 deletions
-
79src/main/java/com/xujie/modules/srm/controller/SrmGroupController.java
-
23src/main/java/com/xujie/modules/srm/mapper/SrmGroupMapper.java
-
24src/main/java/com/xujie/modules/srm/service/SrmGroupService.java
-
178src/main/java/com/xujie/modules/srm/service/impl/SrmGroupServiceImpl.java
@ -0,0 +1,79 @@ |
|||
package com.xujie.modules.srm.controller; |
|||
|
|||
import com.xujie.modules.srm.entity.SrmGroup; |
|||
import com.xujie.modules.srm.service.SrmGroupService; |
|||
import com.xujie.common.utils.R; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
@RequestMapping("/srmGroup") |
|||
public class SrmGroupController { |
|||
|
|||
@Autowired |
|||
private SrmGroupService srmGroupService; |
|||
|
|||
/** |
|||
* 获取供应商分组列表 |
|||
*/ |
|||
@PostMapping("/getSupplierGroupList") |
|||
public R getSupplierGroupList(@RequestBody(required = false) Map<String, Object> params) { |
|||
if (params == null) { |
|||
params = new HashMap<>(); |
|||
} |
|||
|
|||
List<SrmGroup> groupList = srmGroupService.getSupplierGroupList(params); |
|||
return R.ok().put("data", groupList); |
|||
} |
|||
|
|||
/** |
|||
* 新增供应商分组 |
|||
*/ |
|||
@PostMapping("/addSupplierGroup") |
|||
public R addSupplierGroup(@RequestBody SrmGroup group) { |
|||
srmGroupService.addSupplierGroup(group); |
|||
return R.ok(); |
|||
} |
|||
|
|||
/** |
|||
* 更新供应商分组 |
|||
*/ |
|||
@PostMapping("/updateSupplierGroup") |
|||
public R updateSupplierGroup(@RequestBody SrmGroup group) { |
|||
srmGroupService.updateSupplierGroup(group); |
|||
return R.ok(); |
|||
} |
|||
|
|||
/** |
|||
* 删除供应商分组 |
|||
*/ |
|||
@PostMapping("/deleteSupplierGroup") |
|||
public R deleteSupplierGroup(@RequestBody Map<String, Object> params) { |
|||
// 获取必要参数 |
|||
String supplierGroup = (String) params.get("supplierGroup"); |
|||
String site = (String) params.get("site"); |
|||
|
|||
// 参数校验 |
|||
if (supplierGroup == null || supplierGroup.trim().isEmpty()) { |
|||
return R.error("供应商分组代码不能为空"); |
|||
} |
|||
|
|||
if (site == null || site.trim().isEmpty()) { |
|||
return R.error("站点不能为空"); |
|||
} |
|||
|
|||
try { |
|||
// 执行删除 |
|||
srmGroupService.deleteSupplierGroupByCode(site, supplierGroup); |
|||
return R.ok("删除成功"); |
|||
} catch (RuntimeException e) { |
|||
return R.error(e.getMessage()); |
|||
} catch (Exception e) { |
|||
return R.error("删除失败:" + e.getMessage()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
package com.xujie.modules.srm.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.xujie.modules.srm.entity.SrmGroup; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Mapper |
|||
public interface SrmGroupMapper extends BaseMapper<SrmGroup> { |
|||
|
|||
//查询供应商分组列表 |
|||
List<SrmGroup> selectSupplierGroupList(@Param("params") Map<String, Object> params); |
|||
|
|||
// 检查供应商分组是否已存在 |
|||
int checkSupplierGroupExists(@Param("site") String site, @Param("supplierGroup") String supplierGroup); |
|||
|
|||
// 检查供应商分组名称是否已存在 |
|||
int checkSupplierGroupDescExists(@Param("site") String site, @Param("groupDesc") String groupDesc); |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.xujie.modules.srm.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.xujie.modules.srm.entity.SrmGroup; |
|||
import com.xujie.common.utils.PageUtils; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
public interface SrmGroupService extends IService<SrmGroup> { |
|||
// 获取供应商分组列表 |
|||
List<SrmGroup> getSupplierGroupList(Map<String, Object> params); |
|||
|
|||
|
|||
// 新增供应商分组 |
|||
void addSupplierGroup(SrmGroup group); |
|||
|
|||
|
|||
// 更新供应商分组 |
|||
void updateSupplierGroup(SrmGroup group); |
|||
|
|||
// 删除供应商分组 |
|||
void deleteSupplierGroupByCode(String site, String supplierGroup); |
|||
} |
|||
@ -0,0 +1,178 @@ |
|||
package com.xujie.modules.srm.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.xujie.modules.srm.entity.SrmGroup; |
|||
import com.xujie.modules.srm.entity.SrmSupplier; |
|||
import com.xujie.modules.srm.mapper.SrmGroupMapper; |
|||
import com.xujie.modules.srm.service.SrmGroupService; |
|||
import com.xujie.modules.srm.service.SrmSupplierService; |
|||
import jakarta.transaction.Transactional; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class SrmGroupServiceImpl extends ServiceImpl<SrmGroupMapper, SrmGroup> implements SrmGroupService { |
|||
|
|||
@Autowired |
|||
private SrmSupplierService srmSupplierService; |
|||
@Override |
|||
public List<SrmGroup> getSupplierGroupList(Map<String, Object> params) { |
|||
// 使用XML中的方法进行查询 |
|||
return baseMapper.selectSupplierGroupList(params); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public void addSupplierGroup(SrmGroup group) { |
|||
// 检查必要参数是否存在 |
|||
if (group.getSupplierGroup() == null || group.getSupplierGroup().isEmpty()) { |
|||
throw new RuntimeException("供应商分组代码不能为空"); |
|||
} |
|||
|
|||
if (group.getSite() == null || group.getSite().isEmpty()) { |
|||
throw new RuntimeException("站点信息不能为空"); |
|||
} |
|||
|
|||
// 检查供应商分组代码是否已存在(基于站点和分组代码) |
|||
int count = baseMapper.checkSupplierGroupExists(group.getSite(), group.getSupplierGroup()); |
|||
if (count > 0) { |
|||
throw new RuntimeException("供应商分组代码已存在:" + group.getSupplierGroup() + ",请使用不同的分组代码"); |
|||
} |
|||
|
|||
// 如果提供了分组名称,检查分组名称是否已存在 |
|||
if (group.getGroupDesc() != null && !group.getGroupDesc().isEmpty()) { |
|||
int descCount = baseMapper.checkSupplierGroupDescExists(group.getSite(), group.getGroupDesc()); |
|||
if (descCount > 0) { |
|||
throw new RuntimeException("供应商分组名称已存在:" + group.getGroupDesc() + ",请使用不同的分组名称"); |
|||
} |
|||
} |
|||
|
|||
// 设置默认值 |
|||
if (group.getActive() == null || group.getActive().isEmpty()) { |
|||
group.setActive("Y"); // 默认激活 |
|||
} |
|||
|
|||
if (group.getGroupType() == null || group.getGroupType().isEmpty()) { |
|||
group.setGroupType("DEFAULT"); // 默认类型 |
|||
} |
|||
|
|||
// 保存供应商分组信息 |
|||
this.save(group); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public void updateSupplierGroup(SrmGroup group) { |
|||
// 参数校验 |
|||
if (group == null) { |
|||
throw new RuntimeException("供应商分组信息不能为空"); |
|||
} |
|||
|
|||
if (group.getSite() == null || group.getSite().trim().isEmpty()) { |
|||
throw new RuntimeException("站点不能为空"); |
|||
} |
|||
|
|||
if (group.getSupplierGroup() == null || group.getSupplierGroup().trim().isEmpty()) { |
|||
throw new RuntimeException("供应商分组代码不能为空"); |
|||
} |
|||
|
|||
if (group.getGroupDesc() == null || group.getGroupDesc().trim().isEmpty()) { |
|||
throw new RuntimeException("供应商分组描述不能为空"); |
|||
} |
|||
|
|||
// 根据站点和分组代码检查分组是否存在 |
|||
QueryWrapper<SrmGroup> queryWrapper = new QueryWrapper<>(); |
|||
queryWrapper.eq("site", group.getSite()) |
|||
.eq("supplier_group", group.getSupplierGroup()); |
|||
|
|||
SrmGroup existingGroup = this.getOne(queryWrapper); |
|||
|
|||
// 如果分组不存在,无法修改 |
|||
if (existingGroup == null) { |
|||
throw new RuntimeException(String.format( |
|||
"供应商分组不存在:站点[%s],分组代码[%s]", |
|||
group.getSite(), group.getSupplierGroup() |
|||
)); |
|||
} |
|||
|
|||
// 检查新的分组描述是否与其他分组冲突(同一站点内) |
|||
if (!existingGroup.getGroupDesc().equals(group.getGroupDesc())) { |
|||
int count = baseMapper.checkSupplierGroupDescExists(group.getSite(), group.getGroupDesc()); |
|||
if (count > 0) { |
|||
throw new RuntimeException("供应商分组名称已存在:" + group.getGroupDesc() + ",请使用不同的分组名称"); |
|||
} |
|||
} |
|||
|
|||
// 分组存在,进行修改 |
|||
existingGroup.setGroupDesc(group.getGroupDesc()); |
|||
|
|||
if (group.getActive() != null) { |
|||
existingGroup.setActive(group.getActive()); |
|||
} |
|||
|
|||
if (group.getGroupType() != null) { |
|||
existingGroup.setGroupType(group.getGroupType()); |
|||
} |
|||
|
|||
// 执行更新 |
|||
this.updateById(existingGroup); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public void deleteSupplierGroupByCode(String site, String supplierGroup) { |
|||
// 参数校验 |
|||
if (site == null || site.trim().isEmpty()) { |
|||
throw new RuntimeException("站点不能为空"); |
|||
} |
|||
|
|||
if (supplierGroup == null || supplierGroup.trim().isEmpty()) { |
|||
throw new RuntimeException("供应商分组代码不能为空"); |
|||
} |
|||
|
|||
// 1. 检查分组是否存在 |
|||
QueryWrapper<SrmGroup> queryWrapper = new QueryWrapper<>(); |
|||
queryWrapper.eq("site", site) |
|||
.eq("supplier_group", supplierGroup); |
|||
|
|||
SrmGroup group = this.getOne(queryWrapper); |
|||
if (group == null) { |
|||
throw new RuntimeException(String.format( |
|||
"供应商分组不存在:站点[%s],分组代码[%s]", site, supplierGroup |
|||
)); |
|||
} |
|||
|
|||
// 2. 检查是否有关联数据 |
|||
checkIfHasRelatedData(site, supplierGroup); |
|||
|
|||
// 3. 执行删除操作 |
|||
boolean result = this.remove(queryWrapper); |
|||
if (!result) { |
|||
throw new RuntimeException(String.format( |
|||
"删除供应商分组失败:站点[%s],分组代码[%s]", site, supplierGroup |
|||
)); |
|||
} |
|||
} |
|||
|
|||
// 检查是否有关联数据 |
|||
private void checkIfHasRelatedData(String site, String supplierGroup) { |
|||
// 检查供应商表是否有使用此分组的记录 |
|||
QueryWrapper<SrmSupplier> supplierQuery = new QueryWrapper<>(); |
|||
supplierQuery.eq("site", site) |
|||
.eq("supplier_group", supplierGroup); |
|||
|
|||
// 获取关联供应商数量 |
|||
Long supplierCount = srmSupplierService.count(supplierQuery); |
|||
|
|||
if (supplierCount != null && supplierCount > 0) { |
|||
throw new RuntimeException(String.format( |
|||
"该分组已被 %d 个供应商使用,无法删除", supplierCount |
|||
)); |
|||
} |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue