package application import ( "finclip-app-manager/domain/entity" "finclip-app-manager/domain/service" "finclip-app-manager/infrastructure/utility" "finclip-app-manager/infrastructure/utils" "github.com/gin-gonic/gin" "gitlab.finogeeks.club/finclip-backend-v2/finclip-mgo/bson" "gitlab.finogeeks.club/finclip-backend/apm" "net/http" "sort" ) type listTypeConfigResponse struct { Total int `json:"total"` List []entity.TypeConfig `json:"list"` } /** * @api {GET} * @apiGroup Finclip App Manager * @apiSuccessExample {json} Success Status: * HTTP/1.1 200 OK * { * "data": { * "total": 1, * "list": [ * { * "typeConfigId": "619659a31bcd700001146eb1", * "namespace": "appClass", * "value": "jinrong", * "marketId": "", * "customData": { * "chinese": "金融" * }, * "sortNum": 1 * } * ] * }, * "errcode": "OK", * "error": "" * } * @apiErrorExample Error Status: * HTTP/1.1 !=200 服务端异常 */ func ListTypeConfig(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) queryFilter, sortFilter, searchFilter, _, _, err := utils.GetCommonParam(c) if err != nil { utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, nil) return } if len(sortFilter) == 0 { sortFilter = []string{"namespace"} } filter := bson.M{"namespace": "appClass"} if len(searchFilter) > 0 { filter = searchFilter } if len(queryFilter) > 0 { filter = bson.M{"$and": []bson.M{filter, queryFilter}} } svr := service.NewTypeConfigService() //total, cfgs, err := svr.GetTypeConfigList(traceCtx, pageSize, pageNo) total, cfgs, err := svr.GetAllTypeConfigList(traceCtx) if err != nil { utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, nil) return } sort.Sort(entity.TypeConfigList(cfgs)) utility.MakeLocRsp(c, http.StatusOK, utility.OK, listTypeConfigResponse{ Total: total, List: cfgs, }) } type typeConfigRequest struct { AdministratorID string `json:"administratorId"` entity.TypeConfig } /** * @api {POST} * @apiGroup Finclip App Manager * @apiParam (RequestBody) {string} administratorId * @apiParam (RequestBody) {string} namespace * @apiParam (RequestBody) {string} value * @apiParam (RequestBody) {string} customData * @apiParam (RequestBody) {string} marketId * @apiParamExample {json} Request-Example: * { * "administratorId":"1", * "namespace": "appClass", * "value": "1", * "customData": { * "chinese": "哈哈" * }, * "marketId": "1" * } * @apiSuccessExample {json} Success Status: * HTTP/1.1 200 OK * { * "errcode": "OK", * "error": "成功", * "data":{ * * } * } * @apiErrorExample Error Status: * HTTP/1.1 !=200 服务端异常 */ func AddTypeConfig(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) reqJSON := typeConfigRequest{} if err := c.ShouldBindJSON(&reqJSON); err != nil { utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, nil) return } if reqJSON.AdministratorID == "" { utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, nil) return } t := entity.TypeConfig{ TypeConfigID: bson.NewObjectId().Hex(), Namespace: reqJSON.Namespace, Value: reqJSON.Value, MarketID: reqJSON.MarketID, CustomData: reqJSON.CustomData, } log.Errorln(111) svr := service.NewTypeConfigService() exist, err := svr.Exist(traceCtx, reqJSON.Namespace, reqJSON.Value) log.Errorln(222) log.Errorln(exist) log.Errorln(err) if err != nil && !svr.NotFound(err) { utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, nil) return } if exist { utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, nil) return } else { //获取当前最高sortNum nowSortNumInfo, err := svr.GetNowSortNumInfo(traceCtx) if err != nil { utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, nil) return } t.SortNum = nowSortNumInfo.SortNum + 1 err = svr.Insert(traceCtx, &t) if err != nil { utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, nil) return } } utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{}) } /** * @api {GET} * @apiGroup Finclip App Manager * @apiSuccessExample {json} Success Status: * HTTP/1.1 200 OK * { * "data": {}, * "errcode": "OK", * "error": "" * } * @apiErrorExample Error Status: * HTTP/1.1 !=200 服务端异常 */ func DeleteTypeConfig(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) typeConfigID := c.Param("typeConfigId") administratorID := c.Query("administratorId") if typeConfigID == "" { utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, nil) return } if administratorID == "" { utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, nil) return } svr := service.NewTypeConfigService() err := svr.Delete(traceCtx, typeConfigID) if err != nil { utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, nil) return } utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{}) return }