Commit 77da1d2c authored by 谢希宇's avatar 谢希宇

Submit by Strive

Date 2021/04/115
Project End
parent 60e88cfe
......@@ -400,7 +400,7 @@
"aTargets": [3],
"mData": "userName",
"mRender": function (a, b, c, d) {
if (c) {
if (c.userName) {
return c.userName.slice(0, 1) + '*' + c.userName.slice(2, c.userName.length);
} else {
return null;
......
......@@ -151,8 +151,8 @@
<th style="width: 50px">大区</th>
<th style="width: 50px">省份</th>
<th style="width: 50px">城市</th>
<th style="width: 60px">销售代表</th>
<th style="width: 65px">医院</th>
<th style="width: 60px">销售代表</th>
<th style="width: 50px">科室</th>
<th style="width: 60px">医生姓名</th>
<th style="width: 60px">医生职称</th>
......@@ -277,10 +277,10 @@
"mData": "city"
},
{
"mData": "salesRepresent"
"mData": "hospital"
},
{
"mData": "hospital"
"mData": "salesRepresent"
},
{
"mData": "department"
......
......@@ -294,18 +294,18 @@
<!--查询报表人员信息-->
<select id="selectReportPeopleInfo" resultMap="resultMapPeopleInfo" parameterType="java.util.Map">
SELECT
product.product_name productName,
detail.drugs_num drugsNum,
ord.number orderNumber,
consult.consult_id consultNumber,
CONVERT ( AES_DECRYPT( consult.user_name, 'aideakey' ) USING UTF8 ) userName,
CONVERT ( AES_DECRYPT( consult.phone, 'aideakey' ) USING UTF8 ) phone,
qyuser.`name` cfDoctor,
org1.org_name cfHospital,
ord.pay_time fkTime,
waybill.send_express_date fhTime,
waybill.accept_express_date sjTime,
ord.openid openId
product.common_name productName,
detail.drugs_num drugsNum,
ord.number orderNumber,
consult.consult_id consultNumber,
CONVERT ( AES_DECRYPT( consult.user_name, 'aideakey' ) USING UTF8 ) userName,
CONVERT ( AES_DECRYPT( consult.phone, 'aideakey' ) USING UTF8 ) phone,
qyuser.`name` cfDoctor,
org1.org_name cfHospital,
ord.pay_time fkTime,
waybill.send_express_date fhTime,
waybill.accept_express_date sjTime,
ord.openid openId
FROM
t_order_details detail
LEFT JOIN t_aidea_product product ON product.id = detail.drugs_id AND product.del_flag = 0
......
package com.cftech.report.job;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.model.SysJob;
import com.cftech.accounts.service.JobService;
import com.cftech.accounts.service.MpAccountsService;
import com.cftech.base.org.model.OrgUnit;
import com.cftech.base.org.model.Qyuser;
import com.cftech.base.org.service.OrgUnitService;
......@@ -11,6 +13,7 @@ import com.cftech.core.sql.Conds;
import com.cftech.core.sql.Sort;
import com.cftech.core.util.Constants;
import com.cftech.core.util.SpringContextHolder;
import com.cftech.core.util.StringUtils;
import com.cftech.core.util.SystemConfig;
import com.cftech.report.model.Report;
import com.cftech.report.model.ReportCode;
......@@ -34,6 +37,11 @@ import java.util.List;
@Slf4j
public class ReportJob implements Job {
/**
* 区域组织长字段
*/
private static String REGION_LONG_ID = SystemConfig.p.getProperty("REGION_LONG_ID");
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
boolean isCluster = Boolean.valueOf(SystemConfig.p.getProperty("quartz.isCluster"));
......@@ -47,183 +55,74 @@ public class ReportJob implements Job {
ReportService reportService = SpringContextHolder.getBean(ReportService.class);
OrgUnitService orgUnitService = SpringContextHolder.getBean(OrgUnitService.class);
QyuserService qyuserService = SpringContextHolder.getBean(QyuserService.class);
MpAccountsService mpAccountsService = SpringContextHolder.getBean(MpAccountsService.class);
MpAccountsEntity accountsEntity = mpAccountsService.getMpAccountsAppid(SystemConfig.p.getProperty("WX_MP_SERVER_APPID"));
//获取报表用户信息
Conds condPeople = new Conds();
condPeople.equal("DATE_FORMAT(detail.create_time ,'%Y-%m-%d')", format.format(today));
//condPeople.equal("DATE_FORMAT(detail.create_time ,'%Y-%m-%d')", "2021-04-12");
condPeople.equal("detail.del_flag", Constants.DEL_FLAG_0);
Sort sortPeople = new Sort("detail.create_time", OrderType.DESC);
//获取报表用户信息
List<ReportPeopleInfo> listPeople = reportService.selectReportPeopleInfo(condPeople, sortPeople);
if (listPeople == null || listPeople.size() == 0) {
return;
}
Report report = null;
if (listPeople.size() > 0) {
for (ReportPeopleInfo reportPeopleInfo : listPeople) {
report = new Report();
report.setProductName(reportPeopleInfo.getProductName());
report.setDrugsNum(reportPeopleInfo.getDrugsNum());
report.setOrderNumber(reportPeopleInfo.getOrderNumber());
report.setConsultNumber(reportPeopleInfo.getConsultNumber());
report.setUserName(reportPeopleInfo.getUserName());
report.setPhone(reportPeopleInfo.getPhone());
report.setCfDoctor(reportPeopleInfo.getCfDoctor());
report.setCfHospital(reportPeopleInfo.getCfHospital());
report.setFkTime(reportPeopleInfo.getFkTime());
report.setFhTime(reportPeopleInfo.getFhTime());
report.setSjTime(reportPeopleInfo.getSjTime());
//根据openId获取扫码记录 只获取医生和组织二维码
Conds condCode = new Conds();
condCode.equal("record.openid", reportPeopleInfo.getOpenId());
condCode.in("record.type", new String[]{"3", "4"});
Sort sortCode = new Sort("record.create_time", OrderType.DESC);
List<ReportCode> listCode = reportService.selectReportCodeInfo(condCode, sortCode);
if (listCode.size() > 0) {
if (listCode.get(0).getType().equals("3")) {
//二维码类型为医生 根据绑定的医生人员ID查医生信息
Conds condDoctor = new Conds();
condDoctor.equal("qyuser.id", listCode.get(0).getBindId());
condDoctor.equal("qyuser.del_flag", "0");
ReportDoctorInfo reportDoctorInfo = reportService.selectReportDoctorInfo(condDoctor);
if (reportDoctorInfo != null) {
report.setDoctorName(reportDoctorInfo.getUserName());
report.setDoctorPhone(reportDoctorInfo.getUserPhone());
report.setDoctorTitle("医生");
report.setSex(reportDoctorInfo.getGender());
String orgParentIds = reportDoctorInfo.getOrgParentIds();
String[] orgParentIdArray = orgParentIds.split(",");
String regionOrgIds = SystemConfig.p.getProperty("REGION_LONG_ID");
if (orgParentIds.contains(regionOrgIds) && orgParentIdArray.length > regionOrgIds.split(",").length) {
//若果医生组织id在区域组织下面 则根据大区长编码获取下面所有组织信息
String areIds = regionOrgIds + orgParentIdArray[3] + "," + orgParentIdArray[4];
Conds condOrg = new Conds();
condOrg.rightLike("t.parent_ids", areIds);
condOrg.equalOr("t.parent_ids",regionOrgIds + orgParentIdArray[3]+",");
Sort sortOrg = new Sort("t.parent_id", OrderType.ASC);
List<OrgUnit> orgUnits = orgUnitService.fetchSearchByPage(0L, condOrg, sortOrg, 0, 0);
if (orgUnits.size() > 0) {
//若根据大区长编码查出数据 循环
for (OrgUnit orgUnit : orgUnits) {
int level = orgUnit.getParentIds().split(",").length;
if (level == 4) {
// 大区
report.setRegion(orgUnit.getOrgName());
} else if (level == 5) {
// 省
report.setProvince(orgUnit.getOrgName());
} else if (level == 6) {
// 市
report.setCity(orgUnit.getOrgName());
} else if (level == 7) {
//医院
report.setHospital(orgUnit.getOrgName());
// 根据医院组织ID 查找医院下面的销售代表
Conds condDepartment = new Conds();
condDepartment.equal("t.org_id", orgUnit.getId());
List<Qyuser> listUser = qyuserService.fetchSearchByPage(0L, condDepartment, null, 0, 0);
StringBuffer sb = new StringBuffer();
if (listUser.size() > 0) {
for (Qyuser qyuser : listUser) {
sb.append(qyuser.getName() + ",");
}
}
report.setSalesRepresent(sb.toString());
} else if (level == 8) {
//科室
report.setDepartment(orgUnit.getOrgName());
}
}
}
}
}
} else {
//二维码类型为组织 根据绑定的组织ID获取对应组织信息
OrgUnit orgUnitObj = orgUnitService.fetchById(listCode.get(0).getBindId());
if (orgUnitObj != null) {
String orgParentIds = orgUnitObj.getParentIds();
String[] orgParentIdArray = orgParentIds.split(",");
String regionOrgIds = SystemConfig.p.getProperty("REGION_LONG_ID");
if (orgParentIds.contains(regionOrgIds) && orgParentIdArray.length > regionOrgIds.split(",").length) {
//若果医生组织id在区域组织下面 则根据大区长编码获取下面所有组织信息
String areIds = regionOrgIds + orgParentIdArray[3] + "," + orgParentIdArray[4];
Conds condOrg = new Conds();
condOrg.rightLike("t.parent_ids", areIds);
condOrg.equalOr("t.parent_ids",regionOrgIds + orgParentIdArray[3]+",");
Sort sortOrg = new Sort("t.parent_id", OrderType.ASC);
List<OrgUnit> orgUnits = orgUnitService.fetchSearchByPage(0L, condOrg, sortOrg, 0, 0);
if (orgUnits.size() > 0) {
//若根据大区长编码查出数据 循环
for (OrgUnit orgUnit : orgUnits) {
int level = orgUnit.getParentIds().split(",").length;
if (level == 4) {
// 大区
report.setRegion(orgUnit.getOrgName());
} else if (level == 5) {
// 省
report.setProvince(orgUnit.getOrgName());
} else if (level == 6) {
// 市
report.setCity(orgUnit.getOrgName());
} else if (level == 7) {
//医院
report.setHospital(orgUnit.getOrgName());
// 根据医院组织ID 查找医院下面的销售代表
Conds condDepartment = new Conds();
condDepartment.equal("t.org_id", orgUnit.getId());
List<Qyuser> listUser = qyuserService.fetchSearchByPage(0L, condDepartment, null, 0, 0);
StringBuffer sb = new StringBuffer();
if (listUser.size() > 0) {
for (int i = 0; i < listUser.size(); i++) {
Qyuser qyUser = listUser.get(i);
if (i == listUser.size() - 1) {
sb.append(qyUser.getName());
} else {
sb.append(qyUser.getName() + ",");
}
}
}
report.setSalesRepresent(sb.toString());
} else if (level == 8) {
//科室
report.setDepartment(orgUnit.getOrgName());
}
}
}
}
}
//查找医生信息
Conds conds = new Conds();
conds.equal("record.openid", reportPeopleInfo.getOpenId());
conds.in("record.type", new String[]{"3"});
Sort sort = new Sort("record.create_time", OrderType.DESC);
List<ReportCode> list = reportService.selectReportCodeInfo(conds, sort);
if (list.size() > 0) {
Conds condDoctor = new Conds();
condDoctor.equal("qyuser.id", listCode.get(0).getBindId());
condDoctor.equal("qyuser.del_flag", "0");
ReportDoctorInfo reportDoctorInfo = reportService.selectReportDoctorInfo(condDoctor);
if (reportDoctorInfo != null) {
report.setDoctorName(reportDoctorInfo.getUserName());
report.setDoctorPhone(reportDoctorInfo.getUserPhone());
report.setDoctorTitle("医生");
report.setSex(reportDoctorInfo.getGender());
}
}
}
for (ReportPeopleInfo reportPeopleInfo : listPeople) {
Report report = new Report();
report.setAccountsId(accountsEntity.getId());
report.setProductName(reportPeopleInfo.getProductName());
report.setDrugsNum(reportPeopleInfo.getDrugsNum());
report.setOrderNumber(reportPeopleInfo.getOrderNumber());
report.setConsultNumber(reportPeopleInfo.getConsultNumber());
report.setUserName(reportPeopleInfo.getUserName());
report.setPhone(reportPeopleInfo.getPhone());
report.setCfDoctor(reportPeopleInfo.getCfDoctor());
report.setCfHospital(reportPeopleInfo.getCfHospital());
report.setFkTime(reportPeopleInfo.getFkTime());
report.setFhTime(reportPeopleInfo.getFhTime());
report.setSjTime(reportPeopleInfo.getSjTime());
//根据openId获取扫码记录 只获取医生和组织二维码
Conds condCode = new Conds();
condCode.equal("record.openid", reportPeopleInfo.getOpenId());
condCode.in("record.type", new String[]{"3", "4"});
Sort sortCode = new Sort("record.create_time", OrderType.DESC);
List<ReportCode> listCode = reportService.selectReportCodeInfo(condCode, sortCode);
if (listCode == null || listCode.size() == 0) {
continue;
}
ReportCode reportCode = listCode.get(0);
if (StringUtils.equals(reportCode.getType(), "3")) {
//二维码类型为医生 根据绑定的医生人员ID查医生信息
Conds condDoctor = new Conds();
condDoctor.equal("qyuser.id", reportCode.getBindId());
condDoctor.equal("qyuser.del_flag", "0");
ReportDoctorInfo reportDoctorInfo = reportService.selectReportDoctorInfo(condDoctor);
if (reportDoctorInfo != null) {
report.setDoctorTitle("医生");
report.setDoctorName(reportDoctorInfo.getUserName());
report.setSex(reportDoctorInfo.getGender());
report.setDoctorPhone(reportDoctorInfo.getUserPhone());
//如果医生组织id在区域组织下面 则根据大区长编码获取下面所有组织信息
String orgParentIds = reportDoctorInfo.getOrgParentIds();
setReportOrgs(orgUnitService, qyuserService, report, orgParentIds);
}
} else {
//二维码类型为组织 根据绑定的组织ID获取对应区域组织信息
OrgUnit orgUnitObj = orgUnitService.fetchById(reportCode.getBindId());
if (orgUnitObj != null) {
String orgParentIds = orgUnitObj.getParentIds();
setReportOrgs(orgUnitService, qyuserService, report, orgParentIds);
}
//新增报表记录
reportService.save(report);
}
//新增报表记录
reportService.save(report);
}
//获得明细数据
JobDataMap jobInfo = context.getJobDetail().getJobDataMap();
//这个也是ID主键
......@@ -243,16 +142,49 @@ public class ReportJob implements Job {
}
}
public static void main(String[] args) {
String str = "0,1,5,36,40,41,";
String[] arry = str.split(",");
if (str.contains("0,1,5,")) {
System.out.println(arry.length);
private void setReportOrgs(OrgUnitService orgUnitService, QyuserService qyuserService, Report report, String orgParentIds) {
if (orgParentIds.contains(REGION_LONG_ID)) {
Conds condOrg = new Conds();
condOrg.equal("t.del_flag", Constants.DEL_FLAG_0);
condOrg.in("t.id", orgParentIds.split(","));
Sort sortOrg = new Sort("LENGTH(t.parent_id)", OrderType.ASC);
List<OrgUnit> orgUnits = orgUnitService.fetchSearchByPage(0L, condOrg, sortOrg, 0, 0);
if (orgUnits != null && orgUnits.size() > 0) {
orgUnits.forEach(item -> {
int level = item.getParentIds().split(",").length;
switch (level) {
case 4://大区
report.setRegion(item.getOrgName());
break;
case 5://省份
report.setProvince(item.getOrgName());
break;
case 6://城市
report.setCity(item.getOrgName());
break;
case 7://医院
report.setHospital(item.getOrgName());
//根据医院组织ID 查找医院下面的销售代表
Conds condHospital = new Conds();
condHospital.equal("t.del_flag", Constants.DEL_FLAG_0);
condHospital.equal("t.org_id", item.getId());
List<Qyuser> listUser = qyuserService.fetchSearchByPage(0L, condHospital, null, 0, 0);
StringBuffer sb = new StringBuffer();
for (Qyuser qyuser : listUser) {
sb.append(qyuser.getName() + ",");
}
if (sb.length() > 0) {
report.setSalesRepresent(sb.toString());
}
break;
case 8://科室
report.setDepartment(item.getOrgName());
break;
}
});
}
}
}
public Report setOrgUnitInfo(String orgParentId, Report report) {
return report;
}
}
-- 订单已付款视图
create view view_order_record as
SELECT
o.id, --订单主键
o.number, --订单编码
o.total_amount, --订单总金额
od.drugs_num, --订单数量
sb.drugs_num split_num, --拆分数量
sb.drugs_batchno, --拆分批次号
p.product_name, --产品名称
p.product_number, --产品编码
o.create_time, --创建时间
o.pay_time --付款时间
FROM
t_order o
LEFT JOIN t_order_details od ON o.id = od.order_id AND od.del_flag = 0
LEFT JOIN t_order_split_batch sb ON o.id = sb.order_id AND sb.del_flag = 0
LEFT JOIN t_aidea_product p ON od.drugs_id = p.id AND p.del_flag = 0
WHERE o.status IN ('2', '3', '4') -- 待发货、待收货、已完成订单
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment