k94314517
2024-02-18 79243a38ffb959be94e1a81f922675d093850454
server/dmvisit_service/src/main/java/com/doumee/service/system/impl/SystemDictDataServiceImpl.java
@@ -1,13 +1,13 @@
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.LaborConfigDTO;
import com.doumee.dao.admin.request.VisitConfigDTO;
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;
@@ -27,6 +27,7 @@
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;
@@ -130,138 +131,236 @@
    @Override
    public VisitConfigDTO getVisitConfigDTO() {
        try {
            String jasonStr = Constants.toUnderlineJSONString(new VisitConfigDTO());
            JSONObject parse = (JSONObject) JSONObject.parse(jasonStr);
            List<String> collect = parse.entrySet().stream().map(s -> s.getKey().toUpperCase()).collect(Collectors.toList());
            QueryWrapper<SystemDict> systemDictQuery = new QueryWrapper<>();
            systemDictQuery.lambda()
                            .eq(SystemDict::getDeleted,Boolean.FALSE)
                            .eq(SystemDict::getCode,Constants.VISIT_CONFIG);
            SystemDict systemDict = systemDictMapper.selectOne(systemDictQuery);
            if (Objects.isNull(systemDict)){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在");
            }
            QueryWrapper<SystemDictData> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(SystemDictData::getDictId,systemDict.getId())
                    .in(SystemDictData::getLabel,collect);
            List<SystemDictData> systemDictData = systemDictDataMapper.selectList(wrapper);
            if (CollectionUtils.isEmpty(systemDictData)){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典值不存在");
            }
            systemDictData.forEach(s->{
                parse.put(s.getLabel().toLowerCase(),s.getCode());
            });
            String s = parse.toJSONString();
            VisitConfigDTO miniProgrammeDTO = Constants.toSnakeObject(s, VisitConfigDTO.class);
            return miniProgrammeDTO;
        } catch (Exception e) {
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"字典值解析有误");
        VisitConfigDTO visitConfigDTO = new VisitConfigDTO();
        SystemDict systemDict = systemDictMapper.selectOne(new QueryWrapper<SystemDict>().lambda().eq(SystemDict::getCode,Constants.SYSTEM));
        if(Objects.isNull(systemDict)){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在");
        }
        List<SystemDictData> systemDictList = systemDictDataMapper.selectList(
                new QueryWrapper<SystemDictData>().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());
        return visitConfigDTO;
    }
    @Override
    public void updateVisitConfig(VisitConfigDTO miniProgrammeDTO) {
    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<SystemDict>().lambda().eq(SystemDict::getCode,Constants.SYSTEM));
        if(Objects.isNull(systemDict)){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在");
        }
        List<SystemDictData> systemDictList = systemDictDataMapper.selectList(
                new QueryWrapper<SystemDictData>().lambda().eq(SystemDictData::getDictId,systemDict.getId()));
        if(!com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(systemDictList)){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在");
        }
            QueryWrapper<SystemDict> systemDictQuery = new QueryWrapper<>();
            systemDictQuery.lambda()
                    .eq(SystemDict::getDeleted,Boolean.FALSE)
                    .eq(SystemDict::getCode,Constants.VISIT_CONFIG);
            SystemDict systemDict = systemDictMapper.selectOne(systemDictQuery);
        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());
            if (Objects.isNull(systemDict)){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在");
            }
            QuerySystemDictDataDTO dictData = new QuerySystemDictDataDTO();
            dictData.setDictId((systemDict.getId()));
            List<SystemDictDataListVO> systemDictDataListVOS = systemDictDataMapper.selectManageList(dictData);
            if(null != systemDictDataListVOS && systemDictDataListVOS.size() > 0) {
                LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
                SystemDictData systemDictData = new SystemDictData();
                systemDictData.setDictId(systemDict.getId());
                systemDictData.setCode(JSONObject.toJSONString(miniProgrammeDTO.getVisitConfigParam()));
                systemDictData.setDisabled(true);
                systemDictData.setSort(Constants.ZERO);
                systemDictData.setLabel(miniProgrammeDTO.getTheme());
                systemDictData.setRemark(miniProgrammeDTO.getDescription());
                systemDictData.setCreateTime(new Date());
                systemDictData.setUpdateTime(new Date());
                systemDictData.setCreateUser(loginUserInfo.getId());
                systemDictData.setUpdateUser(loginUserInfo.getId());
                if(null == systemDictDataListVOS.get(0).getId()) {
                    systemDictDataMapper.insert(systemDictData);
                }else {
                    systemDictData.setId(systemDictDataListVOS.get(0).getId());
                    systemDictDataMapper.updateById(systemDictData);
                }
            }
        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());
        systemDictDataMapper.updateById(reservationWay);
        systemDictDataMapper.updateById(checkVisit);
        systemDictDataMapper.updateById(healthCard);
        systemDictDataMapper.updateById(isAnswer);
        systemDictDataMapper.updateById(theme);
        systemDictDataMapper.updateById(description);
    }
    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 LaborConfigDTO getLaborConfigDTO() {
        try {
            String jasonStr = Constants.toUnderlineJSONString(new LaborConfigDTO());
            JSONObject parse = (JSONObject) JSONObject.parse(jasonStr);
            List<String> collect = parse.entrySet().stream().map(s -> s.getKey().toUpperCase()).collect(Collectors.toList());
            QueryWrapper<SystemDict> systemDictQuery = new QueryWrapper<>();
            systemDictQuery.lambda()
                    .eq(SystemDict::getDeleted,Boolean.FALSE)
                    .eq(SystemDict::getCode,Constants.LABOR_CONFIG);
            SystemDict systemDict = systemDictMapper.selectOne(systemDictQuery);
            if (Objects.isNull(systemDict)){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在");
            }
            QueryWrapper<SystemDictData> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(SystemDictData::getDictId,systemDict.getId())
                    .in(SystemDictData::getLabel,collect);
            List<SystemDictData> systemDictData = systemDictDataMapper.selectList(wrapper);
            if (CollectionUtils.isEmpty(systemDictData)){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典值不存在");
            }
            systemDictData.forEach(s->{
                parse.put(s.getLabel().toLowerCase(),s.getCode());
            });
            String s = parse.toJSONString();
            LaborConfigDTO miniProgrammeDTO = Constants.toSnakeObject(s, LaborConfigDTO.class);
            return miniProgrammeDTO;
        } catch (Exception e) {
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"字典值解析有误");
    public VisitConfigDTO getLaborConfigDTO() {
        VisitConfigDTO visitConfigDTO = new VisitConfigDTO();
        SystemDict systemDict = systemDictMapper.selectOne(new QueryWrapper<SystemDict>().lambda().eq(SystemDict::getCode,Constants.SYSTEM));
        if(Objects.isNull(systemDict)){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在");
        }
        List<SystemDictData> systemDictList = systemDictDataMapper.selectList(
                new QueryWrapper<SystemDictData>().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(LaborConfigDTO miniProgrammeDTO) {
        try {
            QueryWrapper<SystemDict> systemDictQuery = new QueryWrapper<>();
            systemDictQuery.lambda()
                    .eq(SystemDict::getDeleted,Boolean.FALSE)
                    .eq(SystemDict::getCode,Constants.VISIT_CONFIG);
            SystemDict systemDict = systemDictMapper.selectOne(systemDictQuery);
            if (Objects.isNull(systemDict)){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典不存在");
            }
            String jasonStr = Constants.toUnderlineJSONString(miniProgrammeDTO);
            JSONObject parse = (JSONObject) JSONObject.parse(jasonStr);
            parse.entrySet().forEach(s->{
                UpdateWrapper<SystemDictData> wrapper = new UpdateWrapper<>();
                wrapper.lambda()
                        .eq(SystemDictData::getDictId,systemDict.getId())
                        .eq(SystemDictData::getLabel,s.getKey().toUpperCase())
                        .set(SystemDictData::getCode,s.getValue());
                systemDictDataMapper.update(null,wrapper);
            });
        } catch (JsonProcessingException e) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"字典值解析有误");
    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<SystemDict>().lambda().eq(SystemDict::getCode,Constants.SYSTEM));
        if(Objects.isNull(systemDict)){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"字典类不存在");
        }
        List<SystemDictData> systemDictList = systemDictDataMapper.selectList(
                new QueryWrapper<SystemDictData>().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);
    }
}