编目修改字段,修改属性表对应字段的值

This commit is contained in:
dinggang 2022-06-06 18:16:37 +08:00
parent c56ba6400e
commit 1c20988f72
5 changed files with 33 additions and 18 deletions

View File

@ -17,7 +17,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.io.File;
@ -60,7 +59,6 @@ public class CategoryController {
@PostMapping("/insert")
@ApiOperation("保存")
@Transactional(rollbackFor = Exception.class)
public Object insert(@RequestBody CategoryDTO categoryDTO) {
//效验数据
ValidatorUtils.validateEntity(categoryDTO, AddGroup.class, DefaultGroup.class);
@ -74,10 +72,8 @@ public class CategoryController {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return new Result<>().error("开发指南文件夹创建失败!");
return new Result<>().error("创建开发指南文件夹失败!");
}
} else {
return new Result<>().error("开发指南文件夹创建失败!");
}
}
categoryService.save(categoryDTO);

View File

@ -8,18 +8,24 @@ import io.renren.modules.category.dao.CategoryDao;
import io.renren.modules.category.dto.CategoryDTO;
import io.renren.modules.category.entity.Category;
import io.renren.modules.category.service.CategoryService;
import io.renren.modules.resource.dao.AttrDao;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category, CategoryDTO> implements CategoryService {
@Autowired
private CategoryDao categoryDao;
@Autowired
private AttrDao attrDao;
@Override
public Object getTopCategory() {
@ -46,7 +52,7 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
} else {
ArrayList<CategoryDTO> list = new ArrayList<>();
categoryDao.selectByParentId(categoryDto.getId())
.stream().forEach(item -> {
.forEach(item -> {
CategoryDTO dto = new CategoryDTO();
BeanUtils.copyProperties(item, dto);
list.add(dto);
@ -74,8 +80,7 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
.eq("del_flag",0)
.eq("is_attr", "true")
.orderByAsc("xh");
List<Category> categories = categoryDao.selectList(wrapper);
return categories;
return categoryDao.selectList(wrapper);
}
@Override
@ -101,4 +106,14 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
public QueryWrapper<Category> getWrapper(Map<String, Object> params) {
return null;
}
@Override
@Transactional
public void update(CategoryDTO categoryDTO) {
super.update(categoryDTO);
String oldName = categoryDao.selectById(categoryDTO.getId()).getName();
if (!oldName.equals(categoryDTO.getName())) {
attrDao.updateAttrType(oldName, categoryDTO.getName());
}
}
}

View File

@ -1,13 +1,10 @@
package io.renren.modules.resource.dao;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.common.dao.BaseDao;
import io.renren.modules.resource.entity.AttrEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.sql.SQLOutput;
import java.util.List;
/**
@ -20,5 +17,6 @@ import java.util.List;
public interface AttrDao extends BaseDao<AttrEntity> {
Integer delete4Resource(@Param("resourceIds") List<Long> idList);
Integer updateAttrType(String oldName, String newName);
}

View File

@ -50,4 +50,4 @@ hisense:
url: http://devtest-security-app.hismarttv.com:8080
qdyjj:
ipAndPort: 15.2.21.238:9015
ipAndPort: 15.72.178.136:9494

View File

@ -21,14 +21,20 @@
</resultMap>
<update id="delete4Resource">
update tb_data_attr
set del_flag = 1,
UPDATE tb_data_attr
SET del_flag = 1,
update_date = now()
where 1 = 1
and data_resource_id in
WHERE 1 = 1
AND data_resource_id IN
<foreach collection="resourceIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>
<update id="updateAttrType">
UPDATE tb_data_attr
SET attr_type = #{newName}
WHERE attr_type = #{oldName}
</update>
</mapper>