package cn.lihu.jh.module.ecg.service.devmanage; import cn.lihu.jh.module.system.api.dict.DictDataApi; import cn.lihu.jh.module.system.api.dict.dto.DictDataRespDTO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import cn.lihu.jh.module.ecg.controller.admin.devmanage.vo.*; import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DevModelDO; import cn.lihu.jh.framework.common.pojo.PageResult; import cn.lihu.jh.framework.common.util.object.BeanUtils; import cn.lihu.jh.module.ecg.dal.mysql.devmanage.DevModelMapper; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; /** * 设备型号 Service 实现类 * * @author majianbo */ @Service @Validated public class DevModelServiceImpl implements DevModelService { @Resource private DevModelMapper devModelMapper; @Resource private DictDataApi dictDataApi; @Override public Integer createDevModel(DevModelSaveReqVO createReqVO) { // 插入 DevModelDO devModel = BeanUtils.toBean(createReqVO, DevModelDO.class); devModelMapper.insert(devModel); // 返回 return devModel.getId(); } @Override public void updateDevModel(DevModelSaveReqVO updateReqVO) { // 校验存在 validateDevModelExists(updateReqVO.getId()); // 更新 DevModelDO updateObj = BeanUtils.toBean(updateReqVO, DevModelDO.class); devModelMapper.updateById(updateObj); } @Override public void deleteDevModel(Integer id) { // 校验存在 validateDevModelExists(id); // 删除 devModelMapper.deleteById(id); } private void validateDevModelExists(Integer id) { if (devModelMapper.selectById(id) == null) { throw exception(DEV_MODEL_NOT_EXISTS); } } @Override public DevModelDO getDevModel(Integer id) { return devModelMapper.selectById(id); } @Override public PageResult getDevModelPage(DevModelPageReqVO pageReqVO) { return devModelMapper.selectPage(pageReqVO); } @Override public List getBrandOptions(String devCategory) { List list = devModelMapper.getBrandByCategory(devCategory); List dictDataRespDTOList = dictDataApi.getDictDataList("ecg_dev_brand"); Map map = dictDataRespDTOList.stream().collect(Collectors.toMap(DictDataRespDTO::getValue, DictDataRespDTO::getLabel)); List optionVOList = new ArrayList<>(); list.forEach(item -> { OptionVO optionVO = new OptionVO(); optionVO.setLabel( map.get(item) ); optionVO.setValue( item ); optionVOList.add( optionVO ); }); return optionVOList; } @Override public List getBrandModelOptions(String devCategory, String devBrand) { List list = devModelMapper.getModelByCategoryBrand(devCategory, devBrand); List optionVOList = new ArrayList<>(); list.forEach(item -> { OptionVO optionVO = new OptionVO(); optionVO.setLabel( item ); optionVO.setValue( item ); optionVOList.add( optionVO ); }); return optionVOList; } }