service) {
+ this.service = service;
+ }
+
+ /**
+ * 保存实体对象
+ *
+ * 将保存项转换为实体对象后保存,返回保存后的实体ID。
+ * 支持新增和更新操作,通过事务保证数据一致性。
+ *
+ *
+ * @param item 需要保存的项
+ * @return 返回保存后的实体ID响应对象,格式:{status: 0, message: "OK", data: 实体ID}
+ * @throws Exception 保存过程中可能抛出的异常
+ */
+ @Transactional(rollbackFor = Throwable.class)
+ @PostMapping(SAVE)
+ @Override
+ public GlobalResponse save(@RequestBody SAVE_ITEM item) throws Exception {
+ var mapper = saveItemMapper();
+ return GlobalResponse.responseSuccess(service.save(mapper.apply(item)));
+ }
+
+ /**
+ * 获取所有实体列表
+ *
+ * 查询所有记录,不带任何过滤条件,返回分页格式的数据。
+ * 将实体对象转换为列表项对象后返回。
+ *
+ *
+ * @return 返回实体列表响应对象,格式:{status: 0, message: "OK", data: {items: [...], total: total}}
+ * @throws Exception 查询过程中可能抛出的异常
+ */
+ @Transactional(readOnly = true)
+ @GetMapping(LIST)
+ @Override
+ public GlobalResponse> list() throws Exception {
+ var mapper = listItemMapper();
+ var result = service.list();
+ return GlobalResponse.responseListData(
+ result
+ .stream()
+ .map(entity -> {
+ try {
+ return mapper.apply(entity);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ })
+ .toList(),
+ result.size()
+ );
+ }
+
+ /**
+ * 根据查询条件获取实体列表
+ *
+ * 支持复杂的查询条件、排序和分页,返回符合条件的数据。
+ * 将实体对象转换为列表项对象后返回。
+ *
+ *
+ * @param query 查询条件对象,包含过滤条件、排序规则和分页信息
+ * @return 返回符合条件的实体列表响应对象,格式:{status: 0, message: "OK", data: {items: [...], total: total}}
+ * @throws Exception 查询过程中可能抛出的异常
+ */
+ @Transactional(readOnly = true)
+ @PostMapping(LIST)
+ @Override
+ public GlobalResponse> list(@RequestBody Query query) throws Exception {
+ if (ObjectHelper.isNull(query)) {
+ return GlobalResponse.responseListData();
+ }
+ var mapper = listItemMapper();
+ var result = service.list(query);
+ return GlobalResponse.responseListData(
+ result.items()
+ .stream()
+ .map(entity -> {
+ try {
+ return mapper.apply(entity);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ })
+ .toList(),
+ result.total()
+ );
+ }
+
+ /**
+ * 根据ID获取实体详情
+ *
+ * 根据主键ID查询单条记录的详细信息,转换为详情项对象后返回。
+ * 如果记录不存在则抛出异常。
+ *
+ *
+ * @param id 实体主键ID
+ * @return 返回实体详情响应对象,格式:{status: 0, message: "OK", data: 详情数据}
+ * @throws Exception 查询过程中可能抛出的异常
+ */
+ @Transactional(readOnly = true)
+ @GetMapping(DETAIL)
+ @Override
+ public GlobalResponse detail(@PathVariable("id") Long id) throws Exception {
+ var mapper = detailItemMapper();
+ return GlobalResponse.responseSuccess(mapper.apply(service.detailOrThrow(id)));
+ }
+
+ /**
+ * 根据ID删除实体对象
+ *
+ * 根据主键ID删除指定的记录,执行成功后返回成功响应。
+ * 通过事务保证删除操作的一致性。
+ *
+ *
+ * @param id 需要删除的实体主键ID
+ * @return 返回删除结果响应对象,格式:{status: 0, message: "OK", data: null}
+ * @throws Exception 删除过程中可能抛出的异常
+ */
+ @Transactional(rollbackFor = Throwable.class)
+ @GetMapping(REMOVE)
+ @Override
+ public GlobalResponse