package service import ( "encoding/json" "vamicro/scene-service/models" "vamicro/scene-service/vo" ) type AreaCamPolygonService struct { } func (sv *AreaCamPolygonService) Save(reqBody vo.AreaCamPVo) bool { var acp models.AreaCameraPolygon rows, _ := acp.SelectById(reqBody.Id) pgnB, _ := json.Marshal(reqBody.CamPolygons) if rows >0 { //已经存在,则更新 a := models.AreaCameraPolygon{ Id: reqBody.Id, Name: reqBody.Name, Desc: reqBody.Desc, CameraPgn: string(pgnB), } return a.Update() } else { a := models.AreaCameraPolygon{ Id: reqBody.Id, Name: reqBody.Name, Desc: reqBody.Desc, CameraPgn: string(pgnB), } return a.Insert() } } func (sv *AreaCamPolygonService) Delete(ids []string) bool { var acp models.AreaCameraPolygon if acp.Delete(ids) { return true } return false } func (sv *AreaCamPolygonService) FindAll() (list []vo.AreaCamPVo) { var acp models.AreaCameraPolygon all, _ := acp.FindAll() if all != nil { for _, entity :=range all { var cPgnList []vo.CamP err := json.Unmarshal([]byte(entity.CameraPgn), &cPgnList) v := vo.AreaCamPVo{ Id: entity.Id, Name: entity.Name, Desc: entity.Desc, } if err ==nil { v.CamPolygons = cPgnList } list = append(list, v) } } return list }