package com.farriver.bwf.service.question; import com.farriver.bwf.common.model.ApiData; import com.farriver.bwf.common.model.ApiPageData; import com.farriver.bwf.common.options.ActionType; import com.farriver.bwf.common.options.MapDataType; import com.farriver.bwf.common.statics.LangConstants; import com.farriver.bwf.data.master.entity.QuestionMasterWithBLOBsExtend; import com.farriver.bwf.data.master.mapper.QuestionMasterMapper; import com.farriver.bwf.data.master.model.*; import com.farriver.bwf.data.transferobject.queryobject.question.QuestionMasterQueryObject; import com.farriver.bwf.data.transferobject.viewmodel.question.QuestionMasterAnswerViewModel; import com.farriver.bwf.data.transferobject.viewmodel.question.QuestionMasterOptionViewModel; import com.farriver.bwf.data.transferobject.viewmodel.question.QuestionMasterViewModel; import com.farriver.bwf.data.transferobject.viewmodel.question.QuestionPaperQuestionMasterRelationViewModel; import com.farriver.bwf.service.ServiceBase; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import jakarta.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service @CacheConfig(cacheNames = "kbs_QuestionMaster_cache") public class QuestionMasterService extends ServiceBase { private static final Logger logger = LoggerFactory.getLogger(QuestionMasterService.class); @Resource QuestionMasterMapper mapper; @Resource QuestionMasterAnswerService questionMasterAnswerService; @Resource QuestionMasterOptionService questionMasterOptionService; @Resource QuestionPaperQuestionMasterRelationService questionMasterPaperRelationService; private String message; public Map GetList(QuestionMasterQueryObject queryObject) { if (queryObject == null) return null; QuestionMasterExample example = new QuestionMasterExample(); QuestionMasterExample.Criteria criteria = example.createCriteria(); //查询条件 if (queryObject.getFilter() != null && !queryObject.getFilter().isEmpty()) { criteria.andNameLike("%" + queryObject.getFilter() + "%"); QuestionMasterExample.Criteria criteria2 = example.createCriteria(); criteria2.andCodeLike("%" + queryObject.getFilter() + "%"); example.or(criteria2); } else { if (queryObject.getId() != null && !queryObject.getId().isEmpty()) { criteria.andIdEqualTo(queryObject.getId()); } if (queryObject.getCode() != null && !queryObject.getCode().isEmpty()) { criteria.andCodeLike("%" + queryObject.getCode() + "%"); } if (queryObject.getName() != null && !queryObject.getName().isEmpty()) { criteria.andNameLike("%" + queryObject.getName() + "%"); } if (queryObject.getSubjectid() != null && !queryObject.getSubjectid().isEmpty()) { criteria.andSubjectidEqualTo(queryObject.getSubjectid()); } if (queryObject.getSubjectname() != null && !queryObject.getSubjectname().isEmpty()) { criteria.andSubjectnameLike("%" + queryObject.getSubjectname() + "%"); } if (queryObject.getKnowledgepointid() != null && !queryObject.getKnowledgepointid().isEmpty()) { criteria.andKnowledgepointidEqualTo(queryObject.getKnowledgepointid()); } if (queryObject.getKnowledgepointname() != null && !queryObject.getKnowledgepointname().isEmpty()) { criteria.andKnowledgepointnameLike("%" + queryObject.getKnowledgepointname() + "%"); } if (queryObject.getCategoryid() != null && !queryObject.getCategoryid().isEmpty()) { criteria.andCategoryidEqualTo(queryObject.getCategoryid()); } if (queryObject.getCategoryname() != null && !queryObject.getCategoryname().isEmpty()) { criteria.andCategorynameLike("%" + queryObject.getCategoryname() + "%"); } if (queryObject.getStatus() != null && queryObject.getStatus() >= 0) { criteria.andStatusEqualTo(queryObject.getStatus()); } if (queryObject.getStatuslist() != null && queryObject.getStatuslist().size() > 0) { criteria.andStatusIn(queryObject.getStatuslist()); } if (queryObject.getStartDateTime() != null && queryObject.getEndDateTime() != null) { criteria.andCreatetimeBetween(queryObject.getStartDateTime(), queryObject.getEndDateTime()); } } //查询总数 long total = mapper.countByExample(example); //分页 int pageIndex = queryObject.getPageIndex(); int pageSize = queryObject.getPageSize(); if (pageIndex > 0 && pageSize > 0) { example.setRows(pageSize); example.setOffset((pageIndex - 1) * pageSize); } List list = mapper.selectByExample(example); Map map = new HashMap<>(); map.put(MapDataType.DATA_LIST, list); map.put(MapDataType.TOTAL_COUNT, total); map.put(MapDataType.PAGE_INDEX, pageIndex); map.put(MapDataType.PAGE_SIZE, pageSize); return map; } public Map GetListWithBLOBs(QuestionMasterQueryObject queryObject) { if (queryObject == null) return null; QuestionMasterExample example = new QuestionMasterExample(); QuestionMasterExample.Criteria criteria = example.createCriteria(); //查询条件 if (queryObject.getFilter() != null && !queryObject.getFilter().isEmpty()) { criteria.andNameLike("%" + queryObject.getFilter() + "%"); } else { if (queryObject.getId() != null && !queryObject.getId().isEmpty()) { criteria.andIdEqualTo(queryObject.getId()); } if (queryObject.getCode() != null && !queryObject.getCode().isEmpty()) { criteria.andCodeLike("%" + queryObject.getCode() + "%"); } if (queryObject.getName() != null && !queryObject.getName().isEmpty()) { criteria.andNameLike("%" + queryObject.getName() + "%"); } if (queryObject.getSubjectid() != null && !queryObject.getSubjectid().isEmpty()) { criteria.andSubjectidEqualTo(queryObject.getSubjectid()); } if (queryObject.getSubjectname() != null && !queryObject.getSubjectname().isEmpty()) { criteria.andSubjectnameLike("%" + queryObject.getSubjectname() + "%"); } if (queryObject.getKnowledgepointid() != null && !queryObject.getKnowledgepointid().isEmpty()) { criteria.andKnowledgepointidEqualTo(queryObject.getKnowledgepointid()); } if (queryObject.getKnowledgepointname() != null && !queryObject.getKnowledgepointname().isEmpty()) { criteria.andKnowledgepointnameLike("%" + queryObject.getKnowledgepointname() + "%"); } if (queryObject.getCategoryid() != null && !queryObject.getCategoryid().isEmpty()) { criteria.andCategoryidEqualTo(queryObject.getCategoryid()); } if (queryObject.getCategoryname() != null && !queryObject.getCategoryname().isEmpty()) { criteria.andCategorynameLike("%" + queryObject.getCategoryname() + "%"); } if (queryObject.getStatus() != null && queryObject.getStatus() >= 0) { criteria.andStatusEqualTo(queryObject.getStatus()); } if (queryObject.getStatuslist() != null && queryObject.getStatuslist().size() > 0) { criteria.andStatusIn(queryObject.getStatuslist()); } if (queryObject.getStartDateTime() != null && queryObject.getEndDateTime() != null) { criteria.andCreatetimeBetween(queryObject.getStartDateTime(), queryObject.getEndDateTime()); } if (queryObject.getIds() != null && queryObject.getIds().size() > 0) { criteria.andIdIn(queryObject.getIds()); } } //查询总数 long total = mapper.countByExample(example); //分页 int pageIndex = queryObject.getPageIndex(); int pageSize = queryObject.getPageSize(); if (pageIndex > 0 && pageSize > 0) { example.setRows(pageSize); example.setOffset((pageIndex - 1) * pageSize); } List list = mapper.selectByExampleWithBLOBs(example); Map map = new HashMap<>(); map.put(MapDataType.DATA_LIST, list); map.put(MapDataType.TOTAL_COUNT, total); map.put(MapDataType.PAGE_INDEX, pageIndex); map.put(MapDataType.PAGE_SIZE, pageSize); return map; } public Map GetListWithBLOBsExtend(QuestionMasterQueryObject queryObject) { if (queryObject == null) return null; QuestionMasterExample example = new QuestionMasterExample(); QuestionMasterExample.Criteria criteria = example.createCriteria(); //查询条件 if (queryObject.getFilter() != null && !queryObject.getFilter().isEmpty()) { criteria.andNameLike("%" + queryObject.getFilter() + "%"); } else { if (queryObject.getId() != null && !queryObject.getId().isEmpty()) { criteria.andIdEqualTo(queryObject.getId()); } if (queryObject.getCode() != null && !queryObject.getCode().isEmpty()) { criteria.andCodeLike("%" + queryObject.getCode() + "%"); } if (queryObject.getName() != null && !queryObject.getName().isEmpty()) { criteria.andNameLike("%" + queryObject.getName() + "%"); } if (queryObject.getSubjectid() != null && !queryObject.getSubjectid().isEmpty()) { criteria.andSubjectidEqualTo(queryObject.getSubjectid()); } if (queryObject.getSubjectname() != null && !queryObject.getSubjectname().isEmpty()) { criteria.andSubjectnameLike("%" + queryObject.getSubjectname() + "%"); } if (queryObject.getKnowledgepointid() != null && !queryObject.getKnowledgepointid().isEmpty()) { criteria.andKnowledgepointidEqualTo(queryObject.getKnowledgepointid()); } if (queryObject.getKnowledgepointname() != null && !queryObject.getKnowledgepointname().isEmpty()) { criteria.andKnowledgepointnameLike("%" + queryObject.getKnowledgepointname() + "%"); } if (queryObject.getCategoryid() != null && !queryObject.getCategoryid().isEmpty()) { criteria.andCategoryidEqualTo(queryObject.getCategoryid()); } if (queryObject.getCategoryname() != null && !queryObject.getCategoryname().isEmpty()) { criteria.andCategorynameLike("%" + queryObject.getCategoryname() + "%"); } if (queryObject.getStatus() != null && queryObject.getStatus() >= 0) { criteria.andStatusEqualTo(queryObject.getStatus()); } if (queryObject.getStatuslist() != null && queryObject.getStatuslist().size() > 0) { criteria.andStatusIn(queryObject.getStatuslist()); } if (queryObject.getStartDateTime() != null && queryObject.getEndDateTime() != null) { criteria.andCreatetimeBetween(queryObject.getStartDateTime(), queryObject.getEndDateTime()); } if (queryObject.getIds() != null && queryObject.getIds().size() > 0) { criteria.andIdIn(queryObject.getIds()); } } //查询总数 long total = mapper.countByExample(example); //分页 int pageIndex = queryObject.getPageIndex(); int pageSize = queryObject.getPageSize(); if (pageIndex > 0 && pageSize > 0) { example.setRows(pageSize); example.setOffset((pageIndex - 1) * pageSize); } List list = mapper.selectByExampleWithBLOBsExtend(example); Map map = new HashMap<>(); map.put(MapDataType.DATA_LIST, list); map.put(MapDataType.TOTAL_COUNT, total); map.put(MapDataType.PAGE_INDEX, pageIndex); map.put(MapDataType.PAGE_SIZE, pageSize); return map; } public QuestionMaster GetDetail(QuestionMasterQueryObject queryObject) { Map map = GetList(queryObject); Object object = map.get(MapDataType.DATA_LIST); if (object != null) { List list = (List) object; if (list != null && list.size() == 1) return list.get(0); } return null; } public QuestionMasterWithBLOBs GetDetailWithBLOBs(QuestionMasterQueryObject queryObject) { Map map = GetListWithBLOBs(queryObject); Object object = map.get(MapDataType.DATA_LIST); if (object != null) { List list = (List) object; if (list != null && list.size() == 1) return list.get(0); } return null; } @Transactional @CacheEvict(allEntries = true) public ApiData Create(QuestionMasterViewModel model) { QuestionMasterWithBLOBs entity = Check(ActionType.CREATE, model); if (entity != null) { questionMasterAnswerService.BatchCreate(entity.getId(), model.getAnswers()); questionMasterOptionService.BatchCreate(entity.getId(), model.getOptions()); return ApiData.ok(LangConstants.MSG_INFO_SUCCESS, mapper.insertSelective(entity)); } else { return ApiData.error(message); } } @Transactional @CacheEvict(allEntries = true) public ApiData Update(QuestionMasterViewModel model) { QuestionMasterWithBLOBs entity = Check(ActionType.UPDATE, model); if (entity != null) { questionMasterAnswerService.BatchDelete(entity.getId()); questionMasterAnswerService.BatchCreate(entity.getId(), model.getAnswers()); questionMasterOptionService.BatchDelete(entity.getId()); questionMasterOptionService.BatchCreate(entity.getId(), model.getOptions()); return ApiData.ok(LangConstants.MSG_INFO_SUCCESS, mapper.updateByPrimaryKeySelective(entity)); } else { return ApiData.error(message); } } @CacheEvict(allEntries = true) public ApiData Delete(String id) { return ApiData.ok("", mapper.deleteByPrimaryKey(id)); } @Transactional @CacheEvict(allEntries = true) public ApiData BatchDelete(QuestionMasterQueryObject queryObject) { Map map = GetList(queryObject); Object object = map.get(MapDataType.DATA_LIST); int count = 0; if (object != null) { List list = (List) object; if (list != null && list.size() == 1) { count += mapper.deleteByPrimaryKey(list.get(0).getId()); } } return ApiData.ok("", count); } @Cacheable public QuestionMasterViewModel GetViewDetail(QuestionMasterQueryObject queryObject) { QuestionMaster entity = GetDetail(queryObject); return BuildViewModel(entity); } @Cacheable public QuestionMasterViewModel GetViewDetailWithBLOBs(QuestionMasterQueryObject queryObject) { QuestionMasterWithBLOBs entity = GetDetailWithBLOBs(queryObject); return BuildViewModel(entity); } @Cacheable public ApiData GetViewDetailWithBLOBs(String id) { QuestionMasterQueryObject queryObject = new QuestionMasterQueryObject(); queryObject.setId(id); QuestionMasterWithBLOBs entity = GetDetailWithBLOBs(queryObject); QuestionMasterViewModel result = BuildViewModel(entity); if (result != null) return ApiData.ok(LangConstants.MSG_INFO_SUCCESS, result); else return ApiData.error(LangConstants.MSG_ERROR_PARAMETERS); } @Cacheable public ApiPageData GetViewPageList(QuestionMasterQueryObject queryObject) { Map map = GetList(queryObject); List list = (List) map.get(MapDataType.DATA_LIST); List viewModels = new ArrayList<>(); for (QuestionMaster entity : list) { QuestionMasterViewModel viewModel = BuildViewModel(entity); viewModels.add(viewModel); } ApiPageData bean = ApiPageData.build(); bean.setData(viewModels); bean.setTotal((Long) map.get(MapDataType.TOTAL_COUNT)); return bean; } @Cacheable public ApiPageData GetViewPageListWithBLOBs(QuestionMasterQueryObject queryObject) { Map map = GetListWithBLOBs(queryObject); List list = (List) map.get(MapDataType.DATA_LIST); List viewModels = new ArrayList<>(); for (QuestionMasterWithBLOBs entity : list) { QuestionMasterViewModel viewModel = BuildViewModel(entity); viewModels.add(viewModel); } ApiPageData bean = ApiPageData.build(); bean.setData(viewModels); bean.setTotal((Long) map.get(MapDataType.TOTAL_COUNT)); return bean; } @Cacheable public ApiPageData GetViewPageListWithBLOBsExtend(QuestionMasterQueryObject queryObject) { Map map = GetListWithBLOBsExtend(queryObject); List list = (List) map.get(MapDataType.DATA_LIST); List viewModels = new ArrayList<>(); for (QuestionMasterWithBLOBsExtend entity : list) { QuestionMasterViewModel viewModel = BuildViewModel(entity); viewModels.add(viewModel); } ApiPageData bean = ApiPageData.build(); bean.setData(viewModels); bean.setTotal((Long) map.get(MapDataType.TOTAL_COUNT)); return bean; } @Cacheable public ApiData GetQuestionMasterListByPaperid(String paperid) { ApiPageData relations = questionMasterPaperRelationService.GetViewPageListByPrimaryKey(paperid); if (relations == null) { return ApiData.error(LangConstants.MSG_ERROR_PARAMETERS); } List relationViewModels = (List) relations.getData(); if (relationViewModels == null || relationViewModels.size() <= 0) { return ApiData.error(LangConstants.MSG_ERROR_PARAMETERS); } List questionids = relationViewModels.stream().map(QuestionPaperQuestionMasterRelationViewModel::getQuestionid).collect(Collectors.toList()); if (questionids == null || questionids.size() <= 0) { return ApiData.error(LangConstants.MSG_ERROR_PARAMETERS); } QuestionMasterQueryObject questionMasterQueryObject = new QuestionMasterQueryObject(); questionMasterQueryObject.setIds(questionids); ApiPageData questions = GetViewPageListWithBLOBsExtend(questionMasterQueryObject); if (questions == null) { return ApiData.error(LangConstants.MSG_ERROR_PARAMETERS); } List questionMasterViewModels = (List) questions.getData(); return ApiData.ok(LangConstants.MSG_INFO_SUCCESS, questionMasterViewModels); } //private methods public static QuestionMasterViewModel BuildViewModel(QuestionMaster entity) { if (entity == null) return null; QuestionMasterViewModel model = new QuestionMasterViewModel(); model.setId(entity.getId()); model.setCode(entity.getCode()); model.setName(entity.getName()); model.setIsdeleted(entity.getIsdeleted()); model.setRemark(entity.getRemark()); model.setCreatetime(entity.getCreatetime()); model.setUpdatetime(entity.getUpdatetime()); model.setStatus(entity.getStatus()); model.setSubjectid(entity.getSubjectid()); model.setSubjectname(entity.getSubjectname()); model.setSubjectcode(entity.getSubjectcode()); model.setCategoryid(entity.getCategoryid()); model.setCategoryname(entity.getCategoryname()); model.setLevel(entity.getLevel()); model.setScore(entity.getScore()); model.setKnowledgepointid(entity.getKnowledgepointid()); model.setKnowledgepointcode(entity.getKnowledgepointcode()); model.setKnowledgepointname(entity.getKnowledgepointname()); return model; } public static QuestionMasterViewModel BuildViewModel(QuestionMasterWithBLOBs entity) { if (entity == null) return null; QuestionMasterViewModel model = new QuestionMasterViewModel(); model.setId(entity.getId()); model.setCode(entity.getCode()); model.setName(entity.getName()); model.setIsdeleted(entity.getIsdeleted()); model.setRemark(entity.getRemark()); model.setCreatetime(entity.getCreatetime()); model.setUpdatetime(entity.getUpdatetime()); model.setStatus(entity.getStatus()); model.setStem(entity.getStem()); model.setAnswer(entity.getAnswer()); model.setCasebody(entity.getCasebody()); model.setAnalysis(entity.getAnalysis()); model.setSubjectid(entity.getSubjectid()); model.setSubjectname(entity.getSubjectname()); model.setSubjectcode(entity.getSubjectcode()); model.setCategoryid(entity.getCategoryid()); model.setCategoryname(entity.getCategoryname()); model.setLevel(entity.getLevel()); model.setScore(entity.getScore()); model.setKnowledgepointid(entity.getKnowledgepointid()); model.setKnowledgepointcode(entity.getKnowledgepointcode()); model.setKnowledgepointname(entity.getKnowledgepointname()); return model; } public static QuestionMasterViewModel BuildViewModel(QuestionMasterWithBLOBsExtend entity) { if (entity == null) return null; QuestionMasterViewModel model = new QuestionMasterViewModel(); model.setId(entity.getId()); model.setCode(entity.getCode()); model.setName(entity.getName()); model.setIsdeleted(entity.getIsdeleted()); model.setRemark(entity.getRemark()); model.setCreatetime(entity.getCreatetime()); model.setUpdatetime(entity.getUpdatetime()); model.setStatus(entity.getStatus()); model.setStem(entity.getStem()); model.setAnswer(entity.getAnswer()); model.setCasebody(entity.getCasebody()); model.setAnalysis(entity.getAnalysis()); model.setSubjectid(entity.getSubjectid()); model.setSubjectname(entity.getSubjectname()); model.setSubjectcode(entity.getSubjectcode()); model.setCategoryid(entity.getCategoryid()); model.setCategoryname(entity.getCategoryname()); model.setLevel(entity.getLevel()); model.setScore(entity.getScore()); model.setKnowledgepointid(entity.getKnowledgepointid()); model.setKnowledgepointcode(entity.getKnowledgepointcode()); model.setKnowledgepointname(entity.getKnowledgepointname()); if (entity.getAnswers() != null && entity.getAnswers().size() > 0) { List answers = new ArrayList<>(); List questionMasterAnswers = entity.getAnswers(); Collections.sort(questionMasterAnswers, (QuestionMasterAnswer o1, QuestionMasterAnswer o2) -> { if (o2.getSequenceno() == null || o1.getSequenceno() == null) return o2.getQkey().compareTo(o1.getQkey()); int levelC = o2.getSequenceno() - o1.getSequenceno(); if (levelC == 0) return o2.getQkey().compareTo(o1.getQkey()); else return levelC; }); for (QuestionMasterAnswer answer : questionMasterAnswers) { QuestionMasterAnswerViewModel viewModel = QuestionMasterAnswerService.BuildViewModel(answer); if (viewModel != null) { answers.add(viewModel); } } model.setAnswers(answers); } if (entity.getOptions() != null && entity.getOptions().size() > 0) { List options = new ArrayList<>(); List questionMasterOptions = entity.getOptions(); Collections.sort(questionMasterOptions, (QuestionMasterOption o1, QuestionMasterOption o2) -> { if (o2.getSequenceno() == null || o1.getSequenceno() == null) return o2.getQkey().compareTo(o1.getQkey()); int levelC = o2.getSequenceno() - o1.getSequenceno(); if (levelC == 0) return o2.getQkey().compareTo(o1.getQkey()); else return levelC; }); for (QuestionMasterOption option : questionMasterOptions) { QuestionMasterOptionViewModel viewModel = QuestionMasterOptionService.BuildViewModel(option); if (viewModel != null) { options.add(viewModel); } } model.setOptions(options); } return model; } public QuestionMasterWithBLOBs Check(ActionType actionType, QuestionMasterViewModel model) { message = ""; if (model == null) { message = LangConstants.MSG_ERROR_PARAMETERS; return null; } QuestionMasterWithBLOBs entity = null; if (ActionType.CREATE == actionType) { entity = new QuestionMasterWithBLOBs(); entity.setId(UUID.randomUUID().toString()); entity.setCreatetime(new Date()); entity.setIsdeleted(false); String oldCode = GetLatestCode(); String newCode = generateCode(oldCode); if (newCode == null) return null; entity.setCode(newCode); } else { QuestionMasterQueryObject queryObject = new QuestionMasterQueryObject(); queryObject.setId(model.getId()); entity = GetDetailWithBLOBs(queryObject); entity.setUpdatetime(new Date()); } entity.setName(model.getName()); entity.setRemark(model.getRemark()); entity.setStatus(model.getStatus()); entity.setStem(model.getStem()); entity.setAnswer(model.getAnswer()); entity.setCasebody(model.getCasebody()); entity.setAnalysis(model.getAnalysis()); entity.setSubjectid(model.getSubjectid()); entity.setSubjectname(model.getSubjectname()); entity.setSubjectcode(model.getSubjectcode()); entity.setCategoryid(model.getCategoryid()); entity.setCategoryname(model.getCategoryname()); entity.setLevel(model.getLevel()); entity.setScore(model.getScore()); entity.setKnowledgepointid(model.getKnowledgepointid()); entity.setKnowledgepointcode(model.getKnowledgepointcode()); entity.setKnowledgepointname(model.getKnowledgepointname()); return entity; } @Nullable public String generateCode(String oldCode) { String preNo = "Q"; int _newCodeNum = 1; try { int _oldCodeNum = 0; if (oldCode != null && !oldCode.equals("") && oldCode.length() > 2) { String _oldNoNumString = oldCode.substring(2); _oldCodeNum = Integer.parseInt(_oldNoNumString); } if (_oldCodeNum != 0) { int a = _oldCodeNum + 1; _newCodeNum = a; } } catch (NumberFormatException e) { e.printStackTrace(); message = LangConstants.MSG_ERROR_SYSTEM; return null; } return String.format("%s%07d", preNo, _newCodeNum); } public String GetLatestCode() { String oldCode = ""; QuestionMasterExample example = new QuestionMasterExample(); example.setOrderByClause("code desc"); example.setRows(1); example.setOffset(0); List list = mapper.selectByExample(example); if (list != null && list.size() > 0) { QuestionMaster entity2 = list.get(0); if (entity2 != null) { oldCode = entity2.getCode(); } } return oldCode; } }