我有这两个表data class ClassStatus(val status: Int, val error_message: String?, val data: Map<String,Map<String, ArrayList<Model>>>)
data class Model(val id: Long, val person_id: Long, val friend_id: Long)
fun main(args: Array<String>) {
val fromJson = Gson().fromJson<ClassStatus>(jj, ClassStatus::class.java)
printResult(fromJson)
//result
//ClassStatus(status=0, error_message=null, data={1={7=[Model(id=1, person_id=3, friend_id=2)]}}) class pl.jac.gson2.not.ClassStatus--> 1
//{1={7=[Model(id=1, person_id=3, friend_id=2)]}} class com.google.gson.internal.LinkedTreeMap--> 2
//{7=[Model(id=1, person_id=3, friend_id=2)]} class com.google.gson.internal.LinkedTreeMap--> 3
//[Model(id=1, person_id=3, friend_id=2)] class java.util.ArrayList--> 4
//Model(id=1, person_id=3, friend_id=2) class pl.jac.gson2.not.Model--> 5
//1 long--> 6
}
private fun printResult(fromMapDefault: ClassStatus) {
println("""
result
${fromMapDefault} ${fromMapDefault.javaClass}--> 1
${fromMapDefault.data} ${fromMapDefault.data.javaClass}--> 2
${fromMapDefault.data["1"]} ${fromMapDefault.data["1"]?.javaClass}--> 3
${fromMapDefault.data["1"]!!["7"]} ${fromMapDefault.data["1"]!!["7"]!!.javaClass}--> 4
${fromMapDefault.data["1"]?.get("7")!![0]} ${fromMapDefault.data["1"]!!["7"]!![0].javaClass}--> 5
${fromMapDefault.data["1"]?.get("7")!![0].id} ${fromMapDefault.data["1"]!!["7"]!![0].id!!.javaClass}--> 6
""".trimIndent())
}
val jj = "{\n" +
"\"status\": 0,\n" +
"\"error_message\": null,\n" +
"\"data\": {\n" +
"\"1\": {\n" +
" \"7\": [\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"person_id\": \"3\",\n" +
" \"friend_id\": \"2\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}\n" +
"}"
和palle_tb
,我正在尝试使用csvName
在id
内的palle_tb
中使用csvName
的{ strong>表已连接,但我在FK_Name内没有任何值。
我很确定我应该在FK_Name
中使用一个变量,但是由于我已经有了这个':FK_Name' =>
这是我的代码:
FK_Name INT(11),
FOREIGN KEY (FK_Name) REFERENCES palle_tb(id),
如果您需要按钮,那么这里是代码。我需要它是自动的,所以用外键进行选择不会做。
public function createPalleTable($latest_filename){
return $this->db->toList("CREATE TABLE IF NOT EXISTS `palle_tb`(
id INT(11) AUTO_INCREMENT PRIMARY KEY,
Palle_nr VARCHAR(50),
Varenummer VARCHAR(50),
Ordre_nummer VARCHAR(50),
Operatoer VARCHAR(50),
Maskine_nr VARCHAR(50),
Raavare_batch_nr VARCHAR(50),
Dato_ur_stillet VARCHAR(50),
Klokke_fuldsvejst VARCHAR(50),
Fuldstoebning_af_klokke VARCHAR(50),
Afgratning_af_overflade VARCHAR(50),
Vaegt DECIMAL(10,2))
");
}
public function insertPalleTable($latest_filename ,$palledata){
return $this->db->toList("INSERT INTO `palle_tb` (`Palle_nr`, `Varenummer`, `Ordre_nummer`, `Operatoer`, `Maskine_nr`,
`Raavare_batch_nr`, `Dato_ur_stillet`,`Klokke_fuldsvejst`,`Fuldstoebning_af_klokke`,`Afgratning_af_overflade`,`Vaegt`)
VALUES (:Palle_nr, :Varenummer, :Ordre_nummer, :Operatoer, :Maskine_nr, :Raavare_batch_nr, :Dato_ur_stillet,
:Klokke_fuldsvejst, :Fuldstoebning_af_klokke, :Afgratning_af_overflade, :Vaegt)",
[
':Palle_nr' => $palledata[0],
':Varenummer'=> $palledata[1],
':Ordre_nummer'=> $palledata[2],
':Operatoer'=> $palledata[3],
':Maskine_nr'=> $palledata[4],
':Raavare_batch_nr'=> $palledata[5],
':Dato_ur_stillet'=> $palledata[6],
':Klokke_fuldsvejst'=> $palledata[7],
':Fuldstoebning_af_klokke'=> $palledata[8],
':Afgratning_af_overflade'=> $palledata[9],
':Vaegt'=> $palledata[10]
]
);
}
/*The idea with the functions under this is that it creates a table with the Name of the data only and creates a foreign key to connect them*/
public function createCsvTable(){
return $this->db->toList("CREATE TABLE IF NOT EXISTS `CsvName`(
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
FK_Name INT(11),
FOREIGN KEY (FK_Name) REFERENCES palle_tb(id),
Name VARCHAR(50))
");
}
public function insertCsvData($myArray){
$this->db->query("INSERT INTO CsvName (Name,FK_Name)
VALUES (:Name,:FK_Name)",
[
':Name' => $myArray[0], /*This array contains all my data, but when i add the [0] it only takes the Name*/
':FK_Name' => /*This should contain the id from the palle_tb i need help with how to get that*/
]
);
}
感谢您的帮助!
答案 0 :(得分:0)
我是这样做的。
async def Main_Loop(interval):
global theMessages#[[message,interval,killinterval,clock,intArg,killArg],[message,interval,killinterval,clock,intArg,killArg]]
global theServer
global theChannel
global theHistory#[[messageobject,killinterval,clock],[messageobject,killinterval,clock]]
while True:
curTime = round(time.time())
#--------------DELETE OLD MESSAGES
n=0
for historyData in theHistory:
messageObject=historyData[0]
killInterval=historyData[1]
killTime=historyData[2]
print(theHistory)
if curTime-killTime > killInterval:#if the timer is up
print("delete time")
print(messageObject)
await dBot.change_presence(game=discord.Game(name="Housekeeping....."))
await dBot.delete_message(messageObject)
await dBot.change_presence(game=discord.Game(name=DEFAULT_STATUS))
del theHistory[n]
await SaveHistory()
n+=1
await asyncio.sleep(interval)#pause