|
@@ -485,7 +485,7 @@ func Up_TaskData(T_task_id string, Id string, T_t string, T_rh string, T_time st
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
|
|
|
|
-// 添加
|
|
|
|
|
|
+// 删除
|
|
func Del_TaskData(T_task_id string, Id string) bool {
|
|
func Del_TaskData(T_task_id string, Id string) bool {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
o := orm.NewOrm()
|
|
@@ -972,28 +972,29 @@ func GroupDataByTID(data []TaskData) map[string][]TaskData {
|
|
}
|
|
}
|
|
|
|
|
|
// 删除的重复数据
|
|
// 删除的重复数据
|
|
-func DeleteDeduplicate(T_task_id string) error {
|
|
|
|
|
|
+func DeleteDeduplicate(T_task_id string) (int64, error) {
|
|
localOrm := orm2.NewOrmUsingDB(conf.Local_AliasName)
|
|
localOrm := orm2.NewOrmUsingDB(conf.Local_AliasName)
|
|
tb_name := "z_task_data_" + T_task_id
|
|
tb_name := "z_task_data_" + T_task_id
|
|
-
|
|
|
|
|
|
+ var cnt int64
|
|
// 创建临时表
|
|
// 创建临时表
|
|
- sqlCreate := "CREATE TABLE `tmp_table` AS (SELECT MAX(`ID`) AS `max_id` FROM " + tb_name + " GROUP BY `t_sn`,`t_id`,`t_time`);"
|
|
|
|
|
|
+ sqlCreate := "CREATE TABLE `tmp_table` AS (SELECT MIN(`ID`) AS `min_id` FROM " + tb_name + " GROUP BY `t_sn`,`t_id`,`t_time`);"
|
|
_, err := localOrm.Raw(sqlCreate).Exec()
|
|
_, err := localOrm.Raw(sqlCreate).Exec()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(lib.FuncName(), err)
|
|
logs.Error(lib.FuncName(), err)
|
|
- return err
|
|
|
|
|
|
+ return cnt, err
|
|
}
|
|
}
|
|
- sqlDelete := "DELETE FROM " + tb_name + " WHERE `ID` NOT IN (SELECT `max_id` FROM `tmp_table`);"
|
|
|
|
- _, err = localOrm.Raw(sqlDelete).Exec()
|
|
|
|
|
|
+ sqlDelete := "DELETE FROM " + tb_name + " WHERE `ID` NOT IN (SELECT `min_id` FROM `tmp_table`);"
|
|
|
|
+ res, err := localOrm.Raw(sqlDelete).Exec()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(lib.FuncName(), err)
|
|
logs.Error(lib.FuncName(), err)
|
|
- return err
|
|
|
|
|
|
+ return cnt, err
|
|
}
|
|
}
|
|
|
|
+ cnt, _ = res.RowsAffected()
|
|
sqlDrop := "DROP TABLE `tmp_table`;"
|
|
sqlDrop := "DROP TABLE `tmp_table`;"
|
|
_, err = localOrm.Raw(sqlDrop).Exec()
|
|
_, err = localOrm.Raw(sqlDrop).Exec()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(lib.FuncName(), err)
|
|
logs.Error(lib.FuncName(), err)
|
|
- return err
|
|
|
|
|
|
+ return cnt, err
|
|
}
|
|
}
|
|
- return nil
|
|
|
|
|
|
+ return cnt, nil
|
|
}
|
|
}
|