package com.hfkj.controller; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.BsUserGradeConfig; import com.hfkj.model.ResponseData; import com.hfkj.service.user.BsUserGradeConfigService; import com.hfkj.sysenum.user.UserGradeEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; /** * @className: BsUserGradeConfigController * @author: HuRui * @date: 2024/10/23 **/ @Controller @RequestMapping(value = "/userGradeConfig") @Api(value = "用户等级配置") public class BsUserGradeConfigController { private static Logger log = LoggerFactory.getLogger(BsUserCountController.class); @Resource private BsUserGradeConfigService userGradeConfigService; @RequestMapping(value="/update",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "修改") public ResponseData update(@RequestBody BsUserGradeConfig body) { try { if (body.getGrade() == null || body.getGradeIncomeRatio() == null || body.getOrderIncomeRatio() == null ) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } // 查询配置 BsUserGradeConfig config = userGradeConfigService.getConfig(UserGradeEnum.getDataByType(body.getGrade())); if (config == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } config.setGradeIncomeRatio(body.getGradeIncomeRatio()); config.setOrderIncomeRatio(body.getOrderIncomeRatio()); config.setPromotionConditions1(body.getPromotionConditions1()); config.setPromotionConditions2(body.getPromotionConditions2()); config.setPromotionConditions3(body.getPromotionConditions3()); userGradeConfigService.updateData(config); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/getConfig",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询配置") public ResponseData getConfig(@RequestParam(value = "grade" , required = true) Integer grade) { try { return ResponseMsgUtil.success(userGradeConfigService.getConfig(UserGradeEnum.getDataByType(grade))); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/getList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询列表") public ResponseData getList() { try { return ResponseMsgUtil.success(userGradeConfigService.getList(new HashMap<>())); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } }