浏览代码

iaw

master
chenchaod 1 个月前
父节点
当前提交
ac0094a0af

+ 40
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/api/comm/DicController.java 查看文件

@@ -0,0 +1,40 @@
package cn.com.taiji.iaw.api.comm;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.web.ApiResponse;
import cn.com.taiji.iaw.api.MyValidController;
import cn.com.taiji.iaw.dto.CommRequestDTO;
import cn.com.taiji.iaw.dto.comm.DictItemModel;
import cn.com.taiji.iaw.manager.comm.DictManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
* @Author:ChenChao
* @Date:2025/7/17 15:36
* @Filename:DicController
* @description:
*/
@Api(tags = {"字典"})
@RestController
@RequestMapping("/api/dic")
public class DicController extends MyValidController {

@Autowired
private DictManager dictManager;
@ApiOperation(value = "2-4.字典项目获取所有")
@PostMapping(value = "/itemGetAll")
public ApiResponse<Map<String, List<DictItemModel>>> itemGetAll(@RequestBody @Valid CommRequestDTO req) throws ManagerException {
Map<String, List<DictItemModel>> response = dictManager.getAllDictItem(req);
return ApiResponse.of(response);
}
}

+ 29
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/dto/comm/DictItemModel.java 查看文件

@@ -0,0 +1,29 @@
package cn.com.taiji.iaw.dto.comm;

import cn.com.taiji.common.model.BaseModel;
import cn.com.taiji.core.entity.basic.DictItem;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class DictItemModel extends BaseModel {
private String dictTypeId;
private String code;
private String name;
private String description;
private Integer order;
private String dictItemId;
public static DictItemModel fromDictItem(DictItem dictItem) {
DictItemModel dictItemModel = new DictItemModel();
dictItemModel.setDictItemId(dictItem.getId());
dictItemModel.setDictTypeId(dictItem.getTypeId());
dictItemModel.setCode(dictItem.getCode());
dictItemModel.setName(dictItem.getName());
dictItemModel.setDescription(dictItem.getDescription());
// dictItemModel.setOrder(dictItem.getOrder());
return dictItemModel;
}
}



+ 44
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/manager/comm/DictManager.java 查看文件

@@ -0,0 +1,44 @@
package cn.com.taiji.iaw.manager.comm;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.core.entity.basic.DictItem;
import cn.com.taiji.core.entity.basic.DictType;
import cn.com.taiji.core.repo.jpa.basic.DictItemRepo;
import cn.com.taiji.core.repo.jpa.basic.DictTypeRepo;
import cn.com.taiji.iaw.dto.CommRequestDTO;
import cn.com.taiji.iaw.dto.comm.DictItemModel;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @Author:ChenChao
* @Date:2025/7/17 15:41
* @Filename:DictManager
* @description:
*/
@Service
public class DictManager {

@Autowired
private DictItemRepo dictItemRepo;
@Autowired
private DictTypeRepo dictTypeRepo;

public Map<String, List<DictItemModel>> getAllDictItem(CommRequestDTO req) throws ManagerException {
Map<String, List<DictItemModel>> dictTypeModels = Maps.newHashMap();
List<DictType> dictTypes = dictTypeRepo.findAll();
for (DictType dictType : dictTypes) {
List<DictItem> dictItemList = dictItemRepo.findByTypeId(dictType.getId());
if (dictItemList == null)
throw new ManagerException("未查询到对应数据,请检查参数!");
List<DictItemModel> dictItemModels =
dictItemList.stream().map(DictItemModel::fromDictItem).collect(Collectors.toList());
dictTypeModels.put(dictType.getCode(), dictItemModels);
}
return dictTypeModels;
}
}

正在加载...
取消
保存