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

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 io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.File; import java.io.File;
@ -60,7 +59,6 @@ public class CategoryController {
@PostMapping("/insert") @PostMapping("/insert")
@ApiOperation("保存") @ApiOperation("保存")
@Transactional(rollbackFor = Exception.class)
public Object insert(@RequestBody CategoryDTO categoryDTO) { public Object insert(@RequestBody CategoryDTO categoryDTO) {
//效验数据 //效验数据
ValidatorUtils.validateEntity(categoryDTO, AddGroup.class, DefaultGroup.class); ValidatorUtils.validateEntity(categoryDTO, AddGroup.class, DefaultGroup.class);
@ -74,10 +72,8 @@ public class CategoryController {
file.createNewFile(); file.createNewFile();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return new Result<>().error("开发指南文件夹创建失败!"); return new Result<>().error("创建开发指南文件夹失败!");
} }
} else {
return new Result<>().error("开发指南文件夹创建失败!");
} }
} }
categoryService.save(categoryDTO); 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.dto.CategoryDTO;
import io.renren.modules.category.entity.Category; import io.renren.modules.category.entity.Category;
import io.renren.modules.category.service.CategoryService; import io.renren.modules.category.service.CategoryService;
import io.renren.modules.resource.dao.AttrDao;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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 @Service
public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category, CategoryDTO> implements CategoryService { public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category, CategoryDTO> implements CategoryService {
@Autowired @Autowired
private CategoryDao categoryDao; private CategoryDao categoryDao;
@Autowired
private AttrDao attrDao;
@Override @Override
public Object getTopCategory() { public Object getTopCategory() {
@ -46,7 +52,7 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
} else { } else {
ArrayList<CategoryDTO> list = new ArrayList<>(); ArrayList<CategoryDTO> list = new ArrayList<>();
categoryDao.selectByParentId(categoryDto.getId()) categoryDao.selectByParentId(categoryDto.getId())
.stream().forEach(item -> { .forEach(item -> {
CategoryDTO dto = new CategoryDTO(); CategoryDTO dto = new CategoryDTO();
BeanUtils.copyProperties(item, dto); BeanUtils.copyProperties(item, dto);
list.add(dto); list.add(dto);
@ -74,8 +80,7 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
.eq("del_flag",0) .eq("del_flag",0)
.eq("is_attr", "true") .eq("is_attr", "true")
.orderByAsc("xh"); .orderByAsc("xh");
List<Category> categories = categoryDao.selectList(wrapper); return categoryDao.selectList(wrapper);
return categories;
} }
@Override @Override
@ -101,4 +106,14 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
public QueryWrapper<Category> getWrapper(Map<String, Object> params) { public QueryWrapper<Category> getWrapper(Map<String, Object> params) {
return null; 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; 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.common.dao.BaseDao;
import io.renren.modules.resource.entity.AttrEntity; import io.renren.modules.resource.entity.AttrEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.sql.SQLOutput;
import java.util.List; import java.util.List;
/** /**
@ -21,4 +18,5 @@ public interface AttrDao extends BaseDao<AttrEntity> {
Integer delete4Resource(@Param("resourceIds") List<Long> idList); 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 url: http://devtest-security-app.hismarttv.com:8080
qdyjj: qdyjj:
ipAndPort: 15.2.21.238:9015 ipAndPort: 15.72.178.136:9494

View File

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