行业分类分页查询脚本错误以及更新接口

This commit is contained in:
sunflower2014 2025-05-28 00:17:23 +08:00
parent cd2751e633
commit 7d8243c4f6
5 changed files with 47 additions and 8 deletions

View File

@ -7,11 +7,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import com.jinrui.reference.admin.controller.NewsController;
import com.jinrui.reference.core.model.vo.ResultObject;
import com.jinrui.reference.core.model.vo.news.NewsDetailVO;
import com.jinrui.reference.core.service.NewsService;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisPoolConfig;
@ -26,7 +21,6 @@ public class AdminApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args); SpringApplication.run(AdminApplication.class, args);
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
} }
@Bean @Bean

View File

@ -81,6 +81,24 @@ public class IndustryController {
return industryService.delete(saveIndustryDTO.getId()); return industryService.delete(saveIndustryDTO.getId());
} }
@PostMapping("/update")
public ResultObject<Void> update(@RequestHeader("auth-token") String token,
@RequestBody SaveIndustryDTO saveIndustryDTO
) {
AdminUser adminUser = AdminJwtService.parseToken(token);
if (adminUser == null) {
log.warn("解析token {}拿不到AdminUser对象!", token);
return ResultObject.failed("登陆Token有误请联系系统管理员!");
}
if (!adminUser.isActive()) {
log.warn("当前用户已被封禁! id = {}", adminUser.getId());
return ResultObject.failed("当前用户已被封禁!请联系系统管理员!");
}
return industryService.update(saveIndustryDTO.getId(), saveIndustryDTO.getPrimaryName(), saveIndustryDTO.getSecondaryName());
}
/** /**
* 行业分类搜索接口 * 行业分类搜索接口
* *

View File

@ -31,11 +31,12 @@ public class NewsController {
private final NewsService newsService; private final NewsService newsService;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
public NewsController(NewsService newsService, public NewsController(NewsService newsService,
ObjectMapper objectMapper) { ObjectMapper objectMapper) {
this.newsService = newsService; this.newsService = newsService;
this.objectMapper = objectMapper; this.objectMapper = objectMapper;;
} }
@PostMapping("/publish") @PostMapping("/publish")

View File

@ -41,6 +41,12 @@ public interface IndustryMapper {
@Select("select * from industry where secondary_name = #{secondaryName} and parent_id = #{parentId}") @Select("select * from industry where secondary_name = #{secondaryName} and parent_id = #{parentId}")
Industry querySecondaryIndustry(Long parentId,String secondaryName); Industry querySecondaryIndustry(Long parentId,String secondaryName);
@Select("select * from industry where secondary_name = #{secondaryName}")
Industry querySecondaryIndustryByName(String secondaryName);
@Insert("update industry set parent_id = #{parentId},primary_name=#{primaryName}, secondary_name= #{secondaryName}, update_time=now() where id=#{id}")
void updateIndustry(@Param("id") Long id,@Param("parentId") Long parentId, @Param("primaryName") String primaryName,@Param("secondaryName") String secondaryName);
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@Insert("insert into industry(parent_id, primary_name, secondary_name, create_time, update_time) values (#{parentId}, #{primaryName}, #{secondaryName}, now(), now())") @Insert("insert into industry(parent_id, primary_name, secondary_name, create_time, update_time) values (#{parentId}, #{primaryName}, #{secondaryName}, now(), now())")
void saveIndustry(Industry industry); void saveIndustry(Industry industry);
@ -76,7 +82,7 @@ public interface IndustryMapper {
"and primary_name like concat('%', #{keyword}, '%') or secondary_name like concat('%', #{keyword}, '%') " + "and primary_name like concat('%', #{keyword}, '%') or secondary_name like concat('%', #{keyword}, '%') " +
"</if>" + "</if>" +
"</where>" + "</where>" +
"order by tag.${orderBy} " + "order by industry.${orderBy} " +
"<if test=\"'desc'.equals(direction)\">" + "<if test=\"'desc'.equals(direction)\">" +
"desc" + "desc" +
"</if>" + "</if>" +

View File

@ -64,6 +64,26 @@ public class IndustryService {
return ResultObject.success(); return ResultObject.success();
} }
public ResultObject<Void> update(Long id, String primaryName, String secondaryName) {
Industry industry = industryMapper.queryPrimaryIndustry(primaryName);
if (industry == null) {
Industry primaryIndustry = new Industry();
primaryIndustry.setParentId(0L);
primaryIndustry.setPrimaryName(primaryName);
industryMapper.saveIndustry(primaryIndustry);
industry = primaryIndustry;
}
Industry secondaryIndustry = industryMapper.querySecondaryIndustryByName(secondaryName);
if(secondaryIndustry != null && secondaryIndustry.getId() != id){
return ResultObject.failed("该行业分类已存在!");
}
industryMapper.updateIndustry(id, industry.getId(), primaryName, secondaryName);
return ResultObject.success();
}
/** /**
* 标签搜索接口 * 标签搜索接口
* *