You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.0 KiB

package SchoolController
import (
"dsBigData/Business/Area/AreaService"
"dsBigData/Business/Dict/DictService"
"dsBigData/Business/School/SchoolModel"
"dsBigData/Business/School/SchoolService"
"dsBigData/Model"
"dsBigData/Utils/CommonUtil"
"encoding/json"
"github.com/gin-gonic/gin"
"net/http"
)
//模块的路由配置
func Routers(r *gin.RouterGroup) {
rr := r.Group("/school")
rr.GET("/GetSchoolCountByCity", GetSchoolCountByCity)
rr.GET("/GetEduAssistCountByCity", GetEduAssistCountByCity)
return
}
/**
功能:根据市获取各区的教辅单位个数
*/
func GetEduAssistCountByCity(c *gin.Context) {
areaType := c.Query("areaType")
cityCode := c.Query("cityCode")
//获取区信息
areaInfo, err := AreaService.PageDistrictByCityCode(cityCode, areaType)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: err.Error(),
})
return
}
//生成区信息的数组
areaCodeArr := make([]string, 0)
for i := range areaInfo {
areaCodeArr = append(areaCodeArr, areaInfo[i].AreaCode)
}
resArr, err := SchoolService.AggsDistrictStatEduAssist(areaCodeArr)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: err.Error(),
})
return
}
resArrByte, _ := json.Marshal(resArr)
resList := CommonUtil.ConvertJsonStringToMapArray(string(resArrByte))
resMap := make(map[string]int)
for i := 0; i < len(resList); i++ {
areaCode := resList[i]["area_code"].(string)
count := CommonUtil.ConvertStringToInt(resList[i]["count"].(string))
resMap[areaCode] = count
}
eduAssistCountArr := make([]SchoolModel.EduAssistCount, 0)
for i := range areaInfo {
var eduAssistCount SchoolModel.EduAssistCount
areaCode := areaInfo[i].AreaCode
areaName := areaInfo[i].AreaName
eduAssistCount.AreaCode = areaCode
eduAssistCount.AreaName = areaName
if _, ok := resMap[areaCode]; ok {
eduAssistCount.Count = resMap[areaCode]
}
eduAssistCountArr = append(eduAssistCountArr, eduAssistCount)
}
c.JSON(http.StatusOK, Model.Res{
Success: true,
List: eduAssistCountArr,
})
}
/**
功能:根据市获取各区的学校个数
*/
func GetSchoolCountByCity(c *gin.Context) {
areaType := c.Query("areaType")
cityCode := c.Query("cityCode")
xxbxlx := c.Query("xxbxlx")
aggsXxbxlx := false
if xxbxlx == "1" {
aggsXxbxlx = true
}
//获取区信息
areaInfo, err := AreaService.PageDistrictByCityCode(cityCode, areaType)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: err.Error(),
})
return
}
//生成区信息的数组
areaCodeArr := make([]string, 0)
for i := range areaInfo {
areaCodeArr = append(areaCodeArr, areaInfo[i].AreaCode)
}
resArr, err := SchoolService.AggsDistrictStatSchoolCount(areaCodeArr)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: err.Error(),
})
return
}
resArrByte, _ := json.Marshal(resArr)
resList := CommonUtil.ConvertJsonStringToMapArray(string(resArrByte))
resMap := make(map[string]int)
for i := 0; i < len(resList); i++ {
areaCode := resList[i]["area_code"].(string)
count := CommonUtil.ConvertStringToInt(resList[i]["count"].(string))
resMap[areaCode] = count
}
//获取办学类型信息
xxbxlxInfo, err := DictService.GetDictInfo("xxbxlxm")
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: err.Error(),
})
return
}
schoolCountArr := make([]SchoolModel.SchoolCount, 0)
for i := range areaInfo {
var schoolCount SchoolModel.SchoolCount
areaCode := areaInfo[i].AreaCode
areaName := areaInfo[i].AreaName
schoolCount.AreaCode = areaCode
schoolCount.AreaName = areaName
if _, ok := resMap[areaCode]; ok {
schoolCount.Count = resMap[areaCode]
}
xxbxlxArr := make([]SchoolModel.Xxbxlx, 0)
if aggsXxbxlx {
resArr, err := SchoolService.AggsXxbxlxStatSchoolCountByDistrictCode(areaCode)
if err != nil {
c.JSON(http.StatusOK, Model.Res{
Success: false,
Message: err.Error(),
})
return
}
resArrByte, _ := json.Marshal(resArr)
resList := CommonUtil.ConvertJsonStringToMapArray(string(resArrByte))
resMap := make(map[string]int)
for i := 0; i < len(resList); i++ {
areaCode := resList[i]["xxbxlxm"].(string)
count := CommonUtil.ConvertStringToInt(resList[i]["count"].(string))
resMap[areaCode] = count
}
for j := range xxbxlxInfo {
var xxbxlx SchoolModel.Xxbxlx
dictCode := xxbxlxInfo[j].DictCode
dictValue := xxbxlxInfo[j].DictValue
xxbxlx.XxbxlxCode = dictCode
xxbxlx.XxbxlxName = dictValue
if _, ok := resMap[dictCode]; ok {
xxbxlx.Count = resMap[dictCode]
}
xxbxlxArr = append(xxbxlxArr, xxbxlx)
}
}
schoolCount.Xxbxlx = xxbxlxArr
schoolCountArr = append(schoolCountArr, schoolCount)
}
schoolCountArrByte, _ := json.Marshal(schoolCountArr)
schoolCountArrStr := string(schoolCountArrByte)
if !aggsXxbxlx {
schoolCountArrStr = CommonUtil.RemoveArrKey(schoolCountArrStr, "xxbxlx")
}
c.JSON(http.StatusOK, Model.Res{
Success: true,
List: CommonUtil.ConvertJsonStringToMapArray(schoolCountArrStr),
})
}