123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package com.bowintek.practice.services.impl;
- import com.bowintek.practice.filter.exception.BaseException;
- import com.bowintek.practice.mapper.SrSubjectMapper;
- import com.bowintek.practice.mapper.SrSubjectfieldMapper;
- import com.bowintek.practice.mapper.cquery.SubjectCQuery;
- import com.bowintek.practice.model.*;
- import com.bowintek.practice.services.service.SubjectService;
- import com.bowintek.practice.services.service.system.DictionaryService;
- import com.bowintek.practice.util.Constant;
- import com.bowintek.practice.util.StringUtils;
- import com.bowintek.practice.vo.SubjectfieldVo;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.UUID;
- import java.util.stream.Collectors;
- @Service("SubjectService")
- public class SubjectServiceImpl implements SubjectService {
- @Autowired
- private SrSubjectMapper subjectMapper;
- @Autowired
- private SrSubjectfieldMapper subjectfieldMapper;
- @Autowired
- private SubjectCQuery subjectCQuery;
- @Autowired
- private StringUtils stringUtils;
- @Autowired
- private DictionaryService dictionaryService;
- @Override
- public PageInfo<SrSubject> getList(Integer page, Integer rows,
- String subjectName, String tabName, String tabCode, List<String> idList) {
- PageHelper.startPage(page, rows);
- List<SrSubject> dataList = subjectCQuery.getList(subjectName, tabName,
- tabCode, stringUtils.ListToInSql(idList));
- PageInfo<SrSubject> result = new PageInfo(dataList);
- return result;
- }
- @Override
- public SrSubject getSubject(String subjectId) {
- return subjectMapper.selectByPrimaryKey(subjectId);
- }
- @Override
- public int saveSubject(SrSubject model, List<SrSubjectfield> fieldList, String userId) {
- if (model.getIsReferences() == 0) {
- model.setExecSql(model.getTabCode());
- }
- SrSubject dbData = subjectMapper.selectByPrimaryKey(model.getSubId());
- int result = 0;
- if (dbData == null) {
- model.setSubId(UUID.randomUUID().toString());
- model.setStatus(1);
- model.setCreatedBy(userId);
- model.setCreateTime(new Date());
- model.setModiTime(new Date());
- result = subjectMapper.insert(model);
- } else {
- model.setModiTime(new Date());
- result = subjectMapper.updateByPrimaryKey(model);
- }
- if (fieldList != null && fieldList.size() > 0) {
- SrSubjectfieldExample example = new SrSubjectfieldExample();
- SrSubjectfieldExample.Criteria criteria = example.or();
- criteria.andSubIdEqualTo(model.getSubId());
- List<SrSubjectfield> dbList = subjectfieldMapper.selectByExample(example);
- List<String> ids = fieldList.stream().map(x -> x.getFieldId()).collect(Collectors.toList());
- criteria.andFieldIdNotIn(ids);
- subjectfieldMapper.deleteByExample(example);
- fieldList.stream().forEach(x -> {
- long count = dbList.stream().filter(f -> f.getFieldId() == x.getFieldId()).count();
- //不是外键字段编码和显示别名需一致
- x.setFieldAlias(x.getIsForeignKey() == 0 ? x.getFieldCode() : x.getFieldAlias());
- if (count > 0) {
- subjectfieldMapper.updateByPrimaryKeySelective(x);
- } else {
- x.setSubId(model.getSubId());
- x.setFieldId(UUID.randomUUID().toString());
- x.setStatus(1);
- subjectfieldMapper.insertSelective(x);
- }
- });
- }
- return result;
- }
- @Override
- public List<SrSubjectfield> getFieldList(String subjectId) {
- SrSubjectfieldExample example = new SrSubjectfieldExample();
- SrSubjectfieldExample.Criteria criteria = example.or();
- criteria.andSubIdEqualTo(subjectId);
- List<SrSubjectfield> dbList = subjectfieldMapper.selectByExample(example);
- return dbList;
- }
- @Override
- public int delete(List<String> idList) {
- try {
- SrSubjectfieldExample example = new SrSubjectfieldExample();
- SrSubjectfieldExample.Criteria criteria = example.or();
- criteria.andSubIdIn(idList);
- subjectfieldMapper.selectByExample(example);
- SrSubjectExample subExp = new SrSubjectExample();
- subExp.or().andSubIdIn(idList);
- subjectMapper.deleteByExample(subExp);
- } catch (Exception e) {
- return 0;
- }
- return 1;
- }
- @Override
- public List<SubjectfieldVo> importData(List<SubjectfieldVo> dataList, String loginUserID) {
- if (dataList.size() <= 0)
- throw new BaseException("", "请添加导入数据!");
- List<SysDictionaryItem> dicQueryTypeList = dictionaryService.getDictionaryItemList("queryType");
- List<SysDictionaryItem> dicSettingTypeList = dictionaryService.getDictionaryItemList("settingType");
- dataList.forEach(item -> {
- String errorInfo = "";
- SysDictionaryItem dicQueryType = dicQueryTypeList.stream().filter(e -> e.getName().equals(item.getQueryTypeName())).findFirst().orElse(null);
- SysDictionaryItem dicSettingType = dicSettingTypeList.stream().filter(e -> e.getName().equals(item.getSettingTypeName())).findFirst().orElse(null);
- if (stringUtils.IsNullOrEmpty(item.getFieldCode()))
- errorInfo += "请填写字段编码!";
- if (stringUtils.IsNullOrEmpty(item.getFieldName()))
- errorInfo += "请填写字段名称!";
- if (stringUtils.IsNullOrEmpty(item.getSettingTypeName()))
- errorInfo += "请填写配置类型!";
- if (stringUtils.IsNullOrEmpty(item.getDataType()))
- errorInfo += "请填写数据类型!";
- if ("字典值".equals(item.getDataType())) {
- if (stringUtils.IsNullOrEmpty(item.getDictionaryCode()))
- errorInfo += "查询类型为字典值请填写取数字典编码!";
- }
- if (item.getDisOrder() == null)
- errorInfo += "请填写显示排序!";
- if (stringUtils.IsNullOrEmpty(item.getIsSearchFieldText()))
- errorInfo += "请填写是否查询字段!";
- else if (!Constant.YES.equals(item.getIsSearchFieldText()) && !Constant.No.equals(item.getIsSearchFieldText())) {
- errorInfo += "是否查询字段请填是或者否!";
- }
- if (stringUtils.IsNullOrEmpty(item.getIsForeignKeyText()))
- errorInfo += "请填写是否关联字段!";
- else if (!Constant.YES.equals(item.getIsForeignKeyText()) && !Constant.No.equals(item.getIsForeignKeyText())) {
- errorInfo += "是否关联字段请填是或者否!";
- }
- if (Constant.YES.equals(item.getIsForeignKeyText())) {
- if (stringUtils.IsNullOrEmpty(item.getFieldAlias()))
- errorInfo += "关联字段请填写显示别名!";
- if (stringUtils.IsNullOrEmpty(item.getReferencesTab()))
- errorInfo += "关联字段请填写外键表!";
- if (stringUtils.IsNullOrEmpty(item.getReferencesTab()))
- errorInfo += "关联字段请填写外键列!";
- if (stringUtils.IsNullOrEmpty(item.getReferencesTab()))
- errorInfo += "关联字段请填写外键表显示列!";
- }
- if (dicSettingType == null)
- errorInfo += "配置类型数据有误!";
- if (dicQueryType == null)
- errorInfo += "查询类型不在支持范围!";
- if (stringUtils.IsNullOrEmpty(errorInfo)) {
- item.setQueryTypeId(dicQueryType.getValue());
- item.setSettingTypeId(dicSettingType.getValue());
- item.setIsSearchField(Constant.YES.equals(item.getIsSearchFieldText()) ? 1 : 0);
- item.setIsForeignKey(Constant.YES.equals(item.getIsForeignKeyText()) ? 1 : 0);
- }
- item.setErrorMessage(errorInfo);
- });
- return dataList;
- }
- }
|