package com.doumee.service.systembiz.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; import com.doumee.core.utils.Constants; import com.doumee.dao.system.SystemDictDataMapper; import com.doumee.dao.system.SystemDictMapper; import com.doumee.dao.system.dto.VisitConfigDTO; import com.doumee.dao.system.model.SystemDict; import com.doumee.dao.system.model.SystemDictData; import com.doumee.service.systembiz.SystemDictDataBizService; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.util.Date; import java.util.List; import java.util.Objects; /** * 字典数据Service实现 * @author Eva.Caesar Liu * @date 2023/03/21 14:49 */ @Service public class SystemDictDataBizServiceImpl implements SystemDictDataBizService { @Autowired private SystemDictDataMapper systemDictDataMapper; @Autowired private SystemDictMapper systemDictMapper; @Override public VisitConfigDTO getVisitConfigDTO() { VisitConfigDTO visitConfigDTO = new VisitConfigDTO(); SystemDict systemDict = systemDictMapper.selectOne(new QueryWrapper().lambda().eq(SystemDict::getCode,Constants.SYSTEM)); if(Objects.isNull(systemDict)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在"); } List systemDictList = systemDictDataMapper.selectList( new QueryWrapper().lambda().eq(SystemDictData::getDictId,systemDict.getId())); if(!com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(systemDictList)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在"); } SystemDictData reservationWay = systemDictList.stream().filter(m->m.getLabel().equals(Constants.MDJ_VISIT_REQUIRED)).findFirst().get(); if(Objects.isNull(reservationWay)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客来访预约方式 字典不存在"); } visitConfigDTO.setReservationWay(Integer.valueOf(reservationWay.getCode())); SystemDictData checkVisit = systemDictList.stream().filter(m->m.getLabel().equals(Constants.BEVISITED_USER_VALID)).findFirst().get(); if(Objects.isNull(checkVisit)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客被访人校验方式 字典不存在"); } visitConfigDTO.setCheckVisit(Integer.valueOf(checkVisit.getCode())); SystemDictData healthCard = systemDictList.stream().filter(m->m.getLabel().equals(Constants.HEALTH_CARD)).findFirst().get(); if(Objects.isNull(healthCard)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客健康证是否必填 字典不存在"); } visitConfigDTO.setHealthCard(Integer.valueOf(healthCard.getCode())); SystemDictData isAnswer = systemDictList.stream().filter(m->m.getLabel().equals(Constants.PROBLEM_VISIT_REQUIRED)).findFirst().get(); if(Objects.isNull(isAnswer)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客是否需要答题 字典不存在"); } visitConfigDTO.setIsAnswer(Integer.valueOf(isAnswer.getCode())); SystemDictData theme = systemDictList.stream().filter(m->m.getLabel().equals(Constants.THEME)).findFirst().get(); if(Objects.isNull(theme)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客答题主题 字典不存在"); } visitConfigDTO.setTheme(theme.getCode()); SystemDictData description = systemDictList.stream().filter(m->m.getLabel().equals(Constants.DESCRIPTION)).findFirst().get(); if(Objects.isNull(description)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客答题说明 字典不存在"); } visitConfigDTO.setDescription(description.getCode()); SystemDictData visitNotice = systemDictList.stream().filter(m->m.getLabel().equals(Constants.VISIT_NOTICE)).findFirst().get(); if(Objects.isNull(visitNotice)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"入厂须知 字典不存在"); } visitConfigDTO.setVisitNotice(visitNotice.getCode()); SystemDictData doorsVisitRequired = systemDictList.stream().filter(m->m.getLabel().equals(Constants.SELECT_DOORS_VISIT_REQUIRED)).findFirst().get(); if(Objects.isNull(doorsVisitRequired)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"自选门禁配置 字典不存在"); } visitConfigDTO.setDoorsVisitRequired(Integer.valueOf(doorsVisitRequired.getCode())); return visitConfigDTO; } @Override public void updateVisitConfig(VisitConfigDTO visitConfigDTO) { if(Objects.isNull(visitConfigDTO) ||Objects.isNull(visitConfigDTO.getReservationWay()) ||Objects.isNull(visitConfigDTO.getCheckVisit()) ||Objects.isNull(visitConfigDTO.getHealthCard()) ||Objects.isNull(visitConfigDTO.getIsAnswer()) || StringUtils.isEmpty(visitConfigDTO.getTheme()) || StringUtils.isEmpty(visitConfigDTO.getDescription()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } SystemDict systemDict = systemDictMapper.selectOne(new QueryWrapper().lambda().eq(SystemDict::getCode,Constants.SYSTEM)); if(Objects.isNull(systemDict)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在"); } List systemDictList = systemDictDataMapper.selectList( new QueryWrapper().lambda().eq(SystemDictData::getDictId,systemDict.getId())); if(!com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(systemDictList)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在"); } SystemDictData reservationWay = systemDictList.stream().filter(m->m.getLabel().equals(Constants.MDJ_VISIT_REQUIRED)).findFirst().get(); if(Objects.isNull(reservationWay)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客来访预约方式 字典不存在"); } reservationWay.setCode(visitConfigDTO.getReservationWay().toString()); SystemDictData checkVisit = systemDictList.stream().filter(m->m.getLabel().equals(Constants.BEVISITED_USER_VALID)).findFirst().get(); if(Objects.isNull(checkVisit)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客被访人校验方式 字典不存在"); } checkVisit.setCode(visitConfigDTO.getCheckVisit().toString()); SystemDictData healthCard = systemDictList.stream().filter(m->m.getLabel().equals(Constants.HEALTH_CARD)).findFirst().get(); if(Objects.isNull(healthCard)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客健康证是否必填 字典不存在"); } healthCard.setCode(visitConfigDTO.getHealthCard().toString()); SystemDictData isAnswer = systemDictList.stream().filter(m->m.getLabel().equals(Constants.PROBLEM_VISIT_REQUIRED)).findFirst().get(); if(Objects.isNull(isAnswer)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客是否需要答题 字典不存在"); } isAnswer.setCode(visitConfigDTO.getIsAnswer().toString()); SystemDictData theme = systemDictList.stream().filter(m->m.getLabel().equals(Constants.THEME)).findFirst().get(); if(Objects.isNull(theme)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客答题主题 字典不存在"); } theme.setCode(visitConfigDTO.getTheme()); SystemDictData description = systemDictList.stream().filter(m->m.getLabel().equals(Constants.DESCRIPTION)).findFirst().get(); if(Objects.isNull(description)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"访客答题说明 字典不存在"); } description.setCode(visitConfigDTO.getDescription()); SystemDictData visitNotice = systemDictList.stream().filter(m->m.getLabel().equals(Constants.VISIT_NOTICE)).findFirst().get(); if(Objects.isNull(visitNotice)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"入厂须知 字典不存在"); } visitNotice.setCode(visitConfigDTO.getVisitNotice()); SystemDictData doorsVisitRequired = systemDictList.stream().filter(m->m.getLabel().equals(Constants.SELECT_DOORS_VISIT_REQUIRED)).findFirst().get(); if(Objects.isNull(doorsVisitRequired)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"自选门禁配置 字典不存在"); } doorsVisitRequired.setCode(visitConfigDTO.getDoorsVisitRequired().toString()); systemDictDataMapper.updateById(reservationWay); systemDictDataMapper.updateById(checkVisit); systemDictDataMapper.updateById(healthCard); systemDictDataMapper.updateById(isAnswer); systemDictDataMapper.updateById(theme); systemDictDataMapper.updateById(description); systemDictDataMapper.updateById(visitNotice); systemDictDataMapper.updateById(doorsVisitRequired); } private SystemDictData getSystemDictDataListVO(SystemDict systemDict) { LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); SystemDictData systemDictData = new SystemDictData(); systemDictData.setDictId(systemDict.getId()); systemDictData.setDisabled(true); systemDictData.setSort(Constants.ONE); systemDictData.setCreateTime(new Date()); systemDictData.setUpdateTime(new Date()); systemDictData.setCreateUser(loginUserInfo.getId()); systemDictData.setUpdateUser(loginUserInfo.getId()); return systemDictData; } @Override public VisitConfigDTO getLaborConfigDTO() { VisitConfigDTO visitConfigDTO = new VisitConfigDTO(); SystemDict systemDict = systemDictMapper.selectOne(new QueryWrapper().lambda().eq(SystemDict::getCode,Constants.SYSTEM)); if(Objects.isNull(systemDict)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在"); } List systemDictList = systemDictDataMapper.selectList( new QueryWrapper().lambda().eq(SystemDictData::getDictId,systemDict.getId())); if(!com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(systemDictList)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在"); } SystemDictData reservationWay = systemDictList.stream().filter(m->m.getLabel().equals(Constants.MDJ_LW_REQUIRED)).findFirst().get(); if(Objects.isNull(reservationWay)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客来访预约方式 字典不存在"); } visitConfigDTO.setReservationWay(Integer.valueOf(reservationWay.getCode())); SystemDictData checkVisit = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_BEVISITED_USER_VALID)).findFirst().get(); if(Objects.isNull(checkVisit)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客被访人校验方式 字典不存在"); } visitConfigDTO.setCheckVisit(Integer.valueOf(checkVisit.getCode())); SystemDictData healthCard = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_HEALTH_CARD)).findFirst().get(); if(Objects.isNull(healthCard)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客健康证是否必填 字典不存在"); } visitConfigDTO.setHealthCard(Integer.valueOf(healthCard.getCode())); SystemDictData isAnswer = systemDictList.stream().filter(m->m.getLabel().equals(Constants.PROBLEM_LW_REQUIRED)).findFirst().get(); if(Objects.isNull(isAnswer)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客是否需要答题 字典不存在"); } visitConfigDTO.setIsAnswer(Integer.valueOf(isAnswer.getCode())); SystemDictData theme = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_THEME)).findFirst().get(); if(Objects.isNull(theme)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客答题主题 字典不存在"); } visitConfigDTO.setTheme(theme.getCode()); SystemDictData description = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_DESCRIPTION)).findFirst().get(); if(Objects.isNull(description)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客答题说明 字典不存在"); } visitConfigDTO.setDescription(description.getCode()); return visitConfigDTO; } @Override public void updateLaborConfigDTO(VisitConfigDTO visitConfigDTO) { if(Objects.isNull(visitConfigDTO) ||Objects.isNull(visitConfigDTO.getReservationWay()) ||Objects.isNull(visitConfigDTO.getCheckVisit()) ||Objects.isNull(visitConfigDTO.getHealthCard()) ||Objects.isNull(visitConfigDTO.getIsAnswer()) || StringUtils.isEmpty(visitConfigDTO.getTheme()) || StringUtils.isEmpty(visitConfigDTO.getDescription()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } SystemDict systemDict = systemDictMapper.selectOne(new QueryWrapper().lambda().eq(SystemDict::getCode,Constants.SYSTEM)); if(Objects.isNull(systemDict)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在"); } List systemDictList = systemDictDataMapper.selectList( new QueryWrapper().lambda().eq(SystemDictData::getDictId,systemDict.getId())); if(!com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(systemDictList)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在"); } SystemDictData reservationWay = systemDictList.stream().filter(m->m.getLabel().equals(Constants.MDJ_LW_REQUIRED)).findFirst().get(); if(Objects.isNull(reservationWay)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客来访预约方式 字典不存在"); } reservationWay.setCode(visitConfigDTO.getReservationWay().toString()); SystemDictData checkVisit = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_BEVISITED_USER_VALID)).findFirst().get(); if(Objects.isNull(checkVisit)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客被访人校验方式 字典不存在"); } checkVisit.setCode(visitConfigDTO.getCheckVisit().toString()); SystemDictData healthCard = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_HEALTH_CARD)).findFirst().get(); if(Objects.isNull(healthCard)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客健康证是否必填 字典不存在"); } healthCard.setCode(visitConfigDTO.getHealthCard().toString()); SystemDictData isAnswer = systemDictList.stream().filter(m->m.getLabel().equals(Constants.PROBLEM_LW_REQUIRED)).findFirst().get(); if(Objects.isNull(isAnswer)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客是否需要答题 字典不存在"); } isAnswer.setCode(visitConfigDTO.getIsAnswer().toString()); SystemDictData theme = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_THEME)).findFirst().get(); if(Objects.isNull(theme)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客答题主题 字典不存在"); } theme.setCode(visitConfigDTO.getTheme()); SystemDictData description = systemDictList.stream().filter(m->m.getLabel().equals(Constants.LW_DESCRIPTION)).findFirst().get(); if(Objects.isNull(description)){ throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"劳务访客答题说明 字典不存在"); } description.setCode(visitConfigDTO.getDescription()); systemDictDataMapper.updateById(reservationWay); systemDictDataMapper.updateById(checkVisit); systemDictDataMapper.updateById(healthCard); systemDictDataMapper.updateById(isAnswer); systemDictDataMapper.updateById(theme); systemDictDataMapper.updateById(description); } }