Esempio n. 1
0
func GetFillObjectPage(db *sql.DB, sql string, currPageNo, pageSize, totalNum int, params []interface{}) (*commonlib.TraditionPage, error) {

	rows, err := db.Query(sql, params...)

	if err != nil {
		Log.Error(err.Error())
		return nil, err
	}

	objects := []interface{}{}

	columns, err := rows.Columns()

	if err != nil {
		Log.Error(err.Error())
		return nil, err
	}

	for rows.Next() {

		model := new(Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for index, column := range columns {
			if index > 0 { //第一个列必须是id
				prop := new(Prop)
				prop.Name = column
				prop.Value = ""
				fillObjects = append(fillObjects, &prop.Value)
				model.Props = append(model.Props, prop)
			}
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			Log.Error(err.Error())
			return nil, err
		}

		objects = append(objects, model)
	}

	return commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects), nil
}
func ClassScheduleAttachListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	childId := r.FormValue("childId")
	scheduleId := r.FormValue("scheduleId")

	params := []interface{}{}

	sql := "select csa.id,csa.url,csa.intro,csa.upload_time,csa.pc_thumb_url,ce.domain_name from class_schedule_attach csa left join class_schedule_detail csd on csd.id=csa.schedule_detail_id left join center ce on ce.cid=csd.center_id where csa.schedule_detail_id=? and csa.relation_childs like ? "
	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	params = append(params, scheduleId)
	params = append(params, "%["+childId+"]%")

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " limit ?,? "

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 5; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
/*
select c.id,e.really_name,ce.name,c.mother,c.mother_phone,c.father,c.father_phone,c.home_phone,c.child,c.contact_status
from tmk_consumer tc
left join consumer c on tc.consumer_id=c.id
left join employee e on e.user_id=tc.employee_id
left join center ce on ce.cid=c.center_id
where tc.employee_id=?
*/
func TmkStatisticsDetailAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	id := r.FormValue("id")

	params := []interface{}{}

	sql := " select c.id,e.user_id,e.really_name,ce.name,c.mother,c.mother_phone,c.father,c.father_phone,c.home_phone,c.child,c.contact_status "
	sql += " from tmk_consumer tc "
	sql += " left join consumer c on tc.consumer_id=c.id "
	sql += " left join employee e on e.user_id=tc.employee_id "
	sql += " left join center ce on ce.cid=c.center_id "
	sql += " where tc.employee_id=? "

	countSql := "select count(1) from tmk_consumer where employee_id=?"

	params = append(params, id)

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " limit ?,?"

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	lessgo.Log.Debug(sql)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)
		r := rand.New(rand.NewSource(time.Now().UnixNano()))
		model.Id = fmt.Sprint(r.Intn(1000))
		model.Props = []*lessgo.Prop{}

		fillObjects := []interface{}{}

		for i := 0; i < 11; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")
}
/*
select em.user_id,aa.num as '电话数',bb.num as '名单数',cc.num as '邀约数',dd.num as '签到数',ee.num as '缴费数'
from employee em left join
(select count(1) num,e.user_id from audio a left join employee e on a.cid=e.center_id and a.localphone=e.phone_in_center
where e.user_id is not null group by e.user_id ) aa on em.user_id= aa.user_id
left join
(select count(1) num,tmk_id from tmk_consumer group by tmk_id )bb on em.user_id=bb.tmk_id
left join
(select count(1) num,create_user from wyclass_free_child where create_time>=? and create_time <=? group by create_user) cc on em.user_id=cc.tmk_id
left join
(select count(1) num,tmk_id from(select tc.tmk_id,tc.consumer_id,wfsi.sign_in_time from tmk_consumer tc left join wyclass_free_sign_in wfsi on tc.consumer_id=wfsi.consumer_id
where wfsi.sign_in_time is not null ) a group by tmk_id )dd on em.user_id=dd.tmk_id
left join
(select count(1) num,tmk_id from(select tc.tmk_id,tc.consumer_id,pl.pay_time from tmk_consumer tc left join pay_log pl on tc.consumer_id=pl.consumer_id
where pl.pay_time is not null) b group by tmk_id) ee on em.user_id=ee.tmk_id
where cc.num is not null
order by em.user_id
*/
func TmkStatisticsAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	centerId := r.FormValue("centerId-eq")
	startTime := r.FormValue("startTime-ge")
	endTime := r.FormValue("endTime-le")
	employeeId := r.FormValue("employee_id-eq")

	dataType := ""

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "admin" || roleCode == "yyzj" || roleCode == "zjl" || roleCode == "yyzy" {
			dataType = "all"
			break
		} else if roleCode == "cd" {
			dataType = "center"
			break
		} else {
			dataType = "self"
			break
		}
	}

	params := []interface{}{}

	sql := `select em.user_id,em.really_name,aa.num as '电话数',bb.num as '名单数',cc.num as '邀约数',dd.num as '签到数',ee.num as '定金',ff.num as '全额',1,2,3
		    from employee em left join
			(select count(1) num,e.user_id from audio a left join employee e on a.cid=e.center_id and a.localphone=e.phone_in_center
	        where e.user_id is not null and start_time >=? and start_time<=?  group by e.user_id ) aa on em.user_id= aa.user_id
			left join
			(select count(1) num,tmk_id from tmk_consumer where tmk_create_time >=? and tmk_create_time<=? group by tmk_id )bb on em.user_id=bb.tmk_id
			left join
			(select count(1) num,create_user from schedule_detail_child where create_time>=? and create_time <=? and is_free=1 group by create_user) cc on em.user_id=cc.create_user
			left join
			(select count(1) num,tmk_id from( select tc.tmk_id,si.sid from tmk_consumer tc
			left join consumer_new cons on tc.consumer_id=cons.id left join parent p  on p.pid=cons.parent_id  left join child ch on ch.pid=p.pid left join sign_in si on si.child_id=ch.cid
			where si.type=1 and si.is_free=1 and sign_time>=? and sign_time<=? )a group by tmk_id )dd on em.user_id=dd.tmk_id
			left join
			(select count(1) num,tmk_id from(select tc.tmk_id,tc.consumer_id from tmk_consumer tc left join pay_log pl on tc.consumer_id=pl.consumer_id left join consumer_new cons on cons.id=tc.consumer_id
			where pl.pay_time is not null and pl.pay_time>=? and pl.pay_time<=? and cons.pay_status=1 ) b group by tmk_id) ee on em.user_id=ee.tmk_id
			left join
			(select count(1) num,tmk_id from(select tc.tmk_id,tc.consumer_id from tmk_consumer tc left join pay_log pl on tc.consumer_id=pl.consumer_id left join consumer_new cons on cons.id=tc.consumer_id
			where pl.pay_time is not null and pl.pay_time>=? and pl.pay_time<=? and cons.pay_status=2 ) b group by tmk_id) ff on em.user_id=ff.tmk_id
			left join employee_role er on em.user_id=er.user_id
			left join role r on r.role_id=er.role_id
			where (r.code='tmk' or r.code='tmk_center') and em.is_leave=0 `

	defaultStartTime := "2000-01-01 00:0:000"
	defaultEndTime := "2999-12-31 00:00:00"

	if startTime != "" {
		defaultStartTime = startTime
	}

	if endTime != "" {
		defaultEndTime = endTime
	}
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)

	defaultStartTime = strings.Replace(defaultStartTime, "-", "", -1)
	defaultStartTime = strings.Replace(defaultStartTime, " ", "", -1)
	defaultStartTime = strings.Replace(defaultStartTime, ":", "", -1)

	defaultEndTime = strings.Replace(defaultEndTime, "-", "", -1)
	defaultEndTime = strings.Replace(defaultEndTime, " ", "", -1)
	defaultEndTime = strings.Replace(defaultEndTime, ":", "", -1)

	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)

	if dataType == "center" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
		params = append(params, _employee.CenterId)
		sql += " and em.center_id=? "
	}

	if centerId != "" && dataType == "all" {
		params = append(params, centerId)
		sql += " and em.center_id=? "
	}

	if dataType == "self" {
		params = append(params, employee.UserId)
		sql += " and em.user_id=? "
	}

	if dataType != "self" && employeeId != "" {
		params = append(params, employeeId)
		sql += " and em.user_id=? "
	}

	countSql := "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by em.user_id limit ?,?"

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	lessgo.Log.Debug(sql)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 10; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")
}
Esempio n. 5
0
//商品分类分页数据服务
func GalleryListAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	title := r.FormValue("title-like")
	comment := r.FormValue("comment-like")

	params := []interface{}{}

	sql := "select gal.id, gal.title, gal.comment, gal.image_name, gal.image_suffix, "
	sql += "    (select GROUP_CONCAT(c.name) "
	sql += "        from category c left join category_gallery cg ON c.id = cg.category_id "
	sql += "        where cg.gallery_id = gal.id) as image_category "
	sql += "from gallery gal where 1=1"
	if strings.TrimSpace(title) != "" {
		params = append(params, "%"+title+"%")
		sql += " and gal.title like ? "
	}
	if strings.TrimSpace(comment) != "" {
		params = append(params, "%"+comment+"%")
		sql += " and gal.comment like ? "
	}

	countSql := "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by gal.id desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 5; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
//顾问分页数据服务
func ConsultantPhoneListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	dataType := ""

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "admin" || roleCode == "yyzj" || roleCode == "zjl" || roleCode == "yyzy" {
			dataType = "all"
			break
		} else if roleCode == "cd" {
			dataType = "center"
			break
		} else {
			dataType = "self"
		}
	}

	cid := r.FormValue("cid-eq")
	employeeId := r.FormValue("employee_id-eq")
	year := r.FormValue("year-eq")
	month := r.FormValue("month-eq")
	week := r.FormValue("week-eq")
	startTime := r.FormValue("start_time-eq")

	st := ""
	et := ""
	flag := true

	if startTime != "" {
		st = startTime + " 00:00:00"
		et = startTime + " 23:59:59"
	} else {
		if week != "" && month != "" && year != "" {
			st, et, flag = lessgo.FindRangeTimeDim("", "", year+month+week)
		} else if month != "" && year != "" {
			st, et, flag = lessgo.FindRangeTimeDim("", year+month, "")
		} else if year != "" {
			st, et, flag = lessgo.FindRangeTimeDim(year, "", "")
		}
	}

	params := []interface{}{}

	sql := ""
	countSql := ""

	if dataType == "all" {

		sql += "select c.name,c.cid,e.user_id,e.really_name,phone_count.num a,rank.rowNo b,phone_count.localphone from (select count(*) num,localphone,cid from audio where remotephone!='' and remotephone is not null "

		if cid != "" {
			sql += " and cid=? "
			params = append(params, cid)
		}

		if flag {
			if st != "" && et != "" {
				sql += " and start_time >= ? and start_time<= ?"
				params = append(params, st)
				params = append(params, et)
			}
		} else { //找不到相应的时间区间
			sql += " and start_time >= ? and start_time<= ?"
			params = append(params, "2000-01-01 00:00:00")
			params = append(params, "2000-01-01 00:00:01")
		}

		sql += " group by  localphone,cid) phone_count left join center c on c.cid=phone_count.cid left join employee e on e.phone_in_center=phone_count.localphone and e.center_id=phone_count.cid left join (select a.*,(@rowNum:=@rowNum+1) as rowNo from (select count(*) num,localphone,cid from audio where remotephone!='' and remotephone is not null "

		if flag {
			if st != "" && et != "" {
				sql += " and start_time >= ? and start_time<= ?"
				params = append(params, st)
				params = append(params, et)
			}
		} else { //找不到相应的时间区间
			sql += " and start_time >= ? and start_time<= ?"
			params = append(params, "2000-01-01 00:00:00")
			params = append(params, "2000-01-01 00:00:01")
		}

		sql += " group by  localphone,cid order by num desc) a,(Select (@rowNum :=0) ) b)rank on rank.localphone=phone_count.localphone and rank.cid=phone_count.cid"

		if employeeId != "" {
			sql += " where e.user_id = ? "
			params = append(params, employeeId)
		}

		sql += " order by rank.rowNo "

	} else if dataType == "center" {

		sql += "select c.name,c.cid,e.user_id,e.really_name,phone_count.num a,rank.rowNo b,phone_count.localphone from (select count(*) num,localphone,cid from audio  where cid=? and remotephone!='' and remotephone is not null "

		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
		params = append(params, _employee.CenterId)

		if flag {
			if st != "" && et != "" {
				sql += " and start_time >= ? and start_time<= ?"
				params = append(params, st)
				params = append(params, et)
			}
		} else { //找不到相应的时间区间
			sql += " and start_time >= ? and start_time<= ?"
			params = append(params, "2000-01-01 00:00:00")
			params = append(params, "2000-01-01 00:00:01")
		}

		sql += " group by  localphone,cid) phone_count left join center c on c.cid=phone_count.cid left join employee e on e.phone_in_center=phone_count.localphone and e.center_id=phone_count.cid  left join (select a.*,(@rowNum:=@rowNum+1) as rowNo from (select count(*) num,localphone,cid from audio where remotephone!='' and remotephone is not null "

		if flag {
			if st != "" && et != "" {
				sql += " and start_time >= ? and start_time<= ?"
				params = append(params, st)
				params = append(params, et)
			}
		} else { //找不到相应的时间区间
			sql += " and start_time >= ? and start_time<= ?"
			params = append(params, "2000-01-01 00:00:00")
			params = append(params, "2000-01-01 00:00:01")
		}

		sql += " group by  localphone,cid order by num desc) a,(Select (@rowNum :=0) ) b)rank on rank.localphone=phone_count.localphone and rank.cid=phone_count.cid "

		if employeeId != "" {
			sql += " where e.user_id = ? "
			params = append(params, employeeId)
		}

		sql += " order by rank.rowNo "

	} else if dataType == "self" {

		sql += "select c.name,c.cid,e.user_id,e.really_name,phone_count.num a,rank.rowNo b,phone_count.localphone from (select count(*) num,localphone,cid from audio where remotephone!='' and remotephone is not null "

		if flag {
			if st != "" && et != "" {
				sql += " and start_time >= ? and start_time<= ?"
				params = append(params, st)
				params = append(params, et)
			}
		} else { //找不到相应的时间区间
			sql += " and start_time >= ? and start_time<= ?"
			params = append(params, "2000-01-01 00:00:00")
			params = append(params, "2000-01-01 00:00:01")
		}

		sql += " group by  localphone,cid) phone_count left join center c on c.cid=phone_count.cid left join employee e on e.phone_in_center=phone_count.localphone and e.center_id=phone_count.cid left join (select a.*,(@rowNum:=@rowNum+1) as rowNo from (select count(*) num,localphone,cid from audio where remotephone!='' and remotephone is not null "

		if flag {
			if st != "" && et != "" {
				sql += " and start_time >= ? and start_time<= ?"
				params = append(params, st)
				params = append(params, et)
			}
		} else { //找不到相应的时间区间
			sql += " and start_time >= ? and start_time<= ?"
			params = append(params, "2000-01-01 00:00:00")
			params = append(params, "2000-01-01 00:00:01")
		}

		sql += " group by  localphone,cid order by num desc) a,(Select (@rowNum :=0) ) b)rank on rank.localphone=phone_count.localphone and rank.cid=phone_count.cid "

		sql += " where e.user_id=? "

		params = append(params, employee.UserId)

		sql += " order by rank.rowNo "
	}

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	lessgo.Log.Debug(sql + " limit ?,?")

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql+" limit ?,?", params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)
		r := rand.New(rand.NewSource(time.Now().UnixNano()))
		model.Id = fmt.Sprint(r.Intn(1000))
		model.Props = []*lessgo.Prop{}

		fillObjects := []interface{}{}

		for i := 0; i < 7; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Esempio n. 7
0
func WyClassListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	dataType := ""

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "admin" || roleCode == "yyzj" || roleCode == "zjl" || roleCode == "yyzy" || roleCode == "tmk" {
			dataType = "all"
			break
		} else {
			dataType = "center"
			break
		}
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	centerId := r.FormValue("cid-eq")

	params := []interface{}{}

	sql := "select  c.class_id,c.name,ce.name as cename,cou.name as courseName,c.end_time,c.deadline,c.max_child_num,tea.really_name as teacherName,ass.really_name as assName,c.center_id from wyclass c left join center ce on ce.cid=c.center_id left join employee tea on tea.user_id=c.teacher_id left join employee ass on ass.user_id=c.assistant_id left join course cou on c.course_id=cou.cid where 1=1 and (c.start_time is null or c.start_time = '') "

	if dataType == "center" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
		params = append(params, _employee.CenterId)
		sql += " and ce.cid=? "
	}

	if centerId != "" && dataType == "all" {
		params = append(params, centerId)
		sql += " and c.center_id=? "
	}

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by c.class_id desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 9; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Esempio n. 8
0
func EmployeeSignInListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	dataType := ""

	roleIds := strings.Split(employee.RoleId, ",")

	for _, roleId := range roleIds {
		if roleId == "1" || roleId == "3" || roleId == "6" || roleId == "10" {
			dataType = "all"
			break
		} else if roleId == "2" {
			dataType = "center"
			break
		} else {
			dataType = "self"
		}
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	centerId := r.FormValue("cid-eq")
	st := r.FormValue("st-ge")
	et := r.FormValue("et-le")

	params := []interface{}{}

	sql := "select  esi.id,e.really_name,esi.sign_time from employee_sign_in esi left join employee e on esi.employee_id=e.user_id where 1=1 "

	if dataType == "center" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
		params = append(params, _employee.CenterId)
		sql += " and e.center_id=? "
	}

	if centerId != "" && dataType == "all" {
		params = append(params, centerId)
		sql += " and e.center_id=? "
	}

	if dataType == "self" {
		params = append(params, employee.UserId)
		sql += " and esi.employee_id=? "
	}

	if st != "" {
		params = append(params, st)
		sql += " and esi.sign_time >= ? "
	}

	if et != "" {
		params = append(params, et)
		sql += " and esi.sign_time <= ? "
	}

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by esi.id desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 2; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
func ValidForCallCenterListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	status := r.FormValue("status-eq")

	params := []interface{}{}

	sql := "select c.id,e.really_name,c.mother,c.mother_phone,c.father,c.father_phone,c.home_phone,c.child,c.contact_status from consumer c left join employee e on e.user_id = c.employee_id where 1=1 and c.center_id=? and c.id not in (select consumer_id from tmk_consumer) "

	userId, _ := strconv.Atoi(employee.UserId)
	_employee, err := FindEmployeeById(userId)
	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	params = append(params, _employee.CenterId)

	if status != "" {
		sql += " and c.contact_status=? "
		params = append(params, status)
	} else {
		sql += " and (c.contact_status=1 or c.contact_status=2) "
	}

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by c.id desc  limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 8; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")
}
Esempio n. 10
0
//查找分页数据
func FindTraditionPage(entity Entity, currPageNo, pageSize int, searchParam []Search, colmuns []Column) (*commonlib.TraditionPage, error) {

	countSql, dataSql := bulidSelectSql(entity, colmuns)

	countSql, dataSql, params := bulidWhereSql(entity, countSql, dataSql, searchParam)

	Log.Debug(countSql)

	db := DBPool{}.getMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		Log.Error(err.Error())
		return nil, err
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			Log.Error(err.Error())
			return nil, err
		}
	}

	dataSql += " order by " + entity.Pk + " desc "
	dataSql += " limit ?,?"

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	params = append(params, (currPageNo-1)*pageSize, pageSize)
	Log.Debug(dataSql)

	rows, err = db.Query(dataSql, params...)

	if err != nil {
		Log.Error(err.Error())
		return nil, err
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(Model)
		model.Entity = entity
		model.Id = 0
		model.Props = []*Prop{}

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for _, column := range colmuns {
			prop := new(Prop)
			prop.Name = column.Field
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			Log.Error(err.Error())
			return nil, err
		}

		objects = append(objects, model)
	}

	return commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects), nil
}
Esempio n. 11
0
func TmkAllConsumerListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	dataType := ""

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "tmk" || roleCode == "yyzj" {
			dataType = "all"
			break
		} else {
			dataType = "center"
			break
		}
	}

	centerId1 := r.FormValue("centerId-eq")
	status := r.FormValue("status-eq")
	//	lastContractStartTime := r.FormValue("lastContractStartTime-ge")
	//	lastContractEndTime := r.FormValue("lastContractEndTime-le")
	kw := r.FormValue("kw-like")
	partTimeName := r.FormValue("partTimeName-eq")
	level := r.FormValue("level-eq")
	comeFromId := r.FormValue("comeFromId-eq")

	//番茄田逻辑补丁,番茄田添加的用户都属于福州台江中心
	if centerId1 == "1" {
		centerId1 = "7"
	}

	params := []interface{}{}
	paramsForCount := []interface{}{}

	sql := `select cons.id,ce.name as centerName,e.really_name,cons.level,cont.name,cont.phone,cons.child,cons.birthday,cons.year,cons.contact_status,cons.parent_id,d.remark,cf.name comeFromName,cons.parttime_name
			from
			(select a.consumer_id,min(a.id) contacts_id from contacts a left join consumer_new b on a.consumer_id=b.id
			where (a.name like ? or b.child like ? or a.phone like ? or b.home_phone like ?) and b.is_own_by_tmk=2 and b.pay_time is null and b.contact_status!=5 `

	params = append(params, "%"+kw+"%")
	params = append(params, "%"+kw+"%")
	params = append(params, "%"+kw+"%")
	params = append(params, "%"+kw+"%")

	if dataType == "center" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		//番茄田逻辑补丁,番茄田添加的用户都属于福州台江中心
		if _employee.CenterId == "1" {
			_employee.CenterId = "7"
		}

		params = append(params, _employee.CenterId)
		sql += " and b.center_id=? "
	}

	if status != "" {
		params = append(params, status)
		sql += " and b.contact_status=? "
	}

	if centerId1 != "" && dataType == "all" {
		params = append(params, centerId1)
		sql += " and b.center_id=? "
	}

	if partTimeName != "" {
		params = append(params, partTimeName)
		sql += " and b.parttime_name=? "
	}

	if level != "" {
		params = append(params, level)
		sql += " and b.level=? "
	}

	if comeFromId != "" {
		params = append(params, comeFromId)
		sql += " and b.come_from_id=? "
	}

	sql += `group by a.consumer_id order by b.id desc  limit ?,?) c
	left join consumer_new cons on cons.id=c.consumer_id
	left join contacts cont on cont.id=c.contacts_id
	left join center ce on ce.cid=cons.center_id
	left join come_from cf on cf.id=cons.come_from_id
	left join (select consumer_id,GROUP_CONCAT(concat(DATE_FORMAT(create_time,'%Y-%m-%d %H:%i'),' ',note) ORDER BY id DESC SEPARATOR '<br/>') remark from consumer_contact_log group by consumer_id) d on d.consumer_id=cons.id
	left join employee e on e.user_id=cons.last_tmk_id	`

	countSql := `select count(1) from(select a.consumer_id,min(a.id) contacts_id from contacts a left join consumer_new b on a.consumer_id=b.id
	where (a.name like ? or b.child like ? or a.phone like ? or b.home_phone like ?) and b.is_own_by_tmk=2 and b.pay_time is null and b.contact_status!=5 `

	paramsForCount = append(paramsForCount, "%"+kw+"%")
	paramsForCount = append(paramsForCount, "%"+kw+"%")
	paramsForCount = append(paramsForCount, "%"+kw+"%")
	paramsForCount = append(paramsForCount, "%"+kw+"%")

	if dataType == "center" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		//番茄田逻辑补丁,番茄田添加的用户都属于福州台江中心
		if _employee.CenterId == "1" {
			_employee.CenterId = "7"
		}

		paramsForCount = append(paramsForCount, _employee.CenterId)
		countSql += " and b.center_id=? "
	}

	if status != "" {
		paramsForCount = append(paramsForCount, status)
		countSql += " and b.contact_status=? "
	}

	if centerId1 != "" && dataType == "all" {
		paramsForCount = append(paramsForCount, centerId1)
		countSql += " and b.center_id=? "
	}

	if partTimeName != "" {
		paramsForCount = append(paramsForCount, partTimeName)
		countSql += " and b.parttime_name=? "
	}

	if level != "" {
		paramsForCount = append(paramsForCount, level)
		countSql += " and b.level=? "
	}

	if comeFromId != "" {
		paramsForCount = append(paramsForCount, comeFromId)
		countSql += " and b.come_from_id=? "
	}

	countSql += " group by a.consumer_id) aa "

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, paramsForCount...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 13; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Esempio n. 12
0
/*
select c.aid,ce.name as centerName,e.really_name,c.start_time,c.seconds,c.inout,c.localphone,c.filename,c.is_upload_finish,c.contractName,c.note from(
select  a.aid,a.start_time,a.seconds,a.inout,a.localphone,a.filename,a.is_upload_finish,contract_phone.name contractName,a.note,a.cid from audio a
inner join (select phone,name from contacts where consumer_id=1) contract_phone on
contract_phone.phone=a.remotephone
union
select  a.aid,a.start_time,a.seconds,a.inout,a.localphone,a.filename,a.is_upload_finish,'家庭电话' contractName,a.note,a.cid from audio a
inner join (select home_phone,child from consumer_new where id=1 and home_phone is not null and home_phone !='') b on
b.home_phone=a.remotephone
)c
left join employee e on e.center_id=c.cid and e.phone_in_center=c.localphone
left join center ce on ce.cid=e.center_id
*/
func ConsumerContactRecordListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	id := r.FormValue("consumerId")

	params := []interface{}{}

	sql := " select c.aid,ce.name as centerName,e.really_name,c.start_time,c.seconds,c.inout,c.localphone,c.filename,c.is_upload_finish,c.contractName,c.note,c.cid from( "
	sql += " select  a.aid,a.start_time,a.seconds,a.inout,a.localphone,a.filename,a.is_upload_finish,contract_phone.name contractName,a.note,a.cid from audio a "
	sql += " inner join (select phone,name from contacts where consumer_id=?) contract_phone on "
	sql += " contract_phone.phone=a.remotephone "
	sql += " union "
	sql += " select  a.aid,a.start_time,a.seconds,a.inout,a.localphone,a.filename,a.is_upload_finish,'家庭电话' contractName,a.note,a.cid from audio a "
	sql += " inner join (select home_phone,child from consumer_new where id=? and home_phone is not null and home_phone !='') b on "
	sql += " b.home_phone=a.remotephone "
	sql += " )c "
	sql += " left join employee e on e.center_id=c.cid and e.phone_in_center=c.localphone "
	sql += " left join center ce on ce.cid=e.center_id "

	params = append(params, id)
	params = append(params, id)

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by c.start_time desc ,c.aid desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 11; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Error(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Esempio n. 13
0
/*
select cons.*,cont.name,cont.phone
from
tmk_consumer tc
left join (select c.consumer_id,min(c.id) contacts_id from contacts c group by c.consumer_id) a on a.consumer_id=tc.consumer_id
left join contacts cont on cont.id=a.contacts_id
left join consumer_new cons on cons.id=a.consumer_id
*/
func TmkConsumerSelfListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	centerId1 := r.FormValue("centerId-eq")
	status := r.FormValue("status-eq")
	lastContractStartTime := r.FormValue("lastContractStartTime-ge")
	lastContractEndTime := r.FormValue("lastContractEndTime-le")
	kw := r.FormValue("kw-like")
	payStatus := r.FormValue("payStatus-eq")
	timeType := r.FormValue("timeType-eq")
	partTimeName := r.FormValue("partTimeName-eq")
	level := r.FormValue("level-eq")
	comeFromId := r.FormValue("comeFromId-eq")

	params := []interface{}{}

	sql := " select cons.id,ce.name as centerName,cont.name,cons.level,cont.phone,cons.child,cons.birthday,cons.year,cons.contact_status,cons.parent_id,b.remark,cons.center_id,cons.pay_status,cons.pay_time,cf.name comeFromName,cons.parttime_name "
	sql += " from tmk_consumer tc"
	sql += " inner join (select c.consumer_id,min(c.id) contacts_id from contacts c  "
	if kw != "" {
		sql += "left join consumer_new b on b.id=c.consumer_id where c.phone like ? or c.name like ? or b.child like ? or b.remark like ? or b.home_phone like ? "
		params = append(params, "%"+kw+"%")
		params = append(params, "%"+kw+"%")
		params = append(params, "%"+kw+"%")
		params = append(params, "%"+kw+"%")
		params = append(params, "%"+kw+"%")
	}
	sql += " group by c.consumer_id)a on a.consumer_id=tc.consumer_id "
	sql += " left join consumer_new cons on cons.id=a.consumer_id "
	sql += " left join contacts cont on cont.id=a.contacts_id "
	sql += " left join center ce on ce.cid=cons.center_id "
	sql += " left join come_from cf on cf.id=cons.come_from_id "
	sql += " left join (select consumer_id,GROUP_CONCAT(concat(DATE_FORMAT(create_time,'%Y-%m-%d %H:%i'),' ',note)  ORDER BY id DESC SEPARATOR '<br/>') remark from consumer_contact_log group by consumer_id) b on b.consumer_id=cons.id "
	sql += " where tc.tmk_id= " + employee.UserId

	if status != "" {
		params = append(params, status)
		sql += " and cons.contact_status=? "
	}

	if lastContractStartTime != "" && timeType == "1" {
		params = append(params, lastContractStartTime)
		sql += " and cons.sign_in_time>=? "
	}

	if lastContractStartTime != "" && timeType == "2" {
		params = append(params, lastContractStartTime)
		sql += " and cons.pay_time>=? "
	}

	if lastContractEndTime != "" && timeType == "1" {
		params = append(params, lastContractEndTime)
		sql += " and cons.sign_in_time<=? "
	}

	if lastContractEndTime != "" && timeType == "2" {
		params = append(params, lastContractEndTime)
		sql += " and cons.pay_time<=? "
	}

	if partTimeName != "" {
		params = append(params, partTimeName)
		sql += " and cons.parttime_name=? "
	}

	if payStatus == "1" {
		sql += " and cons.pay_time is not null and cons.pay_time != '' and cons.pay_status=1 "
	} else if payStatus == "2" {
		sql += " and cons.pay_time is not null and cons.pay_time != '' and cons.pay_status=2 "
	} else if payStatus == "3" {
		sql += " and (cons.pay_time is null or cons.pay_time ='')"
	}

	if centerId1 != "" {
		params = append(params, centerId1)
		sql += " and cons.center_id=? "
	}

	if level != "" {
		params = append(params, level)
		sql += " and cons.level=? "
	}

	if comeFromId != "" {
		params = append(params, comeFromId)
		sql += " and cons.come_from_id=? "
	}

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by tc.tmk_create_time desc,cons.contact_status ,cons.last_contact_time desc limit ?,? "

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 15; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
/*
select ce.cid,ce.name,a.num as '全部名单', b.num as '未联系', c.num as '待确认', d.num as '已废弃', e.num as '已邀约',f.num as '已签到'  from center ce
left join
(select count(1) num,center_id from consumer_new group by center_id )a on a.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=1 group by center_id )b on a.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=2 group by center_id )c on b.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=3 group by center_id )d on c.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=4 group by center_id )e on d.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=5 group by center_id )f on e.center_id=ce.cid
*/
func CallCenterStatisticsAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	dataType := ""

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "admin" || roleCode == "yyzj" || roleCode == "zjl" || roleCode == "yyzy" {
			dataType = "all"
			break
		} else {
			dataType = "center"
			break
		}
	}

	startTime := r.FormValue("startTime-ge")
	endTime := r.FormValue("endTime-le")

	params := []interface{}{}

	sql := " select ce.cid,ce.name,a.num as '全部名单', b.num as '未联系', c.num as '拨打电话数', d.num as '邀约数', e.num as '签到数',f.num as '定金',g.num as '全额',1,2,3  from center ce "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new group by center_id )a on a.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new where contact_status=1 group by center_id )b on b.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,cid from audio where start_time >=? and start_time<=? group by cid )c on c.cid=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,ch.center_id from schedule_detail_child sdc left join child ch on sdc.child_id=ch.cid where sdc.is_free=1 and sdc.create_time>=? and sdc.create_time <=? group by ch.center_id)d on d.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,ch.center_id from sign_in si left join child ch on si.child_id=ch.cid where si.type=1 and  si.is_free=1 and si.sign_time>=? and si.sign_time<=? group by ch.center_id )e on e.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new where pay_status=1 and pay_time>=? and pay_time<=? group by center_id )f on f.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new where pay_status=2 and pay_time>=? and pay_time<=? group by center_id )g on g.center_id=ce.cid where ce.cid!=9 " //屏蔽总部数据

	defaultStartTime := "2000-01-01 00:0:000"
	defaultEndTime := "2999-12-31 00:00:00"

	if startTime != "" {
		defaultStartTime = startTime
	}

	if endTime != "" {
		defaultEndTime = endTime
	}
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)

	defaultStartTime = strings.Replace(defaultStartTime, "-", "", -1)

	defaultEndTime = strings.Replace(defaultEndTime, "-", "", -1)

	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)

	userId, _ := strconv.Atoi(employee.UserId)
	_employee, err := FindEmployeeById(userId)

	if dataType == "center" {
		sql += " and ce.cid=? "

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		params = append(params, _employee.CenterId)
	}

	countSql := "select count(1) from center where cid!=9 "

	if dataType == "center" {
		countSql += " and cid=" + _employee.CenterId
	}

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by ce.cid limit ?,?"

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	lessgo.Log.Debug(sql)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 11; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")
}
func CenterCallCenterDetailAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	status := r.FormValue("status-eq")
	name := r.FormValue("name-eq")
	centerId := r.FormValue("id")

	dataType := ""

	roleIds := strings.Split(employee.RoleId, ",")

	for _, roleId := range roleIds {
		if roleId == "1" || roleId == "3" || roleId == "6" || roleId == "10" {
			dataType = "all"
			break
		} else if roleId == "2" {
			dataType = "center"
			break
		} else {
			dataType = "self"
		}
	}

	params := []interface{}{}

	sql := ""
	countSql := ""

	sql += "select tc.id,e.really_name,c.mother,c.mother_phone,c.father,c.father_phone,c.home_phone,c.child,c.contact_status,c.id as 'cid',c.parent_id from tmk_consumer tc left join consumer c on tc.consumer_id=c.id left join employee e on e.user_id = tc.employee_id where tc.center_id=? "

	if dataType == "all" {
		params = append(params, centerId)

		if status != "" {
			if status == "no employee" {
				sql += " and tc.employee_id is null or tc.employee_id=0 "
			} else {
				sql += " and c.contact_status=? "
				params = append(params, status)
			}
		}

	} else if dataType == "center" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
		params = append(params, _employee.CenterId)

		if status != "" {
			if status == "no employee" {
				sql += " and tc.employee_id is null or tc.employee_id=0 "
			} else {
				sql += " and c.contact_status=? "
				params = append(params, status)
			}
		}

	} else {

		params = append(params, centerId)

		sql += " and tc.employee_id=? "
		params = append(params, employee.UserId)

		if status != "" && status != "no employee" {
			sql += " and c.contact_status=? "
			params = append(params, status)
		}
	}

	if name != "" {
		sql += " and (c.mother like ? or c.mother_phone like ? or c.father like ? or c.father_phone like ? or c.home_phone like ? or c.child like ? )"
		params = append(params, "%"+name+"%")
		params = append(params, "%"+name+"%")
		params = append(params, "%"+name+"%")
		params = append(params, "%"+name+"%")
		params = append(params, "%"+name+"%")
		params = append(params, "%"+name+"%")
	}

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by tc.cd_create_time desc  limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 10; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Esempio n. 16
0
func ChildSignInLogListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	childId := r.FormValue("childId")
	startTime := r.FormValue("startTime-ge")
	endTime := r.FormValue("endTime-le")

	params := []interface{}{}

	sql := `
	select si.sid,si.sign_time,contr.contract_no,si.card_id,cour.name,contr.apply_time,cour1.name courseName1
	 		from sign_in si
	 				left join class_schedule_detail csd on csd.id=si.schedule_detail_id
	 				left join contract contr on contr.id=si.contract_id
	 				left join course cour on cour.cid=contr.course_id
	 				left join course cour1 on cour1.cid=csd.course_id
	 		where si.child_id=? and si.is_free=2 `

	params = append(params, childId)

	if startTime != "" {
		sql += " and si.sign_time>=? "
		params = append(params, startTime)
	}

	if endTime != "" {
		sql += " and si.sign_time<=? "
		params = append(params, endTime)
	}

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by si.sign_time desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 6; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
/*
select a.aid,cons.child,b.remark,cont.name contName,a.remotephone,ce.name centerName,a.start_time,a.seconds,a.inout,a.is_upload_finish,cons.id,a.filename,a.cid,e1.really_name
from
(
	select au.* from audio au
	left join employee e on e.phone_in_center=au.localphone and e.center_id=au.cid
	where e.user_id=37 and au.remotephone != '' and  au.remotephone is not null order by au.aid desc,au.start_time desc  limit 0,20
) a
left join contacts cont on a.remotephone=cont.phone
left join consumer_new cons on cont.consumer_id=cons.id
left join employee e2 on e2.phone_in_center=a.localphone and e2.center_id=a.cid
left join center ce on ce.cid=cons.center_id
left join (select consumer_id,GROUP_CONCAT(concat(DATE_FORMAT(create_time,'%Y-%m-%d %H:%i'),' ',note) ORDER BY id  SEPARATOR '<br/>') remark from consumer_contact_log group by consumer_id) b on b.consumer_id=cons.id
left join  employee e1 on e1.user_id=cons.current_tmk_id
*/
func ConsultantPhoneDetailListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	eid := r.FormValue("eid")
	year := r.FormValue("year-eq")
	month := r.FormValue("month-eq")
	week := r.FormValue("week-eq")
	startTime := r.FormValue("start_time-eq")

	st := ""
	et := ""
	flag := true

	if startTime != "" {
		st = startTime + " 00:00:00"
		et = startTime + " 23:59:59"
	} else {
		if week != "" && month != "" && year != "" {
			st, et, flag = lessgo.FindRangeTimeDim("", "", year+month+week)
		} else if month != "" && year != "" {
			st, et, flag = lessgo.FindRangeTimeDim("", year+month, "")
		} else if year != "" {
			st, et, flag = lessgo.FindRangeTimeDim(year, "", "")
		}
	}

	params := []interface{}{}

	sql := `select a.aid,cons.child,b.remark,cont.name contName,a.remotephone,ce.name centerName,a.start_time,a.seconds,a.inout,a.is_upload_finish,cons.id,a.filename,a.cid,e1.really_name
			from
			(
				select au.* from audio au
				left join employee e on e.phone_in_center=au.localphone and e.center_id=au.cid
				where e.user_id=? and au.remotephone != '' and  au.remotephone is not null %v order by au.aid desc,au.start_time desc  limit ?,?
			) a
			left join contacts cont on a.remotephone=cont.phone
			left join consumer_new cons on cont.consumer_id=cons.id
			left join employee e2 on e2.phone_in_center=a.localphone and e2.center_id=a.cid
			left join center ce on ce.cid=cons.center_id
			%v
			left join  employee e1 on e1.user_id=cons.current_tmk_id`

	params = append(params, eid)

	whereSql := ""

	if flag {
		if st != "" && et != "" {
			whereSql += " and au.start_time >= ? and au.start_time<= ?"
			params = append(params, st)
			params = append(params, et)
		}
	} else { //找不到相应的时间区间
		whereSql += " and au.start_time >= ? and au.start_time<= ?"
		params = append(params, "2000-01-01 00:00:00")
		params = append(params, "2000-01-01 00:00:01")
	}

	countSql := `select count(1) from (
			select au.* from audio au
			left join employee e on e.phone_in_center=au.localphone and e.center_id=au.cid
			where e.user_id=? and au.remotephone != '' and  au.remotephone is not null %v) num`

	lessgo.Log.Debug(fmt.Sprintf(countSql, whereSql))

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(fmt.Sprintf(countSql, whereSql), params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	lessgo.Log.Debug(fmt.Sprintf(sql, whereSql, "left join (select consumer_id,GROUP_CONCAT(concat(DATE_FORMAT(create_time,'%Y-%m-%d %H:%i'),' ',note) ORDER BY id  SEPARATOR '<br/>') remark from consumer_contact_log group by consumer_id) b on b.consumer_id=cons.id"))

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(fmt.Sprintf(sql, whereSql, "left join (select consumer_id,GROUP_CONCAT(concat(DATE_FORMAT(create_time,'%Y-%m-%d %H:%i'),' ',note) ORDER BY id  SEPARATOR '<br/>') remark from consumer_contact_log group by consumer_id) b on b.consumer_id=cons.id"), params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 13; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Esempio n. 18
0
//顾问分页数据服务
func VideoListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	dataType := ""

	roleIds := strings.Split(employee.RoleId, ",")

	for _, roleId := range roleIds {
		if roleId == "1" || roleId == "3" || roleId == "6" || roleId == "10" {
			dataType = "all"
			break
		} else if roleId == "2" {
			dataType = "center"
			break
		} else {
			dataType = "self"
		}
	}

	//fmt.Println("dataType:" ,dataType, ",roleIds:", roleIds)
	//r.FormValue("cid-eq")
	//fmt.Println(r.Form)

	sql := ""

	params := []interface{}{}

	if dataType == "all" {
		sql += `select v.vid,v.cid,ce.name as centername,r.name rname,c.course_id,co.name,c.teacher_id,e.really_name,v.start_time,v.end_time from
				video v left join class_schedule_detail c on v.schedule_detail_id=c.id left join room r on r.rid=v.rid left join employee e
					on c.teacher_id=e.user_id left join course co on c.course_id=co.cid left join center ce on v.cid=ce.cid
						where data_rel_status=2`
	} else if dataType == "center" {
		sql += `select v.vid,v.cid,ce.name as centername,r.name rname,c.course_id,co.name,c.teacher_id,e.really_name,v.start_time,v.end_time from
				video v left join class_schedule_detail c on v.schedule_detail_id=c.id left join room r on r.rid=v.rid left join employee e
					on c.teacher_id=e.user_id left join course co on c.course_id=co.cid left join center ce on v.cid=ce.cid
						where v.cid=? and data_rel_status=2`
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		params = append(params, _employee.CenterId)

	} else if dataType == "self" {
		sql += `select v.vid,v.cid,ce.name as centername,r.name rname,c.course_id,co.name,c.teacher_id,e.really_name,v.start_time,v.end_time from
			video v left join class_schedule_detail c on v.schedule_detail_id=c.id left join room r on r.rid=v.rid left join employee e
				on c.teacher_id=e.user_id left join course co on c.course_id=co.cid left join center ce on v.cid=ce.cid
					where c.teacher_id=? and data_rel_status=2`

		params = append(params, employee.UserId)
	}

	center_id := r.FormValue("cid-eq")
	if center_id != "" {
		sql += " and v.cid=?"
		params = append(params, center_id)
		lessgo.Log.Debug(sql)
		lessgo.Log.Debug(params)
	}

	course_id := r.FormValue("courseId-eq")
	if course_id != "" {
		sql += " and c.course_id=?"
		params = append(params, course_id)
		lessgo.Log.Debug(params...)
	}

	name := r.FormValue("name-like")
	if name != "" {
		sql += " and e.really_name like ?"
		params = append(params, "%"+name+"%")
	}

	countSql := "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	lessgo.Log.Debug(sql + " limit ?,?")
	lessgo.Log.Debug(params...)
	lessgo.Log.Debug(params[0], ":", params[1])
	rows, err = db.Query(sql+" limit ?,?", params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}
	colums, _ := rows.Columns()
	column_len := len(colums) - 1
	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < column_len; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Esempio n. 19
0
func ContactsListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	consumerId := r.FormValue("consumerId")

	params := []interface{}{}

	sql := " select id,name,phone,is_default from contacts where consumer_id=? "

	params = append(params, consumerId)

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, consumerId)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by is_default,id desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 3; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")
}