1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012 |
- package Task
- import (
- "ColdVerify_server/conf"
- "ColdVerify_server/lib"
- "ColdVerify_server/logs"
- "ColdVerify_server/models/InfoCollection"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/astaxie/beego/cache"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- _ "github.com/go-sql-driver/mysql"
- "time"
- )
- var (
- TaskSchemeStateWaitSubmit = 0 // 待提交
- TaskSchemeStateSubmitted = 5 // 已提交
- TaskSchemeStateClientPass = 1 // 已通过(客户)
- TaskSchemeStateClientReturn = 2 // 已退回(客户)
- TaskSchemeStatePass = 3 // 已通过(负责人)
- TaskSchemeStateReturn = 4 // 已退回(负责人)
- TaskSchemeStateMap = map[int]string{
- TaskSchemeStateWaitSubmit: "待提交",
- TaskSchemeStateSubmitted: "已提交",
- TaskSchemeStateClientPass: "已通过(客户)",
- TaskSchemeStateClientReturn: "已退回(客户)",
- TaskSchemeStatePass: "已通过(负责人)",
- TaskSchemeStateReturn: "已退回(负责人)",
- }
- // 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(报告负责人) 6已退回(报告负责人)
- TaskCollectionStateWaitSubmit = 0 // 待提交
- TaskCollectionStateFinish = 1 // 已完成
- TaskCollectionStateInProgress = 2 // 处理中
- TaskCollectionStateNoData = 3 // 已采集-无数据
- TaskCollectionStateSubmitted = 4 // 已提交
- TaskCollectionStatePass = 5 // 已通过(负责人)
- TaskCollectionStateReturn = 6 // 已退回(负责人)
- TaskCollectionStateMap = map[int]string{
- TaskCollectionStateWaitSubmit: "待提交",
- TaskCollectionStateFinish: "已完成",
- TaskCollectionStateInProgress: "处理中",
- TaskCollectionStateNoData: "已采集-无数据",
- TaskCollectionStateSubmitted: "数据编辑已完成",
- TaskCollectionStatePass: "已通过(负责人)",
- TaskCollectionStateReturn: "已退回(负责人)",
- }
- TaskReportingStateWaitSubmit = 0 // 待提交
- TaskReportingStateSubmitted = 5 // 已提交
- TaskReportingStateClientPass = 1 // 已通过(客户)
- TaskReportingStateClientReturn = 2 // 已退回(客户)
- TaskReportingStatePass = 3 // 已通过(负责人)
- TaskReportingStateReturn = 4 // 已退回(负责人)
- TaskReportingStateMap = map[int]string{
- TaskReportingStateWaitSubmit: "待提交",
- TaskReportingStateSubmitted: "已提交",
- TaskReportingStateClientPass: "已通过(客户)",
- TaskReportingStateClientReturn: "已退回(客户)",
- TaskReportingStatePass: "已通过(负责人)",
- TaskReportingStateReturn: "已退回(负责人)",
- }
- TaskDeliveryStateUnfinished = 0 // 未完成
- TaskDeliveryStateFinished = 1 // 已完成
- TaskDeliveryStateGoing = 2 // 进行中
- TaskDeliveryStateMap = map[int]string{
- TaskDeliveryStateUnfinished: "未完成",
- TaskDeliveryStateFinished: "已完成",
- TaskDeliveryStateGoing: "处理中",
- }
- TaskMarkingStateUnfinished = 0 // 未完成
- TaskMarkingStateFinished = 1 // 已完成
- TaskMarkingStateMap = map[int]string{
- TaskMarkingStateUnfinished: "未完成",
- TaskMarkingStateFinished: "已完成",
- }
- )
- var (
- TaskSchemeTimeLimit = map[string]float64{
- "LC": 60, // LC-冷藏车
- "XT": 30, // XT-系统
- "WZ": 80, // WZ-位置
- "LK": 60, // LK-冷库
- "LG": 30, // LG-冷柜
- "BWX": 30, // BWX-保温箱
- }
- TaskReportingTimeLimit = map[string]float64{
- "LC": 300, // LC-冷藏车
- "XT": 300, // XT-系统
- "WZ": 240, // WZ-位置
- "LK": 360, // LK-冷库
- "LG": 180, // LG-冷柜
- "BWX": 180, // BWX-保温箱
- }
- TaskCollectionTimeLimit float64 = 7 * 24 * 60
- )
- type AuditRecord struct {
- T_uuid string `orm:"size(256);null"` // 提交人(客户)UUID
- T_uuid_name string `orm:"size(256);null"` // 提交人名称
- T_admin string `orm:"size(256);null"` // 提交人(报告负责人)UUID
- T_admin_name string `orm:"size(256);null"` // 提交人名称
- T_state int `orm:"size(2);default(0)"` // 状态 1 已完成(客户通过) 2已退回(客户) 3已通过(报告负责人) 4已退回(报告负责人) 5已提交
- T_reason string `orm:"type(text)"` // 原因
- T_time string `orm:"type(256)"` // 时间
- T_type string `orm:"type(256)"` // 退回类型 scheme方案 reporting报告
- }
- // 模板
- type Task struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_class int `orm:"size(200);default(0)"` // 分类id
- T_InfoCollection_id string `orm:"size(256);null"` // 信息采集ID
- T_InfoTemplate_id string `orm:"size(256);null"` // 信息采集模板ID
- T_task_id string `orm:"size(256);null"` // 任务ID
- T_uuid string `orm:"size(256);null"` // 用户 UUID
- T_name string `orm:"size(256);null"` // 标题
- T_VerifyTemplate_class string `orm:"size(256);null"` // 模板id
- T_VerifyTemplate_id string `orm:"size(256);null"` // 模板id
- T_deadline string `orm:"size(256);null"` // 截止时间
- T_scheme string `orm:"size(256);null"` // 实施方案 负责人UUID
- T_collection string `orm:"size(256);null"` // 数据采集 负责人UUID
- T_reporting string `orm:"size(256);null"` // 报告编写 负责人UUID
- T_delivery string `orm:"size(256);null"` // 交付审核 负责人UUID
- T_scheme_state int `orm:"size(2);default(0)"` // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_collection_state int `orm:"size(2);default(0)"` // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- T_reporting_state int `orm:"size(2);default(0)"` // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_delivery_state int `orm:"size(2);default(0)"` // 交付审核 状态 0 未完成 1 已完成 2 处理中
- T_marking_state int `orm:"size(2);default(0)"` // 验证标识 状态 0 未完成 1 已完成
- T_VerifyDeviceDataStartTime string `orm:"size(256);null"` // 验证设备数据开始时间
- T_VerifyDeviceDataEndTime string `orm:"size(256);null"` // 验证设备数据开始时间
- T_BindDeviceDataStartTime string `orm:"size(256);null"` // 绑定设备数据开始时间
- T_BindDeviceDataEndTime string `orm:"size(256);null"` // 绑定设备数据结束时间
- T_doc1 string `orm:"type(text);null"` // 封面
- T_pdf1 string `orm:"type(text);null"` // 验证方案
- T_pdf1_watermark string `orm:"type(text);null"` // 验证方案 带水印
- T_doc2 string `orm:"type(text);null"` // 报告
- T_pdf2 string `orm:"type(text);null"` // 验证报告
- T_pdf2_watermark string `orm:"type(text);null"` // 验证报告 带水印
- T_doc3 string `orm:"type(text);null"` // 证书
- T_pdf3 string `orm:"type(text);null"` // 证书
- T_pdf4 string `orm:"type(text);null"` // 验证标识
- T_Show int `orm:"size(2);default(1)"` // 0 隐藏 1 公开
- T_Visit int `orm:"size(200);default(0)"` // 浏览量
- T_State int `orm:"size(2);default(1)"` // 0 删除 1 正常
- T_step int `orm:"size(2);default(-1)"` // 验证步骤
- T_sn string `orm:"size(256);null"` // sn
- T_CalibrationExpirationTime string `orm:"size(256);null"` // 校准到期时间
- T_project string `orm:"size(256);null"` // 项目 负责人UUID
- T_province string `orm:"size(256);null"` // 省
- T_city string `orm:"size(256);null"` // 市
- T_district string `orm:"size(256);null"` // 区
- T_province_code string `orm:"size(256);null"` // 省 code
- T_city_code string `orm:"size(256);null"` // 市 code
- T_district_code string `orm:"size(256);null"` // 区 code
- T_category string `orm:"size(256);null"` // 类别
- T_device_type string `orm:"size(256);null"` // 设备类型
- T_volume string `orm:"size(256);null"` // 规格/容积
- T_verify_type string `orm:"size(256);null"` // 验证类型
- T_subject_matter string `orm:"size(256);null"` // 标的物名称
- T_temp_range string `orm:"size(256);null"` // 验证温度范围
- T_report_number string `orm:"size(256);null"` // 报告编号
- T_report_type string `orm:"size(256);null"` // 报告类型
- T_start_time string `orm:"size(256);null"` // 项目开始时间
- T_end_time string `orm:"size(256);null"` // 结束时间 报告审核通过时间
- T_time_interval float64 `orm:"size(256);null"` // 时间间隔 单位分钟
- T_reject_times int `orm:"size(256);null"` // 驳回次数 客户退回方案和报告时
- T_reject_record string `orm:"type(text)"` // 驳回记录
- // 方案
- T_scheme_start_time string `orm:"size(256);null"` // 验证方案开始时间 接收信息采集表的时间
- T_scheme_end_time string `orm:"size(256);null"` // 验证方案结束时间 负责人审核通过后最后一次上传时间
- T_scheme_time_interval float64 `orm:"size(256);null"` // 时间间隔 单位分钟
- T_scheme_overtime float64 `orm:"size(256);null"` // 验证方案超时时间 单位分钟
- T_scheme_signature string `orm:"type(text)"` // 验证方案客户签字确认图片
- T_scheme_return_times int `orm:"size(256);null"` // 验证方案退回次数
- T_scheme_audit_record string `orm:"type(text)"` // 验证方案审核记录
- // 实施
- T_enter_area_time string `orm:"size(256);null"` // 进场时间
- T_collection_start_time string `orm:"size(256);null"` // 实施开始时间(app开始验证时间)
- T_collection_end_time string `orm:"size(256);null"` // 实施结束时间 (审核通过后签字确认提交时间)
- T_collection_time_interval float64 `orm:"size(256);null"` // 时间间隔 单位分钟
- T_collection_overtime float64 `orm:"size(256);null"` // 实施超时时间 单位分钟
- T_collection_signature string `orm:"type(text)"` // 实施人员签字确认图片
- T_collection_return_times int `orm:"size(256);null"` // 实施方案退回次数
- T_collection_audit_record string `orm:"type(text);null"` // 实施方案审核记录
- // 报告
- T_reporting_start_time string `orm:"size(256);null"` // 验证报告开始时间 接收信息采集表的时间
- T_reporting_end_time string `orm:"size(256);null"` // 验证报告结束时间 负责人审核通过后最后一次上传时间
- T_reporting_time_interval float64 `orm:"size(256);null"` // 时间间隔 单位分钟
- T_reporting_overtime float64 `orm:"size(256);null"` // 验证报告超时时间 单位分钟
- T_reporting_signature string `orm:"type(text)"` // 验证报告客户签字确认图片
- T_reporting_return_times int `orm:"size(256);null"` // 验证报告退回次数
- T_reporting_audit_record string `orm:"type(text);null"` // 验证报告审核记录
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
- UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
- }
- type Task_ struct {
- Id int
- T_class int // 分类ID
- T_InfoCollection_id string // 信息采集ID
- T_task_id string // 任务ID
- T_uuid string // 用户 UUID
- T_user_name string // 用户 UUID
- T_name string // 标题
- T_VerifyTemplate_class string // 任务模板id
- T_VerifyTemplate_id string // 任务模板id
- T_deadline string // 截止时间
- T_scheme string // 实施方案 负责人UUID
- T_collection string // 数据采集 负责人UUID
- T_reporting string // 报告编写 负责人UUID
- T_delivery string // 交付审核 负责人UUID
- T_scheme_state int // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_collection_state int // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- T_reporting_state int // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_delivery_state int // 交付审核 状态 0 未完成 1 已完成 2 处理中
- T_marking_state int // 验证标识 状态 0 未完成 1 已完成
- T_scheme_state_str string // 实施方案 状态 字符串
- T_collection_state_str string // 数据采集 状态 字符串
- T_reporting_state_str string // 报告编写 状态 字符串
- T_delivery_state_str string // 交付审核 状态 字符串
- T_marking_state_str string // 验证标识 状态 字符串
- T_scheme_name string // 实施方案 负责人姓名
- T_collection_name string // 数据采集 负责人姓名
- T_reporting_name string // 报告编写 负责人姓名
- T_delivery_name string // 交付审核 负责人姓名
- T_VerifyDeviceDataTime [2]string // 验证设备数据开始-结束时间
- T_BindDeviceDataTime [2]string // 绑定设备数据开始-结束时间
- T_doc1 string // 封面
- T_pdf1 string // 验证方案
- T_doc2 string // 报告
- T_pdf2 string // 报告
- T_doc3 string // 证书
- T_pdf3 string // 证书
- T_pdf4 string // 验证标识
- T_Show int // 0 公开 1 隐藏
- T_Visit int // 浏览量
- T_State int // 0 删除 1 正常
- T_sn string // sn
- T_CalibrationExpirationTime string // 校准到期时间
- T_province string // 省
- T_city string // 市
- T_district string // 区
- T_area []string // 省市区
- T_province_code string // 省 code
- T_city_code string // 市 code
- T_district_code string // 区 code
- T_area_code []string // 省市区
- InfoCollection InfoCollection.InfoCollection //信息采集
- }
- type Task_Stat struct {
- Id int
- T_class int // 分类ID
- T_InfoCollection_id string // 信息采集ID
- T_InfoTemplate_id string // 信息采集模板ID
- T_task_id string // 任务ID
- T_uuid string // 用户 UUID
- T_user_name string // 用户 UUID
- T_name string // 标题
- T_VerifyTemplate_class string // 任务模板id
- T_VerifyTemplate_id string // 任务模板id
- T_deadline string // 截止时间
- T_scheme string // 实施方案 负责人UUID
- T_collection string // 数据采集 负责人UUID
- T_reporting string // 报告编写 负责人UUID
- T_delivery string // 交付审核 负责人UUID
- T_scheme_state int // 实施方案 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_collection_state int // 数据采集 状态 0 未完成 1 数据来源已完成 2 处理中 3 已采集-无数据 4-数据编辑已完成(已提交) 5已通过(负责人) 6已退回(负责人)
- T_reporting_state int // 报告编写 状态 0 未完成 1 已完成(客户通过) 2已退回(客户) 3已通过(负责人) 4已退回(负责人) 5已提交
- T_delivery_state int // 交付审核 状态 0 未完成 1 已完成 2 处理中
- T_marking_state int // 验证标识 状态 0 未完成 1 已完成
- T_scheme_state_str string // 实施方案 状态 字符串
- T_collection_state_str string // 数据采集 状态 字符串
- T_reporting_state_str string // 报告编写 状态 字符串
- T_delivery_state_str string // 交付审核 状态 字符串
- T_marking_state_str string // 验证标识 状态 字符串
- T_scheme_name string // 实施方案 负责人姓名
- T_collection_name string // 数据采集 负责人姓名
- T_reporting_name string // 报告编写 负责人姓名
- T_delivery_name string // 交付审核 负责人姓名
- T_VerifyDeviceDataTime [2]string // 验证设备数据开始-结束时间
- T_BindDeviceDataTime [2]string // 绑定设备数据开始-结束时间
- T_doc1 string // 封面
- T_pdf1 string // 验证方案
- T_doc2 string // 报告
- T_pdf2 string // 报告
- T_doc3 string // 证书
- T_pdf3 string // 证书
- T_pdf4 string // 验证标识
- T_Show int // 0 公开 1 隐藏
- T_Visit int // 浏览量
- T_State int // 0 删除 1 正常
- T_sn string // sn
- T_CalibrationExpirationTime string // 校准到期时间
- T_project string // 项目 负责人UUID
- T_project_name string // 项目 负责人姓名
- T_province string // 省
- T_city string // 市
- T_district string // 区
- T_area []string // 省市区
- T_province_code string // 省 code
- T_city_code string // 市 code
- T_district_code string // 区 code
- T_area_code []string // 省市区
- T_category string // 类别
- T_device_type string // 设备类型
- T_volume string // 规格/容积
- T_verify_type string // 验证类型
- T_subject_matter string // 标的物名称
- T_temp_range string // 验证温度范围
- T_report_number string // 报告编号
- T_report_type string // 报告类型
- T_start_time string // 项目开始时间
- T_end_time string // 结束时间 报告审核通过时间
- T_time_interval string // 时间间隔 单位分钟
- T_reject_times int // 驳回次数 客户退回方案和报告时
- T_reject_record string // 驳回记录
- // 方案
- T_scheme_start_time string // 验证方案开始时间 接收信息采集表的时间
- T_scheme_end_time string // 验证方案结束时间
- T_scheme_time_interval string // 时间间隔 单位分钟
- T_scheme_overtime string // 验证方案超时时间 单位分钟
- T_scheme_signature string // 验证方案客户签字确认图片
- T_scheme_return_times int // 验证方案退回次数
- T_scheme_audit_record string // 验证方案审核记录
- // 实施
- T_enter_area_time string // 进场时间
- T_collection_start_time string // 实施开始时间(app开始验证时间)
- T_collection_end_time string // 实施结束时间 (签字确认提交时间)
- T_collection_time_interval string // 时间间隔 单位分钟
- T_collection_overtime string // 实施超时时间 单位分钟
- T_collection_signature string // 实施人员签字确认图片
- T_collection_return_times int // 实施方案退回次数
- T_collection_audit_record string // 实施方案审核记录
- // 报告
- T_reporting_start_time string // 验证报告开始时间 接收信息采集表的时间
- T_reporting_end_time string // 验证报告结束时间
- T_reporting_time_interval string // 时间间隔 单位分钟
- T_reporting_overtime string // 验证报告超时时间 单位分钟
- T_reporting_signature string // 验证报告客户签字确认图片
- T_reporting_return_times int // 验证报告退回次数
- T_reporting_audit_record string // 验证报告审核记录
- InfoCollection InfoCollection.InfoCollection_R //信息菜鸡
- }
- func (t *Task) TableName() string {
- return "task" // 数据库名称 // ************** 替换 FormulaList **************
- }
- var redisCache_Task cache.Cache
- func init() {
- //注册模型
- orm.RegisterModel(new(Task))
- config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
- "redis_"+"Task", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
- logs.Println(config)
- var err error
- redisCache_Task, err = cache.NewCache("redis", config)
- if err != nil || redisCache_Task == nil {
- errMsg := "failed to init redis"
- logs.Println(errMsg, err)
- }
- }
- // -------------------------------------------------------------
- func TaskToTask_(T Task, userMap, adminMap map[string]string) (T_ Task_) {
- T_.Id = T.Id
- T_.T_class = T.T_class
- T_.T_InfoCollection_id = T.T_InfoCollection_id
- if len(T.T_InfoCollection_id) > 0 {
- T_.InfoCollection, _ = InfoCollection.Read_InfoCollection(T.T_InfoCollection_id)
- }
- T_.T_task_id = T.T_task_id
- T_.T_uuid = T.T_uuid
- T_.T_user_name = userMap[T.T_uuid]
- T_.T_name = T.T_name
- T_.T_VerifyTemplate_class = T.T_VerifyTemplate_class
- T_.T_VerifyTemplate_id = T.T_VerifyTemplate_id
- T_.T_deadline = T.T_deadline
- T_.T_scheme = T.T_scheme
- T_.T_collection = T.T_collection
- T_.T_reporting = T.T_reporting
- T_.T_delivery = T.T_delivery
- T_.T_scheme_state = T.T_scheme_state
- T_.T_collection_state = T.T_collection_state
- T_.T_reporting_state = T.T_reporting_state
- T_.T_delivery_state = T.T_delivery_state
- T_.T_marking_state = T.T_marking_state
- T_.T_scheme_state_str = TaskSchemeStateMap[T.T_scheme_state]
- T_.T_collection_state_str = TaskCollectionStateMap[T.T_collection_state]
- T_.T_reporting_state_str = TaskReportingStateMap[T.T_reporting_state]
- T_.T_delivery_state_str = TaskDeliveryStateMap[T.T_delivery_state]
- T_.T_marking_state_str = TaskMarkingStateMap[T.T_marking_state]
- T_.T_scheme_name = adminMap[T.T_scheme]
- T_.T_collection_name = adminMap[T.T_collection]
- T_.T_reporting_name = adminMap[T.T_reporting]
- T_.T_delivery_name = adminMap[T.T_delivery]
- T_.T_VerifyDeviceDataTime = [2]string{T.T_VerifyDeviceDataStartTime, T.T_VerifyDeviceDataEndTime}
- T_.T_BindDeviceDataTime = [2]string{T.T_BindDeviceDataStartTime, T.T_BindDeviceDataEndTime}
- T_.T_doc1 = T.T_doc1
- T_.T_doc2 = T.T_doc2
- T_.T_doc3 = T.T_doc3
- T_.T_pdf1 = T.T_pdf1_watermark
- if T_.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney || len(T.T_InfoCollection_id) == 0 || len(T.T_pdf1_watermark) == 0 {
- T_.T_pdf1 = T.T_pdf1
- }
- T_.T_pdf2 = T.T_pdf2_watermark
- if T_.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney || len(T.T_InfoCollection_id) == 0 || len(T.T_pdf2_watermark) == 0 {
- T_.T_pdf2 = T.T_pdf2
- }
- T_.T_pdf3 = T.T_pdf3
- T_.T_pdf4 = T.T_pdf4
- T_.T_Show = T.T_Show
- T_.T_Visit = T.T_Visit
- T_.T_State = T.T_State
- T_.T_sn = T.T_sn
- T_.T_CalibrationExpirationTime = T.T_CalibrationExpirationTime
- return T_
- }
- func TaskToTask_Stat(T Task, userMap, adminMap map[string]string) (T_ Task_Stat) {
- T_.Id = T.Id
- T_.T_class = T.T_class
- T_.T_InfoCollection_id = T.T_InfoCollection_id
- if len(T.T_InfoCollection_id) > 0 {
- infoCollection, _ := InfoCollection.Read_InfoCollection(T.T_InfoCollection_id)
- T_.InfoCollection = InfoCollection.InfoCollectionToInfoCollection_R(infoCollection, userMap, adminMap, map[string]string{}, map[string]string{})
- }
- T_.T_task_id = T.T_task_id
- T_.T_uuid = T.T_uuid
- T_.T_user_name = userMap[T.T_uuid]
- T_.T_name = T.T_name
- T_.T_VerifyTemplate_class = T.T_VerifyTemplate_class
- T_.T_VerifyTemplate_id = T.T_VerifyTemplate_id
- T_.T_deadline = T.T_deadline
- T_.T_scheme = T.T_scheme
- T_.T_collection = T.T_collection
- T_.T_reporting = T.T_reporting
- T_.T_delivery = T.T_delivery
- T_.T_scheme_state = T.T_scheme_state
- T_.T_collection_state = T.T_collection_state
- T_.T_reporting_state = T.T_reporting_state
- T_.T_delivery_state = T.T_delivery_state
- T_.T_marking_state = T.T_marking_state
- T_.T_scheme_state_str = TaskSchemeStateMap[T.T_scheme_state]
- T_.T_collection_state_str = TaskCollectionStateMap[T.T_collection_state]
- T_.T_reporting_state_str = TaskReportingStateMap[T.T_reporting_state]
- T_.T_delivery_state_str = TaskDeliveryStateMap[T.T_delivery_state]
- T_.T_marking_state_str = TaskMarkingStateMap[T.T_marking_state]
- T_.T_project_name = adminMap[T.T_project]
- T_.T_scheme_name = adminMap[T.T_scheme]
- T_.T_collection_name = adminMap[T.T_collection]
- T_.T_reporting_name = adminMap[T.T_reporting]
- T_.T_delivery_name = adminMap[T.T_delivery]
- T_.T_VerifyDeviceDataTime = [2]string{T.T_VerifyDeviceDataStartTime, T.T_VerifyDeviceDataEndTime}
- T_.T_BindDeviceDataTime = [2]string{T.T_BindDeviceDataStartTime, T.T_BindDeviceDataEndTime}
- T_.T_doc1 = T.T_doc1
- T_.T_doc2 = T.T_doc2
- T_.T_doc3 = T.T_doc3
- T_.T_pdf1 = T.T_pdf1_watermark
- if T_.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney || len(T.T_InfoCollection_id) == 0 || len(T.T_pdf1_watermark) == 0 {
- T_.T_pdf1 = T.T_pdf1
- }
- T_.T_pdf2 = T.T_pdf2_watermark
- if T_.InfoCollection.T_status == InfoCollection.InfoCollectionStatusReturnedMoney || len(T.T_InfoCollection_id) == 0 || len(T.T_pdf2_watermark) == 0 {
- T_.T_pdf2 = T.T_pdf2
- }
- T_.T_pdf3 = T.T_pdf3
- T_.T_pdf4 = T.T_pdf4
- T_.T_Show = T.T_Show
- T_.T_Visit = T.T_Visit
- T_.T_State = T.T_State
- T_.T_sn = T.T_sn
- T_.T_CalibrationExpirationTime = T.T_CalibrationExpirationTime
- T_.T_project = T.T_project
- T_.T_province = T.T_province
- T_.T_city = T.T_city
- T_.T_district = T.T_district
- T_.T_area = []string{T.T_province, T.T_city, T.T_district}
- T_.T_province_code = T.T_province_code
- T_.T_city_code = T.T_city_code
- T_.T_district_code = T.T_district_code
- T_.T_area_code = []string{T.T_province_code, T.T_city_code, T.T_district_code}
- T_.T_category = T.T_category
- T_.T_device_type = T.T_device_type
- T_.T_volume = T.T_volume
- T_.T_verify_type = T.T_verify_type
- T_.T_subject_matter = T.T_subject_matter
- T_.T_temp_range = T.T_temp_range
- T_.T_report_number = T.T_report_number
- T_.T_report_type = T.T_report_type
- T_.T_start_time = T.T_start_time
- T_.T_end_time = T.T_end_time
- T_.T_time_interval = lib.ConvertMinutesToDHM(int(T.T_time_interval))
- T_.T_reject_times = T.T_reject_times
- T_.T_reject_record = T.T_reject_record
- // 方案
- T_.T_scheme_start_time = T.T_scheme_start_time
- T_.T_scheme_end_time = T.T_scheme_end_time
- if T.T_scheme_state == TaskSchemeStateClientPass ||
- T.T_scheme_state == TaskSchemeStateClientReturn ||
- T.T_scheme_state == TaskSchemeStatePass {
- T_.T_scheme_time_interval = lib.ConvertMinutesToDHM(int(T.T_scheme_time_interval))
- T_.T_scheme_overtime = lib.ConvertMinutesToDHM(int(T.T_scheme_overtime))
- }
- T_.T_scheme_signature = T.T_scheme_signature
- T_.T_scheme_return_times = T.T_scheme_return_times
- T_.T_scheme_audit_record = T.T_scheme_audit_record
- // 实施
- T_.T_enter_area_time = T.T_enter_area_time
- T_.T_collection_start_time = T.T_collection_start_time
- T_.T_collection_end_time = T.T_collection_end_time
- if T.T_collection_state == TaskCollectionStatePass {
- T_.T_collection_time_interval = lib.ConvertMinutesToDHM(int(T.T_collection_time_interval))
- T_.T_collection_overtime = lib.ConvertMinutesToDHM(int(T.T_collection_overtime))
- }
- T_.T_collection_signature = T.T_collection_signature
- T_.T_collection_return_times = T.T_collection_return_times
- T_.T_collection_audit_record = T.T_collection_audit_record
- // 报告
- T_.T_reporting_start_time = T.T_reporting_start_time
- T_.T_reporting_end_time = T.T_reporting_end_time
- if T.T_reporting_state == TaskReportingStateClientPass ||
- T.T_reporting_state == TaskReportingStateClientReturn ||
- T.T_reporting_state == TaskReportingStatePass {
- T_.T_reporting_time_interval = lib.ConvertMinutesToDHM(int(T.T_reporting_time_interval))
- T_.T_reporting_overtime = lib.ConvertMinutesToDHM(int(T.T_reporting_overtime))
- }
- T_.T_reporting_signature = T.T_reporting_signature
- T_.T_reporting_return_times = T.T_reporting_return_times
- T_.T_reporting_audit_record = T.T_reporting_audit_record
- return T_
- }
- // ---------------- Redis -------------------
- // Redis_Set(m.T_sn,m) // Redis 更新缓存
- func Redis_Task_Set(key string, r Task) (err error) {
- //json序列化
- str, err := json.Marshal(r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- err = redisCache_Task.Put(key, str, 24*time.Hour)
- if err != nil {
- logs.Println("set key:", key, ",value:", str, err)
- }
- return
- }
- // if r,is :=Redis_Get(T_sn);is{
- // return r,nil
- // }
- func Redis_Task_Get(key string) (r Task, is bool) {
- if redisCache_Task.IsExist(key) {
- logs.Println("找到key:", key)
- v := redisCache_Task.Get(key)
- json.Unmarshal(v.([]byte), &r)
- return r, true
- }
- logs.Println("没有 找到key:", key)
- return Task{}, false
- }
- func Redis_Task_DelK(key string) (err error) {
- err = redisCache_Task.Delete(key)
- return
- }
- // ---------------- 特殊方法 -------------------
- // 获取 ById
- func Read_Task_ById(id int) (r Task, is bool) {
- o := orm.NewOrm()
- r = Task{Id: id}
- err := o.Read(&r) // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, false
- }
- return r, true
- }
- // 获取 By
- func Read_Task(T_task_id string) (r Task, is bool) {
- if r, is = Redis_Task_Get(T_task_id); is == true {
- return r, true
- }
- o := orm.NewOrm()
- qs := o.QueryTable(new(Task))
- //err := qs.Filter("T_task_id", T_task_id).Filter("T_State", 1).One(&r)
- err := qs.Filter("T_task_id", T_task_id).Filter("T_State", 1).One(&r)
- if err != nil {
- return r, false
- }
- Redis_Task_Set(T_task_id, r)
- return r, true
- }
- // 添加
- func Add_Task(r Task) (string, bool) {
- o := orm.NewOrm()
- // 生成编号
- rand_x := 0
- for true {
- r.T_task_id = lib.GetRandstring(12, "abcdefghijklmnopqrstuvwxyz0123456789", int64(rand_x)) // 1,336,336
- err := o.Read(&r, "T_task_id") // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
- if err != nil {
- break
- }
- rand_x += 1
- }
- _, err := o.Insert(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return "", false
- }
- if !CREATE_TaskData(r.T_task_id) {
- return "", false
- }
- Redis_Task_Set(r.T_task_id, r)
- return r.T_task_id, true
- }
- func Add_Task_Tool(r Task) (string, bool) {
- o := orm.NewOrm()
- _, err := o.Insert(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return "", false
- }
- return r.T_task_id, true
- }
- // 删除
- func Delete_Task(v Task) bool {
- o := orm.NewOrm()
- if num, err := o.Delete(&v); err == nil {
- logs.Println("Number of records deleted in database:", num)
- } else {
- logs.Error(lib.FuncName(), err)
- return false
- }
- Redis_Task_DelK(v.T_task_id)
- return true
- }
- // 删除
- func Delete_Task_(v Task) bool {
- o := orm.NewOrm()
- v.T_State = 0
- if num, err := o.Update(&v, "T_State"); err == nil {
- logs.Println("Number of records updated in database:", num)
- } else {
- logs.Error(lib.FuncName(), err)
- return false
- }
- Redis_Task_DelK(v.T_task_id)
- return true
- }
- // 修改
- func Update_Task(m Task, cols ...string) bool {
- o := orm.NewOrm()
- if num, err := o.Update(&m, cols...); err == nil {
- logs.Println("Number of records updated in database:", num)
- Redis_Task_Set(m.T_task_id, m)
- return true
- } else {
- logs.Error(lib.FuncName(), err)
- }
- return false
- }
- // 添加浏览量
- func Add_Task_Visit(m Task) bool {
- o := orm.NewOrm()
- m.T_Visit += 1
- if num, err := o.Update(&m, "T_Visit"); err == nil {
- logs.Println("Number of records updated in database:", num)
- Redis_Task_Set(m.T_task_id, m)
- return true
- } else {
- logs.Error(lib.FuncName(), err)
- }
- return false
- }
- // 获取用户任务列表
- func Read_UserTask_List(T_uuid string, T_name string, userMap, adminMap map[string]string, page int, page_z int) ([]Task_, int) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Task))
- var r []Task
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- //cond1 := cond.And("T_name__icontains", T_name).And("T_State", 1)
- cond1 := cond.And("T_name__icontains", T_name).And("T_Show", 1).And("T_State", 1)
- if len(T_uuid) > 0 {
- cond1 = cond1.And("T_uuid", T_uuid)
- }
- qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
- cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
- // 转换
- var TaskList []Task_
- for _, v := range r {
- TaskList = append(TaskList, TaskToTask_(v, userMap, adminMap))
- }
- return TaskList, int(cnt)
- }
- // 获取任务列表
- func Read_Task_List(T_uuid, T_admin, T_name, T_InfoCollection_id string, T_scheme, T_collection, T_reporting, T_delivery,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state string,
- T_company_list []string, userMap, adminMap map[string]string, page int, page_z int) ([]Task_, int) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Task))
- var r []Task
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- cond1 := cond.AndCond(cond.Or("T_name__icontains", T_name).Or("T_task_id__icontains", T_name)).And("T_State", 1)
- if len(T_uuid) > 0 {
- cond1 = cond1.And("T_uuid", T_uuid)
- }
- if len(T_InfoCollection_id) > 0 {
- cond1 = cond1.And("T_InfoCollection_id", T_InfoCollection_id)
- }
- if len(T_admin) > 0 {
- cond1 = cond1.AndCond(cond.Or("T_scheme", T_admin).Or("T_collection", T_admin).
- Or("T_reporting", T_admin).Or("T_delivery", T_admin))
- }
- if len(T_company_list) > 0 {
- cond1 = cond1.And("T_uuid__in", T_company_list)
- }
- if len(T_scheme) > 0 {
- cond1 = cond1.And("T_scheme", T_scheme)
- }
- if len(T_collection) > 0 {
- cond1 = cond1.And("T_collection", T_collection)
- }
- if len(T_reporting) > 0 {
- cond1 = cond1.And("T_reporting", T_reporting)
- }
- if len(T_delivery) > 0 {
- cond1 = cond1.And("T_delivery", T_delivery)
- }
- if len(T_scheme_state) > 0 {
- cond1 = cond1.And("T_scheme_state", T_scheme_state)
- }
- if len(T_collection_state) > 0 {
- cond1 = cond1.And("T_collection_state", T_collection_state)
- }
- if len(T_reporting_state) > 0 {
- cond1 = cond1.And("T_reporting_state", T_reporting_state)
- }
- if len(T_delivery_state) > 0 {
- cond1 = cond1.And("T_delivery_state", T_delivery_state)
- }
- if len(T_marking_state) > 0 {
- cond1 = cond1.And("T_marking_state", T_marking_state)
- }
- qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
- cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
- // 转换
- var TaskList []Task_
- for _, v := range r {
- TaskList = append(TaskList, TaskToTask_(v, userMap, adminMap))
- }
- return TaskList, int(cnt)
- }
- func Read_Task_BySN(sn string) (r Task, err error) {
- if task, is := Redis_Task_Get(sn); is == true {
- return task, nil
- }
- o := orm.NewOrm()
- qs := o.QueryTable(new(Task))
- err = qs.Filter("T_sn", sn).Filter("T_State", 1).One(&r)
- if err != nil {
- return r, err
- }
- Redis_Task_Set(sn, r)
- return r, nil
- }
- // 修改
- func Update_Task_T_InfoTemplate_id(T_InfoCollection_id, T_InfoTemplate_id string) error {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Task))
- var r []Task
- o.Begin()
- qs.Filter("T_InfoCollection_id", T_InfoCollection_id).All(&r)
- for _, task := range r {
- task.T_InfoTemplate_id = T_InfoTemplate_id
- if _, err := o.Update(&task, "T_InfoTemplate_id"); err == nil {
- Redis_Task_Set(task.T_task_id, task)
- } else {
- o.Rollback()
- logs.Error(lib.FuncName(), err)
- return err
- }
- }
- o.Commit()
- return nil
- }
- func Add_AuditRecord(T_audit_record string, T_uuid, T_admin string, T_scheme_state int, T_reason string, T_type string) (string, error) {
- auditRecord := AuditRecord{
- T_uuid: T_uuid,
- T_admin: T_admin,
- T_state: T_scheme_state,
- T_reason: T_reason,
- T_type: T_type,
- T_time: time.Now().Format("2006-01-02 15:04:05"),
- }
- var returnRecordList []AuditRecord
- if len(T_audit_record) > 0 {
- err := json.Unmarshal([]byte(T_audit_record), &returnRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return "", errors.New("JSON 反序列化失败")
- }
- }
- returnRecordList = append(returnRecordList, auditRecord)
- returnRecordJson, err := json.Marshal(returnRecordList)
- if err != nil {
- logs.Error("JSON 反序列化失败:", err)
- return "", errors.New("JSON 反序列化失败")
- }
- return string(returnRecordJson), nil
- }
- // 获取项目负责人列表
- func Get_Task_UserList(T_type string) []string {
- o := orm.NewOrm()
- var err error
- var pl_lists []string
- switch T_type {
- case "T_project":
- _, err = o.Raw("SELECT DISTINCT t_project FROM task LIMIT 0,1000").QueryRows(&pl_lists)
- case "T_scheme":
- _, err = o.Raw("SELECT DISTINCT t_scheme FROM task LIMIT 0,1000").QueryRows(&pl_lists)
- case "T_collection":
- _, err = o.Raw("SELECT DISTINCT t_collection FROM task LIMIT 0,1000").QueryRows(&pl_lists)
- case "T_reporting":
- _, err = o.Raw("SELECT DISTINCT t_reporting FROM task LIMIT 0,1000").QueryRows(&pl_lists)
- }
- if err != nil {
- logs.Error("获取项目负责人列表失败:", err)
- }
- return pl_lists
- }
- func Read_Task_Stat(T_uuid, T_admin, T_name, T_InfoCollection_id string, T_project, T_scheme, T_collection, T_reporting, T_delivery,
- T_scheme_state, T_collection_state, T_reporting_state, T_delivery_state, T_marking_state string,
- T_company_list []string, userMap, adminMap map[string]string, page int, page_z int) ([]Task_Stat, int) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Task))
- var r []Task
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- cond1 := cond.AndCond(cond.Or("T_name__icontains", T_name).Or("T_task_id__icontains", T_name)).And("T_State", 1)
- if len(T_uuid) > 0 {
- cond1 = cond1.And("T_uuid", T_uuid)
- }
- if len(T_InfoCollection_id) > 0 {
- cond1 = cond1.And("T_InfoCollection_id", T_InfoCollection_id)
- }
- if len(T_admin) > 0 {
- cond1 = cond1.AndCond(cond.Or("T_scheme", T_admin).Or("T_collection", T_admin).
- Or("T_reporting", T_admin).Or("T_delivery", T_admin))
- }
- if len(T_company_list) > 0 {
- cond1 = cond1.And("T_uuid__in", T_company_list)
- }
- if len(T_project) > 0 {
- cond1 = cond1.And("T_project", T_project)
- }
- if len(T_scheme) > 0 {
- cond1 = cond1.And("T_scheme", T_scheme)
- }
- if len(T_collection) > 0 {
- cond1 = cond1.And("T_collection", T_collection)
- }
- if len(T_reporting) > 0 {
- cond1 = cond1.And("T_reporting", T_reporting)
- }
- if len(T_delivery) > 0 {
- cond1 = cond1.And("T_delivery", T_delivery)
- }
- if len(T_scheme_state) > 0 {
- cond1 = cond1.And("T_scheme_state", T_scheme_state)
- }
- if len(T_collection_state) > 0 {
- cond1 = cond1.And("T_collection_state", T_collection_state)
- }
- if len(T_reporting_state) > 0 {
- cond1 = cond1.And("T_reporting_state", T_reporting_state)
- }
- if len(T_delivery_state) > 0 {
- cond1 = cond1.And("T_delivery_state", T_delivery_state)
- }
- if len(T_marking_state) > 0 {
- cond1 = cond1.And("T_marking_state", T_marking_state)
- }
- if page_z == 9999 {
- qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
- } else {
- qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
- }
- cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
- // 转换
- var TaskList []Task_Stat
- for _, v := range r {
- TaskList = append(TaskList, TaskToTask_Stat(v, userMap, adminMap))
- }
- return TaskList, int(cnt)
- }
|