|
@@ -15,6 +15,7 @@ from exceptions import AppException, HmacException
|
|
|
from database import get_db
|
|
|
from typing import List
|
|
|
from models import *
|
|
|
+import xlrd
|
|
|
from utils import *
|
|
|
from utils.ry_system_util import *
|
|
|
from utils.video_util import *
|
|
@@ -670,8 +671,9 @@ async def create_contact(
|
|
|
try:
|
|
|
book = xlrd.open_workbook(file_path)
|
|
|
sheet = book.sheet_by_index(0)
|
|
|
- except:
|
|
|
- msg = f'\n文件打开失败,请核实文件格式为xlsx/xlx>'
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ msg = f'\n文件打开失败,请核实文件格式为xlsx/xlx>{str(e)}'
|
|
|
code = 500
|
|
|
return JSONResponse(status_code=code, content={
|
|
|
"code": code,
|
|
@@ -685,25 +687,25 @@ async def create_contact(
|
|
|
user_data = []
|
|
|
start_date = sheet.cell(row, 0).value
|
|
|
if start_date == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{start_date}>'
|
|
|
+ msg = f'\n行<{row + 1}>开始日期不能为空<{start_date}>'
|
|
|
code = 500
|
|
|
start_time = sheet.cell(row, 1).value
|
|
|
if start_time == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{start_time}>'
|
|
|
+ msg = f'\n行<{row + 1}>开始时间不能为空<{start_time}>'
|
|
|
code = 500
|
|
|
end_date = sheet.cell(row, 2).value
|
|
|
if end_date == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{end_date}>'
|
|
|
+ msg = f'\n行<{row + 1}>结束日期不能为空<{end_date}>'
|
|
|
code = 500
|
|
|
end_time = sheet.cell(row, 3).value
|
|
|
if end_time == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{end_time}>'
|
|
|
+ msg = f'\n行<{row + 1}>结束时间不能为空<{end_time}>'
|
|
|
code = 500
|
|
|
dbld = sheet.cell(row, 4).value
|
|
|
if dbld == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{dbld}>'
|
|
|
+ msg = f'\n行<{row + 1}>带班领导不能为空<{dbld}>'
|
|
|
code = 500
|
|
|
- for name in dbld.split(','):
|
|
|
+ for name in dbld.split(','):
|
|
|
personnel_id_list = name_get_user_id(db, name)
|
|
|
if len(personnel_id_list)==0:
|
|
|
import_status = False
|
|
@@ -713,9 +715,9 @@ async def create_contact(
|
|
|
user_data.append({"position_id":1,"personnel_id":personnel_id})
|
|
|
kjdb = sheet.cell(row, 5).value
|
|
|
if kjdb == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{kjdb}>'
|
|
|
+ msg = f'\n行<{row + 1}>科级带班不能为空<{kjdb}>'
|
|
|
code = 500
|
|
|
- for name in kjdb.split(','):
|
|
|
+ for name in kjdb.split(','):
|
|
|
personnel_id_list = name_get_user_id(db, name)
|
|
|
if len(personnel_id_list)==0:
|
|
|
import_status = False
|
|
@@ -725,9 +727,9 @@ async def create_contact(
|
|
|
user_data.append({"position_id":1,"personnel_id":personnel_id})
|
|
|
zb = sheet.cell(row, 6).value
|
|
|
if zb == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{zb}>'
|
|
|
+ msg = f'\n行<{row + 1}>主班不能为空<{zb}>'
|
|
|
code = 500
|
|
|
- for name in zb.split(','):
|
|
|
+ for name in zb.split(','):
|
|
|
personnel_id_list = name_get_user_id(db, name)
|
|
|
if len(personnel_id_list)==0:
|
|
|
import_status = False
|
|
@@ -737,9 +739,9 @@ async def create_contact(
|
|
|
user_data.append({"position_id":1,"personnel_id":personnel_id})
|
|
|
zz = sheet.cell(row, 7).value
|
|
|
if zz == '':
|
|
|
- msg = f'\n行<{row + 1}>日期不能为空<{zz}>'
|
|
|
+ msg = f'\n行<{row + 1}>专职不能为空<{zz}>'
|
|
|
code = 500
|
|
|
- for name in zz.split(','):
|
|
|
+ for name in zz.split(','):
|
|
|
personnel_id_list = name_get_user_id(db, name)
|
|
|
if len(personnel_id_list)==0:
|
|
|
import_status = False
|
|
@@ -754,19 +756,20 @@ async def create_contact(
|
|
|
shift_type = '2'
|
|
|
else:
|
|
|
shift_type = '3'
|
|
|
+ start_date1 = xlrd.xldate.xldate_as_datetime(start_date, book.datemode).strftime('%Y-%m-%d')
|
|
|
|
|
|
new_duty_data = DutySchedule(
|
|
|
- start_time=f'{start_date} {start_time}',
|
|
|
- end_time=f'{end_date} {end_time}',
|
|
|
- duty_date=start_date,
|
|
|
+ start_time=xlrd.xldate.xldate_as_datetime(start_date+start_time, book.datemode).strftime('%Y-%m-%d %H:%M:%S'), #f'{start_date} {start_time}',
|
|
|
+ end_time=xlrd.xldate.xldate_as_datetime(end_date+end_date, book.datemode).strftime('%Y-%m-%d %H:%M:%S'), #f'{end_date} {end_time}',
|
|
|
+ duty_date=start_date1,
|
|
|
shift_type=shift_type,
|
|
|
duty_unit=duty_unit,
|
|
|
duty_type=duty_type,
|
|
|
create_by=user_id
|
|
|
)
|
|
|
- duty_data[start_date+str(shift_type)] = new_duty_data
|
|
|
+ duty_data[start_date1+str(shift_type)] = new_duty_data
|
|
|
# 添加到会话并提交
|
|
|
- duty_persion_data[start_date + str(shift_type)] = user_data
|
|
|
+ duty_persion_data[start_date1+ str(shift_type)] = user_data
|
|
|
# db.add(new_duty_data)
|
|
|
# db.commit()
|
|
|
# db.refresh(new_duty_data)
|