package p2.application.tsubmiteditmodel;

import baseclass.PaoCust;
import com.cnd3b.common.data.Row;
import com.cnd3b.common.data.Rows;
import com.cnd3b.common.data.db.DBConnect;
import p2.pao.PaoSet;
import p2.util.P2Exception;

import java.util.ArrayList;
import java.util.Random;

public class tsubmiteditmodel extends PaoCust {
    public tsubmiteditmodel(PaoSet arg0) {
        super(arg0);
    }

    public void createRandomData() throws P2Exception {
        DBConnect dbConnect = new DBConnect();
        Rows userRows = dbConnect.runSqlQuery("select t1.tenterprise_userid,t2.fname from tsubmitedit t1 inner join tenterprise_users t2 on t1.siteid=t2.siteid and t1.tenterprise_userid=t2.tenterprise_userid where t1.tsubmiteditmodelid='" + getUniqueIDValue() + "'");

        {
            ArrayList<String> SQllist = new ArrayList<>();
            for (Row user : userRows) {
                String tenterprise_userid = user.getString("tenterprise_userid");
                String fname = user.getString("fname");

                if (getRandomint(0, 2) == 1) {
                    SQllist.add("update tsubmitedit set description='随机数据', changeby='" + fname + "',changedate=getdate(),submitdate=getdate(),fcontent='提报内容',submitby='" + fname + "',fisread=1,fstatus='提交' where siteid='" + getString("siteid") + "' and tenterprise_userid='" + tenterprise_userid + "' and tsubmiteditmodelid='" + getUniqueIDValue() + "'");
                } else if (getRandomint(0, 2) == 1) {
                    SQllist.add("update tsubmitedit set description='随机数据', changeby='" + fname + "',changedate=getdate(),fisread=1 where siteid='" + getString("siteid") + "' and tenterprise_userid='" + tenterprise_userid + "' and tsubmiteditmodelid='" + getUniqueIDValue() + "'");
                }
            }
            dbConnect.runSqlUpdate(SQllist);
            setValue("description", "随机创建数据" + getDateTime_Str(), 11L);
        }
    }

    public int getRandomint(int minvalue, int maxvalue) {
        return new Random().nextInt(maxvalue) % (maxvalue - minvalue + 1) + minvalue;
    }
}
