提交 ec82ddb7 authored 作者: 张颂恩's avatar 张颂恩

Merge branch 'dev' of http://124.225.116.118:35236/tj_django/datacenter into dev

......@@ -8,6 +8,7 @@
!/manage.py
!/README.md
!/.gitignore
!/.gitlab-ci.yml
### NotepadPP template
# Notepad++ backups #
......
stages:
- deploy
deploy_job:
stage: deploy
script:
- cd "E:\datacenter"
- git checkout test
- git pull
only:
# 只有test分支才执行
- test
tags:
- "36"
\ No newline at end of file
......@@ -5,3 +5,6 @@
项目根目录下static和media两个文件夹不会上传到代码仓库,**如果有修改需要通知其他成员同步。**
**_TODO: 服务器环境需要建立一个conda._**
# requirements:
django 3.1.4
\ No newline at end of file
......@@ -416,7 +416,12 @@ class News_Form(ModelForm):
model=News
fields = ['news_from','subtitle','desc','poster','content','is_active','remark','pub_date']
def __init__(self, *args, **kwargs):
super(News_Form, self).__init__(*args, **kwargs)
self.fields['subtitle'].widget.attrs['placeholder'] = '必填'
self.fields['content'].widget.attrs['placeholder'] = '必填'
self.fields['desc'].widget.attrs['placeholder'] = '必填'
self.fields['news_from'].widget.attrs['placeholder'] = '必填'
#2021-02-24
......
......@@ -228,6 +228,12 @@ urlpatterns = [
url(r'^inventory/upload/label_replace/$', inventory_views.upload_label_replace),
#2022-09-19 酒鬼酒在线绑定标签替换
# url(r'^test/wx/test/$', inventory_views.upload_label_replace_sh),
# url(r'^test/wx/test/yemian/$', inventory_views.yemian),
url(r'^inventory/upload/label_replace_sh/$', inventory_views.upload_label_replace_sh),
url(r'^inventory/upload/yemian/$', inventory_views.yemian),
url(r'^inventory/app/stock/(?P<company_id>\d+)/$', inventory_views.app_stock),
url(r'^inventory/app/(?P<company_id>\d+)/children/$', inventory_views.app_childcompany),
......
......@@ -2374,13 +2374,7 @@ def fg_update(request,is_app=False):
if vch_id == 1 and 'stack_binding' in r:
st = r['stack_binding']
if len(st) > 0:
stack_binding = jcs_virtual_stack_binding(batch, r['stack_binding'])
stacks = stack_binding['stacks']
if stacks and vch_id == 1:
aSql = stack_binding['insert_sql']
if aSql:
sSql = "insert into codes(label_code,tb,product_id,stack_id) values " + ",".join(aSql)+" on CONFLICT(label_code) do update set stack_id = EXCLUDED.stack_id"
cur.execute(sSql)
stack_binding = jcs_virtual_stack_binding(batch, r['stack_binding'],cmp_id)
#2022-05-10 保存原始标签号码
......@@ -5037,6 +5031,168 @@ def upload_label_replace(request):
return JsonResponse(data)
# 酒鬼在线绑定标签替换页面
@login_required
def yemian(request):
return render(request, 'inventory/label_replace_online.html')
# 酒鬼在线绑定标签替换接口
# @login_required
@tj_login_required
@csrf_exempt
def upload_label_replace_sh(request):
data = {'files': [], 'e': ''}
t = datetime.datetime.now().strftime('%Y-%m-%d')
# dt = datetime.datetime.now()
u_id = str(request.user.id)
c = request.user.company
c_name = c.name
# p = settings.MEDIA_ROOT + '/' + c_name + '/txt/label_replace_sh/' + \
# str(dt.year) + str(dt.month).zfill(2) + str(dt.day).zfill(2)
p = settings.MEDIA_ROOT + '/' + c_name + '/txt/label_replace_sh/' + t
if not os.path.exists(p):
os.makedirs(p)
c_id = str(c.id)
files = request.FILES.getlist('files')
type = request.POST.get('type')
# print(type)
er = []
cur = connection.cursor()
cur.execute("create temp table tmp(code0 character varying(20),code character varying(20))")
# 替换要改成一行行读取
for f in files:
fn = f.name
with open(p + '/' + fn, 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
f.seek(0)
cur.execute("truncate table tmp")
cur.copy_from(f, 'tmp', sep=',', null='') # 写入临时表
# 写入BATCH
s = "insert into label.lbl_replace_batch(user_id,company_id,txt_file) values " + \
"(" + u_id + "," + c_id + ",'" + fn + "') returning id"
cur.execute(s)
id = str(cur.fetchone()[0])
# print(id)
if type == 'qh':
# 判断新标签是否存在redis中
rd = redis.StrictRedis(host='localhost', port=16379, db=10, password='tjredis139', decode_responses=True)
s = "select * from tmp"
cur.execute(s)
rs = cur.fetchall()
for r in rs:
label = rd.hget("bottle_" + str(r[1]), 'label')
if label:
a = (decrypt_11h(label))
# print(a)
# 将替换前的标签数据备份到标里
s = "insert into temp.z_bottlecap_binding_replace(label,code,box_code,label_pk_id,bottle,company_id,batch_id) " + \
f"select label,code,box_code,label_pk_id,bottle,company_id,'{id}' from temp.z_bottlecap_binding " + \
f"where bottle='{r[0]}'"
cur.execute(s)
s = f"""
update temp.z_bottlecap_binding set label='{label}',
code='{a}',bottle='{r[1]}' where bottle='{r[0]}'
"""
cur.execute(s)
else:
s = f"""select bottle from temp.z_bottlecap_binding where bottle='{r[1]}'
"""
cur.execute(s)
rrs = cur.fetchone()
# print(rrs)
if rrs:
s = f"""
INSERT INTO temp.z_bottlecap_binding_replace(label,code,box_code,label_pk_id,bottle,company_id,batch_id)
select label,code,box_code,label_pk_id,bottle,company_id,'{id}' from temp.z_bottlecap_binding
where bottle='{r[0]}'
"""
cur.execute(s)
s = f"""
update temp.z_bottlecap_binding set label=(select label from temp.z_bottlecap_binding where '{r[1]}'=bottle),
code=(select code from temp.z_bottlecap_binding where '{r[1]}'=bottle),
bottle='{r[1]}' where bottle='{r[0]}'
"""
cur.execute(s)
else:
s = f"""
INSERT INTO temp.z_bottlecap_binding_replace(bottle,err,batch_id) values ('{r[1]}','标签错误','{id}')
"""
# print(s)
cur.execute(s)
s = "select count(*)," + \
"(select count(*) from temp.z_bottlecap_binding_replace where err is null and batch_id=" + id + ") from tmp"
cur.execute(s)
r = cur.fetchone()
tt = r[0]
ok = r[1]
s = ''
s2 = f"""
select bottle from temp.z_bottlecap_binding_replace where batch_id='{id}' and err='标签错误'
"""
cur.execute(s2)
error = cur.fetchall()
er.append(error)
cur.execute(
"update label.lbl_replace_batch set cnt_tt=" + str(tt) + ",cnt_ok=" + str(
ok) + s + " where id=" + id)
data['files'].append({'txt_name': fn, 'total': tt, 'ok': ok, 'err': er})
# 只替换瓶盖
if type == 'pg':
s = "select * from tmp"
cur.execute(s)
rs = cur.fetchall()
for r in rs:
s = f"""select bottle from temp.z_bottlecap_binding where bottle='{r[1]}'
"""
cur.execute(s)
rrs = cur.fetchone()
# print(rrs)
if rrs:
a = (decrypt_11h(r[0]))
s = f"""
INSERT INTO temp.z_bottlecap_binding_replace(label,code,box_code,label_pk_id,bottle,company_id,batch_id)
select label,code,box_code,label_pk_id,bottle,company_id,'{id}' from temp.z_bottlecap_binding where '{r[1]}'=bottle
"""
cur.execute(s)
s = f"""
update temp.z_bottlecap_binding set label='{r[0]}',code='{a}' where bottle='{r[1]}'
"""
cur.execute(s)
else:
s = f"""
INSERT INTO temp.z_bottlecap_binding_replace(bottle,err,batch_id) values ('{r[1]}','标签错误','{id}')
"""
# print(s)
cur.execute(s)
s = "select count(*)," + \
"(select count(*) from temp.z_bottlecap_binding_replace where err is null and batch_id=" + id + ") from tmp"
cur.execute(s)
r = cur.fetchone()
tt = r[0]
ok = r[1]
s = ''
s2 = f"""
select bottle from temp.z_bottlecap_binding_replace where batch_id='{id}' and err='标签错误'
"""
cur.execute(s2)
error = cur.fetchall()
er.append(error)
cur.execute(
"update label.lbl_replace_batch set cnt_tt=" + str(tt) + ",cnt_ok=" + str(
ok) + s + " where id=" + id)
data['files'].append({'txt_name': fn, 'total': tt, 'ok': ok, 'err': er})
return JsonResponse(data)
def list_unhandled_batch(request, company_id):
data = []
......@@ -13867,8 +14023,31 @@ def label_replace(request,what,id=None):
return JsonResponse(data)
def jcs_virtual_stack_binding(batch,stack_binding):
data = {'stacks': [],'insert_sql': []}
def jcs_virtual_stack_binding(batch,stack_binding,company_id):
data = {'e': '' }
# 2022-07-20 数据写入日志
cs = Company.objects.filter(id=int(company_id))
c = cs[0]
cur= connection.cursor()
cur.execute("create temp table temps(" + \
"id serial," + \
"label_code character varying(32) ," + \
"tb character varying(20)," + \
"product_id integer," + \
"stack_id integer," + \
"wrapper_id integer," + \
"code character varying(32)," + \
"label_id bigint," + \
"label_pk_id bigint," + \
"label_pkg smallint," + \
"err character varying(100)," + \
"label_code0 character varying(32)," + \
"from_agent_id integer)"
)
insert_sql = []
codes=[]
for i in stack_binding:
is_physical = True
code = i['stack']
......@@ -13882,22 +14061,105 @@ def jcs_virtual_stack_binding(batch,stack_binding):
stack.product_id = batch.product_id
stack.store_id = batch.store_fr_id
stack.is_physical = is_physical
if 'location' in i:
stack.location = i['location']
if 'qty_lmt' in i:
stack.qty_lmt = i['qty_lmt']
if 'is_fixed' in i:
stack.is_fixed = i['is_fixed']
stack.qty_lmt = 0
stack.save()
if stack.code_is_permanent == False:
# 2022-07-02 如诗仙太白含垛标套标,已事先将对应箱标写入stackdetails,入库时只扫垛标,不会上传垛标下面绑定的箱标
i['labels'] = []
for d in stack.stackdetails_stack.all():
i['labels'].append(d.label_code)
if batch.product_id:
product_id = str(batch.product_id)
else:
product_id = 'null'
for l in i['codes']:
data['insert_sql'].append("('" + l + "','" + l[:4] + "'," + product_id + "," + str(stack.id) + ")")
data['stacks'].append(code)
insert_sql.append("('" + l + "','" + l[:4] + "'," + product_id + "," + str(stack.id) + ")")
codes.append(l)
# s = "INSERT INTO inventory_stackdetails(company_id,product_id,label_pk_id,label_id,label_pkg,label_code,tm,stack_id) " + \
# "select company_id,product_id,label_pk_id,label_id,label_pkg,label_code,now(),stack_id " + \
# "from inventory_stkdetails where batch_id=" + str(batch.id) + " and stack_id>0 " + \
# "on CONFLICT(stack_id,label_pk_id) do nothing"
sSql = "insert into temps(label_code,tb,product_id,stack_id) " \
"values " + ",".join(insert_sql)
cur.execute(sSql)
stacks = []
stack_binding = ''
# 2022-05-10 保存原始标签号码
cur.execute("update temps set label_code0=label_code")
s = "update temps o set code=coalesce" + \
"((select code0 from label.lbl_replace_details where code=o.label_code order by batch_id desc limit 1),o.label_code)"
cur.execute(s)
# 2020-07-27 处理跨段动态绑定
s = "update temps set tb=b.tbname from " + \
"(SELECT tb,label_code from temps) a " + \
"left outer join " + \
"(SELECT segment, tbname FROM label.lbl_tbcross) b " + \
"on a.tb=b.segment " + \
"where temps.label_code=a.label_code and b.tbname is not null"
cur.execute(s)
# 2022-05-09 有些AB样标使用了跨段表里的号段
s = "select " + \
"(select code_a FROM label.lbl_abcode where code_b=label_code or code_a=label_code)," + \
"tb='t'||left((select code_a FROM label.lbl_abcode where code_b=label_code or code_a=label_code),4) " + \
"from temps " + \
"where (select id from label.lbl_abcode where code_a=label_code or code_b=label_code limit 1)>0"
cur.execute(s)
r = cur.fetchone()
s = "update temps set code=" + \
"(select code_a FROM label.lbl_abcode where code_b=label_code or code_a=label_code)," + \
"tb='t'||left((select code_a FROM label.lbl_abcode where code_b=label_code or code_a=label_code),4) " + \
"where (select id from label.lbl_abcode where code_a=label_code or code_b=label_code limit 1)>0"
cur.execute(s)
cur.execute("update temps set tb='t'||left(code,4) where length(tb)=4")
cur.execute("select tb from temps group by tb")
rs = cur.fetchall()
for r in rs:
# cur.execute("select to_regclass('label." + r[0] + "')")
cur.execute("select count(*) from information_schema.tables where table_schema='label' " + \
"and table_type='BASE TABLE' and table_name='" + r[0] + "'"
)
r0 = cur.fetchone()
if r0[0]:
s = "update temps set " + \
"label_id=b.id," + \
"label_pkg=b.package_id," + \
"label_pk_id=coalesce(b.parent_id,b.id) " + \
"from " + \
"(SELECT label_code,code from temps where tb='" + r[0] + "') a " + \
"left outer join " + \
"(select id,code,parent_id,package_id,is_pk from label." + r[0] + ") b " + \
"on a.code=b.code " + \
"where tb='" + r[0] + "' and temps.code=a.code"
cur.execute(s)
# 没有标签id的,看是不是企业第三方标签
s = "update temps set " + \
"label_id=b.id," + \
"label_pkg=b.package_id," + \
"label_pk_id=coalesce(b.parent_id,b.id) " + \
"from " + \
"(SELECT label_code,code from codes where label_id is null) a " + \
"left outer join " + \
"(select id,code,parent_id,package_id,is_pk from label.thirdparty where cid=" + str(c.ancestor_id) + ") b " + \
"on a.code=b.code " + \
"where temps.code=a.code and label_id is null"
cur.execute(s)
s = "INSERT INTO inventory_stackdetails(company_id,product_id,label_pk_id,label_id,label_pkg,label_code,tm,stack_id) " + \
"select "+str(company_id)+",product_id,label_pk_id,label_id,label_pkg,label_code,now(),stack_id " + \
"from temps where label_pk_id is not null and stack_id>0 " + \
"on CONFLICT(stack_id,label_pk_id) do nothing"
cur.execute(s)
return data
......@@ -18,15 +18,20 @@
$('#image-clear_id,#id_image').removeClass('form-control');
$('.btn-save').click(function () {
{#$('.btn-save').click(function () {#}
{# let editorData = editor.txt.html();#}
{# $("#id_content").val(editorData);#}
{# $.SubmitForm('#obj_form form', '{{request.path}}',function (){#}
{# $('.alert').fadeIn();#}
{# setTimeout(function (){#}
{# $('.alert').fadeOut();#}
{# },3000)#}
{# });#}
{# });#}
$('.btn-save').click(function(){
let editorData = editor.txt.html();
$("#id_content").val(editorData);
$.SubmitForm('#obj_form form', '{{request.path}}',function (){
$('.alert').fadeIn();
setTimeout(function (){
$('.alert').fadeOut();
},3000)
});
$.SubmitForm('#obj_form form','{{request.path}}');
});
$('#obj_form .product_photo a').click(function (event) {
......@@ -61,7 +66,7 @@
z-index: 1000002;
}
</style>
{{ block.super }}
<div class="form-group ">
<label class="col-sm-2 control-label ">标题</label>
<div class="col-sm-8">{{ form.subtitle }}</div>
......
{% load i18n %}
<div class="subtitle">
<ol class="breadcrumb">
<li>{% trans "物流工具" %}</li>
<li>{% trans "在线采集标签替换" %}</li>
</ol>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('input[name="info"]').change(function () {
info = $('input[name="info"]:checked').attr('value');
if (info == 'custom') {
$('#fahuo_info').show(400);
} else {
$('#fahuo_info').hide(400);
}
});
var uploadType = '';
$('#upload').on('click',function () {
var Sel = document.getElementById("select");
var index = Sel.selectedIndex;
uploadType = Sel.options[index].value;
// console.log(val);
if (uploadType == '') {
alert("请选择替换类型");
}
else {
document.getElementById('xFile').click();
}
})
$('#xFile').change(function () {
var formData = new FormData();
formData.append("type", uploadType);
$('#info table').html('');
$('#info .info').html('');
$('#errinfo_null_rec').html('');
$('#errinfo_delivered_rec').html('');
$('#errinfo_different_rec').html('');
console
var xhr = new XMLHttpRequest();
var file = document.getElementById('xFile').files;
var formDat;
var cnt = 0;
for (i = 0; i < file.length; i++) {
var fn = file[i].name.substr(0, 2).toUpperCase();
formData.append("files", file[i]);
cnt = cnt + 1;
}
if (cnt == 0) {
//bootbox.alert("{% trans '没有可上传的文件!' %}", function() {});
toastr.error(
"没有可上传的文件!",
"操作错误:",
{ timeOut: 800, positionClass: "toast-center-center" }
);
return;
}
$('#msg').remove();
$('.btn-upload').addClass('disabled');
$('#ajax_loading2').show();
var si = '';
xhr.open('POST', '/inventory/upload/label_replace_sh/');
xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
xhr.send(formData);
xhr.onreadystatechange = (function (_xhr) {
return function () {
if (_xhr.readyState == 4) {
if (_xhr.status == 200) {
console.log('200');
var d = eval('(' + _xhr.responseText + ')');
if (d.e != '') {
$('.btn-upload').removeClass('disabled');
toastr.error(
d.e,
"上传失败:",
{ timeOut: 800, positionClass: "toast-center-center" }
);
//bootbox.alert(d.e, function() {});
return;
};
$('#info table').prepend(
'<tr>' +
'<th style="width:30px">{% trans '上传的TXT文件名' %}</th>' +
'<th style="width:15px">{% trans '总行数' %}</th>' +
'<th style="width:15px">{% trans '写入替换记录数' %}</th>' +
'<th style="width:15px">{% trans '错误标签' %}</th>' +
'</tr>'
);
for (var n in d.files) {
$('#info table').append(
'<tr>' +
'<td>' + d.files[n].txt_name + '</td>' +
'<td>' + d.files[n].total + '</td>' +
'<td>' + d.files[n].ok + '</td>' +
'<td>' + d.files[n].err + '</td>' +
'</tr>'
);
};
var html = '';
$('#info .info').html(html);
$('.btn-upload').removeClass('disabled');
$('#ajax_loading2').hide();
}
else {
$('.btn-upload').removeClass('disabled');
$('#ajax_loading2').hide();
//bootbox.alert("{% trans '通讯错误!' %}", function() {});
toastr.error(
"通讯错误",
"上传失败:",
{ timeOut: 800, positionClass: "toast-center-center" }
);
return;
}
}
}
})(xhr);
xhr.timeout = 300000;
xhr.ontimeout = function (event) {
$('#ajax_loading2').hide();
//bootbox.alert("{% trans '请求超时!' %}", function() {});
toastr.error(
"请求超时!",
"操作失败:",
{ timeOut: 800, positionClass: "toast-center-center" }
);
}
});
});
</script>
<div>
{% trans "点击右边按钮,选择标签替换TXT文件上传服务器:" %}
<select id="select" style="width : 150px;">
<option value="">请选择替换类型</option>
<option value="pg">瓶盖替换</option>
<option value="qh">标签替换(全换)</option>
</select>
<label class="btn btn-primary btn-upload btn-sm" id="upload">{% trans "上传文件" %}</label>
<div style='font-style:italic;'>TXT文件格式:每行两列,先是旧标签号码后是新标签号码,中间用英文逗号分隔</div>
<form>
<input type="file" id="xFile" accept="text/plain" multiple="multiple"
style="position:absolute;clip:rect(0 0 0 0);">
</form>
<div id='info'>
<div id='tb_div' class='table-responsive'>
<table class='table table-bordered table-striped table-condensed table-hover'></table>
</div>
<div class='info'></div>
</div>
<div id='errinfo_null_rec'></div>
<div id='errinfo_delivered_rec'></div>
<div id='errinfo_different_rec'></div>
<div id='msg'></div>
</div>
\ No newline at end of file
......@@ -552,6 +552,10 @@
<li><a class="l-a" href="/inventory/ticketinfo/">{% trans '入库启票' %}</a></li>
{% endifequal %}
{% ifequal user.company.id 16687 %}
<li><a class="l-a" href="/inventory/upload/yemian/">{% trans '在线绑定标签替换TXT' %}</a></li>
{% endifequal %}
{% if perms.company.sys_admin %}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论