Ben Lin
2024-06-20 de7e6c408b6209158b08991d729c4bcc72055eec
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * @Description: file content
 * @Author: Ben Lin
 * @version: 
 * @Date: 2024-06-18 15:09:47
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-19 14:30:04
 */
import { buildUUID } from '../../utils/uuid';
import { ApiActionPage } from '../model/baseModel';
import { DeptListGetResultModel, DeptListItem, DeptPageParams } from './model/systemModel';
import { genAction, Api, genActionPage } from './system';
import { defHttp } from '/@/utils/http/axios';
 
export const getTreeList = () =>
  defHttp.get<DeptListGetResultModel>(
    { url: Api.GetOrgTreeList },
    {
      isTransformResponse: false,
    },
  );
 
export const getProdTreeList = () =>
  defHttp.get<DeptListGetResultModel>(
    { url: Api.GetProdTreeList },
    {
      isTransformResponse: false,
    },
  );
 
/**
 * @description: 获取工厂列表带权限控制
 * @param {string} userId
 * @return {*}
 */  
export async function getProdTree(user: {}) {
    let res = await Promise.all([getProdTreeList(), prodListApi(user['userId'])]);
    let treeData = res[0];
    treeData = treeData.filter((x) =>
      res[1].Data.Items.some((item) => item.PROD_CODE == x.deptCode),
    );
    return treeData;
}
 
export const getDeptListByPage = async (params: DeptPageParams) => {
  let sqlcmd = '';
  console.log(1, params);
  if (params?.deptName != undefined && params?.deptName != '') {
    sqlcmd += " And DEPT_NAME like '%" + params?.deptName + "%'";
  }
  if (params?.status != undefined) {
    sqlcmd += "And STATUS = '" + params?.status + "'";
    console.log(2, params);
  }
  console.log(3, sqlcmd);
  const rParams = genActionPage('SYS_DEPT', sqlcmd, params.page, params.pageSize);
  return getDeptListByPageAsync(rParams);
};
 
async function getDeptListByPageAsync(params: ApiActionPage) {
  const data = await defHttp.post<ApiActionPage>(
    { url: Api.EntityPageList, params },
    {
      isTransformResponse: false,
    },
  );
  const model: DeptListGetResultModel = {
    items: data.Data.data,
    total: data.Data.totals,
  };
  return model;
}
 
/*
 * 新增部门
 */
export const SaveDept = async (params: Recordable, isUpdate: boolean) => {
  const deptitem: DeptListItem = {
    ID: params.id,
    SEQ_NO: params.orderNo,
    REMARK: params.remark,
    ORG_NAME: params.deptName,
    PARENT: params.PARENT,
    STATUS: params.status,
    CREATE_TIME: params.createTime,
    ORG_CODE: params.deptCode,
  };
  let data;
  if (isUpdate) {
    const time = new Date();
    params.CREATE_TIME = time.toDateString();
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('SYS_ORGANIZATION', deptitem) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    params.ID = buildUUID(); //生成GUID
    data = await defHttp.post(
      { url: Api.AddEntity, params: genAction('SYS_ORGANIZATION', deptitem) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
};
 
/*
 * 删除部门
 */
export const DeleteDept = async (params: Recordable) => {
  const deptitem: DeptListItem = {
    ID: params.id,
    SEQ_NO: params.orderNo,
    REMARK: params.remark,
    ORG_NAME: params.deptName,
    PARENT: params.PARENT,
    STATUS: params.status,
    CREATE_TIME: params.createTime,
    ORG_CODE: params.deptCode,
  };
 
  const dParams = genAction('SYS_ORGANIZATION', [deptitem]);
  return await defHttp.post(
    { url: Api.DeleteList, params: dParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
// params: Recordable
// userid: string
// 据点下拉树
export const optionsListApi = async (params: Recordable) => {
  // const usParams = genAction('V_USER_ORG', `USER_ID='${userid}'`);
  const usParams = genAction('V_USER_ORG', {
    QueryAble_T: '',
    where: "USER_ID = '" + params + "'",
    order: '',
  });
  const data = await defHttp.post(
    { url: Api.QueryUrl, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
      // apiUrl: globSetting.taskApiUrl
    },
  );
  return data;
};
 
export const prodListApi = async (userId: string) => {
  // const usParams = genAction('V_USER_ORG', `USER_ID='${userid}'`);
  const usParams = genAction('V_USER_PROD', {
    QueryAble_T: '',
    where: "USER_ID = '" + userId + "'",
    order: '',
  });
  const data = await defHttp.post(
    { url: Api.QueryUrl, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
      // apiUrl: globSetting.taskApiUrl
    },
  );
  return data;
};