import com.google.common.collect.Lists; import com.hbisdt.dtap.system.dao.Aa10Mapper; import com.hbisdt.dtap.system.domain.Aa10; import com.hbisdt.dtap.system.domain.vo.Ga06DetailVo; import com.hbisdt.dtap.system.service.IAa10Service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Service public class TransformValeUtil { @Autowired private IAa10Service serviceAa10; @Autowired private Aa10Mapper aa10Mapper; private List<Aa10> aa10s = new ArrayList<>(); public void transferredMeaning(Ga06DetailVo ga06DetailVo, Class cls) throws IllegalAccessException { List<Aa10> aa10s = serviceAa10.list(); Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { String name = field.getName(); Map<String, String> map = aa10s.stream().filter(aa10 -> aa10.getAaa100().equalsIgnoreCase(name)) .collect(Collectors.toMap(aa10 -> aa10.getAaa102(), aa10 -> aa10.getAaa103())); if (map.size() > 0) { field.setAccessible(true); Object key = field.get(ga06DetailVo); //获取值 if (null != key) { String relVal = map.get(key.toString()); field.set(ga06DetailVo, relVal); } } } } private List<Aa10> getAa10Value() { List<Aa10> aa10sUnRule = Lists.newArrayList(); String columu = "AGC151"; List<Aa10> listAGC151 = aa10Mapper.getJgyxDictMsgByColumu(columu); for (Aa10 aa10 : listAGC151) { aa10.setAaa100("AAC009"); } String columuAGE629 = "AGE629"; List<Aa10> listAGE629 = aa10Mapper.getJgyxDictMsgByColumu(columuAGE629); for (Aa10 aa10 : listAGE629) { aa10.setAaa100("AGE739"); } aa10sUnRule.addAll(listAGC151); aa10sUnRule.addAll(listAGE629); return aa10sUnRule; } public void transferredMeaningObj(Object obj, Class cls) throws IllegalAccessException { if (aa10s.size() <= 0) { aa10s = serviceAa10.list(); aa10s.addAll(getAa10Value()); } Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { String name = field.getName(); Map<String, String> map = aa10s.stream().filter(aa10 -> aa10.getAaa100().equalsIgnoreCase(name)) .collect(Collectors.toMap(aa10 -> aa10.getAaa102(), aa10 -> aa10.getAaa103())); if (map.size() > 0) { field.setAccessible(true); Object key = field.get(obj); //获取值 if (null != key) { String relVal = map.get(key.toString()); field.set(obj, relVal); } } field.setAccessible(true); Object key = field.get(obj); //获取值 if (null != key && !name.equalsIgnoreCase("age537")) { if (key.toString().equalsIgnoreCase("0")) { field.set(obj, "否"); } else if (key.toString().equalsIgnoreCase("1")) { field.set(obj, "是"); } } } } }
04-05
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交