package cn.besteam.modules.medical.controller; import cn.besteam.common.api.vo.Result; import cn.besteam.common.aspect.annotation.AutoLog; import cn.besteam.common.constant.ErrorCode; import cn.besteam.common.exception.BusinessException; import cn.besteam.modules.medical.entity.MwWarningConfig; import cn.besteam.modules.medical.service.IMwWarningConfigService; import cn.besteam.modules.medical.vo.MwWarningConfigVO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; /** * @Title: Controller * @Description: 预警-配置 * @author: besteam * @date: 2020-07-17 * @version: V1.0 */ @RestController @RequestMapping("/medical/mwWarningConfig") @Slf4j @Api(description = "预警-配置") public class MwWarningConfigController { @Autowired private IMwWarningConfigService mwWarningConfigService; /** * 编辑 * * @param mwWarningConfigVO * @return */ @PostMapping(value = "/editByType") @AutoLog(value = "编辑预警配置") @ApiOperation(value = "编辑预警配置", notes = "编辑预警配置", produces = "application/json") public Result editByType(@RequestBody MwWarningConfigVO mwWarningConfigVO) { MwWarningConfig warningConfig = mwWarningConfigService.getOne(new QueryWrapper().lambda().eq(MwWarningConfig::getType, mwWarningConfigVO.getType()).last("limit 1")); if (warningConfig == null) { throw new BusinessException(ErrorCode.ERR_500, "预警配置不存在"); } warningConfig.setDefaultValue(mwWarningConfigVO.getDefaultValue()); warningConfig.setWasteTypes(mwWarningConfigVO.getWasteTypes()); return Result.ok(mwWarningConfigService.updateById(warningConfig)); } @GetMapping(value = "/getByType") @ApiOperation(value = "按类型获取预警配置", notes = "按类型获取预警配置", produces = "application/json") public Result getByType(@RequestParam Integer type) { MwWarningConfig warningConfig = mwWarningConfigService.getOne(new QueryWrapper().lambda().eq(MwWarningConfig::getType, type).last("limit 1")); if (warningConfig == null) { throw new BusinessException(ErrorCode.ERR_500, "预警配置不存在"); } MwWarningConfigVO vo = new MwWarningConfigVO(); BeanUtils.copyProperties(warningConfig, vo); return Result.ok(vo); } }