WCS
dengjunjie
2024-10-14 901c64f294ee75784f3fec80b47ae6b77932fff3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.DB;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.System;
using WIDESEAWCS_ISystemRepository;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_SystemServices
{
    public class Sys_DictionaryService : ServiceBase<Sys_Dictionary, ISys_DictionaryRepository>, ISys_DictionaryService
    {
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        public Sys_DictionaryService(ISys_DictionaryRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
        {
            _unitOfWorkManage = unitOfWorkManage;
        }
 
        public List<VueDictionaryDTO> GetVueDictionary(string[] dicNos)
        {
            if (dicNos == null || dicNos.Count() == 0) return new List<VueDictionaryDTO>();
 
            var dicConfig = BaseDal.GetDictionaries(dicNos, false).Select(s => new
            {
                dicNo = s.DicNo,
                config = s.Config,
                dbSql = s.DBSql,
                list = s.DicList.OrderByDescending(o => o.OrderNo).Select(list => new { key = list.DicValue, value = list.DicName })
            }).ToList();
 
            object GetSourceData(string dicNo, string dbSql, object data)
            {
                if (string.IsNullOrEmpty(dbSql))
                {
                    return data;
                }
                return BaseDal.QueryObjectDataBySql(dbSql, null);
            }
            return dicConfig.Select(item => new VueDictionaryDTO
            {
                DicNo = item.dicNo,
                Config = item.config,
                Data = GetSourceData(item.dicNo, item.dbSql, item.list)
            }).ToList();
        }
    }
}