| | |
| | | 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; |
| | |
| | | @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){ |
| | | columnEntity = ColumnConversion.INSTANCE.updateDtoToEntity(adminUpdateColumnDto); |
| | | |
| | | ColumnEntity hasExist = this.baseMapper.selectByCodeAndCompanyId(columnCode, companyId); |
| | | if(ObjectUtil.isNotEmpty(hasExist)){ |
| | | return Result.fail("栏目编码不能重复"); |
| | | } |
| | | |
| | | // 判断是否编辑了栏目编码且此时栏目处于已发布的状态,然后保存之前的编码。因为如果是未发布状态,多次保存的话,容易覆盖真正的最开始的栏目编码 |
| | | if (!columnEntity.getColumnCode().equals(columnCode) && columnEntity.getReleaseState() == 1) { |
| | | // 若编码进行了修改且该栏目为父栏目,则需要同步修改子栏目的path。 |
| | | if (!columnEntity.getColumnCode().equals(columnCode) && "-1".equals(columnEntity.getColumnCode())) { |
| | | columnEntity.setBeforeColumnCode(columnCode); |
| | | |
| | | if (adminUpdateColumnDto.getParentId() == 0L) { |
| | | List<ColumnEntity> childColumn = this.baseMapper.selectColumnByParentId(columnEntity.getId(), companyId, 2); |
| | | if (CollUtil.isNotEmpty(childColumn)) { |
| | | for (ColumnEntity child : childColumn) { |
| | | child.setPath(columnEntity.getPath() + "/" + child.getColumnCode()); |
| | | this.baseMapper.updateById(child); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | 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) { |
| | | // 栏目修改时,需判断父级ID及栏目编码的修改。若栏目父级ID修改了,则需记录原父级ID,在发布时,需连同原父级栏目同时编译 |
| | | if (!columnEntity.getParentId().equals(parentId) && columnEntity.getParentId() == -1) { |
| | | columnEntity.setBeforeParentId(columnEntity.getParentId()); |
| | | } |
| | | |
| | |
| | | columnEntity.setPath(parent.getPath() + "/" + columnEntity.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); |
| | | return Result.ok("更新成功"); |
| | | } |