You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
6.4 KiB
JavaScript

//----------------------------------------------------------------------------
// Resident / Disabled : 주정차/장애인 의견진술관리
//----------------------------------------------------------------------------
import axios from 'utils/axios';
import {
GET_ADMIN_JUDGE_DATA,
GET_ADMIN_JUDGE_DATA_LIST,
SAVE_ADMIN_JUDGE_DATA,
GET_ADMIN_JUDGE_TARGET_LIST,
GET_ADMIN_JUDGE_LIST,
SAVE_ADMIN_JUDGE_TARGET_LIST,
GET_ADMIN_JUDGE_RESULT_LIST,
GET_PARKING_JUDGE_RESULT_LIST,
REMOVE_ADMIN_JUDGE,
GET_JUDGE_FILE_DOWNLOAD,
REMOVE_ADMIN_JUDGE_DATA,
GET_JUDGE_LIST
} from 'commons/ApiUrl';
import { setRowId } from './common';
import FileSaver from 'file-saver';
import _ from 'lodash';
// eslint-disable-next-line no-return-await
export async function findJudgeDatas(params) {
const res = await axios.get(GET_ADMIN_JUDGE_DATA_LIST, { params });
if (res.success) {
res.data = res.data.map((d, idx) => ({ ...d, rowId: setRowId(params, idx) }));
return res;
}
return res;
}
export async function saveJudgeData(formData) {
// eslint-disable-next-line no-return-await
return await axios(SAVE_ADMIN_JUDGE_DATA, {
method: 'post',
data: formData,
headers: { 'Content-Type': 'multipart/form-data' } // , Authorization: localStorage.getItem('access_token') }
});
}
export async function removeJudgeData(params) {
// eslint-disable-next-line no-return-await
return await axios.post(REMOVE_ADMIN_JUDGE_DATA, params);
}
export async function findJudge(scCode) {
// eslint-disable-next-line no-return-await
return await axios.get(GET_ADMIN_JUDGE_DATA + scCode);
}
export async function findJudges(params) {
const res = await axios.get(GET_ADMIN_JUDGE_LIST, { params });
if (res.success) {
res.data = res.data.map((d, idx) => ({ ...d, rowId: setRowId(params, idx) }));
return res;
}
return res;
}
export async function findJudgeResults2(params) {
// eslint-disable-next-line no-return-await
return await axios.get(GET_ADMIN_JUDGE_RESULT_LIST, { params });
}
/**
* 심의 결과 가공 처리
* @param params
* @param isParking 주정차 심의결과 요청 인지 여부
* @returns {Promise<{judgeData: ([]|*), judgeTeam: *, totJudgeUserData: *[][], simsaUser: *}|*>}
*/
export async function findJudgeResults(params, isParking) {
const res = await axios.get(isParking ? GET_PARKING_JUDGE_RESULT_LIST : GET_ADMIN_JUDGE_RESULT_LIST, { params });
if (res && res.success && res.data) {
const totJudgeUserData = res.data?.totJudgeUserData;
// tot데이타 정제
const totUserData = [[], [], [], []];
totJudgeUserData.forEach((data) => {
totUserData[0].push(data.BU);
totUserData[1].push(data.SEO);
totUserData[2].push(data.MIBU);
totUserData[3].push(data.TOT);
});
// 마지막 '결과' 맵 삭제
totJudgeUserData.pop();
return {
success: true,
data: {
// 심사자별 심사 합산
totJudgeUsers: totJudgeUserData,
// 심사자별 심사 합산에서 추출한 심사 합산 데이타
totJudgeUserData: totUserData,
// 심사대상 차량 목록
judgeCars: res.data?.judgeCarData,
// 차량별 심시 결과
judgeUserData: res.data?.judgeUserData,
judgeTeam: res.data?.teamList[0].msuTeam
}
};
}
return res;
}
export async function findJudgeTargets(params) {
const res = await axios.get(GET_ADMIN_JUDGE_TARGET_LIST, { params });
if (res.success) {
res.data = res.data.map((d, idx) => ({ ...d, rowId: setRowId(params, idx) }));
return res;
}
return res;
}
export async function saveJudgeTargets(params) {
// eslint-disable-next-line no-return-await
return await axios.post(SAVE_ADMIN_JUDGE_TARGET_LIST, params);
}
export async function removeJudge(params) {
// eslint-disable-next-line no-return-await
return await axios.post(REMOVE_ADMIN_JUDGE, params);
}
export async function judgeFileDownload(params, alert) {
await axios
.get(GET_JUDGE_FILE_DOWNLOAD, {
responseType: 'blob',
params
})
// eslint-disable-next-line consistent-return
.then((res) => {
if (res?.isAxiosError || res?.status === 404 || res?.size <= 0) {
alert.show('파일을 다운로드 할 수 없습니다 [파일정보 오류]');
} else {
// eslint-disable-next-line no-lonely-if
if (res?.type.includes('image')) {
// const url = window.URL.createObjectURL(res);
alert.show(<img alt="~~~" src={URL.createObjectURL(res)} style={{ margin: 'auto' }} />);
// URL.revokeObjectURL()
} else {
FileSaver.saveAs(res, 'filename');
}
}
});
}
//----------------------------------------------------------------
// 심사자
//----------------------------------------------------------------
export async function findByUserJudges(params) {
const res = await axios.get(GET_JUDGE_LIST, { params });
if (res.success) {
res.data = res.data.map((d, idx) => ({ ...d, rowId: setRowId(params, idx) }));
return res;
}
return res;
}
// eslint-disable-next-line consistent-return
async function judgeImgDownload(params, alert) {
// const res = await
// eslint-disable-next-line no-return-await
return await axios.get(GET_JUDGE_FILE_DOWNLOAD, {
responseType: 'blob',
params
});
}
async function judgeImgList(res, scCode, fieldCnt, fieldName, dataGb, methodName, alert) {
const arrRtn = [];
// eslint-disable-next-line no-restricted-syntax
for (const idx of _.range(1, fieldCnt, 1)) {
if (res?.data[`${fieldName}${idx}`]) {
// eslint-disable-next-line no-await-in-loop
await judgeImgDownload({ scDatagb: dataGb, scCode, methodName: `${methodName}${idx}` }, alert).then((r) => {
if (r.size > 0) arrRtn.push(URL.createObjectURL(r));
}); // .then((r) => {
}
}
return arrRtn;
}
export async function findImages(row, alert) {
const dataGb = row?.msDatagb;
const scCode = row?.msMaincode;
const res = await findJudge(scCode);
console.log(res);
if (res.success) {
const [picadImgs, frecadImgs, contadImgs] = await Promise.all([
judgeImgList(res, scCode, 5, 'scPicad', dataGb, 'getScPicad', alert),
judgeImgList(res, scCode, 5, 'scFrecad', dataGb, 'getScFrecad', alert),
judgeImgList(res, scCode, 9, 'scContad', dataGb, 'getScContad', alert)
]);
console.log(picadImgs, frecadImgs, contadImgs);
return {
arrPicadImg: picadImgs,
arrFrecadImg: frecadImgs,
arrContadImg: contadImgs
};
}
return res;
}