From f86f962b8813a55ffbddd9a46dbd5f6b9946b5cd Mon Sep 17 00:00:00 2001 From: datou <18319785677@163.com> Date: Tue, 24 Nov 2020 22:02:11 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=8F=96=E6=B6=88=E4=BD=BF=E7=94=A8lombok?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=EF=BC=8CResultInfo=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- share_project/pom.xml | 6 - .../controller/DemandProjectController.java | 35 +++++ .../controller/SkillProjectController.java | 17 +++ .../java/com/share/domain/DemandProject.java | 123 ++++++++++++++++-- .../java/com/share/domain/ResultInfo.java | 88 +++++++++++++ .../java/com/share/domain/SkillProject.java | 114 ++++++++++++++-- .../com/share/domain/UserDemandProject.java | 51 ++++++-- .../com/share/domain/UserSkillProject.java | 55 ++++++-- .../share/mapper/UserSkillProjectMapper.java | 1 - .../share/service/DemandProjectService.java | 21 +++ .../impl/DemandProjectServiceImpl.java | 21 +++ 11 files changed, 492 insertions(+), 40 deletions(-) create mode 100644 share_project/src/main/java/com/share/controller/DemandProjectController.java create mode 100644 share_project/src/main/java/com/share/controller/SkillProjectController.java create mode 100644 share_project/src/main/java/com/share/domain/ResultInfo.java create mode 100644 share_project/src/main/java/com/share/service/DemandProjectService.java create mode 100644 share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java diff --git a/share_project/pom.xml b/share_project/pom.xml index 732f81f2..ffd97c5c 100644 --- a/share_project/pom.xml +++ b/share_project/pom.xml @@ -73,12 +73,6 @@ 1.1.20 - - - org.projectlombok - lombok - 1.18.12 - diff --git a/share_project/src/main/java/com/share/controller/DemandProjectController.java b/share_project/src/main/java/com/share/controller/DemandProjectController.java new file mode 100644 index 00000000..b8c537f7 --- /dev/null +++ b/share_project/src/main/java/com/share/controller/DemandProjectController.java @@ -0,0 +1,35 @@ +package com.share.controller; + +import com.share.domain.DemandProject; +import com.share.domain.ResultInfo; +import com.share.service.DemandProjectService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author 谢佳豪 + * @data 2020/11/24 - 20:12 + * @description 需求项目模块controller层 + */ +@Controller +@ResponseBody +@RequestMapping("/demand") +public class DemandProjectController { + + @Autowired + private DemandProjectService demandProjectService; + + + /** + * post请求 提交需求表单 添加数据 + * @param demandProject 表单数据对象 + * @return + */ + @PostMapping + public ResultInfo addDemandProject(DemandProject demandProject){ + return demandProjectService.addDemandProject(demandProject); + } +} diff --git a/share_project/src/main/java/com/share/controller/SkillProjectController.java b/share_project/src/main/java/com/share/controller/SkillProjectController.java new file mode 100644 index 00000000..a5bff308 --- /dev/null +++ b/share_project/src/main/java/com/share/controller/SkillProjectController.java @@ -0,0 +1,17 @@ +package com.share.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author 谢佳豪 + * @data 2020/11/24 - 20:38 + * @description 技能项目模块controller层 + */ +@Controller +@ResponseBody +@RequestMapping("/skill") +public class SkillProjectController { + +} diff --git a/share_project/src/main/java/com/share/domain/DemandProject.java b/share_project/src/main/java/com/share/domain/DemandProject.java index cde1c827..3e86123b 100644 --- a/share_project/src/main/java/com/share/domain/DemandProject.java +++ b/share_project/src/main/java/com/share/domain/DemandProject.java @@ -1,9 +1,5 @@ package com.share.domain; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString; import java.io.Serializable; import java.util.Date; @@ -13,11 +9,8 @@ import java.util.Date; * @data 2020/11/23 - 22:45 * @description demand_project 需求项目实体类 */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@ToString public class DemandProject implements Serializable { + /** * 项目编号 */ @@ -66,4 +59,118 @@ public class DemandProject implements Serializable { * 截止时间 */ private Date endTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getProjectDesc() { + return projectDesc; + } + + public void setProjectDesc(String projectDesc) { + this.projectDesc = projectDesc; + } + + public String getSubsidy() { + return subsidy; + } + + public void setSubsidy(String subsidy) { + this.subsidy = subsidy; + } + + public Float getPrice() { + return price; + } + + public void setPrice(Float price) { + this.price = price; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getSkill() { + return skill; + } + + public void setSkill(String skill) { + this.skill = skill; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + @Override + public String toString() { + return "DemandProject{" + + "id=" + id + + ", projectName='" + projectName + '\'' + + ", projectDesc='" + projectDesc + '\'' + + ", subsidy='" + subsidy + '\'' + + ", price=" + price + + ", address='" + address + '\'' + + ", skill='" + skill + '\'' + + ", type='" + type + '\'' + + ", method='" + method + '\'' + + ", publisher='" + publisher + '\'' + + ", startTime=" + startTime + + ", endTime=" + endTime + + '}'; + } } diff --git a/share_project/src/main/java/com/share/domain/ResultInfo.java b/share_project/src/main/java/com/share/domain/ResultInfo.java new file mode 100644 index 00000000..c2de8601 --- /dev/null +++ b/share_project/src/main/java/com/share/domain/ResultInfo.java @@ -0,0 +1,88 @@ +package com.share.domain; + + + +/** + * Demo Class + * + * @author 古市 + * @date 2020-04-04 22:28 + **/ +public class ResultInfo { + + /** + * 操作的状态码: + * 成功为1,失败为0,成功但警告为3 + */ + private Integer status; + + /** + * 返回的结果集 + */ + private Object data; + + /** + * 返回的相关信息 + */ + private String message; + + + public static ResultInfo successInfo(){ + return successInfo(null, null); + } + + public static ResultInfo successInfo(String message){ + return successInfo(message, null); + } + + public static ResultInfo successInfo(String message, Object data){ + return new ResultInfo(1, data, message); + } + + public static ResultInfo failInfo(){ + return failInfo(null, null); + } + + public static ResultInfo failInfo(String message){ + return failInfo(message, null); + } + + public static ResultInfo failInfo(String message, Object data){ + return new ResultInfo(0, data, message); + } + + public static ResultInfo warnInfo(String message){ + return new ResultInfo(2, null, message); + } + + + public ResultInfo(Integer status, Object data, String message) { + this.status = status; + this.data = data; + this.message = message; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/share_project/src/main/java/com/share/domain/SkillProject.java b/share_project/src/main/java/com/share/domain/SkillProject.java index 39d7fbbb..966d8786 100644 --- a/share_project/src/main/java/com/share/domain/SkillProject.java +++ b/share_project/src/main/java/com/share/domain/SkillProject.java @@ -1,9 +1,5 @@ package com.share.domain; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString; import java.util.Date; @@ -12,11 +8,8 @@ import java.util.Date; * @data 2020/11/24 - 15:20 * @description skill_project 技能项目表实体类 */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@ToString public class SkillProject { + /** * 项目编号 */ @@ -61,4 +54,109 @@ public class SkillProject { * 截止时间 */ private Date endTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getProjectDesc() { + return projectDesc; + } + + public void setProjectDesc(String projectDesc) { + this.projectDesc = projectDesc; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getSkill() { + return skill; + } + + public void setSkill(String skill) { + this.skill = skill; + } + + public Float getPrice() { + return price; + } + + public void setPrice(Float price) { + this.price = price; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + @Override + public String toString() { + return "SkillProject{" + + "id=" + id + + ", projectName='" + projectName + '\'' + + ", projectDesc='" + projectDesc + '\'' + + ", address='" + address + '\'' + + ", skill='" + skill + '\'' + + ", price=" + price + + ", type='" + type + '\'' + + ", method='" + method + '\'' + + ", publisher='" + publisher + '\'' + + ", startTime=" + startTime + + ", endTime=" + endTime + + '}'; + } } diff --git a/share_project/src/main/java/com/share/domain/UserDemandProject.java b/share_project/src/main/java/com/share/domain/UserDemandProject.java index 06d15888..f1edce58 100644 --- a/share_project/src/main/java/com/share/domain/UserDemandProject.java +++ b/share_project/src/main/java/com/share/domain/UserDemandProject.java @@ -1,9 +1,5 @@ package com.share.domain; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString; import java.io.Serializable; @@ -12,11 +8,8 @@ import java.io.Serializable; * @data 2020/11/24 - 15:08 * @description user_demand_project 用户需求项目关联表的实体类 */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@ToString public class UserDemandProject implements Serializable { + /** * 需求项目id */ @@ -33,4 +26,46 @@ public class UserDemandProject implements Serializable { * 项目状态 TODO(待发布状态--0;待审核状态--1) */ private Integer status; + + public Integer getProjectId() { + return projectId; + } + + public void setProjectId(Integer projectId) { + this.projectId = projectId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + @Override + public String toString() { + return "UserDemandProject{" + + "projectId=" + projectId + + ", username='" + username + '\'' + + ", telephone='" + telephone + '\'' + + ", status=" + status + + '}'; + } } diff --git a/share_project/src/main/java/com/share/domain/UserSkillProject.java b/share_project/src/main/java/com/share/domain/UserSkillProject.java index 918ffd2e..804f9013 100644 --- a/share_project/src/main/java/com/share/domain/UserSkillProject.java +++ b/share_project/src/main/java/com/share/domain/UserSkillProject.java @@ -1,20 +1,15 @@ package com.share.domain; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString; + + +import java.io.Serializable; /** * @author 谢佳豪 * @data 2020/11/24 - 15:25 * @description user_skill_project 用户技能项目关联表的实体类 */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@ToString -public class UserSkillProject { +public class UserSkillProject implements Serializable { /** * 需求项目id */ @@ -31,4 +26,46 @@ public class UserSkillProject { * 项目状态 TODO(待发布状态--0;待审核状态--1) */ private Integer status; + + public Integer getProjectId() { + return projectId; + } + + public void setProjectId(Integer projectId) { + this.projectId = projectId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + @Override + public String toString() { + return "UserSkillProject{" + + "projectId=" + projectId + + ", username='" + username + '\'' + + ", telephone='" + telephone + '\'' + + ", status=" + status + + '}'; + } } diff --git a/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java b/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java index 048cd7a5..d97dcf5c 100644 --- a/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java @@ -1,6 +1,5 @@ package com.share.mapper; -import com.share.domain.UserDemandProject; import com.share.domain.UserSkillProject; import org.springframework.stereotype.Repository; diff --git a/share_project/src/main/java/com/share/service/DemandProjectService.java b/share_project/src/main/java/com/share/service/DemandProjectService.java new file mode 100644 index 00000000..e4deb859 --- /dev/null +++ b/share_project/src/main/java/com/share/service/DemandProjectService.java @@ -0,0 +1,21 @@ +package com.share.service; + + +import com.share.domain.DemandProject; +import com.share.domain.ResultInfo; + +/** + * @author 谢佳豪 + * @data 2020/11/24 - 20:42 + * @description 需求项目模块service接口 + */ +public interface DemandProjectService { + + /** + * 添加需求项目数据 + * @param demandProject 需求项目表单数据 TODO 用户名如何填写到项目表单中! + * @return + */ + ResultInfo addDemandProject(DemandProject demandProject); + +} diff --git a/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java new file mode 100644 index 00000000..2deafdd5 --- /dev/null +++ b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java @@ -0,0 +1,21 @@ +package com.share.service.impl; + +import com.share.domain.DemandProject; +import com.share.domain.ResultInfo; +import com.share.service.DemandProjectService; +import org.springframework.stereotype.Service; + +/** + * @author 谢佳豪 + * @data 2020/11/24 - 20:47 + * @description + */ +@Service +public class DemandProjectServiceImpl implements DemandProjectService { + + @Override + public ResultInfo addDemandProject(DemandProject demandProject) { + + return null; + } +} -- Gitee From 250abbb9c0891b6a98a5dfcb173d39f495e3222c Mon Sep 17 00:00:00 2001 From: kouse <274295865@qq.com> Date: Tue, 24 Nov 2020 22:58:02 +0800 Subject: [PATCH 2/5] =?UTF-8?q?!5=20=E4=BF=AE=E5=A4=8D=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98=20*=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=A1=B9=E7=9B=AE=E4=B8=8D=E8=83=BD=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20*=20*=20!3=20=E5=8F=96=E6=B6=88=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Lombok=E6=8F=92=E4=BB=B6=EF=BC=8C=E6=96=B0=E5=A2=9ERes?= =?UTF-8?q?ultInfo=E7=BB=93=E6=9E=9C=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/share/ShareApplication.java | 2 + .../com/share/controller/TestController.java | 37 +++++++++++++++++++ .../com/share/mapper/DemandProjectMapper.java | 10 +++++ .../com/share/service/ProjectShowService.java | 23 ++++++++++++ .../impl/DemandProjectShowServiceImpl.java | 31 ++++++++++++++++ .../resources/mapper/DemandProjectMapper.xml | 19 ++++++++++ 6 files changed, 122 insertions(+) create mode 100644 share_project/src/main/java/com/share/controller/TestController.java create mode 100644 share_project/src/main/java/com/share/service/ProjectShowService.java create mode 100644 share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java diff --git a/share_project/src/main/java/com/share/ShareApplication.java b/share_project/src/main/java/com/share/ShareApplication.java index 34df01a4..5c8cfbc2 100644 --- a/share_project/src/main/java/com/share/ShareApplication.java +++ b/share_project/src/main/java/com/share/ShareApplication.java @@ -1,9 +1,11 @@ package com.share; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +@MapperScan(basePackages = "com.share.mapper") public class ShareApplication { public static void main(String[] args) { diff --git a/share_project/src/main/java/com/share/controller/TestController.java b/share_project/src/main/java/com/share/controller/TestController.java new file mode 100644 index 00000000..fa36e014 --- /dev/null +++ b/share_project/src/main/java/com/share/controller/TestController.java @@ -0,0 +1,37 @@ +package com.share.controller; + +import com.share.domain.ResultInfo; +import com.share.service.ProjectShowService; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-11-24 22:34 + **/ +@Controller +@RequestMapping("/test") +public class TestController { + + + private ProjectShowService projectShowService; + + @Resource(name = "demandProjectShowService") + public void setProjectShowService(ProjectShowService projectShowService) { + this.projectShowService = projectShowService; + } + + @RequestMapping("/1") + @ResponseBody + public ResultInfo test(){ + return projectShowService.getProjectsByType("美工", 1); + } + + +} diff --git a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java index 020f3e35..73fc0786 100644 --- a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java @@ -1,8 +1,11 @@ package com.share.mapper; import com.share.domain.DemandProject; +import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Repository; +import java.util.List; + /** * @author 谢佳豪 * @data 2020/11/23 - 22:24 @@ -19,4 +22,11 @@ public interface DemandProjectMapper { int insertDemandProject(DemandProject demandProject); + /** + * 通过项目类型获取项目列表 + * @param type + * @param page + * @return + */ + List selectProjectByType(String type, int page); } diff --git a/share_project/src/main/java/com/share/service/ProjectShowService.java b/share_project/src/main/java/com/share/service/ProjectShowService.java new file mode 100644 index 00000000..7e05fbbe --- /dev/null +++ b/share_project/src/main/java/com/share/service/ProjectShowService.java @@ -0,0 +1,23 @@ +package com.share.service; + +import com.share.domain.ResultInfo; +import org.apache.ibatis.annotations.Param; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-11-24 21:30 + **/ +public interface ProjectShowService { + + /** + * 通过项目类型获取相应的项目列表 + * @param type 项目类型 + * @param page 页数 + * @return + */ + ResultInfo getProjectsByType(@Param("type") String type, @Param("page") int page); + + +} diff --git a/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java b/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java new file mode 100644 index 00000000..cca22f10 --- /dev/null +++ b/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java @@ -0,0 +1,31 @@ +package com.share.service.impl; + +import com.share.domain.ResultInfo; +import com.share.domain.SkillProject; +import com.share.mapper.DemandProjectMapper; +import com.share.service.ProjectShowService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-11-24 21:30 + **/ +@Service("demandProjectShowService") +public class DemandProjectShowServiceImpl implements ProjectShowService { + + + private DemandProjectMapper demandProjectMapper; + + @Autowired + public void setDemandProjectMapper(DemandProjectMapper demandProjectMapper) { + this.demandProjectMapper = demandProjectMapper; + } + + @Override + public ResultInfo getProjectsByType(String type, int page) { + return ResultInfo.successInfo("成功", demandProjectMapper.selectProjectByType(type, (page - 1) * 20)); + } +} diff --git a/share_project/src/main/resources/mapper/DemandProjectMapper.xml b/share_project/src/main/resources/mapper/DemandProjectMapper.xml index 1d07d3e6..f3529bb2 100644 --- a/share_project/src/main/resources/mapper/DemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/DemandProjectMapper.xml @@ -4,6 +4,21 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + + + + + + + + + + + + + insert into demand_project @@ -14,4 +29,8 @@ #{type}, #{method}, #{publisher}, #{startTime}, #{endTime}); + + \ No newline at end of file -- Gitee From 853215b04b83213516eeb22190db485642758130 Mon Sep 17 00:00:00 2001 From: datou <18319785677@163.com> Date: Wed, 25 Nov 2020 23:55:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=A8=A1=E5=9D=97v1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DemandProjectController.java | 26 +++-- .../controller/SkillProjectController.java | 23 +++++ .../java/com/share/domain/DemandProject.java | 30 ++++-- .../java/com/share/domain/SkillProject.java | 12 +-- .../com/share/mapper/DemandProjectMapper.java | 8 ++ .../share/service/DemandProjectService.java | 11 ++- .../share/service/SkillProjectService.java | 22 +++++ .../impl/DemandProjectServiceImpl.java | 88 ++++++++++++++++- .../service/impl/SkillProjectServiceImpl.java | 96 +++++++++++++++++++ .../resources/mapper/DemandProjectMapper.xml | 13 ++- .../resources/mapper/SkillProjectMapper.xml | 2 +- 11 files changed, 303 insertions(+), 28 deletions(-) create mode 100644 share_project/src/main/java/com/share/service/SkillProjectService.java create mode 100644 share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java diff --git a/share_project/src/main/java/com/share/controller/DemandProjectController.java b/share_project/src/main/java/com/share/controller/DemandProjectController.java index b8c537f7..11fc5bb1 100644 --- a/share_project/src/main/java/com/share/controller/DemandProjectController.java +++ b/share_project/src/main/java/com/share/controller/DemandProjectController.java @@ -5,9 +5,7 @@ import com.share.domain.ResultInfo; import com.share.service.DemandProjectService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; /** * @author 谢佳豪 @@ -19,17 +17,31 @@ import org.springframework.web.bind.annotation.ResponseBody; @RequestMapping("/demand") public class DemandProjectController { - @Autowired private DemandProjectService demandProjectService; + @Autowired + public void setDemandProjectService(DemandProjectService demandProjectService) { + this.demandProjectService = demandProjectService; + } /** * post请求 提交需求表单 添加数据 * @param demandProject 表单数据对象 + * @param operation 操作符(0-保存、1-发布) + * @return + */ + @PostMapping("/{operation}") + public ResultInfo addDemandProject(@PathVariable String operation, DemandProject demandProject){ + return demandProjectService.addDemandProject(demandProject, operation); + } + + /** + * get请求 获取当前用户发布的需求项目 + * @param username 用户名 * @return */ - @PostMapping - public ResultInfo addDemandProject(DemandProject demandProject){ - return demandProjectService.addDemandProject(demandProject); + @RequestMapping("/{username}") + public ResultInfo getDemandProjectList(@PathVariable String username){ + return demandProjectService.getDemandProjectList(username); } } diff --git a/share_project/src/main/java/com/share/controller/SkillProjectController.java b/share_project/src/main/java/com/share/controller/SkillProjectController.java index a5bff308..ef250f52 100644 --- a/share_project/src/main/java/com/share/controller/SkillProjectController.java +++ b/share_project/src/main/java/com/share/controller/SkillProjectController.java @@ -1,6 +1,12 @@ package com.share.controller; +import com.share.domain.ResultInfo; +import com.share.domain.SkillProject; +import com.share.service.SkillProjectService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -14,4 +20,21 @@ import org.springframework.web.bind.annotation.ResponseBody; @RequestMapping("/skill") public class SkillProjectController { + private SkillProjectService skillProjectService; + + @Autowired + public void setSkillProjectService(SkillProjectService skillProjectService) { + this.skillProjectService = skillProjectService; + } + + /** + * post请求 提交需求表单 添加数据 + * @param skillProject 表单数据对象 + * @param operation 操作符(0-保存、1-发布) + * @return + */ + @PostMapping("/{operation}") + public ResultInfo addSkillProject(@PathVariable String operation, SkillProject skillProject){ + return skillProjectService.addSkillProject(skillProject, operation); + } } diff --git a/share_project/src/main/java/com/share/domain/DemandProject.java b/share_project/src/main/java/com/share/domain/DemandProject.java index 3e86123b..20a12c61 100644 --- a/share_project/src/main/java/com/share/domain/DemandProject.java +++ b/share_project/src/main/java/com/share/domain/DemandProject.java @@ -2,7 +2,6 @@ package com.share.domain; import java.io.Serializable; -import java.util.Date; /** * @author 谢佳豪 @@ -54,11 +53,15 @@ public class DemandProject implements Serializable { /** * 发布时间 */ - private Date startTime; + private String startTime; /** * 截止时间 */ - private Date endTime; + private String endTime; + /** + * 用户需求项目关联 + */ + private UserDemandProject userDemandProject; public Integer getId() { return id; @@ -140,22 +143,30 @@ public class DemandProject implements Serializable { this.publisher = publisher; } - public Date getStartTime() { + public String getStartTime() { return startTime; } - public void setStartTime(Date startTime) { + public void setStartTime(String startTime) { this.startTime = startTime; } - public Date getEndTime() { + public String getEndTime() { return endTime; } - public void setEndTime(Date endTime) { + public void setEndTime(String endTime) { this.endTime = endTime; } + public UserDemandProject getUserDemandProject() { + return userDemandProject; + } + + public void setUserDemandProject(UserDemandProject userDemandProject) { + this.userDemandProject = userDemandProject; + } + @Override public String toString() { return "DemandProject{" + @@ -169,8 +180,9 @@ public class DemandProject implements Serializable { ", type='" + type + '\'' + ", method='" + method + '\'' + ", publisher='" + publisher + '\'' + - ", startTime=" + startTime + - ", endTime=" + endTime + + ", startTime='" + startTime + '\'' + + ", endTime='" + endTime + '\'' + + ", userDemandProject=" + userDemandProject + '}'; } } diff --git a/share_project/src/main/java/com/share/domain/SkillProject.java b/share_project/src/main/java/com/share/domain/SkillProject.java index 966d8786..653b68ca 100644 --- a/share_project/src/main/java/com/share/domain/SkillProject.java +++ b/share_project/src/main/java/com/share/domain/SkillProject.java @@ -49,11 +49,11 @@ public class SkillProject { /** * 发布时间 */ - private Date startTime; + private String startTime; /** * 截止时间 */ - private Date endTime; + private String endTime; public Integer getId() { return id; @@ -127,19 +127,19 @@ public class SkillProject { this.publisher = publisher; } - public Date getStartTime() { + public String getStartTime() { return startTime; } - public void setStartTime(Date startTime) { + public void setStartTime(String startTime) { this.startTime = startTime; } - public Date getEndTime() { + public String getEndTime() { return endTime; } - public void setEndTime(Date endTime) { + public void setEndTime(String endTime) { this.endTime = endTime; } diff --git a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java index 73fc0786..08759209 100644 --- a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java @@ -22,6 +22,14 @@ public interface DemandProjectMapper { int insertDemandProject(DemandProject demandProject); + /** + * 根据用户名查询需求项目 + * @param username + * @return + */ + List selectProjectByUsername(String username); + + /** * 通过项目类型获取项目列表 * @param type diff --git a/share_project/src/main/java/com/share/service/DemandProjectService.java b/share_project/src/main/java/com/share/service/DemandProjectService.java index e4deb859..5ad47de7 100644 --- a/share_project/src/main/java/com/share/service/DemandProjectService.java +++ b/share_project/src/main/java/com/share/service/DemandProjectService.java @@ -12,10 +12,17 @@ import com.share.domain.ResultInfo; public interface DemandProjectService { /** - * 添加需求项目数据 + * 添加需求项目数据z * @param demandProject 需求项目表单数据 TODO 用户名如何填写到项目表单中! + * @param operation 操作符(0-保存、1-发布) * @return */ - ResultInfo addDemandProject(DemandProject demandProject); + ResultInfo addDemandProject(DemandProject demandProject, String operation); + /** + * 根据用户名获取其发布的项目 + * @param username 用户名 + * @return + */ + ResultInfo getDemandProjectList(String username); } diff --git a/share_project/src/main/java/com/share/service/SkillProjectService.java b/share_project/src/main/java/com/share/service/SkillProjectService.java new file mode 100644 index 00000000..a75d8b44 --- /dev/null +++ b/share_project/src/main/java/com/share/service/SkillProjectService.java @@ -0,0 +1,22 @@ +package com.share.service; + + +import com.share.domain.ResultInfo; +import com.share.domain.SkillProject; + +/** + * @author 谢佳豪 + * @data 2020/11/24 - 20:42 + * @description 技能项目模块service接口 + */ +public interface SkillProjectService { + + /** + * 添加需求项目数据 + * @param skillProject 需求项目表单数据 TODO 用户名如何填写到项目表单中! + * @param operation 操作符(0-保存、1-发布) + * @return + */ + ResultInfo addSkillProject(SkillProject skillProject, String operation); + +} diff --git a/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java index 2deafdd5..049b008c 100644 --- a/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java @@ -2,8 +2,18 @@ package com.share.service.impl; import com.share.domain.DemandProject; import com.share.domain.ResultInfo; +import com.share.domain.UserDemandProject; +import com.share.mapper.DemandProjectMapper; +import com.share.mapper.UserDemandProjectMapper; import com.share.service.DemandProjectService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; /** * @author 谢佳豪 @@ -13,9 +23,83 @@ import org.springframework.stereotype.Service; @Service public class DemandProjectServiceImpl implements DemandProjectService { + private DemandProjectMapper demandProjectMapper; + + @Autowired + public void setDemandProjectMapper(DemandProjectMapper demandProjectMapper) { + this.demandProjectMapper = demandProjectMapper; + } + + private UserDemandProjectMapper userDemandProjectMapper; + + @Autowired + public void setUserDemandProjectMapper(UserDemandProjectMapper userDemandProjectMapper) { + this.userDemandProjectMapper = userDemandProjectMapper; + } + + + /** + * 获取当前时间 + * @return 时间字符串 + */ + public static String getCurrentTime(){ + SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date d= new Date(); + return sdf.format(d); + } + @Override - public ResultInfo addDemandProject(DemandProject demandProject) { + @Transactional(rollbackFor=Exception.class) + public ResultInfo addDemandProject(DemandProject demandProject, String operation) { + + //判断操作对应的请求路径是否错误 + int status = Integer.parseInt(operation); + if (status != 0 && status != 1){ + return ResultInfo.failInfo("请求地址出错!"); + } + + //设置发布项目的发布时间 + demandProject.setStartTime(getCurrentTime()); + + //TODO 安全问题:插入数据,需要校验token值,拦截器拦截检验header中的token值 + //添加需求项目表数据 + int i = demandProjectMapper.insertDemandProject(demandProject); + + //封装userDemandProject对象数据 + UserDemandProject userDemandProject = new UserDemandProject(); + userDemandProject.setProjectId(demandProject.getId()); + userDemandProject.setUsername(demandProject.getPublisher()); + //TODO 调用userMapper 根据用户名查询用户信息telephone + userDemandProject.setTelephone("18319785677"); + //根据保存或者发布操作符状态值 + userDemandProject.setStatus(status); - return null; + //添加关联表数据,添加事务管理 + int j = 0; + try { + j = userDemandProjectMapper.addAssociation(userDemandProject); + } catch (Exception e){ + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return ResultInfo.failInfo("后台数据发生错误X﹏X"); + } + + //判断处理数据结果,返回json + if (i == 1 && status == 0 && j == 1){ + return ResultInfo.successInfo("项目保存成功^O^"); + } else if (i == 1 && status == 1 && j == 1){ + return ResultInfo.successInfo("项目发布成功,管理员审核中^_^"); + } else if (i == 0 && status == 0 && j == 1){ + return ResultInfo.failInfo("项目保存失败•﹏•"); + } else if (i == 1 && status == 0 && j == 0){ + return ResultInfo.failInfo("项目保存失败•﹏•"); + } else { + return ResultInfo.failInfo("项目发布失败•﹏•"); + } + } + + @Override + public ResultInfo getDemandProjectList(String username) { + List demandProjectList = demandProjectMapper.selectProjectByUsername(username); + return ResultInfo.successInfo("查询成功^O^", demandProjectList); } } diff --git a/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java b/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java new file mode 100644 index 00000000..9c240f86 --- /dev/null +++ b/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java @@ -0,0 +1,96 @@ +package com.share.service.impl; + +import com.share.domain.*; +import com.share.mapper.SkillProjectMapper; +import com.share.mapper.UserSkillProjectMapper; +import com.share.service.SkillProjectService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author 谢佳豪 + * @data 2020/11/24 - 20:47 + * @description + */ +@Service +public class SkillProjectServiceImpl implements SkillProjectService { + + private SkillProjectMapper skillProjectMapper; + + @Autowired + public void setSkillProjectMapper(SkillProjectMapper skillProjectMapper) { + this.skillProjectMapper = skillProjectMapper; + } + + private UserSkillProjectMapper userSkillProjectMapper; + + @Autowired + public void setUserSkillProjectMapper(UserSkillProjectMapper userSkillProjectMapper) { + this.userSkillProjectMapper = userSkillProjectMapper; + } + + + /** + * 获取当前时间 + * @return 时间字符串 + */ + public static String getCurrentTime(){ + SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date d= new Date(); + return sdf.format(d); + } + + @Override + @Transactional(rollbackFor=Exception.class) + public ResultInfo addSkillProject(SkillProject skillProject, String operation) { + + //判断操作对应的请求路径是否错误 + int status = Integer.parseInt(operation); + if (status != 0 && status != 1){ + return ResultInfo.failInfo("请求地址出错!"); + } + + //设置发布项目的发布时间 + skillProject.setStartTime(getCurrentTime()); + + //TODO 安全问题:插入数据,需要校验token值,拦截器拦截检验header中的token值 + //添加需求项目表数据 + int i = skillProjectMapper.insertSkillProject(skillProject); + + //封装userSkillProject对象数据 + UserSkillProject userSkillProject = new UserSkillProject(); + userSkillProject.setProjectId(skillProject.getId()); + userSkillProject.setUsername(skillProject.getPublisher()); + //TODO 调用userMapper 根据用户名查询用户信息telephone + userSkillProject.setTelephone("18319785677"); + //根据保存或者发布操作符状态值 + userSkillProject.setStatus(status); + + //添加关联表数据,添加事务管理 + int j = 0; + try { + j = userSkillProjectMapper.addAssociation(userSkillProject); + } catch (Exception e){ + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return ResultInfo.failInfo("后台数据发生错误X﹏X"); + } + + //判断处理数据结果,返回json + if (i == 1 && status == 0 && j == 1){ + return ResultInfo.successInfo("项目保存成功^O^"); + } else if (i == 1 && status == 1 && j == 1){ + return ResultInfo.successInfo("项目发布成功,管理员审核中^_^"); + } else if (i == 0 && status == 0 && j == 1){ + return ResultInfo.failInfo("项目保存失败•﹏•"); + } else if (i == 1 && status == 0 && j == 0){ + return ResultInfo.failInfo("项目保存失败•﹏•"); + } else { + return ResultInfo.failInfo("项目发布失败•﹏•"); + } + } +} diff --git a/share_project/src/main/resources/mapper/DemandProjectMapper.xml b/share_project/src/main/resources/mapper/DemandProjectMapper.xml index f3529bb2..de1f462f 100644 --- a/share_project/src/main/resources/mapper/DemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/DemandProjectMapper.xml @@ -17,10 +17,14 @@ + + + + - + insert into demand_project (project_name, project_desc, subsidy, price, address, skill, type, @@ -29,6 +33,13 @@ #{type}, #{method}, #{publisher}, #{startTime}, #{endTime}); + + + diff --git a/share_project/src/main/resources/mapper/SkillProjectMapper.xml b/share_project/src/main/resources/mapper/SkillProjectMapper.xml index 7d2d7d84..a2d0f9a2 100644 --- a/share_project/src/main/resources/mapper/SkillProjectMapper.xml +++ b/share_project/src/main/resources/mapper/SkillProjectMapper.xml @@ -5,7 +5,7 @@ - + insert into skill_project (project_name, project_desc, address, skill, price, type, -- Gitee From 9bdd6cd1bd91de875fb6471df941c1d54bcb88ee Mon Sep 17 00:00:00 2001 From: datou <18319785677@163.com> Date: Sun, 29 Nov 2020 15:35:00 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=A8=A1=E5=9D=97v2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DemandProjectController.java | 11 +- .../controller/UserProjectController.java | 117 +++++++++++++++++ .../java/com/share/domain/DemandProject.java | 13 -- .../com/share/domain/UserDemandProject.java | 4 +- .../com/share/domain/UserSkillProject.java | 2 +- .../com/share/mapper/DemandProjectMapper.java | 24 +++- .../com/share/mapper/SkillProjectMapper.java | 29 ++++- .../share/mapper/UserDemandProjectMapper.java | 11 +- .../java/com/share/mapper/UserInfoMapper.java | 26 ++++ .../share/mapper/UserSkillProjectMapper.java | 3 +- .../share/service/DemandProjectService.java | 18 +++ .../share/service/SkillProjectService.java | 24 ++++ .../impl/DemandProjectServiceImpl.java | 118 +++++++++++++++--- .../service/impl/SkillProjectServiceImpl.java | 99 ++++++++++++++- .../com/share/vo/UserProjectListData.java | 76 +++++++++++ .../resources/mapper/DemandProjectMapper.xml | 56 ++++++++- .../resources/mapper/SkillProjectMapper.xml | 67 ++++++++++ .../mapper/UserDemandProjectMapper.xml | 6 + .../main/resources/mapper/UserInfoMapper.xml | 17 +++ 19 files changed, 659 insertions(+), 62 deletions(-) create mode 100644 share_project/src/main/java/com/share/controller/UserProjectController.java create mode 100644 share_project/src/main/java/com/share/mapper/UserInfoMapper.java create mode 100644 share_project/src/main/java/com/share/vo/UserProjectListData.java create mode 100644 share_project/src/main/resources/mapper/UserInfoMapper.xml diff --git a/share_project/src/main/java/com/share/controller/DemandProjectController.java b/share_project/src/main/java/com/share/controller/DemandProjectController.java index 11fc5bb1..7c51b44d 100644 --- a/share_project/src/main/java/com/share/controller/DemandProjectController.java +++ b/share_project/src/main/java/com/share/controller/DemandProjectController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*; /** * @author 谢佳豪 * @data 2020/11/24 - 20:12 - * @description 需求项目模块controller层 + * @description 需求项目模块controller层(增、查) */ @Controller @ResponseBody @@ -35,13 +35,4 @@ public class DemandProjectController { return demandProjectService.addDemandProject(demandProject, operation); } - /** - * get请求 获取当前用户发布的需求项目 - * @param username 用户名 - * @return - */ - @RequestMapping("/{username}") - public ResultInfo getDemandProjectList(@PathVariable String username){ - return demandProjectService.getDemandProjectList(username); - } } diff --git a/share_project/src/main/java/com/share/controller/UserProjectController.java b/share_project/src/main/java/com/share/controller/UserProjectController.java new file mode 100644 index 00000000..2d02d678 --- /dev/null +++ b/share_project/src/main/java/com/share/controller/UserProjectController.java @@ -0,0 +1,117 @@ +package com.share.controller; + +import com.share.domain.DemandProject; +import com.share.domain.ResultInfo; +import com.share.domain.SkillProject; +import com.share.service.DemandProjectService; +import com.share.service.SkillProjectService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author 谢佳豪 + * @data 2020/11/28 - 12:37 + * @description 用户-项目controller层 + */ +@Controller +@ResponseBody +public class UserProjectController { + + private DemandProjectService demandProjectService; + + private SkillProjectService skillProjectService; + + @Autowired + public void setDemandProjectService(DemandProjectService demandProjectService) { + this.demandProjectService = demandProjectService; + } + + @Autowired + public void setSkillProjectService(SkillProjectService skillProjectService) { + this.skillProjectService = skillProjectService; + } + + /** + * get请求 获取当前用户发布的需求项目列表(基本信息) + * @param username 用户名 + * @return + */ + @RequestMapping("/{username}/demand") + public ResultInfo getDemandProjectList(@PathVariable String username){ + return demandProjectService.getDemandProjectList(username); + } + + /** + * get请求 根据projectId、username获取当前用户任一需求项目数据 + * @param username 用户名 + * @param projectId 需求项目id + * @return + */ + @RequestMapping("/{username}/demand/{projectId}") + public ResultInfo getDemandProject(@PathVariable String username, @PathVariable String projectId){ + //转换类型 String -> Integer + Integer id = Integer.parseInt(projectId); + return demandProjectService.getDemandProject(username, id); + } + + /** + * post请求 根据用户名、id、修改需求项目数据并保存 + * @param username 用户名 + * @param projectId 需求项目id + * @param operation 操作符 + * @param demandProject 需求项目表单数据 + * @return + */ + @PostMapping("/{username}/demand/{projectId}/{operation}") + public ResultInfo updateDemandProject(@PathVariable String username, @PathVariable String projectId, @PathVariable String operation, DemandProject demandProject){ + //转换类型 String -> Integer + Integer id = Integer.parseInt(projectId); + Integer newStatus = Integer.parseInt(operation); + return demandProjectService.updateDemandProject(username, id, newStatus, demandProject); + } + + /** + * get请求 获取当前用户发布的技能项目列表(基本信息) + * @param username 用户名 + * @return + */ + @RequestMapping("/{username}/skill") + public ResultInfo getSkillProjectList(@PathVariable String username){ + return skillProjectService.getSkillProjectList(username); + } + + /** + * get请求 根据用户名、id查询单条技能项目数据 + * @param username 用户名 + * @param projectId 技能项目id + * @return + */ + @RequestMapping("/{username}/skill/{projectId}") + public ResultInfo getSkillProject(@PathVariable String username, @PathVariable String projectId){ + //转换类型 String -> Integer + Integer id = Integer.parseInt(projectId); + return skillProjectService.getSkillProject(username, id); + } + + + /** + * post请求 根据用户名、id、修改技能项目数据并保存 + * @param username 用户名 + * @param projectId 技能项目id + * @param operation 操作符 + * @param skillProject 技能项目表单数据 + * @return + */ + @PostMapping("/{username}/skill/{projectId}/{operation}") + public ResultInfo updateSkillProject(@PathVariable String username, @PathVariable String projectId, @PathVariable String operation, SkillProject skillProject){ + //转换类型 String -> Integer + Integer id = Integer.parseInt(projectId); + Integer newStatus = Integer.parseInt(operation); + return skillProjectService.updateSkillProject(username, id, newStatus, skillProject); + } + +} diff --git a/share_project/src/main/java/com/share/domain/DemandProject.java b/share_project/src/main/java/com/share/domain/DemandProject.java index 20a12c61..38c2f164 100644 --- a/share_project/src/main/java/com/share/domain/DemandProject.java +++ b/share_project/src/main/java/com/share/domain/DemandProject.java @@ -58,10 +58,6 @@ public class DemandProject implements Serializable { * 截止时间 */ private String endTime; - /** - * 用户需求项目关联 - */ - private UserDemandProject userDemandProject; public Integer getId() { return id; @@ -159,14 +155,6 @@ public class DemandProject implements Serializable { this.endTime = endTime; } - public UserDemandProject getUserDemandProject() { - return userDemandProject; - } - - public void setUserDemandProject(UserDemandProject userDemandProject) { - this.userDemandProject = userDemandProject; - } - @Override public String toString() { return "DemandProject{" + @@ -182,7 +170,6 @@ public class DemandProject implements Serializable { ", publisher='" + publisher + '\'' + ", startTime='" + startTime + '\'' + ", endTime='" + endTime + '\'' + - ", userDemandProject=" + userDemandProject + '}'; } } diff --git a/share_project/src/main/java/com/share/domain/UserDemandProject.java b/share_project/src/main/java/com/share/domain/UserDemandProject.java index f1edce58..d2cf2553 100644 --- a/share_project/src/main/java/com/share/domain/UserDemandProject.java +++ b/share_project/src/main/java/com/share/domain/UserDemandProject.java @@ -23,7 +23,7 @@ public class UserDemandProject implements Serializable { */ private String telephone; /** - * 项目状态 TODO(待发布状态--0;待审核状态--1) + * 项目状态 待发布状态--0;待审核状态--1;过期状态--2 */ private Integer status; @@ -61,7 +61,7 @@ public class UserDemandProject implements Serializable { @Override public String toString() { - return "UserDemandProject{" + + return "UserProjectListData{" + "projectId=" + projectId + ", username='" + username + '\'' + ", telephone='" + telephone + '\'' + diff --git a/share_project/src/main/java/com/share/domain/UserSkillProject.java b/share_project/src/main/java/com/share/domain/UserSkillProject.java index 804f9013..2bf81d08 100644 --- a/share_project/src/main/java/com/share/domain/UserSkillProject.java +++ b/share_project/src/main/java/com/share/domain/UserSkillProject.java @@ -23,7 +23,7 @@ public class UserSkillProject implements Serializable { */ private String telephone; /** - * 项目状态 TODO(待发布状态--0;待审核状态--1) + * 项目状态 待发布状态--0;待审核状态--1;过期状态--2 */ private Integer status; diff --git a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java index 08759209..8685c5f5 100644 --- a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java @@ -1,7 +1,8 @@ package com.share.mapper; import com.share.domain.DemandProject; -import org.springframework.context.annotation.Bean; +import com.share.vo.UserProjectListData; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -19,7 +20,7 @@ public interface DemandProjectMapper { * @param demandProject 需求项目表单数据 TODO 用户名如何填写到项目表单中! * @return */ - int insertDemandProject(DemandProject demandProject); + Integer insertDemandProject(DemandProject demandProject); /** @@ -27,7 +28,24 @@ public interface DemandProjectMapper { * @param username * @return */ - List selectProjectByUsername(String username); + List selectDemandProjectListByUsername(String username); + + /** + * 根据用户名和id查询单条需求项目数据 + * @param username 用户名 + * @param id 需求项目id + * @return + */ + DemandProject selectDemandProjectById(String username, Integer id); + + /** + * 根据用户名、id修改指定项目数据,并修改其状态为保存 + * @param username 用户名 + * @param id 需求项目id + * @param demandProject 需求项目表单数据 + * @return + */ + Integer updateDemandProject(@Param("username") String username, @Param("id") Integer id, @Param("demandProject") DemandProject demandProject); /** diff --git a/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java b/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java index d4b2bfc5..7c1da759 100644 --- a/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java @@ -1,8 +1,12 @@ package com.share.mapper; import com.share.domain.SkillProject; +import com.share.vo.UserProjectListData; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.List; + /** * @author 谢佳豪 * @data 2020/11/23 - 22:33 @@ -16,5 +20,28 @@ public interface SkillProjectMapper { * @param skillProject 技能项目表单数据 TODO 用户名如何填写到项目表单中! * @return */ - int insertSkillProject(SkillProject skillProject); + Integer insertSkillProject(SkillProject skillProject); + + /** + * 根据用户名查询技能需求项目 + * @param username 用户名 + * @return + */ + List selectSkillProjectListByUsername(String username); + + /** + * 根据用户名、id查询单条技能项目数据 + * @param username 用户名 + * @param id 技能项目id + * @return + */ + SkillProject selectSkillProjectById(String username, Integer id); + + /** + * 更新技能项目数据 + * @param username 用户名 + * @param id 技能项目id + * @param skillProject 技能项目数据 + */ + void updateSkillProject(@Param("username") String username, @Param("id") Integer id, @Param("skillProject") SkillProject skillProject); } diff --git a/share_project/src/main/java/com/share/mapper/UserDemandProjectMapper.java b/share_project/src/main/java/com/share/mapper/UserDemandProjectMapper.java index ac4089e8..b33b697d 100644 --- a/share_project/src/main/java/com/share/mapper/UserDemandProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/UserDemandProjectMapper.java @@ -16,7 +16,14 @@ public interface UserDemandProjectMapper { * @param userDemandProject 关联数据 * @return */ - int addAssociation(UserDemandProject userDemandProject); + Integer addAssociation(UserDemandProject userDemandProject); + + /** + * 查询当前项目的状态 + * @param id 项目id + * @return + */ + Integer selectStatus(Integer id); /** * 更新项目状态 @@ -24,5 +31,5 @@ public interface UserDemandProjectMapper { * @param status 状态 * @return */ - int updateStatus(Integer id ,Integer status); + Integer updateStatus(Integer id ,Integer status); } diff --git a/share_project/src/main/java/com/share/mapper/UserInfoMapper.java b/share_project/src/main/java/com/share/mapper/UserInfoMapper.java new file mode 100644 index 00000000..45b0754f --- /dev/null +++ b/share_project/src/main/java/com/share/mapper/UserInfoMapper.java @@ -0,0 +1,26 @@ +package com.share.mapper; + +import org.springframework.stereotype.Repository; + +/** + * @author 谢佳豪 + * @data 2020/11/27 - 0:27 + * @description 用户表接口类 + */ +@Repository +public interface UserInfoMapper { + + /** + * 根据用户名查询是否存在用户 + * @param username 用户名 + * @return + */ + int selectUserByUsername(String username); + + /** + * 根据用户名查询电话号码 + * @param username 用户名 + * @return + */ + String selectTelephoneByUsername(String username); +} diff --git a/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java b/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java index d97dcf5c..2d73b2cf 100644 --- a/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/UserSkillProjectMapper.java @@ -22,7 +22,6 @@ public interface UserSkillProjectMapper { * 更新项目状态 * @param id 项目id * @param status 状态 - * @return */ - int updateStatus(Integer id ,Integer status); + void updateStatus(Integer id , Integer status); } diff --git a/share_project/src/main/java/com/share/service/DemandProjectService.java b/share_project/src/main/java/com/share/service/DemandProjectService.java index 5ad47de7..d2318ad4 100644 --- a/share_project/src/main/java/com/share/service/DemandProjectService.java +++ b/share_project/src/main/java/com/share/service/DemandProjectService.java @@ -25,4 +25,22 @@ public interface DemandProjectService { * @return */ ResultInfo getDemandProjectList(String username); + + /** + * 根据用户名、id获取指定项目数据 + * @param username 用户名 + * @param id 需求项目id + * @return + */ + ResultInfo getDemandProject(String username, Integer id); + + /** + * 根据用户名、id修改指定项目数据,并根据操作符修改其状态 + * @param username 用户名 + * @param id 需求项目id + * @param newStatus 项目状态 + * @param demandProject 需求项目表单数据 + * @return + */ + ResultInfo updateDemandProject(String username, Integer id, Integer newStatus, DemandProject demandProject); } diff --git a/share_project/src/main/java/com/share/service/SkillProjectService.java b/share_project/src/main/java/com/share/service/SkillProjectService.java index a75d8b44..67bd5d06 100644 --- a/share_project/src/main/java/com/share/service/SkillProjectService.java +++ b/share_project/src/main/java/com/share/service/SkillProjectService.java @@ -19,4 +19,28 @@ public interface SkillProjectService { */ ResultInfo addSkillProject(SkillProject skillProject, String operation); + /** + * 根据用户名获取需求项目列表 + * @param username 用户名 + * @return + */ + ResultInfo getSkillProjectList(String username); + + /** + * 根据用户名、id获取单条需求项目详细数据 + * @param username 用户名 + * @param id 技能项目id + * @return + */ + ResultInfo getSkillProject(String username, Integer id); + + /** + * 修改指定id技能项目,并根据操作符修改其状态 + * @param username 用户名 + * @param id 技能项目id + * @param newStatus 操作符(项目状态) + * @param skillProject 技能项目数据 + * @return + */ + ResultInfo updateSkillProject(String username, Integer id, Integer newStatus, SkillProject skillProject); } diff --git a/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java index 049b008c..678b7c68 100644 --- a/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java @@ -5,7 +5,9 @@ import com.share.domain.ResultInfo; import com.share.domain.UserDemandProject; import com.share.mapper.DemandProjectMapper; import com.share.mapper.UserDemandProjectMapper; +import com.share.mapper.UserInfoMapper; import com.share.service.DemandProjectService; +import com.share.vo.UserProjectListData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -25,36 +27,43 @@ public class DemandProjectServiceImpl implements DemandProjectService { private DemandProjectMapper demandProjectMapper; + private UserDemandProjectMapper userDemandProjectMapper; + + private UserInfoMapper userInfoMapper; + @Autowired public void setDemandProjectMapper(DemandProjectMapper demandProjectMapper) { this.demandProjectMapper = demandProjectMapper; } - private UserDemandProjectMapper userDemandProjectMapper; - @Autowired public void setUserDemandProjectMapper(UserDemandProjectMapper userDemandProjectMapper) { this.userDemandProjectMapper = userDemandProjectMapper; } + @Autowired + public void setUserInfoMapper(UserInfoMapper userInfoMapper) { + this.userInfoMapper = userInfoMapper; + } /** * 获取当前时间 + * * @return 时间字符串 */ - public static String getCurrentTime(){ - SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date d= new Date(); + public static String getCurrentTime() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date d = new Date(); return sdf.format(d); } @Override - @Transactional(rollbackFor=Exception.class) + @Transactional(rollbackFor = Exception.class) public ResultInfo addDemandProject(DemandProject demandProject, String operation) { //判断操作对应的请求路径是否错误 int status = Integer.parseInt(operation); - if (status != 0 && status != 1){ + if (status != 0 && status != 1) { return ResultInfo.failInfo("请求地址出错!"); } @@ -65,12 +74,14 @@ public class DemandProjectServiceImpl implements DemandProjectService { //添加需求项目表数据 int i = demandProjectMapper.insertDemandProject(demandProject); + String username = demandProject.getPublisher(); + String telephone = userInfoMapper.selectTelephoneByUsername(username); + //封装userDemandProject对象数据 UserDemandProject userDemandProject = new UserDemandProject(); userDemandProject.setProjectId(demandProject.getId()); - userDemandProject.setUsername(demandProject.getPublisher()); - //TODO 调用userMapper 根据用户名查询用户信息telephone - userDemandProject.setTelephone("18319785677"); + userDemandProject.setUsername(username); + userDemandProject.setTelephone(telephone); //根据保存或者发布操作符状态值 userDemandProject.setStatus(status); @@ -78,19 +89,19 @@ public class DemandProjectServiceImpl implements DemandProjectService { int j = 0; try { j = userDemandProjectMapper.addAssociation(userDemandProject); - } catch (Exception e){ + } catch (Exception e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return ResultInfo.failInfo("后台数据发生错误X﹏X"); } //判断处理数据结果,返回json - if (i == 1 && status == 0 && j == 1){ + if (i == 1 && status == 0 && j == 1) { return ResultInfo.successInfo("项目保存成功^O^"); - } else if (i == 1 && status == 1 && j == 1){ + } else if (i == 1 && status == 1 && j == 1) { return ResultInfo.successInfo("项目发布成功,管理员审核中^_^"); - } else if (i == 0 && status == 0 && j == 1){ + } else if (i == 0 && status == 0 && j == 1) { return ResultInfo.failInfo("项目保存失败•﹏•"); - } else if (i == 1 && status == 0 && j == 0){ + } else if (i == 1 && status == 0 && j == 0) { return ResultInfo.failInfo("项目保存失败•﹏•"); } else { return ResultInfo.failInfo("项目发布失败•﹏•"); @@ -99,7 +110,80 @@ public class DemandProjectServiceImpl implements DemandProjectService { @Override public ResultInfo getDemandProjectList(String username) { - List demandProjectList = demandProjectMapper.selectProjectByUsername(username); - return ResultInfo.successInfo("查询成功^O^", demandProjectList); + + //检验用户名是否存在,以免发送错误请求 + int i = userInfoMapper.selectUserByUsername(username); + if (i == 1) { + //根据用户名查询其发布的项目 + List userProjectListData = demandProjectMapper.selectDemandProjectListByUsername(username); + if (userProjectListData.size() > 0) { + return ResultInfo.successInfo("查询成功^O^", userProjectListData); + } else { + return ResultInfo.successInfo("您还未发布过项目,快点行动起来吧^_^"); + } + } else if (i == 0) { + return ResultInfo.failInfo("请求地址出错,不存在此用户的数据•﹏•"); + } else { + return ResultInfo.failInfo("抱歉,后台数据出错(⊙﹏⊙)"); + } + } + + @Override + public ResultInfo getDemandProject(String username, Integer id) { + + //检验用户名是否存在,以免发送错误请求 + int i = userInfoMapper.selectUserByUsername(username); + if (i == 1) { + //根据用户名、id查询单条数据 + DemandProject demandProject = demandProjectMapper.selectDemandProjectById(username, id); + if (demandProject != null) { + return ResultInfo.successInfo("查询成功^O^", demandProject); + } else { + return ResultInfo.successInfo("请求地址出错,该数据不存在•﹏•"); + } + } else if (i == 0) { + return ResultInfo.failInfo("请求地址出错,不存在此用户的数据•﹏•"); + } else { + return ResultInfo.failInfo("抱歉,后台数据出现错误(⊙﹏⊙)"); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public ResultInfo updateDemandProject(String username, Integer id, Integer newStatus, DemandProject demandProject) { + + //检查操作符status是否正确,以免发送错误请求 + if (newStatus != 0 && newStatus != 1) { + return ResultInfo.failInfo("错误请求,请求地址出错!"); + } + + //检验用户名是否存在,以免发送错误请求 + int i = userInfoMapper.selectUserByUsername(username); + + if (i == 1) { + //根据用户名、id修改单条数据 TODO 安全问题:需要验证是否为本人 + try { + demandProjectMapper.updateDemandProject(username, id, demandProject); + } catch (Exception e) { + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return ResultInfo.failInfo("后台数据发生错误X﹏X"); + } + + //根据操作符-newStatus的值,进行判断项目的保存及发布 + if (newStatus == 0) { + userDemandProjectMapper.updateStatus(id, newStatus); + return ResultInfo.successInfo("项目保存成功^O^"); + } else if (newStatus == 1) { + userDemandProjectMapper.updateStatus(id, newStatus); + return ResultInfo.successInfo("项目发布成功,管理员审核中^_^"); + } else { + return ResultInfo.failInfo("错误请求,请求地址错误!"); + } + + } else if (i == 0) { + return ResultInfo.failInfo("请求地址出错,不存在此用户的数据•﹏•"); + } else { + return ResultInfo.failInfo("抱歉,后台数据出现错误(⊙﹏⊙)"); + } } } diff --git a/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java b/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java index 9c240f86..73a1b6a7 100644 --- a/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java @@ -2,8 +2,10 @@ package com.share.service.impl; import com.share.domain.*; import com.share.mapper.SkillProjectMapper; +import com.share.mapper.UserInfoMapper; import com.share.mapper.UserSkillProjectMapper; import com.share.service.SkillProjectService; +import com.share.vo.UserProjectListData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,6 +13,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; /** * @author 谢佳豪 @@ -22,18 +25,24 @@ public class SkillProjectServiceImpl implements SkillProjectService { private SkillProjectMapper skillProjectMapper; + private UserSkillProjectMapper userSkillProjectMapper; + + private UserInfoMapper userInfoMapper; + @Autowired public void setSkillProjectMapper(SkillProjectMapper skillProjectMapper) { this.skillProjectMapper = skillProjectMapper; } - private UserSkillProjectMapper userSkillProjectMapper; - @Autowired public void setUserSkillProjectMapper(UserSkillProjectMapper userSkillProjectMapper) { this.userSkillProjectMapper = userSkillProjectMapper; } + @Autowired + public void setUserInfoMapper(UserInfoMapper userInfoMapper) { + this.userInfoMapper = userInfoMapper; + } /** * 获取当前时间 @@ -62,12 +71,15 @@ public class SkillProjectServiceImpl implements SkillProjectService { //添加需求项目表数据 int i = skillProjectMapper.insertSkillProject(skillProject); + //查询用户名对应的电话号码-主键 + String username = skillProject.getPublisher(); + String telephone = userInfoMapper.selectTelephoneByUsername(username); + //封装userSkillProject对象数据 UserSkillProject userSkillProject = new UserSkillProject(); userSkillProject.setProjectId(skillProject.getId()); - userSkillProject.setUsername(skillProject.getPublisher()); - //TODO 调用userMapper 根据用户名查询用户信息telephone - userSkillProject.setTelephone("18319785677"); + userSkillProject.setUsername(username); + userSkillProject.setTelephone(telephone); //根据保存或者发布操作符状态值 userSkillProject.setStatus(status); @@ -93,4 +105,81 @@ public class SkillProjectServiceImpl implements SkillProjectService { return ResultInfo.failInfo("项目发布失败•﹏•"); } } + + @Override + public ResultInfo getSkillProjectList(String username) { + //检验用户名是否存在,以免发送错误请求 + int i = userInfoMapper.selectUserByUsername(username); + if (i == 1) { + //根据用户名查询其发布的项目 + List userProjectListData = skillProjectMapper.selectSkillProjectListByUsername(username); + if (userProjectListData.size() > 0) { + return ResultInfo.successInfo("查询成功^O^", userProjectListData); + } else { + return ResultInfo.successInfo("您还未发布过项目,快点行动起来吧^_^"); + } + } else if (i == 0){ + return ResultInfo.failInfo("请求地址出错,不存在此用户的数据•﹏•"); + } else { + return ResultInfo.failInfo("抱歉,后台数据出错(⊙﹏⊙)"); + } + } + + @Override + public ResultInfo getSkillProject(String username, Integer id) { + + //检验用户名是否存在,以免发送错误请求 + int i = userInfoMapper.selectUserByUsername(username); + if (i == 1) { + //根据用户名、id查询单条数据 + SkillProject skillProject = skillProjectMapper.selectSkillProjectById(username, id); + if (skillProject != null) { + return ResultInfo.successInfo("查询成功^O^", skillProject); + } else { + return ResultInfo.successInfo("请求地址出错,该数据不存在•﹏•"); + } + } else if (i == 0) { + return ResultInfo.failInfo("请求地址出错,不存在此用户的数据•﹏•"); + } else { + return ResultInfo.failInfo("抱歉,后台数据出现错误(⊙﹏⊙)"); + } + } + + @Override + public ResultInfo updateSkillProject(String username, Integer id, Integer newStatus, SkillProject skillProject) { + + //检查操作符status是否正确,以免发送错误请求 + if (newStatus != 0 && newStatus != 1) { + return ResultInfo.failInfo("错误请求,请求地址出错!"); + } + + //检验用户名是否存在,以免发送错误请求 + int i = userInfoMapper.selectUserByUsername(username); + + if (i == 1) { + //根据用户名、id修改单条数据 TODO 安全问题:需要验证是否为本人 + try { + skillProjectMapper.updateSkillProject(username, id, skillProject); + } catch (Exception e) { + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return ResultInfo.failInfo("后台数据发生错误X﹏X"); + } + + //根据操作符-newStatus的值,进行判断项目的保存及发布 + if (newStatus == 0) { + userSkillProjectMapper.updateStatus(id, newStatus); + return ResultInfo.successInfo("项目保存成功^O^"); + } else if (newStatus == 1) { + userSkillProjectMapper.updateStatus(id, newStatus); + return ResultInfo.successInfo("项目发布成功,管理员审核中^_^"); + } else { + return ResultInfo.failInfo("错误请求,请求地址错误!"); + } + + } else if (i == 0) { + return ResultInfo.failInfo("请求地址出错,不存在此用户的数据•﹏•"); + } else { + return ResultInfo.failInfo("抱歉,后台数据出现错误(⊙﹏⊙)"); + } + } } diff --git a/share_project/src/main/java/com/share/vo/UserProjectListData.java b/share_project/src/main/java/com/share/vo/UserProjectListData.java new file mode 100644 index 00000000..04124676 --- /dev/null +++ b/share_project/src/main/java/com/share/vo/UserProjectListData.java @@ -0,0 +1,76 @@ +package com.share.vo; + +import java.io.Serializable; + +/** + * @author 谢佳豪 + * @data 2020/11/26 - 23:22 + * @description + */ +public class UserProjectListData implements Serializable { + + /** + * 项目编号 + */ + private Integer id; + + /** + * 项目名称 + */ + private String projectName; + + /** + * 项目描述 + */ + private String projectDesc; + + /** + * 发布时间 + */ + private String startTime; + + /** + * 项目状态 待发布状态--0;待审核状态--1 + */ + private Integer status; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getProjectDesc() { + return projectDesc; + } + + public void setProjectDesc(String projectDesc) { + this.projectDesc = projectDesc; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } +} diff --git a/share_project/src/main/resources/mapper/DemandProjectMapper.xml b/share_project/src/main/resources/mapper/DemandProjectMapper.xml index de1f462f..b710e988 100644 --- a/share_project/src/main/resources/mapper/DemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/DemandProjectMapper.xml @@ -17,10 +17,6 @@ - - - - @@ -33,13 +29,61 @@ #{type}, #{method}, #{publisher}, #{startTime}, #{endTime}); - - select id, project_name, project_desc, start_time, status from demand_project as dp, user_demand_project as udp where dp.id = udp.project_id and dp.publisher = #{username}; + + + + + + + + + + + + + + update demand_project + + + project_name = #{demandProject.projectName}, + + + project_desc = #{demandProject.projectDesc}, + + + subsidy = #{demandProject.subsidy}, + + + address = #{demandProject.address}, + + + skill = #{demandProject.skill}, + + + price = #{demandProject.price}, + + + type = #{demandProject.type}, + + + method = #{demandProject.method}, + + + end_time = #{demandProject.endTime} + + + where publisher = #{username} and id = #{id}; + + diff --git a/share_project/src/main/resources/mapper/SkillProjectMapper.xml b/share_project/src/main/resources/mapper/SkillProjectMapper.xml index a2d0f9a2..9cf4cf96 100644 --- a/share_project/src/main/resources/mapper/SkillProjectMapper.xml +++ b/share_project/src/main/resources/mapper/SkillProjectMapper.xml @@ -4,6 +4,20 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + + + + + + + + + + + + insert into skill_project @@ -14,4 +28,57 @@ #{type}, #{method}, #{publisher}, #{startTime}, #{endTime}); + + + + + + + + + + + + + + update skill_project + + + project_name = #{skillProject.projectName}, + + + project_desc = #{skillProject.projectDesc}, + + + address = #{skillProject.address}, + + + skill = #{skillProject.skill}, + + + price = #{skillProject.price}, + + + type = #{skillProject.type}, + + + method = #{skillProject.method}, + + + end_time = #{skillProject.endTime} + + + where publisher = #{username} and id = #{id}; + + + + + + \ No newline at end of file diff --git a/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml b/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml index a49efa25..056cc2e9 100644 --- a/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml @@ -10,6 +10,12 @@ VALUE(#{projectId}, #{username}, #{telephone}, #{status}); + + + update user_demand_project set status = #{status} where project_id = #{id}; diff --git a/share_project/src/main/resources/mapper/UserInfoMapper.xml b/share_project/src/main/resources/mapper/UserInfoMapper.xml new file mode 100644 index 00000000..6ae71f0f --- /dev/null +++ b/share_project/src/main/resources/mapper/UserInfoMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file -- Gitee From 51c5184bc4b4056d2e92e866f20e97e883f618df Mon Sep 17 00:00:00 2001 From: datou <18319785677@163.com> Date: Sun, 6 Dec 2020 23:06:24 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserProjectController.java | 21 +++++----- .../java/com/share/domain/DemandProject.java | 13 +++--- .../java/com/share/domain/SkillProject.java | 12 +++--- .../com/share/mapper/DemandProjectMapper.java | 15 +++++-- .../com/share/mapper/SkillProjectMapper.java | 12 +++++- .../share/service/DemandProjectService.java | 3 +- .../share/service/SkillProjectService.java | 3 +- .../impl/DemandProjectServiceImpl.java | 40 ++++++++++++------- .../service/impl/SkillProjectServiceImpl.java | 38 +++++++++++------- .../resources/mapper/DemandProjectMapper.xml | 13 ++++-- .../resources/mapper/SkillProjectMapper.xml | 14 +++++-- 11 files changed, 118 insertions(+), 66 deletions(-) diff --git a/share_project/src/main/java/com/share/controller/UserProjectController.java b/share_project/src/main/java/com/share/controller/UserProjectController.java index 18f04bf0..ccd0a394 100644 --- a/share_project/src/main/java/com/share/controller/UserProjectController.java +++ b/share_project/src/main/java/com/share/controller/UserProjectController.java @@ -7,10 +7,7 @@ import com.share.service.DemandProjectService; import com.share.service.SkillProjectService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; /** * @author 谢佳豪 @@ -37,13 +34,14 @@ public class UserProjectController { } /** - * get请求 获取当前用户发布的需求项目列表(基本信息) + * get请求 获取当前用户发布的需求项目列表(基本信息)、分页 * @param username 用户名 + * @param currentPageIndex 当前页面 * @return */ - @RequestMapping("/{username}/demand") - public ResultInfo getDemandProjectList(@PathVariable String username){ - return demandProjectService.getDemandProjectList(username); + @GetMapping("/{username}/demand") + public ResultInfo getDemandProjectList(@PathVariable String username, Integer currentPageIndex){ + return demandProjectService.getDemandProjectList(username, currentPageIndex); } /** @@ -78,11 +76,12 @@ public class UserProjectController { /** * get请求 获取当前用户发布的技能项目列表(基本信息) * @param username 用户名 + * @param currentPageIndex 当前页面下标 * @return */ - @RequestMapping("/{username}/skill") - public ResultInfo getSkillProjectList(@PathVariable String username){ - return skillProjectService.getSkillProjectList(username); + @GetMapping("/{username}/skill") + public ResultInfo getSkillProjectList(@PathVariable String username, Integer currentPageIndex){ + return skillProjectService.getSkillProjectList(username, currentPageIndex); } /** diff --git a/share_project/src/main/java/com/share/domain/DemandProject.java b/share_project/src/main/java/com/share/domain/DemandProject.java index 38c2f164..89178208 100644 --- a/share_project/src/main/java/com/share/domain/DemandProject.java +++ b/share_project/src/main/java/com/share/domain/DemandProject.java @@ -2,6 +2,7 @@ package com.share.domain; import java.io.Serializable; +import java.util.Date; /** * @author 谢佳豪 @@ -53,11 +54,11 @@ public class DemandProject implements Serializable { /** * 发布时间 */ - private String startTime; + private Date startTime; /** * 截止时间 */ - private String endTime; + private Date endTime; public Integer getId() { return id; @@ -139,19 +140,19 @@ public class DemandProject implements Serializable { this.publisher = publisher; } - public String getStartTime() { + public Date getStartTime() { return startTime; } - public void setStartTime(String startTime) { + public void setStartTime(Date startTime) { this.startTime = startTime; } - public String getEndTime() { + public Date getEndTime() { return endTime; } - public void setEndTime(String endTime) { + public void setEndTime(Date endTime) { this.endTime = endTime; } diff --git a/share_project/src/main/java/com/share/domain/SkillProject.java b/share_project/src/main/java/com/share/domain/SkillProject.java index 653b68ca..966d8786 100644 --- a/share_project/src/main/java/com/share/domain/SkillProject.java +++ b/share_project/src/main/java/com/share/domain/SkillProject.java @@ -49,11 +49,11 @@ public class SkillProject { /** * 发布时间 */ - private String startTime; + private Date startTime; /** * 截止时间 */ - private String endTime; + private Date endTime; public Integer getId() { return id; @@ -127,19 +127,19 @@ public class SkillProject { this.publisher = publisher; } - public String getStartTime() { + public Date getStartTime() { return startTime; } - public void setStartTime(String startTime) { + public void setStartTime(Date startTime) { this.startTime = startTime; } - public String getEndTime() { + public Date getEndTime() { return endTime; } - public void setEndTime(String endTime) { + public void setEndTime(Date endTime) { this.endTime = endTime; } diff --git a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java index 43f28c00..40a455fc 100644 --- a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java @@ -25,11 +25,20 @@ public interface DemandProjectMapper { /** - * 根据用户名查询需求项目 - * @param username + * 根据用户名查询需求项目、分页查询 + * @param username 用户名 + * @param startIndex 开始取值下标 + * @param pageSize 页面数据数量 + * @return + */ + List selectDemandProjectListByUsername(String username, Integer startIndex, Integer pageSize); + + /** + * 根据用户名查询其需求项目的数量 + * @param username 用户名 * @return */ - List selectDemandProjectListByUsername(String username); + Integer selectTotalNumberByUsername(String username); /** * 根据用户名和id查询单条需求项目数据 diff --git a/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java b/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java index 7c1da759..321f95b0 100644 --- a/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/SkillProjectMapper.java @@ -23,12 +23,20 @@ public interface SkillProjectMapper { Integer insertSkillProject(SkillProject skillProject); /** - * 根据用户名查询技能需求项目 + * 根据用户名查询技能需求项目、分页 * @param username 用户名 + * @param startIndex 开始下标 + * @param pageSize 数据量 * @return */ - List selectSkillProjectListByUsername(String username); + List selectSkillProjectListByUsername(String username, Integer startIndex, Integer pageSize); + /** + * 根据用户名查询其技能项目总数量 + * @param username 用户名 + * @return + */ + Integer selectTotalNumberByUsername(String username); /** * 根据用户名、id查询单条技能项目数据 * @param username 用户名 diff --git a/share_project/src/main/java/com/share/service/DemandProjectService.java b/share_project/src/main/java/com/share/service/DemandProjectService.java index d2318ad4..4b8220d3 100644 --- a/share_project/src/main/java/com/share/service/DemandProjectService.java +++ b/share_project/src/main/java/com/share/service/DemandProjectService.java @@ -22,9 +22,10 @@ public interface DemandProjectService { /** * 根据用户名获取其发布的项目 * @param username 用户名 + * @param currentIndex 当前页面 * @return */ - ResultInfo getDemandProjectList(String username); + ResultInfo getDemandProjectList(String username, Integer currentIndex); /** * 根据用户名、id获取指定项目数据 diff --git a/share_project/src/main/java/com/share/service/SkillProjectService.java b/share_project/src/main/java/com/share/service/SkillProjectService.java index 67bd5d06..5d5d9a75 100644 --- a/share_project/src/main/java/com/share/service/SkillProjectService.java +++ b/share_project/src/main/java/com/share/service/SkillProjectService.java @@ -22,9 +22,10 @@ public interface SkillProjectService { /** * 根据用户名获取需求项目列表 * @param username 用户名 + * @param currentPageIndex 当前页面下标 * @return */ - ResultInfo getSkillProjectList(String username); + ResultInfo getSkillProjectList(String username, Integer currentPageIndex); /** * 根据用户名、id获取单条需求项目详细数据 diff --git a/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java index 694ac54a..185e46a0 100644 --- a/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/DemandProjectServiceImpl.java @@ -15,7 +15,9 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author 谢佳豪 @@ -31,6 +33,8 @@ public class DemandProjectServiceImpl implements DemandProjectService { private UserInfoMapper userInfoMapper; + private Integer pageSize = 10; + @Autowired public void setDemandProjectMapper(DemandProjectMapper demandProjectMapper) { this.demandProjectMapper = demandProjectMapper; @@ -46,17 +50,6 @@ public class DemandProjectServiceImpl implements DemandProjectService { this.userInfoMapper = userInfoMapper; } - /** - * 获取当前时间 - * - * @return 时间字符串 - */ - public static String getCurrentTime() { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date d = new Date(); - return sdf.format(d); - } - @Override @Transactional(rollbackFor = Exception.class) public ResultInfo addDemandProject(DemandProject demandProject, String operation) { @@ -68,7 +61,7 @@ public class DemandProjectServiceImpl implements DemandProjectService { } //设置发布项目的发布时间 - demandProject.setStartTime(getCurrentTime()); + demandProject.setStartTime(new Date()); //TODO 安全问题:插入数据,需要校验token值,拦截器拦截检验header中的token值 //添加需求项目表数据 @@ -110,15 +103,32 @@ public class DemandProjectServiceImpl implements DemandProjectService { } @Override - public ResultInfo getDemandProjectList(String username) { + public ResultInfo getDemandProjectList(String username, Integer currentPageIndex) { //检验用户名是否存在,以免发送错误请求 int i = userInfoMapper.selectUserByUsername(username); if (i == 1) { + //查询下标值 + Integer startIndex = (currentPageIndex - 1) * pageSize; + //根据用户名查询其发布的项目 - List userProjectListData = demandProjectMapper.selectDemandProjectListByUsername(username); + List userProjectListData = demandProjectMapper.selectDemandProjectListByUsername(username, startIndex, pageSize); + + //当项目数 > 0 if (userProjectListData.size() > 0) { - return ResultInfo.successInfo("查询成功^O^", userProjectListData); + //将数据以键值对的形式存入到map中 + Map map = new HashMap<>(); + + //查询用户发布需求项目的总数量 + Integer totalNumber = demandProjectMapper.selectTotalNumberByUsername(username); + + //计算总页数 + Integer pageCount = (totalNumber % pageSize) != 0 ? (totalNumber / pageSize) + 1 : (totalNumber / pageSize); + + map.put("userProjectListData", userProjectListData); + map.put("pageCount", pageCount); + + return ResultInfo.successInfo("查询成功^O^", map); } else { return ResultInfo.successInfo("您还未发布过项目,快点行动起来吧^_^"); } diff --git a/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java b/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java index 468d1e13..cc9b535f 100644 --- a/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/SkillProjectServiceImpl.java @@ -13,7 +13,9 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author 谢佳豪 @@ -29,6 +31,8 @@ public class SkillProjectServiceImpl implements SkillProjectService { private UserInfoMapper userInfoMapper; + private Integer pageSize = 10; + @Autowired public void setSkillProjectMapper(SkillProjectMapper skillProjectMapper) { this.skillProjectMapper = skillProjectMapper; @@ -44,16 +48,6 @@ public class SkillProjectServiceImpl implements SkillProjectService { this.userInfoMapper = userInfoMapper; } - /** - * 获取当前时间 - * @return 时间字符串 - */ - public static String getCurrentTime(){ - SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date d= new Date(); - return sdf.format(d); - } - @Override @Transactional(rollbackFor=Exception.class) public ResultInfo addSkillProject(SkillProject skillProject, String operation) { @@ -65,7 +59,7 @@ public class SkillProjectServiceImpl implements SkillProjectService { } //设置发布项目的发布时间 - skillProject.setStartTime(getCurrentTime()); + skillProject.setStartTime(new Date()); //TODO 安全问题:插入数据,需要校验token值,拦截器拦截检验header中的token值 //添加需求项目表数据 @@ -107,14 +101,30 @@ public class SkillProjectServiceImpl implements SkillProjectService { } @Override - public ResultInfo getSkillProjectList(String username) { + public ResultInfo getSkillProjectList(String username, Integer currentPageIndex) { //检验用户名是否存在,以免发送错误请求 int i = userInfoMapper.selectUserByUsername(username); + if (i == 1) { + //查询下标值 + Integer startIndex = (currentPageIndex - 1) * pageSize; + //根据用户名查询其发布的项目 - List userProjectListData = skillProjectMapper.selectSkillProjectListByUsername(username); + List userProjectListData = skillProjectMapper.selectSkillProjectListByUsername(username, startIndex, pageSize); if (userProjectListData.size() > 0) { - return ResultInfo.successInfo("查询成功^O^", userProjectListData); + //将数据以键值对的形式存入到map中 + Map map = new HashMap<>(); + + //查询用户发布需求项目的总数量 + Integer totalNumber = skillProjectMapper.selectTotalNumberByUsername(username); + + //计算总页数 + Integer pageCount = (totalNumber % pageSize) != 0 ? (totalNumber / pageSize) + 1 : (totalNumber / pageSize); + + map.put("userProjectListData", userProjectListData); + map.put("pageCount", pageCount); + + return ResultInfo.successInfo("查询成功^O^", map); } else { return ResultInfo.successInfo("您还未发布过项目,快点行动起来吧^_^"); } diff --git a/share_project/src/main/resources/mapper/DemandProjectMapper.xml b/share_project/src/main/resources/mapper/DemandProjectMapper.xml index 91a21706..fc45daf3 100644 --- a/share_project/src/main/resources/mapper/DemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/DemandProjectMapper.xml @@ -43,11 +43,12 @@ #{type}, #{method}, #{publisher}, #{startTime}, #{endTime}); - - select id, project_name, project_desc, start_time, status from demand_project as dp, user_demand_project as udp - where dp.id = udp.project_id and dp.publisher = #{username}; + where dp.id = udp.project_id and dp.publisher = #{username} + limit #{startIndex}, #{pageSize}; @@ -58,6 +59,12 @@ + + + + + @@ -43,6 +44,11 @@ + + + update skill_project -- Gitee