package com.doumee.service.system.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 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.admin.request.*; import com.doumee.dao.system.SystemDictMapper; import com.doumee.dao.system.model.SystemDict; import com.fasterxml.jackson.core.JsonProcessingException; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.dao.system.SystemDictDataMapper; import com.doumee.dao.system.dto.QuerySystemDictDataDTO; import com.doumee.dao.system.model.SystemDictData; import com.doumee.dao.system.vo.SystemDictDataListVO; import com.doumee.service.system.SystemDictDataService; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.util.Date; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; import static net.sf.jsqlparser.parser.feature.Feature.set; import static net.sf.jsqlparser.parser.feature.Feature.update; /** * 字典数据Service实现 * @author Eva.Caesar Liu * @date 2023/03/21 14:49 */ @Service public class SystemDictDataServiceImpl implements SystemDictDataService { @Autowired private SystemDictDataMapper systemDictDataMapper; @Autowired private SystemDictMapper systemDictMapper; @Override public Integer create(SystemDictData systemDictData) { systemDictDataMapper.insert(systemDictData); return systemDictData.getId(); } @Override public void deleteById(Integer id) { SystemDictData systemDictData = new SystemDictData(); systemDictData.setId(id); systemDictData.setDeleted(Boolean.TRUE); this.updateById(systemDictData); } @Override @Transactional public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } for (Integer id : ids) { this.deleteById(id); } } @Override public void updateById(SystemDictData systemDictData) { systemDictDataMapper.updateById(systemDictData); } @Override @Transactional public void updateByIdInBatch(List systemDictDatas) { if (CollectionUtils.isEmpty(systemDictDatas)) { return; } for (SystemDictData systemDictData: systemDictDatas) { this.updateById(systemDictData); } } @Override public SystemDictData findById(Integer id) { return systemDictDataMapper.selectById(id); } @Override public SystemDictData findOne(SystemDictData systemDictData) { Wrapper wrapper = new QueryWrapper<>(systemDictData); return systemDictDataMapper.selectOne(wrapper); } @Override public List findList(SystemDictData systemDictData) { Wrapper wrapper = new QueryWrapper<>(systemDictData); return systemDictDataMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); return PageData.from(new PageInfo<>(systemDictDataMapper.selectManageList(pageWrap.getModel()))); } @Override public long count(SystemDictData systemDictData) { Wrapper wrapper = new QueryWrapper<>(systemDictData); return systemDictDataMapper.selectCount(wrapper); } @Override public List findList(Integer dicId,List codes) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.lambda() .eq(Objects.nonNull(dicId),SystemDictData::getDictId,dicId) .in(SystemDictData::getLabel,codes); return systemDictDataMapper.selectList(wrapper); } @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); } }