diff --git a/sql/20201201.sql b/sql/20201201.sql new file mode 100644 index 000000000..75f040182 --- /dev/null +++ b/sql/20201201.sql @@ -0,0 +1,3 @@ +alter table company + add managers varchar(32) null comment '公司管理者'; + diff --git a/src/main/java/club/joylink/rtss/controller/CompanyController.java b/src/main/java/club/joylink/rtss/controller/CompanyController.java index 9a9f74266..124a901f7 100644 --- a/src/main/java/club/joylink/rtss/controller/CompanyController.java +++ b/src/main/java/club/joylink/rtss/controller/CompanyController.java @@ -1,6 +1,7 @@ package club.joylink.rtss.controller; import club.joylink.rtss.services.ICompanyService; +import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.CompanyQueryVO; import club.joylink.rtss.vo.client.CompanyVO; import club.joylink.rtss.vo.client.PageVO; @@ -9,6 +10,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; import java.util.List; @@ -58,4 +60,10 @@ public class CompanyController { public CompanyVO get(@PathVariable Integer id, @RequestBody @Validated CompanyVO company) { return this.iCompanyService.update(id, company); } + + @ApiOperation("添加公司管理者") + @PutMapping("/{id}/addManager") + public void addManager(@PathVariable Integer id, @RequestBody List userIds, @RequestAttribute @ApiIgnore UserVO user) { + iCompanyService.addManager(id, userIds, user); + } } diff --git a/src/main/java/club/joylink/rtss/dao/CompanyDAO.java b/src/main/java/club/joylink/rtss/dao/CompanyDAO.java index b742e4303..ea70cec63 100644 --- a/src/main/java/club/joylink/rtss/dao/CompanyDAO.java +++ b/src/main/java/club/joylink/rtss/dao/CompanyDAO.java @@ -9,4 +9,4 @@ import org.springframework.stereotype.Repository; */ @Repository public interface CompanyDAO extends MyBatisBaseDao { -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/entity/Company.java b/src/main/java/club/joylink/rtss/entity/Company.java index 78bbddacd..29b8eb5e9 100644 --- a/src/main/java/club/joylink/rtss/entity/Company.java +++ b/src/main/java/club/joylink/rtss/entity/Company.java @@ -24,6 +24,11 @@ public class Company implements Serializable { */ private String phone; + /** + * 公司管理者 + */ + private String managers; + private static final long serialVersionUID = 1L; public Integer getId() { @@ -58,6 +63,14 @@ public class Company implements Serializable { this.phone = phone; } + public String getManagers() { + return managers; + } + + public void setManagers(String managers) { + this.managers = managers; + } + @Override public boolean equals(Object that) { if (this == that) { @@ -73,7 +86,8 @@ public class Company implements Serializable { return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) && (this.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress())) - && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone())); + && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone())) + && (this.getManagers() == null ? other.getManagers() == null : this.getManagers().equals(other.getManagers())); } @Override @@ -84,6 +98,7 @@ public class Company implements Serializable { result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode()); result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode()); + result = prime * result + ((getManagers() == null) ? 0 : getManagers().hashCode()); return result; } @@ -97,8 +112,9 @@ public class Company implements Serializable { sb.append(", name=").append(name); sb.append(", address=").append(address); sb.append(", phone=").append(phone); + sb.append(", managers=").append(managers); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/entity/CompanyExample.java b/src/main/java/club/joylink/rtss/entity/CompanyExample.java index 419973023..3e86c909b 100644 --- a/src/main/java/club/joylink/rtss/entity/CompanyExample.java +++ b/src/main/java/club/joylink/rtss/entity/CompanyExample.java @@ -393,6 +393,76 @@ public class CompanyExample { addCriterion("phone not between", value1, value2, "phone"); return (Criteria) this; } + + public Criteria andManagersIsNull() { + addCriterion("managers is null"); + return (Criteria) this; + } + + public Criteria andManagersIsNotNull() { + addCriterion("managers is not null"); + return (Criteria) this; + } + + public Criteria andManagersEqualTo(String value) { + addCriterion("managers =", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersNotEqualTo(String value) { + addCriterion("managers <>", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersGreaterThan(String value) { + addCriterion("managers >", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersGreaterThanOrEqualTo(String value) { + addCriterion("managers >=", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersLessThan(String value) { + addCriterion("managers <", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersLessThanOrEqualTo(String value) { + addCriterion("managers <=", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersLike(String value) { + addCriterion("managers like", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersNotLike(String value) { + addCriterion("managers not like", value, "managers"); + return (Criteria) this; + } + + public Criteria andManagersIn(List values) { + addCriterion("managers in", values, "managers"); + return (Criteria) this; + } + + public Criteria andManagersNotIn(List values) { + addCriterion("managers not in", values, "managers"); + return (Criteria) this; + } + + public Criteria andManagersBetween(String value1, String value2) { + addCriterion("managers between", value1, value2, "managers"); + return (Criteria) this; + } + + public Criteria andManagersNotBetween(String value1, String value2) { + addCriterion("managers not between", value1, value2, "managers"); + return (Criteria) this; + } } /** @@ -489,4 +559,4 @@ public class CompanyExample { this(condition, value, secondValue, null); } } -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/services/CompanyService.java b/src/main/java/club/joylink/rtss/services/CompanyService.java index fe2c41480..f0d801695 100644 --- a/src/main/java/club/joylink/rtss/services/CompanyService.java +++ b/src/main/java/club/joylink/rtss/services/CompanyService.java @@ -3,8 +3,11 @@ package club.joylink.rtss.services; import club.joylink.rtss.dao.CompanyDAO; import club.joylink.rtss.entity.Company; import club.joylink.rtss.entity.CompanyExample; +import club.joylink.rtss.entity.SysUser; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.completition.IRaceQuestionsRuleService; +import club.joylink.rtss.util.JsonUtils; +import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.CompanyQueryVO; import club.joylink.rtss.vo.client.CompanyVO; import club.joylink.rtss.vo.client.PageVO; @@ -16,15 +19,20 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import java.util.List; +import java.util.stream.Collectors; @Service public class CompanyService implements ICompanyService { @Autowired private CompanyDAO companyDAO; + @Autowired private IRaceQuestionsRuleService IRaceQuestionsRuleService; + @Autowired + private ISysUserService iSysUserService; + @Override public List queryOrganizations() { CompanyExample example = new CompanyExample(); @@ -42,7 +50,24 @@ public class CompanyService implements ICompanyService { criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); } Page page = (Page) companyDAO.selectByExample(example); - return PageVO.convert(page, CompanyVO.convert2VOList(page.getResult())); + List voList = page.getResult().stream().filter(company -> StringUtils.hasText(company.getManagers())) + .map(company -> { + List managerIds = JsonUtils.readCollection(company.getManagers(), List.class, Long.class); + List managers = iSysUserService.findEntity(managerIds); + List managerNames = managers.stream().map(SysUser::getNickname).collect(Collectors.toList()); + return CompanyVO.convertFromDB(company, managerNames); + }).collect(Collectors.toList()); + return PageVO.convert(page, voList); + } + + @Override + public void addManager(Integer id, List userIds, UserVO user) { + Company entity = getEntity(id); + List managerIds = JsonUtils.readCollection(entity.getManagers(), List.class, Long.class); + managerIds.addAll(userIds); + managerIds = managerIds.stream().distinct().collect(Collectors.toList()); + entity.setManagers(JsonUtils.writeValueAsString(managerIds)); + companyDAO.updateByPrimaryKey(entity); } @Override @@ -84,4 +109,10 @@ public class CompanyService implements ICompanyService { return true; } + private Company getEntity(Integer id) { + Company company = companyDAO.selectByPrimaryKey(id); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(company); + return company; + } + } diff --git a/src/main/java/club/joylink/rtss/services/ICompanyService.java b/src/main/java/club/joylink/rtss/services/ICompanyService.java index d06c9230b..8c045b2de 100644 --- a/src/main/java/club/joylink/rtss/services/ICompanyService.java +++ b/src/main/java/club/joylink/rtss/services/ICompanyService.java @@ -1,5 +1,6 @@ package club.joylink.rtss.services; +import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.CompanyQueryVO; import club.joylink.rtss.vo.client.CompanyVO; import club.joylink.rtss.vo.client.PageVO; @@ -21,4 +22,9 @@ public interface ICompanyService { boolean isExist(Integer companyId); PageVO queryPageOrganizations(CompanyQueryVO queryVO); + + /** + * 添加公司管理者 + */ + void addManager(Integer id, List userIds, UserVO user); } diff --git a/src/main/java/club/joylink/rtss/services/ISysUserService.java b/src/main/java/club/joylink/rtss/services/ISysUserService.java index 6ef7737d3..8005f75b3 100644 --- a/src/main/java/club/joylink/rtss/services/ISysUserService.java +++ b/src/main/java/club/joylink/rtss/services/ISysUserService.java @@ -5,8 +5,6 @@ import club.joylink.rtss.vo.UserQueryVO; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.UserConfigVO; -import club.joylink.rtss.vo.client.UserSubscribeVO; -import club.joylink.rtss.vo.client.map.MapVO; import club.joylink.rtss.vo.client.user.*; import club.joylink.rtss.vo.wx.WmUserSession; @@ -278,4 +276,6 @@ public interface ISysUserService { List getUsersWithMobile(); List getPlatformUsers(); + + List findEntity(List ids); } diff --git a/src/main/java/club/joylink/rtss/services/SysUserService.java b/src/main/java/club/joylink/rtss/services/SysUserService.java index 45f6b6119..89a4438ef 100644 --- a/src/main/java/club/joylink/rtss/services/SysUserService.java +++ b/src/main/java/club/joylink/rtss/services/SysUserService.java @@ -730,4 +730,11 @@ public class SysUserService implements ISysUserService { List users = sysUsers.stream().map(UserVO::new).collect(Collectors.toList()); return users; } + + @Override + public List findEntity(List ids) { + SysUserExample example = new SysUserExample(); + example.createCriteria().andIdIn(ids); + return sysUserDAO.selectByExample(example); + } } diff --git a/src/main/java/club/joylink/rtss/vo/client/CompanyVO.java b/src/main/java/club/joylink/rtss/vo/client/CompanyVO.java index dad6260f5..215e1d71c 100644 --- a/src/main/java/club/joylink/rtss/vo/client/CompanyVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/CompanyVO.java @@ -1,8 +1,8 @@ package club.joylink.rtss.vo.client; +import club.joylink.rtss.entity.Company; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import club.joylink.rtss.entity.Company; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -29,6 +29,8 @@ public class CompanyVO { /**联系方式*/ private String phone = ""; + private List managerNames; + public CompanyVO(Company entity) { this.id = entity.getId(); this.name = entity.getName(); @@ -44,7 +46,13 @@ public class CompanyVO { return voList; } - public Company toDB() { + public static CompanyVO convertFromDB(Company company, List managerNames) { + CompanyVO vo = new CompanyVO(company); + vo.setManagerNames(managerNames); + return vo; + } + + public Company toDB() { Company entity = new Company(); entity.setId(this.id); entity.setName(this.name); diff --git a/src/main/resources/mybatis/mapper/CompanyDAO.xml b/src/main/resources/mybatis/mapper/CompanyDAO.xml index 70b48c21c..f28fb8e3c 100644 --- a/src/main/resources/mybatis/mapper/CompanyDAO.xml +++ b/src/main/resources/mybatis/mapper/CompanyDAO.xml @@ -1,198 +1,217 @@ - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - + + + + id, `name`, address, phone, managers + + - select - - distinct - - - from company - - - - - order by ${orderByClause} - - - - limit ${offset}, ${limit} - - - limit ${limit} - - - - - + + from company + + + + + order by ${orderByClause} + + + + limit ${offset}, ${limit} + + + limit ${limit} + + + + + delete from company where id = #{id,jdbcType=INTEGER} - - delete from company - - - - - - insert into company (`name`, address, phone - ) - values (#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR} - ) + + delete from company + + + + + + insert into company (`name`, address, phone, + managers) + values (#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, + #{managers,jdbcType=VARCHAR}) - - insert into company - - - `name`, - - - address, - - - phone, - - - - - #{name,jdbcType=VARCHAR}, - - - #{address,jdbcType=VARCHAR}, - - - #{phone,jdbcType=VARCHAR}, - - - - - - update company - - - id = #{record.id,jdbcType=INTEGER}, - - + + insert into company + + + `name`, + + + address, + + + phone, + + + managers, + + + + + #{name,jdbcType=VARCHAR}, + + + #{address,jdbcType=VARCHAR}, + + + #{phone,jdbcType=VARCHAR}, + + + #{managers,jdbcType=VARCHAR}, + + + + + + update company + + + id = #{record.id,jdbcType=INTEGER}, + + + `name` = #{record.name,jdbcType=VARCHAR}, + + + address = #{record.address,jdbcType=VARCHAR}, + + + phone = #{record.phone,jdbcType=VARCHAR}, + + + managers = #{record.managers,jdbcType=VARCHAR}, + + + + + + + + update company + set id = #{record.id,jdbcType=INTEGER}, `name` = #{record.name,jdbcType=VARCHAR}, - - address = #{record.address,jdbcType=VARCHAR}, - - phone = #{record.phone,jdbcType=VARCHAR}, - - - - - - - - update company - set id = #{record.id,jdbcType=INTEGER}, - `name` = #{record.name,jdbcType=VARCHAR}, - address = #{record.address,jdbcType=VARCHAR}, - phone = #{record.phone,jdbcType=VARCHAR} - - - - - - update company - - - `name` = #{name,jdbcType=VARCHAR}, - - - address = #{address,jdbcType=VARCHAR}, - - - phone = #{phone,jdbcType=VARCHAR}, - - - where id = #{id,jdbcType=INTEGER} - - + managers = #{record.managers,jdbcType=VARCHAR} + + + + + + update company + + + `name` = #{name,jdbcType=VARCHAR}, + + + address = #{address,jdbcType=VARCHAR}, + + + phone = #{phone,jdbcType=VARCHAR}, + + + managers = #{managers,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + update company set `name` = #{name,jdbcType=VARCHAR}, address = #{address,jdbcType=VARCHAR}, - phone = #{phone,jdbcType=VARCHAR} + phone = #{phone,jdbcType=VARCHAR}, + managers = #{managers,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER} - \ No newline at end of file +