7 changed files with 652 additions and 139 deletions
-
166src/main/java/com/gaotao/modules/base/controller/ReportFamilyListController.java
-
35src/main/java/com/gaotao/modules/base/dao/ReportFamilyListMapper.java
-
60src/main/java/com/gaotao/modules/base/entity/ReportFamilyList.java
-
238src/main/java/com/gaotao/modules/base/service/Impl/ReportFamilyListServiceImpl.java
-
218src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java
-
72src/main/java/com/gaotao/modules/base/service/ReportFamilyListService.java
-
2src/main/java/com/gaotao/modules/base/service/ReportLabelListService.java
@ -0,0 +1,166 @@ |
|||
package com.gaotao.modules.base.controller; |
|||
|
|||
import com.gaotao.common.utils.PageUtils; |
|||
import com.gaotao.common.utils.R; |
|||
import com.gaotao.modules.base.entity.ReportFamilyList; |
|||
import com.gaotao.modules.base.service.ReportFamilyListService; |
|||
import com.gaotao.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> |
|||
* </ul> |
|||
* |
|||
* @author System |
|||
* @since 2025-10-13 |
|||
*/ |
|||
@Slf4j |
|||
@RestController |
|||
@RequestMapping("/label/labelType") |
|||
public class ReportFamilyListController extends AbstractController { |
|||
|
|||
@Autowired |
|||
private ReportFamilyListService reportFamilyListService; |
|||
|
|||
/** |
|||
* @Author System |
|||
* @Description 分页查询标签类型列表 |
|||
* @Date 2025/10/13 |
|||
* @Param [params] |
|||
* @return com.gaotao.common.utils.R |
|||
**/ |
|||
@PostMapping("getList") |
|||
public R getList(@RequestBody Map<String, Object> params) { |
|||
try { |
|||
log.info("查询标签类型列表 - params: {}", params); |
|||
|
|||
// 转换分页参数为String类型(Query工具类需要String类型) |
|||
if (params.get("page") != null) { |
|||
params.put("page", String.valueOf(params.get("page"))); |
|||
} |
|||
if (params.get("limit") != null) { |
|||
params.put("limit", String.valueOf(params.get("limit"))); |
|||
} |
|||
|
|||
PageUtils page = reportFamilyListService.queryPage(params); |
|||
return R.ok() |
|||
.put("code", 200) |
|||
.put("msg", "查询成功") |
|||
.put("page", page); |
|||
} catch (Exception e) { |
|||
log.error("查询标签类型列表失败: " + e.getMessage(), e); |
|||
return R.error("查询失败: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @Author System |
|||
* @Description 获取所有标签类型(用于下拉选择) |
|||
* @Date 2025/10/13 |
|||
* @Param [params] |
|||
* @return com.gaotao.common.utils.R |
|||
**/ |
|||
@PostMapping("getAllList") |
|||
public R getAllList(@RequestBody Map<String, Object> params) { |
|||
try { |
|||
String site = (String) params.get("site"); |
|||
log.info("获取所有标签类型 - site: {}", site); |
|||
List<ReportFamilyList> list = reportFamilyListService.getLabelTypeList(site); |
|||
return R.ok() |
|||
.put("code", 200) |
|||
.put("msg", "查询成功") |
|||
.put("data", list); |
|||
} catch (Exception e) { |
|||
log.error("获取标签类型失败: " + e.getMessage(), e); |
|||
return R.error("查询失败: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @Author System |
|||
* @Description 保存标签类型 |
|||
* @Date 2025/10/13 |
|||
* @Param [reportFamilyList] |
|||
* @return com.gaotao.common.utils.R |
|||
**/ |
|||
@PostMapping("save") |
|||
public R save(@RequestBody ReportFamilyList reportFamilyList) { |
|||
try { |
|||
log.info("保存标签类型 - name: {}", reportFamilyList.getName()); |
|||
|
|||
// 设置创建人 |
|||
reportFamilyList.setCreatedBy(getUser().getUsername()); |
|||
reportFamilyList.setUpdatedBy(getUser().getUsername()); |
|||
|
|||
reportFamilyListService.saveLabelType(reportFamilyList); |
|||
return R.ok() |
|||
.put("code", 200) |
|||
.put("msg", "保存成功"); |
|||
} catch (Exception e) { |
|||
log.error("保存标签类型失败: " + e.getMessage(), e); |
|||
return R.error("保存失败: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @Author System |
|||
* @Description 更新标签类型 |
|||
* @Date 2025/10/13 |
|||
* @Param [reportFamilyList] |
|||
* @return com.gaotao.common.utils.R |
|||
**/ |
|||
@PostMapping("update") |
|||
public R update(@RequestBody ReportFamilyList reportFamilyList) { |
|||
try { |
|||
log.info("更新标签类型 - name: {}", reportFamilyList.getName()); |
|||
|
|||
// 设置更新人 |
|||
reportFamilyList.setUpdatedBy(getUser().getUsername()); |
|||
|
|||
reportFamilyListService.updateLabelType(reportFamilyList); |
|||
return R.ok() |
|||
.put("code", 200) |
|||
.put("msg", "更新成功"); |
|||
} catch (Exception e) { |
|||
log.error("更新标签类型失败: " + e.getMessage(), e); |
|||
return R.error("更新失败: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @Author System |
|||
* @Description 删除标签类型 |
|||
* @Date 2025/10/13 |
|||
* @Param [params] |
|||
* @return com.gaotao.common.utils.R |
|||
**/ |
|||
@PostMapping("delete") |
|||
public R delete(@RequestBody Map<String, Object> params) { |
|||
try { |
|||
String name = (String) params.get("name"); |
|||
String site = (String) params.get("site"); |
|||
|
|||
log.info("删除标签类型 - name: {}, site: {}", name, site); |
|||
|
|||
reportFamilyListService.deleteLabelType(name, site); |
|||
return R.ok() |
|||
.put("code", 200) |
|||
.put("msg", "删除成功"); |
|||
} catch (Exception e) { |
|||
log.error("删除标签类型失败: " + e.getMessage(), e); |
|||
return R.error("删除失败: " + e.getMessage()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,35 @@ |
|||
package com.gaotao.modules.base.dao; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.gaotao.modules.base.entity.ReportFamilyList; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
|
|||
/** |
|||
* 标签类型管理Mapper接口 |
|||
* |
|||
* <p><b>主要功能:</b></p> |
|||
* <ul> |
|||
* <li>标签类型的增删改查操作</li> |
|||
* <li>标签类型与视图的映射管理</li> |
|||
* </ul> |
|||
* |
|||
* @author System |
|||
* @since 2025-10-13 |
|||
*/ |
|||
@Mapper |
|||
public interface ReportFamilyListMapper extends BaseMapper<ReportFamilyList> { |
|||
|
|||
/** |
|||
* 检查标签类型是否被使用 |
|||
* |
|||
* @param reportFamily 标签类型名称 |
|||
* @param site 站点编码 |
|||
* @return 使用该标签类型的数量 |
|||
*/ |
|||
@Select("SELECT COUNT(1) FROM ReportFileList WHERE ReportFamily = #{reportFamily}") |
|||
Integer countLabelTypeUsage(@Param("reportFamily") String reportFamily, @Param("site") String site); |
|||
|
|||
} |
|||
|
|||
@ -1,24 +1,72 @@ |
|||
package com.gaotao.modules.base.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* report_family_list实体类 |
|||
* 标签类型信息实体类 |
|||
* |
|||
* <p><b>核心字段说明:</b></p> |
|||
* <ul> |
|||
* <li><b>name</b>:标签类型名称(唯一标识)</li> |
|||
* <li><b>site</b>:站点编码</li> |
|||
* <li><b>view_sql</b>:WMS视图名称</li> |
|||
* <li><b>ifs_view_sql</b>:IFS视图名称</li> |
|||
* </ul> |
|||
*/ |
|||
@Data |
|||
@TableName("report_family_list") |
|||
public class ReportFamilyList implements Serializable { |
|||
|
|||
private String name; // 标签类型 |
|||
/** |
|||
* 标签类型名称 - 必须字段 |
|||
*/ |
|||
@TableField("name") |
|||
private String name; |
|||
|
|||
private String site; // 工厂 |
|||
/** |
|||
* 站点编码 |
|||
*/ |
|||
@TableField("site") |
|||
private String site; |
|||
|
|||
private String viewSql; // 视图名称 |
|||
/** |
|||
* 创建人 |
|||
*/ |
|||
@TableField("created_by") |
|||
private String createdBy; |
|||
|
|||
private String ifsViewSql; // IFS视图名称 |
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField("created_time") |
|||
private Date createdTime; |
|||
|
|||
// 其他字段根据实际表结构添加 |
|||
/** |
|||
* 更新人 |
|||
*/ |
|||
@TableField("updated_by") |
|||
private String updatedBy; |
|||
|
|||
/** |
|||
* 更新时间 |
|||
*/ |
|||
@TableField("updated_time") |
|||
private Date updatedTime; |
|||
|
|||
/** |
|||
* WMS视图名称 |
|||
*/ |
|||
@TableField("view_sql") |
|||
private String viewSql; |
|||
|
|||
/** |
|||
* IFS视图名称 |
|||
*/ |
|||
@TableField("ifs_view_sql") |
|||
private String ifsViewSql; |
|||
} |
|||
@ -0,0 +1,238 @@ |
|||
package com.gaotao.modules.base.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.utils.PageUtils; |
|||
import com.gaotao.common.utils.Query; |
|||
import com.gaotao.modules.base.dao.ReportFamilyListMapper; |
|||
import com.gaotao.modules.base.entity.ReportFamilyList; |
|||
import com.gaotao.modules.base.service.ReportFamilyListService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 标签类型管理服务实现类 |
|||
* |
|||
* <p><b>主要功能:</b></p> |
|||
* <ul> |
|||
* <li>标签类型的增删改查</li> |
|||
* <li>标签类型与视图的映射管理</li> |
|||
* </ul> |
|||
* |
|||
* <p><b>关键业务规则:</b></p> |
|||
* <ul> |
|||
* <li>标签类型名称在同一站点下唯一</li> |
|||
* <li>删除标签类型前需要检查是否被标签引用</li> |
|||
* </ul> |
|||
* |
|||
* @author System |
|||
* @since 2025-10-13 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional |
|||
public class ReportFamilyListServiceImpl extends ServiceImpl<ReportFamilyListMapper, ReportFamilyList> |
|||
implements ReportFamilyListService { |
|||
|
|||
/** |
|||
* 分页查询标签类型列表 |
|||
* |
|||
* @param params 查询参数 |
|||
* @return 分页结果 |
|||
*/ |
|||
@Override |
|||
public PageUtils queryPage(Map<String, Object> params) { |
|||
log.info("=== 开始查询标签类型列表 ==="); |
|||
|
|||
String site = (String) params.get("site"); |
|||
String name = (String) params.get("name"); |
|||
|
|||
log.info("查询条件 - site: {}, name: {}", site, name); |
|||
|
|||
LambdaQueryWrapper<ReportFamilyList> wrapper = new LambdaQueryWrapper<>(); |
|||
|
|||
if (StringUtils.isNotBlank(site)) { |
|||
wrapper.eq(ReportFamilyList::getSite, site); |
|||
} |
|||
|
|||
if (StringUtils.isNotBlank(name)) { |
|||
wrapper.like(ReportFamilyList::getName, name); |
|||
} |
|||
|
|||
wrapper.orderByDesc(ReportFamilyList::getCreatedTime); |
|||
|
|||
IPage<ReportFamilyList> page = this.page( |
|||
new Query<ReportFamilyList>().getPage(params), |
|||
wrapper |
|||
); |
|||
|
|||
log.info("查询完成,共 {} 条记录", page.getTotal()); |
|||
return new PageUtils(page); |
|||
} |
|||
|
|||
/** |
|||
* 获取所有标签类型列表(用于下拉选择) |
|||
* |
|||
* @param site 工厂编码 |
|||
* @return 标签类型列表 |
|||
*/ |
|||
@Override |
|||
public List<ReportFamilyList> getLabelTypeList(String site) { |
|||
log.info("获取标签类型列表 - site: {}", site); |
|||
|
|||
LambdaQueryWrapper<ReportFamilyList> wrapper = new LambdaQueryWrapper<>(); |
|||
|
|||
if (StringUtils.isNotBlank(site)) { |
|||
wrapper.eq(ReportFamilyList::getSite, site); |
|||
} |
|||
|
|||
wrapper.orderByAsc(ReportFamilyList::getName); |
|||
|
|||
return this.list(wrapper); |
|||
} |
|||
|
|||
/** |
|||
* 保存标签类型 |
|||
* |
|||
* @param reportFamilyList 标签类型信息 |
|||
*/ |
|||
@Override |
|||
@Transactional |
|||
public void saveLabelType(ReportFamilyList reportFamilyList) { |
|||
log.info("=== 开始保存标签类型 ==="); |
|||
log.info("标签类型: {}, 站点: {}", reportFamilyList.getName(), reportFamilyList.getSite()); |
|||
|
|||
// 验证标签类型名称是否已存在 |
|||
LambdaQueryWrapper<ReportFamilyList> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(ReportFamilyList::getName, reportFamilyList.getName()) |
|||
.eq(ReportFamilyList::getSite, reportFamilyList.getSite()); |
|||
|
|||
ReportFamilyList existing = this.getOne(wrapper); |
|||
if (existing != null) { |
|||
log.error("标签类型已存在: {}", reportFamilyList.getName()); |
|||
throw new RuntimeException("标签类型名称已存在: " + reportFamilyList.getName()); |
|||
} |
|||
|
|||
// 设置创建时间 |
|||
reportFamilyList.setCreatedTime(new Date()); |
|||
reportFamilyList.setUpdatedTime(new Date()); |
|||
|
|||
boolean result = this.save(reportFamilyList); |
|||
|
|||
if (!result) { |
|||
log.error("保存标签类型失败"); |
|||
throw new RuntimeException("保存标签类型失败"); |
|||
} |
|||
|
|||
log.info("=== 标签类型保存成功 ==="); |
|||
} |
|||
|
|||
/** |
|||
* 更新标签类型 |
|||
* |
|||
* @param reportFamilyList 标签类型信息 |
|||
*/ |
|||
@Override |
|||
@Transactional |
|||
public void updateLabelType(ReportFamilyList reportFamilyList) { |
|||
log.info("=== 开始更新标签类型 ==="); |
|||
log.info("标签类型: {}, 站点: {}", reportFamilyList.getName(), reportFamilyList.getSite()); |
|||
|
|||
// 检查标签类型是否正在被使用 |
|||
if (isLabelTypeInUse(reportFamilyList.getName(), reportFamilyList.getSite())) { |
|||
log.error("标签类型正在被使用,不允许修改: {}", reportFamilyList.getName()); |
|||
throw new RuntimeException("该标签类型正在被标签使用,不允许修改"); |
|||
} |
|||
|
|||
// 设置更新时间 |
|||
reportFamilyList.setUpdatedTime(new Date()); |
|||
|
|||
LambdaQueryWrapper<ReportFamilyList> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(ReportFamilyList::getName, reportFamilyList.getName()) |
|||
.eq(ReportFamilyList::getSite, reportFamilyList.getSite()); |
|||
|
|||
boolean result = this.update(reportFamilyList, wrapper); |
|||
|
|||
if (!result) { |
|||
log.error("更新标签类型失败"); |
|||
throw new RuntimeException("更新标签类型失败"); |
|||
} |
|||
|
|||
log.info("=== 标签类型更新成功 ==="); |
|||
} |
|||
|
|||
/** |
|||
* 删除标签类型 |
|||
* |
|||
* @param name 标签类型名称 |
|||
* @param site 工厂编码 |
|||
*/ |
|||
@Override |
|||
@Transactional |
|||
public void deleteLabelType(String name, String site) { |
|||
log.info("=== 开始删除标签类型 ==="); |
|||
log.info("标签类型: {}, 站点: {}", name, site); |
|||
|
|||
// 验证标签类型是否存在 |
|||
LambdaQueryWrapper<ReportFamilyList> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(ReportFamilyList::getName, name) |
|||
.eq(ReportFamilyList::getSite, site); |
|||
|
|||
ReportFamilyList existing = this.getOne(wrapper); |
|||
if (existing == null) { |
|||
log.error("标签类型不存在: {}", name); |
|||
throw new RuntimeException("标签类型不存在: " + name); |
|||
} |
|||
|
|||
// 检查标签类型是否正在被使用 |
|||
if (isLabelTypeInUse(name, site)) { |
|||
log.error("标签类型正在被使用,不允许删除: {}", name); |
|||
throw new RuntimeException("该标签类型正在被标签使用,不允许删除"); |
|||
} |
|||
|
|||
boolean result = this.remove(wrapper); |
|||
|
|||
if (!result) { |
|||
log.error("删除标签类型失败"); |
|||
throw new RuntimeException("删除标签类型失败"); |
|||
} |
|||
|
|||
log.info("=== 标签类型删除成功 ==="); |
|||
} |
|||
|
|||
/** |
|||
* 检查标签类型是否正在被使用 |
|||
* |
|||
* @param name 标签类型名称 |
|||
* @param site 工厂编码 |
|||
* @return true=正在使用,false=未使用 |
|||
*/ |
|||
@Override |
|||
public boolean isLabelTypeInUse(String name, String site) { |
|||
log.info("检查标签类型是否被使用 - name: {}, site: {}", name, site); |
|||
|
|||
try { |
|||
// 使用Mapper接口的@Select注解方法查询 |
|||
Integer count = baseMapper.countLabelTypeUsage(name, site); |
|||
|
|||
boolean inUse = count != null && count > 0; |
|||
log.info("标签类型 {} 的使用情况: {} (使用该类型的标签数量: {})", |
|||
name, inUse ? "正在使用" : "未使用", count); |
|||
|
|||
return inUse; |
|||
} catch (Exception e) { |
|||
log.error("检查标签类型使用情况时发生异常: " + e.getMessage(), e); |
|||
// 出现异常时,为了安全起见,返回true(假设正在使用,不允许删除) |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,72 @@ |
|||
package com.gaotao.modules.base.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.gaotao.common.utils.PageUtils; |
|||
import com.gaotao.modules.base.entity.ReportFamilyList; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 标签类型管理服务接口 |
|||
* |
|||
* <p><b>主要功能:</b></p> |
|||
* <ul> |
|||
* <li>标签类型的增删改查</li> |
|||
* <li>标签类型列表查询</li> |
|||
* <li>标签类型与视图的映射管理</li> |
|||
* </ul> |
|||
* |
|||
* @author System |
|||
* @since 2025-10-13 |
|||
*/ |
|||
public interface ReportFamilyListService extends IService<ReportFamilyList> { |
|||
|
|||
/** |
|||
* 分页查询标签类型列表 |
|||
* |
|||
* @param params 查询参数(包含site、name等) |
|||
* @return 分页结果 |
|||
*/ |
|||
PageUtils queryPage(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 获取所有标签类型列表(用于下拉选择) |
|||
* |
|||
* @param site 工厂编码 |
|||
* @return 标签类型列表 |
|||
*/ |
|||
List<ReportFamilyList> getLabelTypeList(String site); |
|||
|
|||
/** |
|||
* 保存标签类型 |
|||
* |
|||
* @param reportFamilyList 标签类型信息 |
|||
*/ |
|||
void saveLabelType(ReportFamilyList reportFamilyList); |
|||
|
|||
/** |
|||
* 更新标签类型 |
|||
* |
|||
* @param reportFamilyList 标签类型信息 |
|||
*/ |
|||
void updateLabelType(ReportFamilyList reportFamilyList); |
|||
|
|||
/** |
|||
* 删除标签类型 |
|||
* |
|||
* @param name 标签类型名称 |
|||
* @param site 工厂编码 |
|||
*/ |
|||
void deleteLabelType(String name, String site); |
|||
|
|||
/** |
|||
* 检查标签类型是否正在被使用 |
|||
* |
|||
* @param name 标签类型名称 |
|||
* @param site 工厂编码 |
|||
* @return true=正在使用,false=未使用 |
|||
*/ |
|||
boolean isLabelTypeInUse(String name, String site); |
|||
} |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue