From ef5505e22c84a63d966f35cee78afa544ece57df Mon Sep 17 00:00:00 2001 From: wzy <wzy19931122ai@163.com> Date: Sun, 07 Aug 2022 14:33:32 +0800 Subject: [PATCH] fix --- src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java | 87 +++++++++++++++++++------------------------ 1 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java index 7498eb2..7e9986d 100644 --- a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java +++ b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.farmer.cms.common.contants.AppContants; import com.xcong.farmer.cms.common.response.Result; +import com.xcong.farmer.cms.conversion.ColumnConversion; import com.xcong.farmer.cms.modules.system.dto.AdminAddColumnDto; import com.xcong.farmer.cms.modules.system.dto.AdminColumnDto; import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto; @@ -187,67 +188,55 @@ @Override @Transactional public Result updateColumn(AdminUpdateColumnDto adminUpdateColumnDto) { - UserEntity userlogin = LoginUserUtil.getLoginUser(); - long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); - Long id = adminUpdateColumnDto.getId(); - if(ObjectUtil.isEmpty(id)){ - return Result.fail("栏目不存在"); - } - ColumnEntity columnEntity = this.baseMapper.selectById(id); + Long companyId = LoginUserUtil.getCompanyId(); + ColumnEntity columnEntity = this.baseMapper.selectById(adminUpdateColumnDto.getId()); if(ObjectUtil.isEmpty(columnEntity)){ return Result.fail("栏目不存在"); } - String columnName = adminUpdateColumnDto.getColumnName(); - columnEntity.setColumnName(columnName); + String columnCode = adminUpdateColumnDto.getColumnCode(); - QueryWrapper<ColumnEntity> objectQueryWrapper = new QueryWrapper<>(); - objectQueryWrapper.eq("column_code",columnCode); - if(UserEntity.USER_BELONG_TOP != companyId){ - objectQueryWrapper.eq("company_id",companyId); - } - List<ColumnEntity> columnEntities = this.baseMapper.selectList(objectQueryWrapper); - if(CollUtil.isNotEmpty(columnEntities) && columnEntities.size() > 1){ - return Result.fail("栏目编码不能重复"); + ColumnEntity updateEntity = ColumnConversion.INSTANCE.updateDtoToEntity(adminUpdateColumnDto); + + if (!columnEntity.getColumnCode().equals(columnCode)) { + ColumnEntity hasExist = this.baseMapper.selectByCodeAndCompanyId(columnCode, companyId); + if (ObjectUtil.isNotEmpty(hasExist)) { + return Result.fail("栏目编码不能重复"); + } } - // 判断是否编辑了栏目编码且此时栏目处于已发布的状态,然后保存之前的编码。因为如果是未发布状态,多次保存的话,容易覆盖真正的最开始的栏目编码 - if (!columnEntity.getColumnCode().equals(columnCode) && columnEntity.getReleaseState() == 1) { - columnEntity.setBeforeColumnCode(columnCode); - } - columnEntity.setColumnCode(columnCode); - - String remark = adminUpdateColumnDto.getRemark(); - columnEntity.setRemark(remark); - String pic = adminUpdateColumnDto.getPic(); - columnEntity.setPic(pic); - Integer orderNum = adminUpdateColumnDto.getOrderNum(); - if(ObjectUtil.isNotEmpty(orderNum)){ - columnEntity.setOrderNum(orderNum); - } Long parentId = adminUpdateColumnDto.getParentId(); - // 同栏目编码 - if (!columnEntity.getParentId().equals(parentId) && columnEntity.getReleaseState() == 1) { - columnEntity.setBeforeParentId(columnEntity.getParentId()); - } - if(ObjectUtil.isEmpty(parentId)){ - columnEntity.setParentId(ColumnEntity.PARENTID_DEFAULT); - columnEntity.setPath("/" + columnEntity.getColumnCode()); + updateEntity.setParentId(ColumnEntity.PARENTID_DEFAULT); + updateEntity.setPath("/" + updateEntity.getColumnCode()); }else{ - columnEntity.setParentId(parentId); + updateEntity.setParentId(parentId); ColumnEntity parent = this.baseMapper.selectById(parentId); - columnEntity.setPath(parent.getPath() + "/" + columnEntity.getColumnCode()); + updateEntity.setPath(parent.getPath() + "/" + updateEntity.getColumnCode()); } - columnEntity.setListTemplate(adminUpdateColumnDto.getListTemplate()); - columnEntity.setArticleTemplate(adminUpdateColumnDto.getArticleTemplate()); - columnEntity.setType(adminUpdateColumnDto.getType()); - columnEntity.setTargetType(adminUpdateColumnDto.getTargetType()); - columnEntity.setTargetUrl(adminUpdateColumnDto.getTargetUrl()); - columnEntity.setIsNav(adminUpdateColumnDto.getIsNav()); - columnEntity.setContentType(adminUpdateColumnDto.getContentType()); - columnEntity.setReleaseState(2); - this.baseMapper.updateById(columnEntity); + // 若编码进行了修改且该栏目为父栏目,则需要同步修改子栏目的path。 + if (!columnEntity.getColumnCode().equals(columnCode)) { + if ("-1".equals(columnEntity.getBeforeColumnCode())) { + updateEntity.setBeforeColumnCode(columnEntity.getColumnCode()); + } + + if (updateEntity.getParentId() == 0L) { + List<ColumnEntity> childColumn = this.baseMapper.selectColumnByParentId(columnEntity.getId(), companyId, 2); + if (CollUtil.isNotEmpty(childColumn)) { + for (ColumnEntity child : childColumn) { + child.setPath(updateEntity.getPath() + "/" + child.getColumnCode()); + this.baseMapper.updateById(child); + } + } + } + } + + // 栏目修改时,需判断父级ID及栏目编码的修改。若栏目父级ID修改了,则需记录原父级ID,在发布时,需连同原父级栏目同时编译 + if (!columnEntity.getParentId().equals(updateEntity.getParentId()) && columnEntity.getBeforeParentId() == -1) { + updateEntity.setBeforeParentId(columnEntity.getParentId()); + } + + this.baseMapper.updateById(updateEntity); return Result.ok("更新成功"); } -- Gitblit v1.9.1