From b34a44931559d9e0f4f360126a8a9f25e364f6bb Mon Sep 17 00:00:00 2001 From: kouse <274295865@qq.com> Date: Thu, 3 Dec 2020 10:32:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/share/controller/UserController.java | 50 +++++++++++ .../java/com/share/domain/CompanyUser.java | 48 ++++++++++ .../java/com/share/domain/PersonalUser.java | 57 ++++++++++++ .../src/main/java/com/share/domain/User.java | 89 +++++++++++++++++++ .../com/share/mapper/CompanyUserMapper.java | 32 +++++++ .../com/share/mapper/PersonalUserMapper.java | 30 +++++++ .../java/com/share/mapper/UserMapper.java | 36 ++++++++ .../java/com/share/service/UserService.java | 37 ++++++++ .../share/service/impl/UserServiceImpl.java | 77 ++++++++++++++++ .../resources/mapper/CompanyUserMapper.xml | 24 +++++ .../resources/mapper/PersonalUserMapper.xml | 25 ++++++ .../main/resources/mapper/UserInfoMapper.xml | 1 + .../src/main/resources/mapper/UserMapper.xml | 21 +++++ 13 files changed, 527 insertions(+) create mode 100644 share_project/src/main/java/com/share/controller/UserController.java create mode 100644 share_project/src/main/java/com/share/domain/CompanyUser.java create mode 100644 share_project/src/main/java/com/share/domain/PersonalUser.java create mode 100644 share_project/src/main/java/com/share/domain/User.java create mode 100644 share_project/src/main/java/com/share/mapper/CompanyUserMapper.java create mode 100644 share_project/src/main/java/com/share/mapper/PersonalUserMapper.java create mode 100644 share_project/src/main/java/com/share/mapper/UserMapper.java create mode 100644 share_project/src/main/java/com/share/service/UserService.java create mode 100644 share_project/src/main/java/com/share/service/impl/UserServiceImpl.java create mode 100644 share_project/src/main/resources/mapper/CompanyUserMapper.xml create mode 100644 share_project/src/main/resources/mapper/PersonalUserMapper.xml create mode 100644 share_project/src/main/resources/mapper/UserMapper.xml diff --git a/share_project/src/main/java/com/share/controller/UserController.java b/share_project/src/main/java/com/share/controller/UserController.java new file mode 100644 index 00000000..93c2513f --- /dev/null +++ b/share_project/src/main/java/com/share/controller/UserController.java @@ -0,0 +1,50 @@ +package com.share.controller; + +import com.share.domain.CompanyUser; +import com.share.domain.PersonalUser; +import com.share.domain.ResultInfo; +import com.share.domain.User; +import com.share.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-02 23:00 + **/ +@Controller +@RequestMapping("/user") +public class UserController { + + private UserService userService; + + @Autowired + public void setUserService(UserService userService) { + this.userService = userService; + } + + /** + * 注册用户 + * @param user 用户数据 + * @return 注册状态 + */ + @RequestMapping("/registration") + public ResultInfo registration(User user){ + return userService.registration(user); + } + + + @RequestMapping("/supplyCompany") + public ResultInfo supplyPersonalInfo(PersonalUser user){ + return userService.supplyPersonalUser(user); + } + + @RequestMapping("supplyCompany") + public ResultInfo supplyCompanyInfo(CompanyUser user){ + return userService.supplyCompanyUser(user); + } + +} diff --git a/share_project/src/main/java/com/share/domain/CompanyUser.java b/share_project/src/main/java/com/share/domain/CompanyUser.java new file mode 100644 index 00000000..1264127a --- /dev/null +++ b/share_project/src/main/java/com/share/domain/CompanyUser.java @@ -0,0 +1,48 @@ +package com.share.domain; + +import java.io.Serializable; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-02 09:16 + **/ +public class CompanyUser implements Serializable { + + /** + * 用户名 + */ + private String username; + + /** + * 电话 + */ + private String telephone; + + /** + * 营业执照编号 + */ + private String licenseCode; + + /** + * 法人姓名 + */ + private String legalName; + + /** + * 公司类型 + */ + private String companyType; + + /** + * 公司地址 + */ + private String address; + + /** + * 公司简介 + */ + private String profile; + +} diff --git a/share_project/src/main/java/com/share/domain/PersonalUser.java b/share_project/src/main/java/com/share/domain/PersonalUser.java new file mode 100644 index 00000000..86c6d8e4 --- /dev/null +++ b/share_project/src/main/java/com/share/domain/PersonalUser.java @@ -0,0 +1,57 @@ +package com.share.domain; + +import java.io.Serializable; + +/** + * Demo Class + * 个人用户信息表映射类 + * @author 古市 + * @date 2020-12-01 21:52 + **/ +public class PersonalUser implements Serializable { + + /** + * 用户名 + */ + private String username; + + /** + * 电话 + */ + private String telephone; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 身份证 + */ + private String identityCard; + + /** + * 学历 + */ + private String qualification; + + /** + * 个人证书 + */ + private String certificate; + + /** + * 技能 + */ + private String skill; + + /** + * 个人简介 + */ + private String profile; + + + + + +} diff --git a/share_project/src/main/java/com/share/domain/User.java b/share_project/src/main/java/com/share/domain/User.java new file mode 100644 index 00000000..e213c45d --- /dev/null +++ b/share_project/src/main/java/com/share/domain/User.java @@ -0,0 +1,89 @@ +package com.share.domain; + +import java.io.Serializable; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-11-29 20:51 + **/ +public class User implements Serializable { + + /** + * 账号 + */ + private String username; + + /** + * 电话号码 + */ + private String telephone; + + /** + * 电子邮箱 + */ + private String email; + + /** + * 密码 + */ + private String password; + + /** + * 用户类型 个人用户--0;公司用户--1 + */ + private String role; + + + 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 String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + @Override + public String toString() { + return "User{" + + "username='" + username + '\'' + + ", telephone='" + telephone + '\'' + + ", email='" + email + '\'' + + ", password='" + password + '\'' + + ", role='" + role + '\'' + + '}'; + } +} diff --git a/share_project/src/main/java/com/share/mapper/CompanyUserMapper.java b/share_project/src/main/java/com/share/mapper/CompanyUserMapper.java new file mode 100644 index 00000000..b4f9c279 --- /dev/null +++ b/share_project/src/main/java/com/share/mapper/CompanyUserMapper.java @@ -0,0 +1,32 @@ +package com.share.mapper; + +import com.share.domain.CompanyUser; +import com.share.domain.PersonalUser; +import com.share.domain.User; +import org.springframework.stereotype.Repository; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-02 22:13 + **/ +@Repository +public interface CompanyUserMapper { + + /** + * 在公司用户表中提前新增一条记录 + * @param user + * @return + */ + int insertUser(User user); + + /** + * 完善用户的数据 + * @param user + * @return + */ + int supplyInfo(CompanyUser user); + + +} diff --git a/share_project/src/main/java/com/share/mapper/PersonalUserMapper.java b/share_project/src/main/java/com/share/mapper/PersonalUserMapper.java new file mode 100644 index 00000000..ab557c7d --- /dev/null +++ b/share_project/src/main/java/com/share/mapper/PersonalUserMapper.java @@ -0,0 +1,30 @@ +package com.share.mapper; + +import com.share.domain.PersonalUser; +import com.share.domain.User; +import org.springframework.stereotype.Repository; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-02 09:23 + **/ +@Repository +public interface PersonalUserMapper { + + /** + * 在个人用户表中提前新增一条记录 + * @param user + * @return + */ + int insertUser(User user); + + /** + * 完善用户的数据 + * @param user + * @return + */ + int supplyInfo(PersonalUser user); + +} diff --git a/share_project/src/main/java/com/share/mapper/UserMapper.java b/share_project/src/main/java/com/share/mapper/UserMapper.java new file mode 100644 index 00000000..160fc4c5 --- /dev/null +++ b/share_project/src/main/java/com/share/mapper/UserMapper.java @@ -0,0 +1,36 @@ +package com.share.mapper; + +import com.share.domain.User; +import org.springframework.stereotype.Repository; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-11-29 20:58 + **/ +@Repository +public interface UserMapper { + + /** + * 往数据库中新增一条user信息 + * @param user 新添加的用户 + */ + void insertUser(User user); + + /** + * 对用户名进行查重 + * @param username + * @return + */ + int selectUsername(String username); + + /** + * 对手机号进行查重 + * @param telephone + * @return + */ + int selectTelephone(String telephone); + + +} diff --git a/share_project/src/main/java/com/share/service/UserService.java b/share_project/src/main/java/com/share/service/UserService.java new file mode 100644 index 00000000..a8e67011 --- /dev/null +++ b/share_project/src/main/java/com/share/service/UserService.java @@ -0,0 +1,37 @@ +package com.share.service; + +import com.share.domain.CompanyUser; +import com.share.domain.PersonalUser; +import com.share.domain.ResultInfo; +import com.share.domain.User; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-02 22:26 + **/ +public interface UserService { + + /** + * 注册用户 + * @param user + * @return + */ + ResultInfo registration(User user); + + /** + * 补充个人用户的信息 + * @param personalUser + * @return + */ + ResultInfo supplyPersonalUser(PersonalUser personalUser); + + /** + * 补充公司用户的信息 + * @param companyUser + * @return + */ + ResultInfo supplyCompanyUser(CompanyUser companyUser); + +} diff --git a/share_project/src/main/java/com/share/service/impl/UserServiceImpl.java b/share_project/src/main/java/com/share/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..09787b26 --- /dev/null +++ b/share_project/src/main/java/com/share/service/impl/UserServiceImpl.java @@ -0,0 +1,77 @@ +package com.share.service.impl; + +import com.share.domain.CompanyUser; +import com.share.domain.PersonalUser; +import com.share.domain.ResultInfo; +import com.share.domain.User; +import com.share.mapper.CompanyUserMapper; +import com.share.mapper.PersonalUserMapper; +import com.share.mapper.UserMapper; +import com.share.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-02 22:26 + **/ +@Service +public class UserServiceImpl implements UserService { + + + private UserMapper userMapper; + + private PersonalUserMapper personalUserMapper; + + private CompanyUserMapper companyUserMapper; + + @Autowired + public void setPersonalUserMapper(PersonalUserMapper personalUserMapper) { + this.personalUserMapper = personalUserMapper; + } + + @Autowired + public void setCompanyUserMapper(CompanyUserMapper companyUserMapper) { + this.companyUserMapper = companyUserMapper; + } + + @Autowired + public void setUserMapper(UserMapper userMapper) { + this.userMapper = userMapper; + } + + final String roleFlag = "1"; + + @Override + public ResultInfo registration(User user) { + //在用户表中添加信息 + userMapper.insertUser(user); + //判断用户类型 + if (roleFlag.equals(user.getRole())){ + //公司用户 + companyUserMapper.insertUser(user); + }else { + personalUserMapper.insertUser(user); + } + + return ResultInfo.successInfo("注册成功"); + } + + @Override + public ResultInfo supplyPersonalUser(PersonalUser personalUser){ + if (personalUserMapper.supplyInfo(personalUser) == 1){ + return ResultInfo.successInfo("成功录入"); + }; + return ResultInfo.failInfo(); + } + + @Override + public ResultInfo supplyCompanyUser(CompanyUser companyUser){ + if (companyUserMapper.supplyInfo(companyUser) == 1){ + return ResultInfo.successInfo("成功录入"); + }; + return ResultInfo.failInfo(); + } +} diff --git a/share_project/src/main/resources/mapper/CompanyUserMapper.xml b/share_project/src/main/resources/mapper/CompanyUserMapper.xml new file mode 100644 index 00000000..4ac78ac8 --- /dev/null +++ b/share_project/src/main/resources/mapper/CompanyUserMapper.xml @@ -0,0 +1,24 @@ + + + + + + insert into company_user (username, telephone) + values (#{username}, #{telephone}) + + + + update company_user set license_code = #{licenseCode}, legal_name = #{legalName}, + company_type = #{companyType}, address = #{address}, profile = #{profile} + where username = #{username} + + + + insert into company_user (username, telephone, license_code, legal_name, company_type, address, profile) + VALUES (#{username}, #{telephone}, #{licenseCode}, #{legalName}, #{companyType}, #{address}, #{profile}) + + + + \ No newline at end of file diff --git a/share_project/src/main/resources/mapper/PersonalUserMapper.xml b/share_project/src/main/resources/mapper/PersonalUserMapper.xml new file mode 100644 index 00000000..4f87e1da --- /dev/null +++ b/share_project/src/main/resources/mapper/PersonalUserMapper.xml @@ -0,0 +1,25 @@ + + + + + + insert into personal_user (username, telephone) + values (#{username}, #{telephone}) + + + + update personal_user set real_name = #{realName}, identity_card = #{identityCard}, + qualification = #{qualification}, certificate = #{certificate}, + skill = #{skill}, profile = #{profile} + where username = #{username} + + + + insert into personal_user (username, telephone, real_name, identity_card, qualification, certificate, skill, profile) + VALUES (#{username}, #{telephone}, #{realName}, #{identityCard}, #{qualification}, #{certificate}, #{skill}, #{profile}) + + + + \ No newline at end of file diff --git a/share_project/src/main/resources/mapper/UserInfoMapper.xml b/share_project/src/main/resources/mapper/UserInfoMapper.xml index 6ae71f0f..6ff9aa21 100644 --- a/share_project/src/main/resources/mapper/UserInfoMapper.xml +++ b/share_project/src/main/resources/mapper/UserInfoMapper.xml @@ -14,4 +14,5 @@ select telephone from user where username = #{username}; + \ No newline at end of file diff --git a/share_project/src/main/resources/mapper/UserMapper.xml b/share_project/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 00000000..9c54acbf --- /dev/null +++ b/share_project/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,21 @@ + + + + + + insert into user (username, telephone, email, password, role) VALUES (#{username}, #{telephone}, #{email}, #{password}, #{role}) + + + + + + + + + \ No newline at end of file -- Gitee From 84187b30468ba737807b1cf220c2c862d11db61f Mon Sep 17 00:00:00 2001 From: kouse <274295865@qq.com> Date: Fri, 4 Dec 2020 19:35:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/share/controller/UserController.java | 29 +++++++- .../controller/UserProjectController.java | 1 + .../java/com/share/domain/CompanyUser.java | 68 +++++++++++++++++ .../java/com/share/domain/PersonalUser.java | 74 +++++++++++++++++++ .../java/com/share/mapper/UserMapper.java | 9 ++- .../java/com/share/service/UserService.java | 21 ++++++ .../share/service/impl/UserServiceImpl.java | 59 ++++++++++++++- .../src/main/resources/mapper/UserMapper.xml | 20 ++++- 8 files changed, 271 insertions(+), 10 deletions(-) diff --git a/share_project/src/main/java/com/share/controller/UserController.java b/share_project/src/main/java/com/share/controller/UserController.java index 93c2513f..19f3f59e 100644 --- a/share_project/src/main/java/com/share/controller/UserController.java +++ b/share_project/src/main/java/com/share/controller/UserController.java @@ -7,7 +7,9 @@ import com.share.domain.User; import com.share.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpSession; /** * Demo Class @@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping; **/ @Controller @RequestMapping("/user") +@ResponseBody public class UserController { private UserService userService; @@ -37,14 +40,34 @@ public class UserController { } - @RequestMapping("/supplyCompany") + @PostMapping("/supplyPerson") public ResultInfo supplyPersonalInfo(PersonalUser user){ return userService.supplyPersonalUser(user); } - @RequestMapping("supplyCompany") + @PostMapping("/supplyCompany") public ResultInfo supplyCompanyInfo(CompanyUser user){ return userService.supplyCompanyUser(user); } + @GetMapping("/repeatUsername/{username}") + public ResultInfo repeatUsername(@PathVariable String username){ + return userService.repeatUsername(username); + } + + @GetMapping("/repeatTelephone/{telephone}") + public ResultInfo repeatTelephone(@PathVariable String telephone){ + return userService.repeatTelephone(telephone); + } + + @PostMapping("/login") + public ResultInfo login(String account, String password, HttpSession session){ + User user = userService.login(account, password); + if (user != null && user.getUsername() != null){ + session.setAttribute("user", user); + return ResultInfo.successInfo("登录成功"); + } + return ResultInfo.failInfo("请检查用户名和密码"); + } + } 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 2d02d678..18f04bf0 100644 --- a/share_project/src/main/java/com/share/controller/UserProjectController.java +++ b/share_project/src/main/java/com/share/controller/UserProjectController.java @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.ResponseBody; */ @Controller @ResponseBody +@RequestMapping("/user") public class UserProjectController { private DemandProjectService demandProjectService; diff --git a/share_project/src/main/java/com/share/domain/CompanyUser.java b/share_project/src/main/java/com/share/domain/CompanyUser.java index 1264127a..b742cfb4 100644 --- a/share_project/src/main/java/com/share/domain/CompanyUser.java +++ b/share_project/src/main/java/com/share/domain/CompanyUser.java @@ -45,4 +45,72 @@ public class CompanyUser implements Serializable { */ private String profile; + @Override + public String toString() { + return "CompanyUser{" + + "username='" + username + '\'' + + ", telephone='" + telephone + '\'' + + ", licenseCode='" + licenseCode + '\'' + + ", legalName='" + legalName + '\'' + + ", companyType='" + companyType + '\'' + + ", address='" + address + '\'' + + ", profile='" + profile + '\'' + + '}'; + } + + 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 String getLicenseCode() { + return licenseCode; + } + + public void setLicenseCode(String licenseCode) { + this.licenseCode = licenseCode; + } + + public String getLegalName() { + return legalName; + } + + public void setLegalName(String legalName) { + this.legalName = legalName; + } + + public String getCompanyType() { + return companyType; + } + + public void setCompanyType(String companyType) { + this.companyType = companyType; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getProfile() { + return profile; + } + + public void setProfile(String profile) { + this.profile = profile; + } } diff --git a/share_project/src/main/java/com/share/domain/PersonalUser.java b/share_project/src/main/java/com/share/domain/PersonalUser.java index 86c6d8e4..2b048a05 100644 --- a/share_project/src/main/java/com/share/domain/PersonalUser.java +++ b/share_project/src/main/java/com/share/domain/PersonalUser.java @@ -51,7 +51,81 @@ public class PersonalUser implements Serializable { private String profile; + 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 String getRealName() { + return realName; + } + + public void setRealName(String realName) { + this.realName = realName; + } + + public String getIdentityCard() { + return identityCard; + } + + public void setIdentityCard(String identityCard) { + this.identityCard = identityCard; + } + + public String getQualification() { + return qualification; + } + + public void setQualification(String qualification) { + this.qualification = qualification; + } + + public String getCertificate() { + return certificate; + } + + public void setCertificate(String certificate) { + this.certificate = certificate; + } + + public String getSkill() { + return skill; + } + + public void setSkill(String skill) { + this.skill = skill; + } + + public String getProfile() { + return profile; + } + + public void setProfile(String profile) { + this.profile = profile; + } + + @Override + public String toString() { + return "PersonalUser{" + + "username='" + username + '\'' + + ", telephone='" + telephone + '\'' + + ", realName='" + realName + '\'' + + ", identityCard='" + identityCard + '\'' + + ", qualification='" + qualification + '\'' + + ", certificate='" + certificate + '\'' + + ", skill='" + skill + '\'' + + ", profile='" + profile + '\'' + + '}'; + } } diff --git a/share_project/src/main/java/com/share/mapper/UserMapper.java b/share_project/src/main/java/com/share/mapper/UserMapper.java index 160fc4c5..9aff00a4 100644 --- a/share_project/src/main/java/com/share/mapper/UserMapper.java +++ b/share_project/src/main/java/com/share/mapper/UserMapper.java @@ -3,6 +3,8 @@ package com.share.mapper; import com.share.domain.User; import org.springframework.stereotype.Repository; +import java.util.Map; + /** * Demo Class * @@ -32,5 +34,10 @@ public interface UserMapper { */ int selectTelephone(String telephone); - + /** + * 用户登录接口 + * @param map 参数表,包括两个参数 password,account 有三种数据(邮箱、手机号、用户名) + * @return + */ + User login(Map map); } diff --git a/share_project/src/main/java/com/share/service/UserService.java b/share_project/src/main/java/com/share/service/UserService.java index a8e67011..fa11ecf3 100644 --- a/share_project/src/main/java/com/share/service/UserService.java +++ b/share_project/src/main/java/com/share/service/UserService.java @@ -34,4 +34,25 @@ public interface UserService { */ ResultInfo supplyCompanyUser(CompanyUser companyUser); + /** + * 查询是否有重复的手机号 + * @param telephone + * @return + */ + ResultInfo repeatTelephone(String telephone); + + /** + * 查询是否有重复的用户名 + * @param username + * @return + */ + ResultInfo repeatUsername(String username); + + /** + * 用户登录的业务逻辑 + * @param account 用户名、手机号、邮箱 + * @param password 密码 + * @return + */ + User login(String account, String password); } diff --git a/share_project/src/main/java/com/share/service/impl/UserServiceImpl.java b/share_project/src/main/java/com/share/service/impl/UserServiceImpl.java index 09787b26..2ce819f7 100644 --- a/share_project/src/main/java/com/share/service/impl/UserServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/UserServiceImpl.java @@ -10,6 +10,10 @@ import com.share.mapper.UserMapper; import com.share.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.HashMap; +import java.util.Map; /** * Demo Class @@ -46,6 +50,14 @@ public class UserServiceImpl implements UserService { @Override public ResultInfo registration(User user) { + //判断是否有重复的电话,或用户名 + if (userMapper.selectUsername(user.getUsername().strip()) > 0){ + return ResultInfo.failInfo("有重复的用户名"); + } + if (userMapper.selectTelephone(user.getTelephone().strip()) > 0){ + //查询出有重复的手机号 + return ResultInfo.failInfo("有重复的手机号"); + } //在用户表中添加信息 userMapper.insertUser(user); //判断用户类型 @@ -63,15 +75,54 @@ public class UserServiceImpl implements UserService { public ResultInfo supplyPersonalUser(PersonalUser personalUser){ if (personalUserMapper.supplyInfo(personalUser) == 1){ return ResultInfo.successInfo("成功录入"); - }; - return ResultInfo.failInfo(); + } + return ResultInfo.failInfo("写入失败"); } @Override public ResultInfo supplyCompanyUser(CompanyUser companyUser){ if (companyUserMapper.supplyInfo(companyUser) == 1){ return ResultInfo.successInfo("成功录入"); - }; - return ResultInfo.failInfo(); + } + return ResultInfo.failInfo("写入失败"); + } + + @Override + public ResultInfo repeatTelephone(String telephone) { + if (userMapper.selectTelephone(telephone.strip()) > 0){ + //查询出有重复的手机号 + return ResultInfo.failInfo("有重复的手机号"); + } + return ResultInfo.successInfo(); + } + + @Override + public ResultInfo repeatUsername(String username) { + if (userMapper.selectUsername(username.strip()) > 0){ + return ResultInfo.failInfo("有重复的用户名"); + } + return ResultInfo.successInfo(); } + + + @Override + public User login(String account, String password){ + //对account进行类型的判断 + //判断是邮箱还是手机号的正则表达式 + String em = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; + String ph = "^((13[0-9])|(15[^4,\\D])|(17[0-9])|(18[0,5-9]))\\d{8}$"; + + Mapparam = new HashMap<>(); + if(account.matches(ph)) { + param.put("telephone", account); + }else if(account.matches(em)) { + param.put("email", account); + }else { + param.put("username", account); + } + param.put("password", password); + return userMapper.login(param); + } + + } diff --git a/share_project/src/main/resources/mapper/UserMapper.xml b/share_project/src/main/resources/mapper/UserMapper.xml index 9c54acbf..8e4e3c3f 100644 --- a/share_project/src/main/resources/mapper/UserMapper.xml +++ b/share_project/src/main/resources/mapper/UserMapper.xml @@ -8,14 +8,30 @@ insert into user (username, telephone, email, password, role) VALUES (#{username}, #{telephone}, #{email}, #{password}, #{role}) - select count(username) from user where username = #{username} - select count(telephone) from user where telephone = #{telephone} + + \ No newline at end of file -- Gitee From cf50cab02500968f111d1c273493c00f7c60c9ff Mon Sep 17 00:00:00 2001 From: kouse <274295865@qq.com> Date: Sun, 6 Dec 2020 19:17:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DemandProjectController.java | 17 +++ .../com/share/controller/TestController.java | 4 +- .../com/share/mapper/DemandProjectMapper.java | 20 ++- .../com/share/service/ProjectShowService.java | 3 +- .../impl/DemandProjectShowServiceImpl.java | 29 +++- .../com/share/vo/DemandProjectResponse.java | 125 ++++++++++++++++++ .../resources/mapper/DemandProjectMapper.xml | 41 +++++- .../mapper/UserDemandProjectMapper.xml | 10 ++ 8 files changed, 236 insertions(+), 13 deletions(-) create mode 100644 share_project/src/main/java/com/share/vo/DemandProjectResponse.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 7c51b44d..3fd16ce5 100644 --- a/share_project/src/main/java/com/share/controller/DemandProjectController.java +++ b/share_project/src/main/java/com/share/controller/DemandProjectController.java @@ -3,10 +3,13 @@ package com.share.controller; import com.share.domain.DemandProject; import com.share.domain.ResultInfo; import com.share.service.DemandProjectService; +import com.share.service.ProjectShowService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; + /** * @author 谢佳豪 * @data 2020/11/24 - 20:12 @@ -19,6 +22,15 @@ public class DemandProjectController { private DemandProjectService demandProjectService; + private ProjectShowService projectShowService; + + + + @Resource(name = "demandProjectShowService") + public void setProjectShowService(ProjectShowService projectShowService) { + this.projectShowService = projectShowService; + } + @Autowired public void setDemandProjectService(DemandProjectService demandProjectService) { this.demandProjectService = demandProjectService; @@ -35,4 +47,9 @@ public class DemandProjectController { return demandProjectService.addDemandProject(demandProject, operation); } + @GetMapping("/project") + public ResultInfo selectProject(String projectName, String type, int page){ + return projectShowService.getProjectsByType(projectName, type, page); + } + } diff --git a/share_project/src/main/java/com/share/controller/TestController.java b/share_project/src/main/java/com/share/controller/TestController.java index fa36e014..42df09ab 100644 --- a/share_project/src/main/java/com/share/controller/TestController.java +++ b/share_project/src/main/java/com/share/controller/TestController.java @@ -29,8 +29,8 @@ public class TestController { @RequestMapping("/1") @ResponseBody - public ResultInfo test(){ - return projectShowService.getProjectsByType("美工", 1); + public ResultInfo test(String projectName, String type, int page){ + return projectShowService.getProjectsByType(projectName, type, page); } 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 8685c5f5..43f28c00 100644 --- a/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java +++ b/share_project/src/main/java/com/share/mapper/DemandProjectMapper.java @@ -1,6 +1,7 @@ package com.share.mapper; import com.share.domain.DemandProject; +import com.share.vo.DemandProjectResponse; import com.share.vo.UserProjectListData; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -49,10 +50,19 @@ public interface DemandProjectMapper { /** - * 通过项目类型获取项目列表 - * @param type - * @param page - * @return + * 根据条件进行分页查询 + * @param projectName 项目名称,也可以为缩写 + * @param type 项目类型 + * @param page 分页查询出来的页数 + * @return 项目基本信息列表 + */ + List selectProjectByCondition(String projectName, String type, Integer page); + + /** + * 根据条件查询出项目总条数 + * @param projectName 项目名称,模糊查询的参数 + * @param type 项目类型 + * @return 查询出来的项目总数 */ - List selectProjectByType(String type, int page); + Integer countProjectByCondition(@Param("projectName") String projectName, @Param("type") String type); } diff --git a/share_project/src/main/java/com/share/service/ProjectShowService.java b/share_project/src/main/java/com/share/service/ProjectShowService.java index 7e05fbbe..f6d0dc82 100644 --- a/share_project/src/main/java/com/share/service/ProjectShowService.java +++ b/share_project/src/main/java/com/share/service/ProjectShowService.java @@ -15,9 +15,10 @@ public interface ProjectShowService { * 通过项目类型获取相应的项目列表 * @param type 项目类型 * @param page 页数 + * @param projectName 项目名称 * @return */ - ResultInfo getProjectsByType(@Param("type") String type, @Param("page") int page); + ResultInfo getProjectsByType(String projectName, String type, 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 index cca22f10..3d65c962 100644 --- a/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java +++ b/share_project/src/main/java/com/share/service/impl/DemandProjectShowServiceImpl.java @@ -1,12 +1,16 @@ 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 com.share.vo.DemandProjectResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Demo Class * @@ -25,7 +29,26 @@ public class DemandProjectShowServiceImpl implements ProjectShowService { } @Override - public ResultInfo getProjectsByType(String type, int page) { - return ResultInfo.successInfo("成功", demandProjectMapper.selectProjectByType(type, (page - 1) * 20)); + public ResultInfo getProjectsByType(String projectName, String type, int page) { + int totalCount = demandProjectMapper.countProjectByCondition(projectName, type); + int totalPage; + //计算总页数和项目的总条数 + if (totalCount % 20 == 0){ + totalPage = totalCount / 20; + }else { + totalPage = totalCount / 20 + 1; + } + + if (page > totalPage || page <= 0){ + //如果提供的page参数越界,直接返回结果 + return ResultInfo.failInfo("页数错误"); + } + List responseList = demandProjectMapper.selectProjectByCondition(projectName, type, (page - 1) * 20); + //将数据存入hash表中 + Map resultMap = new HashMap<>(); + resultMap.put("totalCount", totalCount); + resultMap.put("totalPage", totalPage); + resultMap.put("result", responseList); + return ResultInfo.successInfo("success", resultMap); } } diff --git a/share_project/src/main/java/com/share/vo/DemandProjectResponse.java b/share_project/src/main/java/com/share/vo/DemandProjectResponse.java new file mode 100644 index 00000000..b49c037b --- /dev/null +++ b/share_project/src/main/java/com/share/vo/DemandProjectResponse.java @@ -0,0 +1,125 @@ +package com.share.vo; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import java.io.Serializable; + +/** + * Demo Class + * + * @author 古市 + * @date 2020-12-06 16:55 + **/ +@JsonIgnoreProperties(value = { "handler" }) +public class DemandProjectResponse implements Serializable { + /** + * 项目编号 + */ + private Integer id; + /** + * 项目名称 + */ + private String projectName; + /** + * 项目描述 + */ + private String projectDesc; + /** + * 价钱 + */ + private Float price; + /** + * 地址 + */ + private String address; + /** + * 所需技能 + */ + private String skill; + /** + * 用户名 + */ + private String username; + /** + * 电话 + */ + private String telephone; + + 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 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 getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + + @Override + public String toString() { + return "DemandProjectResponse{" + + "id=" + id + + ", projectName='" + projectName + '\'' + + ", projectDesc='" + projectDesc + '\'' + + ", price=" + price + + ", address='" + address + '\'' + + ", skill='" + skill + '\'' + + ", username='" + username + '\'' + + ", telephone='" + telephone + '\'' + + '}'; + } +} diff --git a/share_project/src/main/resources/mapper/DemandProjectMapper.xml b/share_project/src/main/resources/mapper/DemandProjectMapper.xml index b710e988..91a21706 100644 --- a/share_project/src/main/resources/mapper/DemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/DemandProjectMapper.xml @@ -4,6 +4,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + @@ -19,6 +20,19 @@ + + + + + + + + + + + + + insert into demand_project @@ -84,8 +98,31 @@ where publisher = #{username} and id = #{id}; - + select id,project_name, price, skill, project_desc, address from demand_project + + + and type = #{type} + + + and project_name like concat('%',#{projectName},'%') + + + limit #{page}, 20 + + + + \ 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 056cc2e9..3bea2db4 100644 --- a/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml +++ b/share_project/src/main/resources/mapper/UserDemandProjectMapper.xml @@ -20,4 +20,14 @@ update user_demand_project set status = #{status} where project_id = #{id}; + + + + + + \ No newline at end of file -- Gitee