| | |
| | | package com.doumee.biz.system.impl; |
| | | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.utils.qiyeweixin.QywxUtil; |
| | | import com.doumee.dao.common.dto.UpdateSortDTO; |
| | | import com.doumee.dao.system.model.SystemDict; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.service.system.SystemDictDataService; |
| | | import com.doumee.service.system.SystemDictService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Autowired |
| | | private SystemDictDataService systemDictDataService; |
| | | @Autowired |
| | | private SystemDictService systemDictService; |
| | | |
| | | @Override |
| | | public Integer create(SystemDictData systemDictData) { |
| | |
| | | |
| | | @Override |
| | | public void updateById(SystemDictData systemDictData) { |
| | | SystemDictData queryDto = new SystemDictData(); |
| | | queryDto.setDictId(systemDictData.getDictId()); |
| | | queryDto.setCode(systemDictData.getCode()); |
| | | queryDto.setDeleted(Boolean.FALSE); |
| | | SystemDictData dictData = systemDictDataService.findOne(queryDto); |
| | | if (dictData != null && !dictData.getId().equals(systemDictData.getId())) { |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "数据值已存在"); |
| | | } |
| | | systemDictDataService.updateById(systemDictData); |
| | | } |
| | | @Override |
| | | public String updateQywxToken(){ |
| | | String corpid = queryByCode(Constants.QYWX,Constants.QYWX_CORPID).getCode(); |
| | | String secret = queryByCode(Constants.QYWX,Constants.QYWX_SECRET).getCode(); |
| | | String token = QywxUtil.getAccessToken(corpid,secret); |
| | | SystemDictData dictData = queryByCode(Constants.QYWX,Constants.QYWX_TOKEN); |
| | | if (dictData != null ) { |
| | | dictData.setCode(token); |
| | | dictData.setUpdateTime(new Date()); |
| | | systemDictDataService.updateById(dictData); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | @Override |
| | |
| | | // 修改 |
| | | systemDictDataService.updateByIdInBatch(dictDataList); |
| | | } |
| | | |
| | | @Override |
| | | public SystemDictData queryByCode(String dicCode, String label){ |
| | | SystemDict queryDto = new SystemDict(); |
| | | queryDto.setCode(dicCode); |
| | | queryDto.setDeleted(Boolean.FALSE); |
| | | SystemDict dictData = systemDictService.findOne(queryDto); |
| | | if (dictData == null) { |
| | | return new SystemDictData(); |
| | | // throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "数据值不存在"); |
| | | } |
| | | SystemDictData data = new SystemDictData(); |
| | | data.setDictId(dictData.getId()); |
| | | data.setLabel(label); |
| | | data.setDeleted(Boolean.FALSE); |
| | | data = systemDictDataService.findOne(data); |
| | | if(data == null){ |
| | | data = new SystemDictData(); |
| | | } |
| | | return data; |
| | | } |
| | | @Override |
| | | public String queryCodeById(Integer id){ |
| | | SystemDictData data = systemDictDataService.findById(id); |
| | | if(data != null){ |
| | | return data.getCode(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<SystemDictData> queryListByCode(String dicCode, String label){ |
| | | SystemDict queryDto = new SystemDict(); |
| | | queryDto.setCode(dicCode); |
| | | queryDto.setDeleted(Boolean.FALSE); |
| | | SystemDict dictData = systemDictService.findOne(queryDto); |
| | | if (dictData == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "数据值不存在"); |
| | | } |
| | | SystemDictData data = new SystemDictData(); |
| | | data.setDictId(dictData.getId()); |
| | | data.setLabel(label); |
| | | data.setDeleted(Boolean.FALSE); |
| | | List<SystemDictData> list= systemDictDataService.findList(data); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public void updateByIdNew(SystemDictData systemDictData) { |
| | | systemDictDataService.updateById(systemDictData); |
| | | } |
| | | |
| | | @Override |
| | | public List<SystemDictData> queryDataByCode(String dicCode, String code){ |
| | | SystemDict queryDto = new SystemDict(); |
| | | queryDto.setCode(dicCode); |
| | | queryDto.setDeleted(Boolean.FALSE); |
| | | SystemDict dictData = systemDictService.findOne(queryDto); |
| | | if (dictData == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "数据值不存在"); |
| | | } |
| | | SystemDictData data = new SystemDictData(); |
| | | data.setDictId(dictData.getId()); |
| | | data.setCode(code); |
| | | data.setDeleted(Boolean.FALSE); |
| | | List<SystemDictData> list= systemDictDataService.findList(data); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public void updateByDicId(List<SystemDictData> list) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | list.stream().forEach(s->{ |
| | | s.setUpdateTime(new Date()); |
| | | s.setUpdateUser(user.getId()); |
| | | systemDictDataService.updateById(s); |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public String getPreFixPath(String resourceCode, String targetCode) { |
| | | |
| | | if (StringUtils.isBlank(resourceCode) || StringUtils.isBlank(targetCode)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"路径参数不完整"); |
| | | } |
| | | SystemDict queryDto = new SystemDict(); |
| | | queryDto.setCode(Constants.FTP); |
| | | queryDto.setDeleted(Boolean.FALSE); |
| | | SystemDict dictData = systemDictService.findOne(queryDto); |
| | | if (dictData == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "数据值不存在"); |
| | | } |
| | | List<SystemDictData> list = systemDictDataService.findList(dictData.getId(), Arrays.asList(resourceCode, targetCode)); |
| | | String resourcePath = list.stream().filter(s->s.getLabel().equals(resourceCode)).findFirst().map(s->s.getCode()).orElse(""); |
| | | String targetPath = list.stream().filter(s -> s.getLabel().equals(targetCode)).findFirst().map(s -> s.getCode()).orElse(""); |
| | | return resourcePath+targetPath; |
| | | } |
| | | |
| | | } |