You've already forked FrameTour-BE
feat(pc): 添加景区项目管理功能
- 新增项目管理相关的 Controller、Service、Mapper 及模型类 - 实现项目分页查询、列表查询、详情查询、新增、修改、删除等功能 - 添加项目状态更新和二维码下载功能 - 集成微信小程序二维码生成和存储服务
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
package com.ycwl.basic.controller.pc;
|
||||
|
||||
import com.ycwl.basic.model.pc.project.entity.ProjectEntity;
|
||||
import com.ycwl.basic.model.pc.project.req.ProjectReqQuery;
|
||||
import com.ycwl.basic.model.pc.project.resp.ProjectRespVO;
|
||||
import com.ycwl.basic.service.pc.ProjectService;
|
||||
import com.ycwl.basic.storage.enums.StorageAcl;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.utils.WxMpUtil;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.storage.StorageFactory;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 景区项目管理控制器
|
||||
*
|
||||
* @Author: Claude
|
||||
* @Date: 2025-01-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/project/v1")
|
||||
public class ProjectController {
|
||||
|
||||
@Autowired
|
||||
private ProjectService projectService;
|
||||
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
|
||||
// 分页查询
|
||||
@PostMapping("/page")
|
||||
public ApiResponse page(@RequestBody ProjectReqQuery projectReqQuery) {
|
||||
return ApiResponse.success(projectService.pageQuery(projectReqQuery));
|
||||
}
|
||||
|
||||
// 列表查询
|
||||
@PostMapping("/list")
|
||||
public ApiResponse list(@RequestBody ProjectReqQuery projectReqQuery) {
|
||||
return ApiResponse.success(projectService.list(projectReqQuery));
|
||||
}
|
||||
|
||||
// 详情查询
|
||||
@GetMapping("/getDetails/{id}")
|
||||
public ApiResponse getDetails(@PathVariable("id") Long id) {
|
||||
return ApiResponse.success(projectService.getById(id));
|
||||
}
|
||||
|
||||
// 新增或修改
|
||||
@PostMapping("/addOrUpdate")
|
||||
public ApiResponse addOrUpdate(@RequestBody ProjectEntity project) {
|
||||
return ApiResponse.success(projectService.addOrUpdate(project));
|
||||
}
|
||||
|
||||
// 删除
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse delete(@PathVariable("id") Long id) {
|
||||
return ApiResponse.success(projectService.delete(id));
|
||||
}
|
||||
|
||||
// 修改状态
|
||||
@PutMapping("/updateStatus/{id}")
|
||||
public ApiResponse updateStatus(@PathVariable("id") Long id) {
|
||||
return ApiResponse.success(projectService.updateStatus(id));
|
||||
}
|
||||
|
||||
// 根据项目ID下载小程序二维码
|
||||
@GetMapping("/{id}/QRCode")
|
||||
public ApiResponse<String> downloadQrCode(@PathVariable Long id) {
|
||||
ProjectRespVO project = projectService.getById(id);
|
||||
if (project == null) {
|
||||
return ApiResponse.fail("项目不存在");
|
||||
}
|
||||
MpConfigEntity mpConfig = scenicRepository.getScenicMpConfig(project.getScenicId());
|
||||
if (mpConfig == null) {
|
||||
return ApiResponse.fail("小程序配置不存在");
|
||||
}
|
||||
String appId = mpConfig.getAppId();
|
||||
String appSecret = mpConfig.getAppSecret();
|
||||
String appState = mpConfig.getState();
|
||||
String path = "pages/home/index?scenicId=" + project.getScenicId() + "&projectId=" + id;
|
||||
String filePath = "qr_code_project_" + id + ".jpg";
|
||||
IStorageAdapter adapter = StorageFactory.use();
|
||||
if (adapter.isExists(filePath)) {
|
||||
return ApiResponse.success(adapter.getUrl(filePath));
|
||||
}
|
||||
try {
|
||||
WxMpUtil.generateWXAQRCode(appId, appSecret, appState, path, filePath);
|
||||
File file = new File(filePath);
|
||||
String s = adapter.uploadFile(null, file, filePath);
|
||||
file.delete();
|
||||
adapter.setAcl(StorageAcl.PUBLIC_READ, filePath);
|
||||
return ApiResponse.success(s);
|
||||
} catch (Exception e) {
|
||||
return ApiResponse.fail("生成二维码失败");
|
||||
}
|
||||
}
|
||||
}
|
48
src/main/java/com/ycwl/basic/mapper/ProjectMapper.java
Normal file
48
src/main/java/com/ycwl/basic/mapper/ProjectMapper.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.ycwl.basic.mapper;
|
||||
|
||||
import com.ycwl.basic.model.pc.project.entity.ProjectEntity;
|
||||
import com.ycwl.basic.model.pc.project.req.ProjectReqQuery;
|
||||
import com.ycwl.basic.model.pc.project.resp.ProjectRespVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 景区项目管理Mapper
|
||||
*
|
||||
* @Author: Claude
|
||||
* @Date: 2025-01-15
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProjectMapper {
|
||||
|
||||
/**
|
||||
* 分页查询项目列表
|
||||
*/
|
||||
List<ProjectRespVO> list(ProjectReqQuery projectReqQuery);
|
||||
|
||||
/**
|
||||
* 根据ID查询项目详情
|
||||
*/
|
||||
ProjectRespVO getById(Long id);
|
||||
|
||||
/**
|
||||
* 新增项目
|
||||
*/
|
||||
int add(ProjectEntity project);
|
||||
|
||||
/**
|
||||
* 根据ID删除项目
|
||||
*/
|
||||
int deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 更新项目信息
|
||||
*/
|
||||
int update(ProjectEntity project);
|
||||
|
||||
/**
|
||||
* 更新项目状态
|
||||
*/
|
||||
int updateStatus(Long id);
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.ycwl.basic.model.pc.project.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 景区项目管理实体类
|
||||
*
|
||||
* @Author: Claude
|
||||
* @Date: 2025-01-15
|
||||
*/
|
||||
@Data
|
||||
@TableName("project")
|
||||
public class ProjectEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
private Long scenicId;
|
||||
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 最少游玩时间(分钟)
|
||||
*/
|
||||
private Integer minPlayTime;
|
||||
|
||||
/**
|
||||
* 最长游玩时间(分钟)
|
||||
*/
|
||||
private Integer maxPlayTime;
|
||||
|
||||
/**
|
||||
* 状态,0禁用,1启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private Date createAt;
|
||||
private Date updateAt;
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.ycwl.basic.model.pc.project.req;
|
||||
|
||||
import com.ycwl.basic.model.common.BaseQueryParameterReq;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 项目查询请求参数
|
||||
*
|
||||
* @Author: Claude
|
||||
* @Date: 2025-01-15
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ProjectReqQuery extends BaseQueryParameterReq {
|
||||
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
private Long scenicId;
|
||||
|
||||
/**
|
||||
* 项目名称(模糊查询)
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 状态,0禁用,1启用
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package com.ycwl.basic.model.pc.project.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 项目响应数据
|
||||
*
|
||||
* @Author: Claude
|
||||
* @Date: 2025-01-15
|
||||
*/
|
||||
@Data
|
||||
public class ProjectRespVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
private Long scenicId;
|
||||
|
||||
/**
|
||||
* 景区名称
|
||||
*/
|
||||
private String scenicName;
|
||||
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 最少游玩时间(分钟)
|
||||
*/
|
||||
private Integer minPlayTime;
|
||||
|
||||
/**
|
||||
* 最长游玩时间(分钟)
|
||||
*/
|
||||
private Integer maxPlayTime;
|
||||
|
||||
/**
|
||||
* 状态,0禁用,1启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private Date createAt;
|
||||
private Date updateAt;
|
||||
}
|
47
src/main/java/com/ycwl/basic/service/pc/ProjectService.java
Normal file
47
src/main/java/com/ycwl/basic/service/pc/ProjectService.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.ycwl.basic.service.pc;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.model.pc.project.entity.ProjectEntity;
|
||||
import com.ycwl.basic.model.pc.project.req.ProjectReqQuery;
|
||||
import com.ycwl.basic.model.pc.project.resp.ProjectRespVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 景区项目管理服务接口
|
||||
*
|
||||
* @Author: Claude
|
||||
* @Date: 2025-01-15
|
||||
*/
|
||||
public interface ProjectService {
|
||||
|
||||
/**
|
||||
* 分页查询项目列表
|
||||
*/
|
||||
PageInfo<ProjectRespVO> pageQuery(ProjectReqQuery projectReqQuery);
|
||||
|
||||
/**
|
||||
* 查询项目列表
|
||||
*/
|
||||
List<ProjectRespVO> list(ProjectReqQuery projectReqQuery);
|
||||
|
||||
/**
|
||||
* 根据ID查询项目详情
|
||||
*/
|
||||
ProjectRespVO getById(Long id);
|
||||
|
||||
/**
|
||||
* 新增或修改项目
|
||||
*/
|
||||
int addOrUpdate(ProjectEntity project);
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
*/
|
||||
int delete(Long id);
|
||||
|
||||
/**
|
||||
* 更新项目状态
|
||||
*/
|
||||
int updateStatus(Long id);
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
package com.ycwl.basic.service.pc.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.mapper.ProjectMapper;
|
||||
import com.ycwl.basic.model.pc.project.entity.ProjectEntity;
|
||||
import com.ycwl.basic.model.pc.project.req.ProjectReqQuery;
|
||||
import com.ycwl.basic.model.pc.project.resp.ProjectRespVO;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.service.pc.ProjectService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 景区项目管理服务实现
|
||||
*
|
||||
* @Author: Claude
|
||||
* @Date: 2025-01-15
|
||||
*/
|
||||
@Service
|
||||
public class ProjectServiceImpl implements ProjectService {
|
||||
|
||||
@Autowired
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
|
||||
@Override
|
||||
public PageInfo<ProjectRespVO> pageQuery(ProjectReqQuery projectReqQuery) {
|
||||
PageHelper.startPage(projectReqQuery.getPageNum(), projectReqQuery.getPageSize());
|
||||
List<ProjectRespVO> list = projectMapper.list(projectReqQuery);
|
||||
|
||||
// 批量获取景区名称
|
||||
List<Long> scenicIds = list.stream()
|
||||
.map(ProjectRespVO::getScenicId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
|
||||
|
||||
// 设置景区名称
|
||||
list.forEach(item -> {
|
||||
if (item.getScenicId() != null) {
|
||||
item.setScenicName(scenicNames.get(item.getScenicId()));
|
||||
}
|
||||
});
|
||||
|
||||
PageInfo<ProjectRespVO> pageInfo = new PageInfo(list);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectRespVO> list(ProjectReqQuery projectReqQuery) {
|
||||
List<ProjectRespVO> list = projectMapper.list(projectReqQuery);
|
||||
|
||||
// 批量获取景区名称
|
||||
List<Long> scenicIds = list.stream()
|
||||
.map(ProjectRespVO::getScenicId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
|
||||
|
||||
// 设置景区名称
|
||||
list.forEach(item -> {
|
||||
if (item.getScenicId() != null) {
|
||||
item.setScenicName(scenicNames.get(item.getScenicId()));
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectRespVO getById(Long id) {
|
||||
return projectMapper.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addOrUpdate(ProjectEntity project) {
|
||||
Long id = project.getId();
|
||||
if (id == null) {
|
||||
return projectMapper.add(project);
|
||||
} else {
|
||||
return projectMapper.update(project);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return projectMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateStatus(Long id) {
|
||||
return projectMapper.updateStatus(id);
|
||||
}
|
||||
}
|
59
src/main/resources/mapper/ProjectMapper.xml
Normal file
59
src/main/resources/mapper/ProjectMapper.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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.ycwl.basic.mapper.ProjectMapper">
|
||||
<insert id="add">
|
||||
insert into project(scenic_id, `name`, min_play_time, max_play_time, status, create_at, update_at)
|
||||
values (#{scenicId}, #{name}, #{minPlayTime}, #{maxPlayTime}, #{status}, now(), now())
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update project set
|
||||
`name` = #{name},
|
||||
min_play_time = #{minPlayTime},
|
||||
max_play_time = #{maxPlayTime},
|
||||
status = #{status},
|
||||
update_at = now()
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateStatus">
|
||||
update project
|
||||
set status = (CASE
|
||||
status
|
||||
WHEN 1 THEN
|
||||
0
|
||||
WHEN 0 THEN
|
||||
1
|
||||
ELSE 1
|
||||
END),
|
||||
update_at = now()
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from project where id = #{id}
|
||||
</delete>
|
||||
|
||||
<select id="list" resultType="com.ycwl.basic.model.pc.project.resp.ProjectRespVO">
|
||||
select p.id, p.scenic_id, p.`name`, p.min_play_time, p.max_play_time, p.status, p.create_at, p.update_at
|
||||
from project p
|
||||
<where>
|
||||
<if test="scenicId != null">
|
||||
and p.scenic_id = #{scenicId}
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
and p.`name` like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and p.`status` = #{status}
|
||||
</if>
|
||||
</where>
|
||||
order by p.create_at desc
|
||||
</select>
|
||||
|
||||
<select id="getById" resultType="com.ycwl.basic.model.pc.project.resp.ProjectRespVO">
|
||||
select p.id, p.scenic_id, p.`name`, p.min_play_time, p.max_play_time, p.status, p.create_at, p.update_at
|
||||
from project p
|
||||
where p.id = #{id}
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user