New file |
| | |
| | | package com.dsh.guns.modular.system.service.impl; |
| | | |
| | | import static com.dsh.guns.core.common.constant.factory.MutiStrFactory.MUTI_STR_CODE; |
| | | import static com.dsh.guns.core.common.constant.factory.MutiStrFactory.MUTI_STR_NAME; |
| | | import static com.dsh.guns.core.common.constant.factory.MutiStrFactory.MUTI_STR_NUM; |
| | | import static com.dsh.guns.core.common.constant.factory.MutiStrFactory.parseKeyValue; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.course.mapper.DictMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.dsh.guns.core.common.exception.BizExceptionEnum; |
| | | import com.dsh.guns.core.exception.GunsException; |
| | | import com.dsh.guns.modular.system.model.Dict; |
| | | import com.dsh.guns.modular.system.service.IDictService; |
| | | |
| | | @Service |
| | | @Transactional |
| | | public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService { |
| | | |
| | | @Resource |
| | | private DictMapper dictMapper; |
| | | |
| | | @Override |
| | | public void addDict(String dictCode,String dictName,String dictTips, String dictValues) { |
| | | //判断有没有该字典 |
| | | //Check if the dictionary exists |
| | | List<Dict> dicts = dictMapper.selectList(new QueryWrapper<Dict>().eq("code", dictCode).eq("pid", 0)); |
| | | if (dicts != null && dicts.size() > 0) { |
| | | throw new GunsException(BizExceptionEnum.DICT_EXISTED); |
| | | } |
| | | |
| | | //解析dictValues |
| | | List<Map<String, String>> items = parseKeyValue(dictValues); |
| | | |
| | | //添加字典 add dict |
| | | Dict dict = new Dict(); |
| | | dict.setName(dictName); |
| | | dict.setCode(dictCode); |
| | | dict.setTips(dictTips); |
| | | dict.setNum(0); |
| | | dict.setPid(0); |
| | | this.dictMapper.insert(dict); |
| | | |
| | | //添加字典条目 Add dictionary entry |
| | | for (Map<String, String> item : items) { |
| | | String code = item.get(MUTI_STR_CODE); |
| | | String name = item.get(MUTI_STR_NAME); |
| | | String num = item.get(MUTI_STR_NUM); |
| | | Dict itemDict = new Dict(); |
| | | itemDict.setPid(dict.getId()); |
| | | itemDict.setCode(code); |
| | | itemDict.setName(name); |
| | | |
| | | try { |
| | | itemDict.setNum(Integer.valueOf(num)); |
| | | } catch (NumberFormatException e) { |
| | | throw new GunsException(BizExceptionEnum.DICT_MUST_BE_NUMBER); |
| | | } |
| | | this.dictMapper.insert(itemDict); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void editDict(Integer dictId,String dictCode, String dictName,String dictTips, String dicts) { |
| | | //删除之前的字典 add before dict |
| | | this.delteDict(dictId); |
| | | |
| | | //重新添加新的字典 Add a new dictionary again |
| | | this.addDict(dictCode,dictName,dictTips, dicts); |
| | | } |
| | | |
| | | @Override |
| | | public void delteDict(Integer dictId) { |
| | | //删除这个字典的子词典 Delete the sub-dictionary of this dictionary. |
| | | QueryWrapper<Dict> dictEntityWrapper = new QueryWrapper<>(); |
| | | dictEntityWrapper = dictEntityWrapper.eq("pid", dictId); |
| | | dictMapper.delete(dictEntityWrapper); |
| | | |
| | | //删除这个词典 Delete the dictionary |
| | | dictMapper.deleteById(dictId); |
| | | } |
| | | |
| | | @Override |
| | | public List<Dict> selectByCode(String code) { |
| | | return this.baseMapper.selectByCode(code); |
| | | } |
| | | |
| | | @Override |
| | | public List<Dict> selectByParentCode(String code) { |
| | | return this.baseMapper.selectByParentCode(code); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> list(String conditiion) { |
| | | return this.baseMapper.list(conditiion); |
| | | } |
| | | } |