|
@@ -0,0 +1,131 @@
|
|
|
+package com.jeeplus.test.proofread.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.jeeplus.core.domain.BaseEntity;
|
|
|
+import com.jeeplus.core.service.TreeService;
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
+import com.jeeplus.sys.utils.StringUtils;
|
|
|
+import com.jeeplus.sys.utils.UserUtils;
|
|
|
+import com.jeeplus.test.proofread.domain.ProofreadType;
|
|
|
+import com.jeeplus.test.proofread.mapper.ProofreadTypeMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ProofreadTypeService extends TreeService<ProofreadTypeMapper, ProofreadType> {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProofreadTypeMapper mapper;
|
|
|
+
|
|
|
+ public List<ProofreadType> list(ProofreadType type) {
|
|
|
+ LambdaQueryWrapper<ProofreadType> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (StringUtils.isNotEmpty(type.getName())) {
|
|
|
+ wrapper.like(ProofreadType::getName, type.getName());
|
|
|
+ }
|
|
|
+ wrapper.eq(BaseEntity::getDelFlag, 0);
|
|
|
+ wrapper.orderByAsc(ProofreadType::getSort);
|
|
|
+ return mapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String saveType(ProofreadType type) {
|
|
|
+ // parentId未传值,则表示一级菜单
|
|
|
+ if(StringUtils.isEmpty(type.getParentId())) {
|
|
|
+ type.setParentId("0");
|
|
|
+ }
|
|
|
+ // 判断名称是否已存在
|
|
|
+ Integer isExist = mapper.checkNameIsExist(type.getName());
|
|
|
+ if (isExist > 0) {
|
|
|
+ return "false";
|
|
|
+ }
|
|
|
+ // 保存数据
|
|
|
+ if (StringUtils.isNotEmpty(type.getId())) {
|
|
|
+ return update(type);
|
|
|
+ }
|
|
|
+ return add(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String add(ProofreadType type) {
|
|
|
+ // 获取当前登录人信息
|
|
|
+ UserDTO userDto = UserUtils.getCurrentUserDTO();
|
|
|
+ // 生成id值
|
|
|
+ String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ type.setId(id);
|
|
|
+ type.setCreateBy(userDto.getId());
|
|
|
+ type.setCreateDate(new Date());
|
|
|
+ type.setUpdateBy(userDto.getId());
|
|
|
+ type.setUpdateDate(new Date());
|
|
|
+ type.setDelFlag(0);
|
|
|
+ // 生成序号/层级
|
|
|
+ getNo(type);
|
|
|
+ mapper.insert(type);
|
|
|
+ return "操作完成";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @param info
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String update(ProofreadType info) {
|
|
|
+ // 获取当前登录人信息
|
|
|
+ UserDTO userDto = UserUtils.getCurrentUserDTO();
|
|
|
+ info.setUpdateBy(userDto.getId());
|
|
|
+ info.setUpdateDate(new Date());
|
|
|
+ mapper.updateById(info);
|
|
|
+ return "操作完成";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成序号/层级
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ProofreadType getNo(ProofreadType type) {
|
|
|
+ ProofreadType parentInfo = null;
|
|
|
+ if (!"0".equals(type.getParentId())) {
|
|
|
+ //根据parentId查询父节点信息
|
|
|
+ LambdaQueryWrapper<ProofreadType> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(BaseEntity::getDelFlag, 0);
|
|
|
+ wrapper.eq(BaseEntity::getId, type.getParentId());
|
|
|
+ parentInfo = mapper.selectOne(wrapper);
|
|
|
+ }
|
|
|
+ //查询序号
|
|
|
+ Integer no = mapper.getNo(type.getParentId());
|
|
|
+ // 该层级下有数据,正常返回序号值
|
|
|
+ if (no != null) {
|
|
|
+ type.setSort(no);
|
|
|
+ } else {
|
|
|
+ // 父节点存在,根据父节点序号生成;不存在,则表示无上级层级,从1开始
|
|
|
+ if (parentInfo != null) {
|
|
|
+ String s = parentInfo.getSort() + "01";
|
|
|
+ type.setSort(Integer.parseInt(s));
|
|
|
+ } else {
|
|
|
+ type.setSort(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 生成层级
|
|
|
+ //查询层级
|
|
|
+ Integer level = mapper.getLevel(type.getParentId());
|
|
|
+ if (level != null) {
|
|
|
+ type.setLevel(level.toString());
|
|
|
+ } else {
|
|
|
+ // 父节点存在,根据父节点level生成,不存在,则表示无上级层级,从1开始
|
|
|
+ if (parentInfo != null) {
|
|
|
+ Integer i = Integer.parseInt(parentInfo.getLevel())+1;
|
|
|
+ type.setLevel(i.toString());
|
|
|
+ } else {
|
|
|
+ type.setLevel("1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+}
|