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