src/main/java/com/mzl/flower/config/ResourceServerConfig.java
@@ -58,6 +58,8 @@ .antMatchers("/api/filmWorks/**").permitAll() .antMatchers("/api/film/category/**").permitAll() .antMatchers("/api/filmLocation/**").permitAll() .antMatchers("/api/aiTaskConfig/**").permitAll() .antMatchers("/api/home/homeConfig/**").permitAll() .antMatchers("api/pub/customer/home/**").permitAll() .antMatchers("/api/customer/point/goods/**").permitAll() .antMatchers("/api/upload/oss/file").permitAll() src/main/java/com/mzl/flower/config/RestTemplateConfig.java
对比新文件 @@ -0,0 +1,21 @@ package com.mzl.flower.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; @Configuration public class RestTemplateConfig { @Bean public RestTemplate restTemplate() { RestTemplate restTemplate = new RestTemplate(); // 可选:添加自定义配置 // restTemplate.setErrorHandler(new CustomErrorHandler()); // restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8)); return restTemplate; } } src/main/java/com/mzl/flower/constant/Constants.java
@@ -795,6 +795,21 @@ } } public enum GENERATOR_CONTENT { film_name("影视作品"), film_content("影视内容"); GENERATOR_CONTENT(String desc) { this.desc = desc; } private String desc; public String getDesc() { return desc; } } src/main/java/com/mzl/flower/dto/request/film/AiContentTaskConfigDTO.java
对比新文件 @@ -0,0 +1,24 @@ package com.mzl.flower.dto.request.film; import lombok.Data; import java.util.Date; @Data public class AiContentTaskConfigDTO { private Long id; private String taskName; private String aiParams; private String cron; private Boolean isEnabled; private Date lastRunTime; private String type; private String promptArticle; private String promptRoute; private String promptTravel; private String promptLocaltion; } src/main/java/com/mzl/flower/dto/request/film/AiContentTaskConfigQueryDTO.java
对比新文件 @@ -0,0 +1,30 @@ package com.mzl.flower.dto.request.film; import lombok.Data; import java.util.Date; @Data public class AiContentTaskConfigQueryDTO { private Integer id; private String taskName; private String aiParams; private String cron; /** * 状态(0禁用,1启用) */ private Boolean isEnabled; private Date lastRunTime; private String type; private String promptArticle; private String promptRoute; private String promptTravel; private String promptLocaltion; } src/main/java/com/mzl/flower/dto/request/film/FilmHotCityDTO.java
对比新文件 @@ -0,0 +1,21 @@ package com.mzl.flower.dto.request.film; import lombok.Data; import java.math.BigDecimal; import java.time.LocalDate; @Data public class FilmHotCityDTO { private Long id; private String name; private String cityUrl; private String country; private String continent; private Boolean isEnabled; private String createBy; private String updateBy; private Integer cityWeight; } src/main/java/com/mzl/flower/dto/request/film/FilmHotCityQueryDTO.java
对比新文件 @@ -0,0 +1,20 @@ package com.mzl.flower.dto.request.film; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class FilmHotCityQueryDTO { @ApiModelProperty(value = "城市名称") private String name; @ApiModelProperty(value = "所在国家") private String country; @ApiModelProperty(value = "所在洲") private String continent; @ApiModelProperty("启用/禁用(USER_ENABLED_OR_DISABLED)") private Integer isEnabled; } src/main/java/com/mzl/flower/dto/response/film/AiContentTaskConfigVO.java
对比新文件 @@ -0,0 +1,43 @@ package com.mzl.flower.dto.response.film; import com.mzl.flower.base.AbstractTransDTO; import com.mzl.flower.base.annotation.DictTrans; import lombok.Data; import java.time.LocalDateTime; import java.util.Date; @Data public class AiContentTaskConfigVO extends AbstractTransDTO { private Long id; private String taskName; private String aiParams; private String cron; /** * 状态(0禁用,1启用) */ private Boolean isEnabled; private Date lastRunTime; /** * 创建者ID */ private String createBy; /** * 最后修改者ID */ private String updateBy; private String type; private String promptArticle; private String promptRoute; private String promptTravel; private String promptLocaltion; } src/main/java/com/mzl/flower/dto/response/film/FilmHotCityVO.java
对比新文件 @@ -0,0 +1,33 @@ package com.mzl.flower.dto.response.film; import com.mzl.flower.base.AbstractTransDTO; import com.mzl.flower.base.annotation.DictTrans; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; import java.time.LocalDate; @Data public class FilmHotCityVO extends AbstractTransDTO { private Long id; @ApiModelProperty("城市名称") private String name; @ApiModelProperty("城市URL") private String cityUrl; @ApiModelProperty("国家") private String country; @ApiModelProperty("洲") private String continent; @ApiModelProperty("是否锁定") private Boolean isEnabled; @ApiModelProperty("热度") private Integer cityWeight; } src/main/java/com/mzl/flower/entity/film/AiContentTaskConfig.java
对比新文件 @@ -0,0 +1,33 @@ package com.mzl.flower.entity.film; import com.baomidou.mybatisplus.annotation.TableName; import com.mzl.flower.base.BaseAutoEntity; import lombok.Data; import java.util.Date; /** * 模型任务配置表 * * @author generator@Fang * @since 2025-07-01 */ @Data @TableName("ai_content_task_config") public class AiContentTaskConfig extends BaseAutoEntity { private String taskName; private String aiParams; private String cron; /** * 状态(0禁用,1启用) */ private Boolean isEnabled; private Date lastRunTime; private String type; private String promptArticle; private String promptRoute; private String promptTravel; private String promptLocaltion; } src/main/java/com/mzl/flower/entity/film/FilmHotCity.java
对比新文件 @@ -0,0 +1,24 @@ package com.mzl.flower.entity.film; import com.baomidou.mybatisplus.annotation.TableName; import com.mzl.flower.base.BaseAutoEntity; import lombok.Data; import java.util.Date; /** * FilmHotCity热门城市表 * * @author generator@Fang * @since 2025-07-01 */ @Data @TableName("film_hot_city") public class FilmHotCity extends BaseAutoEntity { private String name; private String cityUrl; private String country; private String continent; private Boolean isEnabled; private Integer cityWeight; } src/main/java/com/mzl/flower/mapper/film/FilmHotCityMapper.java
对比新文件 @@ -0,0 +1,29 @@ package com.mzl.flower.mapper.film; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.dto.request.film.FilmHotCityQueryDTO; import com.mzl.flower.dto.response.film.FilmHotCityVO; import com.mzl.flower.entity.film.FilmHotCity; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; /** * <p> * FilmHotCity热门城市 Mapper 接口 * </p> * * @author generator@Fang */ public interface FilmHotCityMapper extends BaseMapper<FilmHotCity> { List<FilmHotCityVO> queryPage(@Param("dto") FilmHotCityQueryDTO dto, Page page); @Select("select * from film_hot_city where name = #{name} and deleted = '0' limit 1 ") FilmHotCity selectByName(@Param("name") String name); @Select("select * from film_hot_city where id = #{id} ") FilmHotCityVO selectByIdInfo(Long id); } src/main/java/com/mzl/flower/mapper/film/FilmLocationMapper.java
@@ -42,4 +42,8 @@ "</script>") @MapKey("id") Map<Long, FilmLocationNameDTO> getLocationNamesByIds(@Param("list") List<Long> ids); @Select("select * from film_location where is_enabled = '1' and deleted = '0' order by location_weight desc limit 3") List<FilmLocationVO> getFilmLocationListTop3(); } src/main/java/com/mzl/flower/mapper/film/FilmLocationWorkMapper.java
@@ -1,6 +1,7 @@ package com.mzl.flower.mapper.film; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mzl.flower.dto.response.film.FilmLocationVO; import com.mzl.flower.entity.film.FilmLocationWork; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -35,4 +36,6 @@ "</foreach>" + "</script>") Set<Long> findFilmIdsWithWorks(@Param("list") List<Long> locationIds); } src/main/java/com/mzl/flower/mapper/film/FilmWorksMapper.java
@@ -47,4 +47,7 @@ "</script>") @MapKey("id") List<FilmWorksVO> getFilmWorksByIds(@Param("list") List<Long> ids); @Select("select * from film_works where deleted = '0' and name_cn = #{nameCn} and type = #{type} and release_year = #{releaseYear} limit 1") FilmWorks getFilmWorksByName(@Param("nameCn") String nameCn, @Param("type")String type, @Param("releaseYear") String releaseYear); } src/main/java/com/mzl/flower/schedule/DynamicTaskManager.java
@@ -1,6 +1,7 @@ package com.mzl.flower.schedule; import com.mzl.flower.entity.film.AiContentTaskConfig; import com.mzl.flower.mapper.film.AiContentTaskConfigMapper; import com.mzl.flower.service.film.AiContentTaskConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @@ -8,6 +9,7 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; @@ -19,8 +21,8 @@ @Autowired private ThreadPoolTaskScheduler taskScheduler; @Autowired private AiContentTaskConfigService configService; @Resource private AiContentTaskConfigMapper aiContentTaskConfigMapper; @Autowired private TaskExecutor taskExecutor; @@ -30,7 +32,7 @@ } public synchronized void refreshTasks() { List<AiContentTaskConfig> latestConfigs = configService.getEnabledConfigs(); List<AiContentTaskConfig> latestConfigs = aiContentTaskConfigMapper.getAiContentTaskConfigAll(); Set<Long> latestIds = latestConfigs.stream() .map(AiContentTaskConfig::getId) .collect(Collectors.toSet()); src/main/java/com/mzl/flower/schedule/TaskExecutor.java
@@ -1,11 +1,13 @@ package com.mzl.flower.schedule; import com.mzl.flower.constant.Constants; import com.mzl.flower.entity.film.AiContentTaskConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; import java.util.Date; @@ -28,9 +30,16 @@ System.out.println("定时任务执行 - 时间: " + new Date()); try { // String aiResult = callPythonAiService(paramsJson); // System.out.println("AI 服务返回结果: " + aiResult); System.out.println("开始执行调用AI服务: "); if(Constants.GENERATOR_CONTENT.film_content.name().equals(config.getType())){ System.out.println("开始执行调用内容生成服务: "); String aiResult = callPythonContentService(paramsJson); System.out.println("AI 服务返回结果: " + aiResult); }else{ System.out.println("开始执行调用作品名称生成服务: "); String aiResult = callPythonFilmNameService(paramsJson); System.out.println("AI 服务返回结果: " + aiResult); } // 这里处理结果入库逻辑... } catch (Exception e) { System.err.println("调用 AI 服务失败: " + e.getMessage()); @@ -38,8 +47,24 @@ } } public String callPythonAiService(String paramsJson) { String url = "http://127.0.0.1:5000/crawl-douban"; public String callPythonFilmNameService(String paramsJson) { System.out.println("开始执行调用python crawl: "); String url = "http://14.103.144.28:5000/crawl-douban"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> request = new HttpEntity<>(paramsJson, headers); ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class); return response.getBody(); } public String callPythonContentService(String paramsJson) { System.out.println("开始执行调用python generate: "); // String url = "http://192.168.1.213:5000/generate-film-content"; String url = "http://14.103.144.28:5000/generate-film-content"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); src/main/java/com/mzl/flower/service/film/AiContentTaskConfigService.java
对比新文件 @@ -0,0 +1,39 @@ package com.mzl.flower.service.film; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.mzl.flower.dto.BatchDTO; import com.mzl.flower.dto.request.film.AiContentTaskConfigDTO; import com.mzl.flower.dto.request.film.AiContentTaskConfigQueryDTO; import com.mzl.flower.dto.response.film.AiContentTaskConfigVO; import com.mzl.flower.entity.film.AiContentTaskConfig; import java.util.List; /** * <p> * 模型任务配置表 服务类 * </p> * * @author generator@Fang * @since 2025-05-19 */ public interface AiContentTaskConfigService extends IService<AiContentTaskConfig> { List<AiContentTaskConfigVO> getAiContentTaskConfigAll(); List<AiContentTaskConfigVO> getEnabledAiContentTaskConfig(); Page<AiContentTaskConfigVO> queryPage(AiContentTaskConfigQueryDTO aiContentTaskConfigQueryDTO, Page page); void deleteAiContentTaskConfig(String id); void saveAiContentTaskConfig(AiContentTaskConfigDTO aiContentTaskConfigDTO); void updateAiContentTaskConfig(AiContentTaskConfigDTO aiContentTaskConfigDTO); AiContentTaskConfigVO detail(Long id); //获取配置信息 List<AiContentTaskConfig> getEnabledConfigs(); void batchDelete(BatchDTO dto); } src/main/java/com/mzl/flower/service/film/FilmHotCityService.java
对比新文件 @@ -0,0 +1,33 @@ package com.mzl.flower.service.film; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.mzl.flower.dto.BatchDTO; import com.mzl.flower.dto.request.film.FilmHotCityDTO; import com.mzl.flower.dto.request.film.FilmHotCityQueryDTO; import com.mzl.flower.dto.response.film.FilmHotCityVO; import com.mzl.flower.dto.response.film.FilmWorksVO; import com.mzl.flower.entity.film.FilmHotCity; import java.util.List; /** * <p> * FilmHotCity热门城市表 服务类 * </p> * * @author generator@Fang */ public interface FilmHotCityService extends IService<FilmHotCity> { void saveFilmHotCity(FilmHotCityDTO filmHotCityDTO); void updateFilmHotCity(FilmHotCityDTO filmHotCityDTO); void deleteFilmHotCity(String id); Page<FilmHotCityVO> queryPage(FilmHotCityQueryDTO filmHotCityQueryDTO, Page page); FilmHotCityVO detail(Long id); void isEnable(Long id); void batchDelete(BatchDTO dto); } src/main/java/com/mzl/flower/service/film/FilmLocationService.java
@@ -40,4 +40,6 @@ void batchDelete(BatchDTO dto); List<FilmWorksVO> related(Long locationId); List<FilmLocationVO> getFilmLocationListTop3(); } src/main/java/com/mzl/flower/service/film/impl/AiContentTaskConfigServiceImpl.java
对比新文件 @@ -0,0 +1,175 @@ package com.mzl.flower.service.film.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.dto.BatchDTO; import com.mzl.flower.dto.request.film.AiContentTaskConfigDTO; import com.mzl.flower.dto.request.film.AiContentTaskConfigQueryDTO; import com.mzl.flower.dto.response.film.AiContentTaskConfigVO; import com.mzl.flower.entity.film.AiContentTaskConfig; import com.mzl.flower.entity.system.Role; import com.mzl.flower.mapper.customer.CustomerMapper; import com.mzl.flower.mapper.film.AiContentTaskConfigMapper; import com.mzl.flower.schedule.DynamicTaskManager; import com.mzl.flower.service.film.AiContentTaskConfigService; import com.mzl.flower.service.system.RoleService; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import java.util.ArrayList; import java.util.List; /** * <p> * 影视作品信息表 服务实现类 * </p> * * @author generator@Fang * @since 2025-05-19 */ @Service @Transactional @RequiredArgsConstructor public class AiContentTaskConfigServiceImpl extends ServiceImpl<AiContentTaskConfigMapper, AiContentTaskConfig> implements AiContentTaskConfigService { private final AiContentTaskConfigMapper aiContentTaskConfigMapper; private final CustomerMapper customerMapper; private final RoleService roleService; private final DynamicTaskManager dynamicTaskManager; @Override public List<AiContentTaskConfigVO> getAiContentTaskConfigAll() { return aiContentTaskConfigMapper.getAiContentTaskConfigAllInfo(); } @Override public List<AiContentTaskConfigVO> getEnabledAiContentTaskConfig() { return aiContentTaskConfigMapper.getEnabledAiContentTaskConfig(); } @Override public Page<AiContentTaskConfigVO> queryPage(AiContentTaskConfigQueryDTO dto, Page page) { List<AiContentTaskConfigVO> list = aiContentTaskConfigMapper.queryPage(dto, page); // 测试前端展示用代码,部署发布不适用 page.setRecords(list); return page; } @Override @Transactional public void deleteAiContentTaskConfig(String id) { AiContentTaskConfig filmWork = aiContentTaskConfigMapper.selectById(id); if (filmWork == null) { throw new ValidationException("找不到id为" + id + "的影视作品"); } aiContentTaskConfigMapper.deleteById(id); dynamicTaskManager.refreshTasks(); // 每次删除后刷新定时任务 TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { @Override public void afterCommit() { dynamicTaskManager.refreshTasks(); } }); } @Override @Transactional public void saveAiContentTaskConfig(AiContentTaskConfigDTO aiContentTaskConfigDTO) { //获取当前人员角色,判断是不是编辑角色 List<String> roleIds = new ArrayList<>(); List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); for (Role role : roleList) { roleIds.add(role.getId()); } // if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) { // throw new ValidationException("非编辑角色不能新增"); // } // 转换 AiContentTaskConfig aiContentTaskConfig = new AiContentTaskConfig(); BeanUtils.copyProperties(aiContentTaskConfigDTO, aiContentTaskConfig); aiContentTaskConfig.create(); aiContentTaskConfigMapper.insert(aiContentTaskConfig); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { @Override public void afterCommit() { dynamicTaskManager.refreshTasks(); } }); } @Override @Transactional public void updateAiContentTaskConfig(AiContentTaskConfigDTO aiContentTaskConfigDTO) { AiContentTaskConfig aiContentTaskConfig = new AiContentTaskConfig(); List<String> roleIds = new ArrayList<>(); List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); for (Role role : roleList) { roleIds.add(role.getId()); } // if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) { // throw new ValidationException("非编辑角色不能修改"); // } aiContentTaskConfig = aiContentTaskConfigMapper.selectById(aiContentTaskConfigDTO.getId()); BeanUtils.copyProperties(aiContentTaskConfigDTO, aiContentTaskConfig,"type"); aiContentTaskConfig.update(SecurityUtils.getUserId()); aiContentTaskConfigMapper.updateById(aiContentTaskConfig); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { @Override public void afterCommit() { dynamicTaskManager.refreshTasks(); } }); } @Override public AiContentTaskConfigVO detail(Long id) { // userId 可以是空,因为用户可以登录 String userId = SecurityUtils.getUserId(); AiContentTaskConfigVO aiContentTaskConfigVO = aiContentTaskConfigMapper.selectInfoById(id, userId); if (aiContentTaskConfigVO == null) { return null; } // CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(aiContentTaskConfigVO.getCreateBy()); // if (!ObjectUtils.isEmpty(currentCustomer)) { // aiContentTaskConfigVO.setNickname(currentCustomer.getNickName()); // aiContentTaskConfigVO.setAvatar(currentCustomer.getCover()); // } return aiContentTaskConfigVO; } @Override public List<AiContentTaskConfig> getEnabledConfigs() { return aiContentTaskConfigMapper.getAiContentTaskConfigAll(); } @Override @Transactional public void batchDelete(BatchDTO dto) { aiContentTaskConfigMapper.deleteBatchIds(dto.getIds()); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { @Override public void afterCommit() { dynamicTaskManager.refreshTasks(); } }); } } src/main/java/com/mzl/flower/service/film/impl/FilmHotCityServiceImpl.java
对比新文件 @@ -0,0 +1,132 @@ package com.mzl.flower.service.film.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.dto.BatchDTO; import com.mzl.flower.dto.request.film.FilmHotCityDTO; import com.mzl.flower.dto.request.film.FilmHotCityQueryDTO; import com.mzl.flower.dto.response.film.FilmHotCityVO; import com.mzl.flower.entity.film.FilmHotCity; import com.mzl.flower.mapper.film.FilmHotCityMapper; import com.mzl.flower.mapper.film.FilmWorksMapper; import com.mzl.flower.service.film.FilmHotCityService; import com.mzl.flower.service.system.RoleService; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import java.util.*; /** * <p> * FilmHotCity热门城市表 服务实现类 * </p> * * @author generator@Fang * @since 2025-05-20 */ @Service @Transactional @RequiredArgsConstructor public class FilmHotCityServiceImpl extends ServiceImpl<FilmHotCityMapper, FilmHotCity> implements FilmHotCityService { private final FilmHotCityMapper filmHotCityMapper; private final RoleService roleService; private final FilmWorksMapper filmWorksMapper; @Override public void saveFilmHotCity(FilmHotCityDTO filmHotCityDTO) { // 转换 //增加保存时判断是否有城市名称 if (StringUtils.isEmpty(filmHotCityDTO.getName())) { throw new ValidationException("城市名称不能为空"); } FilmHotCity filmHotCity1 = filmHotCityMapper.selectByName(filmHotCityDTO.getName()); if (!ObjectUtils.isEmpty(filmHotCity1)) { throw new ValidationException("城市名称重复"); } FilmHotCity filmHotCity = new FilmHotCity(); BeanUtils.copyProperties(filmHotCityDTO, filmHotCity); filmHotCity.setIsEnabled(false); filmHotCity.create(); filmHotCityMapper.insert(filmHotCity); } @Override public void updateFilmHotCity(FilmHotCityDTO filmHotCityDTO) { if (StringUtils.isEmpty(filmHotCityDTO.getName())) { throw new ValidationException("城市名称不能为空"); } //增加修改时保存得城市名称是否有重复,排除当前这条 FilmHotCity filmHotCity1 = filmHotCityMapper.selectByName(filmHotCityDTO.getName()); FilmHotCity filmHotCity = filmHotCityMapper.selectById(filmHotCityDTO.getId()); if (!filmHotCity1.getId().equals(filmHotCity.getId())) { throw new ValidationException("城市名称重复"); } BeanUtils.copyProperties(filmHotCityDTO, filmHotCity, "isEnabled"); filmHotCity.update(SecurityUtils.getUserId()); filmHotCityMapper.updateById(filmHotCity); } @Override public void deleteFilmHotCity(String id) { FilmHotCity filmHotCity = filmHotCityMapper.selectById(id); if (filmHotCity == null) { throw new ValidationException("找不到id为" + id + "的城市"); } filmHotCityMapper.deleteById(id); } @Override public Page<FilmHotCityVO> queryPage(FilmHotCityQueryDTO dto, Page page) { List<FilmHotCityVO> list = filmHotCityMapper.queryPage(dto, page); page.setRecords(list); return page; } @Override public FilmHotCityVO detail(Long id) { FilmHotCityVO filmHotCityVO = filmHotCityMapper.selectByIdInfo(id); if (filmHotCityVO == null) { return null; } return filmHotCityVO; } @Override public void isEnable(Long id) { FilmHotCity filmHotCity = filmHotCityMapper.selectById(id); if (filmHotCity == null) { throw new ValidationException("找不到id为" + id + "的城市"); } if (filmHotCity.getIsEnabled()) { filmHotCity.setIsEnabled(false); } else { filmHotCity.setIsEnabled(true); } filmHotCity.update(SecurityUtils.getUserId()); filmHotCityMapper.updateById(filmHotCity); } @Override @Transactional public void batchDelete(BatchDTO dto) { if (CollectionUtils.isEmpty(dto.getIds())) { throw new ValidationException("删除ID列表不能为空"); } filmHotCityMapper.deleteBatchIds(dto.getIds()); } } src/main/java/com/mzl/flower/service/film/impl/FilmLocationServiceImpl.java
@@ -66,6 +66,13 @@ BeanUtils.copyProperties(filmLocationDTO, filmLocation); filmLocation.create(); filmLocationMapper.insert(filmLocation); //此处传入参数是否有影视作品ID,如果不等于空,则需要保存关联关系 if (!StringUtils.isEmpty(filmLocationDTO.getFilmId())) { FilmLocationWork filmLocationWork = new FilmLocationWork(); filmLocationWork.setFilmId(filmLocationDTO.getFilmId()); filmLocationWork.setLocationId(filmLocation.getId()); filmLocationWorkMapper.insert(filmLocationWork); } } @Override @@ -238,6 +245,11 @@ } } @Override public List<FilmLocationVO> getFilmLocationListTop3() { return filmLocationMapper.getFilmLocationListTop3(); } private void updateLocationRelations(Long targetId, List<Long> mergeIds) { // 查询所有待更新的工作记录 LambdaQueryWrapper<FilmLocationWork> query = new LambdaQueryWrapper<>(); src/main/java/com/mzl/flower/service/film/impl/FilmWorksServiceImpl.java
@@ -62,11 +62,16 @@ if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) { throw new ValidationException("非编辑角色不能新增"); } // 判断系统是否存在重复的名称+类型+年份,如果有就不保存 FilmWorks filmWorksByName = filmWorksMapper.getFilmWorksByName(filmWorksDTO.getNameCn(), filmWorksDTO.getType(), filmWorksDTO.getReleaseYear()); if (!ObjectUtils.isEmpty(filmWorksByName)) { throw new ValidationException("系统已存在名称为【" + filmWorksDTO.getNameCn() + "】,类型为【" + filmWorksDTO.getType() + "】,年份为【" + filmWorksDTO.getReleaseYear() + "】的影视作品"); } // 转换 FilmWorks filmWorks = new FilmWorks(); BeanUtils.copyProperties(filmWorksDTO, filmWorks); filmWorks.create(); filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_review.name()); filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_create.name()); filmWorksMapper.insert(filmWorks); } src/main/java/com/mzl/flower/service/system/WeChatService.java
@@ -166,22 +166,29 @@ throw new ValidationException("微信code为空"); } String accessToken=""; try { accessToken=maService.getAccessToken(); } catch (WxErrorException e) { throw new RuntimeException(e); } // String accessToken=""; // try { // accessToken=maService.getAccessToken(); // } catch (WxErrorException e) { // throw new RuntimeException(e); // } // // if(StringUtils.isEmpty(accessToken)){ // accessToken=getAccessToken( // wxMiniappProperties.getCustomer().getAppid(), // wxMiniappProperties.getCustomer().getSecret()); // if(StringUtils.isEmpty(accessToken)){ // throw new ValidationException("获取微信AccessToken失败"); // } // } // 直接使用手动获取token的方式(跳过WxMaService的token) String accessToken = getAccessToken( wxMiniappProperties.getCustomer().getAppid(), wxMiniappProperties.getCustomer().getSecret()); if(StringUtils.isEmpty(accessToken)){ accessToken=getAccessToken( wxMiniappProperties.getCustomer().getAppid(), wxMiniappProperties.getCustomer().getSecret()); if(StringUtils.isEmpty(accessToken)){ throw new ValidationException("获取微信AccessToken失败"); } throw new ValidationException("获取微信AccessToken失败"); } String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+ accessToken; try{ src/main/java/com/mzl/flower/web/film/AiContentTaskConfigController.java
对比新文件 @@ -0,0 +1,81 @@ package com.mzl.flower.web.film; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.base.BaseController; import com.mzl.flower.base.R; import com.mzl.flower.base.ReturnDataDTO; import com.mzl.flower.constant.Constants; import com.mzl.flower.dto.request.film.AiContentTaskConfigDTO; import com.mzl.flower.dto.request.film.AiContentTaskConfigQueryDTO; import com.mzl.flower.dto.response.film.AiContentTaskConfigVO; import com.mzl.flower.schedule.TaskExecutor; import com.mzl.flower.service.film.AiContentTaskConfigService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotNull; import java.util.List; /** * @author fanghaowei * @version version2.0 * @className FilmWorksController * @date 2024/8/26 * @description 模型任务配置 */ @Api(value = "模型任务配置", tags = "模型任务配置") @RestController @RequestMapping("/api") @RequiredArgsConstructor public class AiContentTaskConfigController extends BaseController { private final AiContentTaskConfigService aiContentTaskConfigService; private final TaskExecutor taskExecutor; @GetMapping("/aiTaskConfig/all") @ApiOperation(value = "模型任务配置列表", httpMethod = "GET") public ResponseEntity<ReturnDataDTO<List<AiContentTaskConfigVO>>> getFilmWorksAll() { return returnData(R.SUCCESS.getCode(), aiContentTaskConfigService.getEnabledAiContentTaskConfig()); } @GetMapping("/aiTaskConfig/list") @ApiOperation(value = "模型任务配置列表", httpMethod = "GET") public ResponseEntity<ReturnDataDTO<Page<AiContentTaskConfigVO>>> getFilmWorksList(Page page, AiContentTaskConfigQueryDTO dto) { dto.setType(Constants.GENERATOR_CONTENT.film_content.name()); return returnData(R.SUCCESS.getCode(), aiContentTaskConfigService.queryPage(dto, page)); } @GetMapping(value = "/aiTaskConfig/delete") @ApiOperation(value = "删除模型任务配置 ", httpMethod = "GET", notes = "ID") public ResponseEntity delete(@NotNull(message = "id不能为空") Long id) { aiContentTaskConfigService.deleteAiContentTaskConfig(String.valueOf(id)); return returnData(R.SUCCESS.getCode(), null); } @PostMapping(value = "/aiTaskConfig/new") @ApiOperation(value = "保存模型任务配置", httpMethod = "POST") public ResponseEntity insert(@RequestBody AiContentTaskConfigDTO aiContentTaskConfigDTO) { aiContentTaskConfigDTO.setType(Constants.GENERATOR_CONTENT.film_content.name()); aiContentTaskConfigService.saveAiContentTaskConfig(aiContentTaskConfigDTO); return returnData(R.SUCCESS.getCode(), null); } @PostMapping(value = "/aiTaskConfig/edit") @ApiOperation(value = "更新模型任务配置", httpMethod = "POST") public ResponseEntity update(@RequestBody AiContentTaskConfigDTO aiContentTaskConfigDTO) { aiContentTaskConfigService.updateAiContentTaskConfig(aiContentTaskConfigDTO); return returnData(R.SUCCESS.getCode(), null); } @GetMapping("/aiTaskConfig/list/view") @ApiOperation(value = "详情", notes = "详情") public ResponseEntity<ReturnDataDTO<AiContentTaskConfigVO>> detail(@NotNull(message = "id不能为空") Long id) { return returnData(R.SUCCESS.getCode(),aiContentTaskConfigService.detail(id)); } } src/main/java/com/mzl/flower/web/film/FilmContentTaskConfigController.java
对比新文件 @@ -0,0 +1,91 @@ package com.mzl.flower.web.film; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.base.BaseController; import com.mzl.flower.base.R; import com.mzl.flower.base.ReturnDataDTO; import com.mzl.flower.constant.Constants; import com.mzl.flower.dto.BatchDTO; import com.mzl.flower.dto.request.film.AiContentTaskConfigDTO; import com.mzl.flower.dto.request.film.AiContentTaskConfigQueryDTO; import com.mzl.flower.dto.response.film.AiContentTaskConfigVO; import com.mzl.flower.schedule.TaskExecutor; import com.mzl.flower.service.film.AiContentTaskConfigService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotNull; import java.util.List; /** * @author fanghaowei * @version version2.0 * @className FilmWorksController * @date 2024/8/26 * @description 影视作品任务配置 */ @Api(value = "影视作品任务配置", tags = "影视作品任务配置") @RestController @RequestMapping("/api") @RequiredArgsConstructor public class FilmContentTaskConfigController extends BaseController { private final AiContentTaskConfigService aiContentTaskConfigService; private final TaskExecutor taskExecutor; @GetMapping("/filmTaskConfig/all") @ApiOperation(value = "影视作品任务配置列表", httpMethod = "GET") public ResponseEntity<ReturnDataDTO<List<AiContentTaskConfigVO>>> getFilmWorksAll() { return returnData(R.SUCCESS.getCode(), aiContentTaskConfigService.getAiContentTaskConfigAll()); } @GetMapping("/filmTaskConfig/list") @ApiOperation(value = "影视作品任务配置列表", httpMethod = "GET") public ResponseEntity<ReturnDataDTO<Page<AiContentTaskConfigVO>>> getFilmWorksList(Page page, AiContentTaskConfigQueryDTO dto) { dto.setType(Constants.GENERATOR_CONTENT.film_name.name()); return returnData(R.SUCCESS.getCode(), aiContentTaskConfigService.queryPage(dto, page)); } @GetMapping(value = "/filmTaskConfig/delete") @ApiOperation(value = "删除影视作品任务配置 ", httpMethod = "GET", notes = "ID") public ResponseEntity delete(@NotNull(message = "id不能为空") Long id) { aiContentTaskConfigService.deleteAiContentTaskConfig(String.valueOf(id)); return returnData(R.SUCCESS.getCode(), null); } @PostMapping(value = "/filmTaskConfig/new") @ApiOperation(value = "保存影视作品任务配置", httpMethod = "POST") public ResponseEntity insert(@RequestBody AiContentTaskConfigDTO aiContentTaskConfigDTO) { aiContentTaskConfigDTO.setType(Constants.GENERATOR_CONTENT.film_name.name()); aiContentTaskConfigService.saveAiContentTaskConfig(aiContentTaskConfigDTO); // taskExecutor.callPythonAiService(aiContentTaskConfigDTO.getAiParams()); return returnData(R.SUCCESS.getCode(), null); } @PostMapping(value = "/filmTaskConfig/edit") @ApiOperation(value = "更新影视作品任务配置", httpMethod = "POST") public ResponseEntity update(@RequestBody AiContentTaskConfigDTO aiContentTaskConfigDTO) { aiContentTaskConfigService.updateAiContentTaskConfig(aiContentTaskConfigDTO); return returnData(R.SUCCESS.getCode(), null); } @GetMapping("/filmTaskConfig/list/view") @ApiOperation(value = "详情", notes = "详情") public ResponseEntity<ReturnDataDTO<AiContentTaskConfigVO>> detail(@NotNull(message = "id不能为空") Long id) { return returnData(R.SUCCESS.getCode(),aiContentTaskConfigService.detail(id)); } @PostMapping("/filmTaskConfig/delete/batch") @ApiOperation(value = "批量删除", notes = "批量删除") public ResponseEntity<ReturnDataDTO> batchDelete(@Validated @RequestBody BatchDTO dto) { aiContentTaskConfigService.batchDelete(dto); return returnData(R.SUCCESS.getCode(),null); } } src/main/java/com/mzl/flower/web/film/FilmHotCityController.java
对比新文件 @@ -0,0 +1,87 @@ package com.mzl.flower.web.film; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.base.BaseController; import com.mzl.flower.base.R; import com.mzl.flower.base.ReturnDataDTO; import com.mzl.flower.dto.BatchDTO; import com.mzl.flower.dto.request.film.FilmHotCityDTO; import com.mzl.flower.dto.request.film.FilmHotCityQueryDTO; import com.mzl.flower.dto.response.film.FilmHotCityVO; import com.mzl.flower.service.film.FilmHotCityService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotNull; /** * FilmHotCity热门城市表前端控制器 * * @author generator@Fang */ @Api(value = "热门城市信息管理", tags = "热门城市信息管理") @RestController @RequestMapping("/api") @RequiredArgsConstructor public class FilmHotCityController extends BaseController { private final FilmHotCityService filmHotCityService; @GetMapping("/filmHotCity/list") @ApiOperation(value = "热门城市列表", httpMethod = "GET") public ResponseEntity<ReturnDataDTO<Page<FilmHotCityVO>>> getFilmHotCityList(Page page, FilmHotCityQueryDTO dto) { return returnData(R.SUCCESS.getCode(), filmHotCityService.queryPage(dto, page)); } @GetMapping(value = "/filmHotCity/delete") @ApiOperation(value = "删除热门城市 ", httpMethod = "GET", notes = "ID") public ResponseEntity delete(@NotNull(message = "id不能为空") Long id) { filmHotCityService.deleteFilmHotCity(String.valueOf(id)); return returnData(R.SUCCESS.getCode(), null); } @PostMapping(value = "/filmHotCity/new") @ApiOperation(value = "保存热门城市", httpMethod = "POST") public ResponseEntity insert(@RequestBody FilmHotCityDTO filmHotCityDTO) { filmHotCityService.saveFilmHotCity(filmHotCityDTO); return returnData(R.SUCCESS.getCode(), null); } @PostMapping(value = "/filmHotCity/edit") @ApiOperation(value = "更新热门城市", httpMethod = "POST") public ResponseEntity update(@RequestBody FilmHotCityDTO filmHotCityDTO) { filmHotCityService.updateFilmHotCity(filmHotCityDTO); return returnData(R.SUCCESS.getCode(), null); } @GetMapping("/filmHotCity/list/view") @ApiOperation(value = "详情", notes = "详情") public ResponseEntity<ReturnDataDTO<FilmHotCityVO>> detail(@NotNull(message = "id不能为空") Long id) { return returnData(R.SUCCESS.getCode(), filmHotCityService.detail(id)); } @GetMapping("/filmHotCity/isEnable") @ApiOperation(value = "启用/禁用", notes = "启用/禁用景点") public ResponseEntity<ReturnDataDTO<String>> isEnable(@NotNull(message = "id不能为空") Long id) { filmHotCityService.isEnable(id); return returnData(R.SUCCESS.getCode(), null); } @PostMapping("/filmHotCity/delete/batch") @ApiOperation(value = "批量删除", notes = "批量删除") public ResponseEntity<ReturnDataDTO> batchDelete(@Validated @RequestBody BatchDTO dto) { filmHotCityService.batchDelete(dto); return returnData(R.SUCCESS.getCode(), null); } } src/main/java/com/mzl/flower/web/film/FilmLocationController.java
@@ -42,6 +42,13 @@ return returnData(R.SUCCESS.getCode(), filmLocationService.queryPage(dto, page)); } @GetMapping("/filmLocation/getTop3") @ApiOperation(value = "影视拍摄场地前三", httpMethod = "GET") public ResponseEntity<ReturnDataDTO<List<FilmLocationVO>>> getFilmLocationListTop3() { return returnData(R.SUCCESS.getCode(), filmLocationService.getFilmLocationListTop3()); } @GetMapping(value = "/filmLocation/delete") @ApiOperation(value = "删除影视拍摄场地 ", httpMethod = "GET", notes = "ID") public ResponseEntity delete(@NotNull(message = "id不能为空") Long id) { src/main/resources/application-test.yml
@@ -39,6 +39,7 @@ redis: database: 0 host: 192.168.1.235 # host: 127.0.0.1 password: 123456 port: 6379 src/main/resources/mapper/film/AiContentTaskConfigMapper.xml
对比新文件 @@ -0,0 +1,20 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.mzl.flower.mapper.film.AiContentTaskConfigMapper"> <select id="queryPage" resultType="com.mzl.flower.dto.response.film.AiContentTaskConfigVO"> select t.* from ai_content_task_config t where t.deleted= 0 <if test="dto.taskName != null and dto.taskName != ''"> and t.task_name like concat('%', #{dto.taskName}, '%') </if> <if test="dto.type != null and dto.type != ''"> and t.type = #{dto.type} </if> <if test="dto.isEnabled!=null"> AND t.is_enabled = #{dto.isEnabled} </if> </select> </mapper> src/main/resources/mapper/film/FilmHotCityMapper.xml
对比新文件 @@ -0,0 +1,27 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.mzl.flower.mapper.film.FilmHotCityMapper"> <select id="queryPage" resultType="com.mzl.flower.dto.response.film.FilmHotCityVO"> SELECT t.* FROM film_hot_city t WHERE t.deleted = 0 <if test="dto.name != null and dto.name != ''"> AND t.name LIKE concat('%', #{dto.name},'%') </if> <if test="dto.country != null and dto.country != ''"> AND t.country LIKE concat('%', #{dto.country},'%') </if> <if test="dto.continent != null and dto.continent != ''"> AND t.continent LIKE concat('%', #{dto.continent},'%') </if> <if test="dto.isEnabled!=null"> AND t.is_enabled = #{dto.isEnabled} </if> ORDER BY t.city_weight DESC </select> </mapper>