err=r.o.Raw("SELECT COUNT(*) AS `count` FROM `"+table+"` WHERE `timestamp` < ? AND to_account IN("+inExp+") AND from_account IN("+inExp+")",messagePaginationDto.Timestamp,accounts,accounts).QueryRow(&messageCount)
iferr!=nil{
logs.Warn("GetMessages get one service message list1------------",err)
_,err=r.o.Raw("SELECT * FROM `message` WHERE to_account IN ("+inExp+") AND from_account IN ("+inExp+") AND `timestamp` < ? ORDER BY `sequence` ASC LIMIT ?,?",accounts,accounts,messagePaginationDto.Timestamp,start,end).QueryRows(&messages)
_,err=r.o.Raw("SELECT * FROM `"+table+"` WHERE to_account IN ("+inExp+") AND from_account IN ("+inExp+") AND `timestamp` < ? ORDER BY `sequence` ASC LIMIT ?,?",accounts,accounts,messagePaginationDto.Timestamp,start,end).QueryRows(&messages)
iferr!=nil{
logs.Warn("GetMessages get one service message list2------------",err)
r.o.Raw("SELECT COUNT(*) AS `count` FROM `"+table+"` WHERE to_account IN("+inExp+") AND from_account IN("+inExp+")",accounts,accounts).QueryRow(&messageCount1)
messagePaginationDto.List=messages
messagePaginationDto.Total=total
messagePaginationDto.Total=messageCount1.Count
}else{
messagePaginationDto.List=[]models.Message{}
messagePaginationDto.Total=0
}
return&messagePaginationDto,nil
}
// GetAdminHistoryMessages get admin messages history
_,err:=r.o.Raw("SELECT * FROM (SELECT w.*,w.id AS i_d,w.a_i_d AS `aid`,w.wid AS `w_i_d`,u.nickname AS u_nickname,a.nickname AS a_nickname,a.avatar AS a_avatar,u.avatar AS u_avatar FROM work_order_comment w LEFT JOIN (SELECT * FROM admin) a ON w.a_i_d = a.id LEFT JOIN (SELECT * FROM `user`) u ON w.u_i_d = u.id AND w.wid = ? ORDER BY w.id ASC) b WHERE wid = ?",wid,wid).QueryRows(&workOrderComments)
_,err:=r.o.Raw("SELECT * FROM (SELECT w.*,w.id AS i_d,u.nickname AS u_nickname,a.nickname AS a_nickname,a.avatar AS a_avatar,u.avatar AS u_avatar FROM work_order_comment w LEFT JOIN (SELECT * FROM admin) a ON w.aid = a.id LEFT JOIN (SELECT * FROM `user`) u ON w.uid = u.id AND w.wid = ? ORDER BY w.id ASC) b WHERE wid = ?",wid,wid).QueryRows(&workOrderComments)
iferr!=nil{
logs.Warn("GetWorkOrderComments get WorkOrderComments-----------",err)
err:=r.o.Raw("SELECT * FROM ((SELECT count(*) AS status0 FROM work_order WHERE `status` = 0) w1,(SELECT count(*) AS status2 FROM work_order WHERE `status` = 2) w2,(SELECT count(*) AS status3 FROM work_order WHERE `status` = 3) w3,(SELECT count(*) AS delete_count FROM work_order WHERE `delete` = 1) w4)").QueryRow(&workOrderCouns)
err:=r.o.Raw("SELECT * FROM ((SELECT count(*) AS status0 FROM work_order WHERE `status` = 0 AND `delete` = 0) w1,(SELECT count(*) AS status2 FROM work_order WHERE `status` = 2 AND `delete` = 0) w2,(SELECT count(*) AS status3 FROM work_order WHERE `status` = 3 AND `delete` = 0) w3,(SELECT count(*) AS delete_count FROM work_order WHERE `delete` = 1) w4)").QueryRow(&workOrderCouns)
err:=r.o.Raw("SELECT * FROM (SELECT w.*,w.id AS i_d, w.uid AS u_i_d,u.nickname AS u_nickname FROM work_order w LEFT JOIN (SELECT * FROM `user`) u ON w.uid = u.id) w WHERE w.id = ?",id).QueryRow(&workOrder)
err:=r.o.Raw("SELECT * FROM (SELECT w.*,w.id AS i_d, w.uid AS u_i_d, w.tid AS t_i_d, w.cid AS c_i_d,u.nickname AS u_nickname FROM work_order w LEFT JOIN (SELECT * FROM `user`) u ON w.uid = u.id) w WHERE w.id = ?",id).QueryRow(&workOrder)
iferr!=nil{
logs.Warn("GetWorkOrder get WorkOrder------------",err)
SQLSUB:="SELECT w.*,u.nickname AS u_nickname,a.nickname AS a_nickname,w.id AS i_d,w.uid AS u_i_d FROM work_order w LEFT JOIN (SELECT id, nickname FROM `user`) u ON w.uid = u.id LEFT JOIN (SELECT id, nickname FROM `admin`) a ON w.last_reply = a.id"
SQL:="SELECT *,t_i_d AS tid,c_i_d AS cid FROM ("+SQLSUB+") w WHERE `delete` = "+del+statusSQL+tidSQL+" ORDER BY status ASC, create_at DESC"
SQLSUB:="SELECT w.*,u.nickname AS u_nickname,a.nickname AS a_nickname,w.id AS i_d,w.uid AS u_i_d,w.tid AS t_i_d,w.cid AS c_i_d FROM work_order w LEFT JOIN (SELECT id, nickname FROM `user`) u ON w.uid = u.id LEFT JOIN (SELECT id, nickname FROM `admin`) a ON w.last_reply = a.id"
SQL:="SELECT * FROM ("+SQLSUB+") w WHERE `delete` = "+del+statusSQL+tidSQL+" ORDER BY status ASC, create_at DESC"
_,err:=r.o.Raw("SELECT t.*,IFNULL(w.count,0) as `count` FROM work_order_type t LEFT JOIN (SELECT t_i_d,COUNT(*) AS `count` FROM `work_order` WHERE `delete` = 0 AND status != 3 GROUP BY `t_i_d`) w ON t.id = w.t_i_d").QueryRows(&workOrderTypes)
_,err:=r.o.Raw("SELECT t.*,IFNULL(w.count,0) as `count` FROM work_order_type t LEFT JOIN (SELECT tid,COUNT(*) AS `count` FROM `work_order` WHERE `delete` = 0 AND status != 3 GROUP BY `tid`) w ON t.id = w.tid").QueryRows(&workOrderTypes)
iferr!=nil{
logs.Warn("GetWorkOrderTypes get all------------",err)