25ee5d0977793f58f8aaefabbffde07b7124fa73.svn-base 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package org.jeecg.config;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.jeecg.common.api.CommonAPI;
  4. import org.jeecg.common.system.vo.DictModel;
  5. import org.jeecg.common.util.oConvertUtils;
  6. import org.jeecgframework.dict.service.AutoPoiDictServiceI;
  7. import org.springframework.context.annotation.Lazy;
  8. import org.springframework.stereotype.Service;
  9. import javax.annotation.Resource;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. /**
  13. * 描述:AutoPoi Excel注解支持字典参数设置
  14. * 举例: @Excel(name = "性别", width = 15, dicCode = "sex")
  15. * 1、导出的时候会根据字典配置,把值1,2翻译成:男、女;
  16. * 2、导入的时候,会把男、女翻译成1,2存进数据库;
  17. *
  18. * @Author:scott
  19. * @since:2019-04-09
  20. * @Version:1.0
  21. */
  22. @Slf4j
  23. @Service
  24. public class AutoPoiDictConfig implements AutoPoiDictServiceI {
  25. @Lazy
  26. @Resource
  27. private CommonAPI commonAPI;
  28. /**
  29. * 通过字典查询easypoi,所需字典文本
  30. *
  31. * @Author:scott
  32. * @since:2019-04-09
  33. * @return
  34. */
  35. @Override
  36. public String[] queryDict(String dicTable, String dicCode, String dicText) {
  37. List<String> dictReplaces = new ArrayList<String>();
  38. List<DictModel> dictList = null;
  39. // step.1 如果没有字典表则使用系统字典表
  40. if (oConvertUtils.isEmpty(dicTable)) {
  41. dictList = commonAPI.queryDictItemsByCode(dicCode);
  42. } else {
  43. try {
  44. dicText = oConvertUtils.getString(dicText, dicCode);
  45. dictList = commonAPI.queryTableDictItemsByCode(dicTable, dicText, dicCode);
  46. } catch (Exception e) {
  47. log.error(e.getMessage(),e);
  48. }
  49. }
  50. for (DictModel t : dictList) {
  51. if(t!=null){
  52. dictReplaces.add(t.getText() + "_" + t.getValue());
  53. }
  54. }
  55. if (dictReplaces != null && dictReplaces.size() != 0) {
  56. log.info("---AutoPoi--Get_DB_Dict------"+ dictReplaces.toString());
  57. return dictReplaces.toArray(new String[dictReplaces.size()]);
  58. }
  59. return null;
  60. }
  61. }