添加公司管理员

This commit is contained in:
joylink_zhangsai 2020-12-02 12:03:30 +08:00
parent 700e6274f0
commit 16946294a1
11 changed files with 357 additions and 189 deletions

3
sql/20201201.sql Normal file
View File

@ -0,0 +1,3 @@
alter table company
add managers varchar(32) null comment '公司管理者';

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.controller; package club.joylink.rtss.controller;
import club.joylink.rtss.services.ICompanyService; 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.CompanyQueryVO;
import club.joylink.rtss.vo.client.CompanyVO; import club.joylink.rtss.vo.client.CompanyVO;
import club.joylink.rtss.vo.client.PageVO; 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.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List; import java.util.List;
@ -58,4 +60,10 @@ public class CompanyController {
public CompanyVO get(@PathVariable Integer id, @RequestBody @Validated CompanyVO company) { public CompanyVO get(@PathVariable Integer id, @RequestBody @Validated CompanyVO company) {
return this.iCompanyService.update(id, company); return this.iCompanyService.update(id, company);
} }
@ApiOperation("添加公司管理者")
@PutMapping("/{id}/addManager")
public void addManager(@PathVariable Integer id, @RequestBody List<Long> userIds, @RequestAttribute @ApiIgnore UserVO user) {
iCompanyService.addManager(id, userIds, user);
}
} }

View File

@ -24,6 +24,11 @@ public class Company implements Serializable {
*/ */
private String phone; private String phone;
/**
* 公司管理者
*/
private String managers;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public Integer getId() { public Integer getId() {
@ -58,6 +63,14 @@ public class Company implements Serializable {
this.phone = phone; this.phone = phone;
} }
public String getManagers() {
return managers;
}
public void setManagers(String managers) {
this.managers = managers;
}
@Override @Override
public boolean equals(Object that) { public boolean equals(Object that) {
if (this == 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())) return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress())) && (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 @Override
@ -84,6 +98,7 @@ public class Company implements Serializable {
result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode()); result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode());
result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode()); result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
result = prime * result + ((getManagers() == null) ? 0 : getManagers().hashCode());
return result; return result;
} }
@ -97,6 +112,7 @@ public class Company implements Serializable {
sb.append(", name=").append(name); sb.append(", name=").append(name);
sb.append(", address=").append(address); sb.append(", address=").append(address);
sb.append(", phone=").append(phone); sb.append(", phone=").append(phone);
sb.append(", managers=").append(managers);
sb.append(", serialVersionUID=").append(serialVersionUID); sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();

View File

@ -393,6 +393,76 @@ public class CompanyExample {
addCriterion("phone not between", value1, value2, "phone"); addCriterion("phone not between", value1, value2, "phone");
return (Criteria) this; 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<String> values) {
addCriterion("managers in", values, "managers");
return (Criteria) this;
}
public Criteria andManagersNotIn(List<String> 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;
}
} }
/** /**

View File

@ -3,8 +3,11 @@ package club.joylink.rtss.services;
import club.joylink.rtss.dao.CompanyDAO; import club.joylink.rtss.dao.CompanyDAO;
import club.joylink.rtss.entity.Company; import club.joylink.rtss.entity.Company;
import club.joylink.rtss.entity.CompanyExample; import club.joylink.rtss.entity.CompanyExample;
import club.joylink.rtss.entity.SysUser;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.completition.IRaceQuestionsRuleService; 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.CompanyQueryVO;
import club.joylink.rtss.vo.client.CompanyVO; import club.joylink.rtss.vo.client.CompanyVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
@ -16,15 +19,20 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class CompanyService implements ICompanyService { public class CompanyService implements ICompanyService {
@Autowired @Autowired
private CompanyDAO companyDAO; private CompanyDAO companyDAO;
@Autowired @Autowired
private IRaceQuestionsRuleService IRaceQuestionsRuleService; private IRaceQuestionsRuleService IRaceQuestionsRuleService;
@Autowired
private ISysUserService iSysUserService;
@Override @Override
public List<CompanyVO> queryOrganizations() { public List<CompanyVO> queryOrganizations() {
CompanyExample example = new CompanyExample(); CompanyExample example = new CompanyExample();
@ -42,7 +50,24 @@ public class CompanyService implements ICompanyService {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
} }
Page<Company> page = (Page<Company>) companyDAO.selectByExample(example); Page<Company> page = (Page<Company>) companyDAO.selectByExample(example);
return PageVO.convert(page, CompanyVO.convert2VOList(page.getResult())); List<CompanyVO> voList = page.getResult().stream().filter(company -> StringUtils.hasText(company.getManagers()))
.map(company -> {
List<Long> managerIds = JsonUtils.readCollection(company.getManagers(), List.class, Long.class);
List<SysUser> managers = iSysUserService.findEntity(managerIds);
List<String> 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<Long> userIds, UserVO user) {
Company entity = getEntity(id);
List<Long> 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 @Override
@ -84,4 +109,10 @@ public class CompanyService implements ICompanyService {
return true; return true;
} }
private Company getEntity(Integer id) {
Company company = companyDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(company);
return company;
}
} }

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.services; package club.joylink.rtss.services;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.CompanyQueryVO; import club.joylink.rtss.vo.client.CompanyQueryVO;
import club.joylink.rtss.vo.client.CompanyVO; import club.joylink.rtss.vo.client.CompanyVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
@ -21,4 +22,9 @@ public interface ICompanyService {
boolean isExist(Integer companyId); boolean isExist(Integer companyId);
PageVO<CompanyVO> queryPageOrganizations(CompanyQueryVO queryVO); PageVO<CompanyVO> queryPageOrganizations(CompanyQueryVO queryVO);
/**
* 添加公司管理者
*/
void addManager(Integer id, List<Long> userIds, UserVO user);
} }

View File

@ -5,8 +5,6 @@ import club.joylink.rtss.vo.UserQueryVO;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.UserConfigVO; 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.client.user.*;
import club.joylink.rtss.vo.wx.WmUserSession; import club.joylink.rtss.vo.wx.WmUserSession;
@ -278,4 +276,6 @@ public interface ISysUserService {
List<UserVO> getUsersWithMobile(); List<UserVO> getUsersWithMobile();
List<UserVO> getPlatformUsers(); List<UserVO> getPlatformUsers();
List<SysUser> findEntity(List<Long> ids);
} }

View File

@ -730,4 +730,11 @@ public class SysUserService implements ISysUserService {
List<UserVO> users = sysUsers.stream().map(UserVO::new).collect(Collectors.toList()); List<UserVO> users = sysUsers.stream().map(UserVO::new).collect(Collectors.toList());
return users; return users;
} }
@Override
public List<SysUser> findEntity(List<Long> ids) {
SysUserExample example = new SysUserExample();
example.createCriteria().andIdIn(ids);
return sysUserDAO.selectByExample(example);
}
} }

View File

@ -1,8 +1,8 @@
package club.joylink.rtss.vo.client; package club.joylink.rtss.vo.client;
import club.joylink.rtss.entity.Company;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import club.joylink.rtss.entity.Company;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -29,6 +29,8 @@ public class CompanyVO {
/**联系方式*/ /**联系方式*/
private String phone = ""; private String phone = "";
private List<String> managerNames;
public CompanyVO(Company entity) { public CompanyVO(Company entity) {
this.id = entity.getId(); this.id = entity.getId();
this.name = entity.getName(); this.name = entity.getName();
@ -44,6 +46,12 @@ public class CompanyVO {
return voList; return voList;
} }
public static CompanyVO convertFromDB(Company company, List<String> managerNames) {
CompanyVO vo = new CompanyVO(company);
vo.setManagerNames(managerNames);
return vo;
}
public Company toDB() { public Company toDB() {
Company entity = new Company(); Company entity = new Company();
entity.setId(this.id); entity.setId(this.id);

View File

@ -6,6 +6,7 @@
<result column="name" jdbcType="VARCHAR" property="name"/> <result column="name" jdbcType="VARCHAR" property="name"/>
<result column="address" jdbcType="VARCHAR" property="address"/> <result column="address" jdbcType="VARCHAR" property="address"/>
<result column="phone" jdbcType="VARCHAR" property="phone"/> <result column="phone" jdbcType="VARCHAR" property="phone"/>
<result column="managers" jdbcType="VARCHAR" property="managers"/>
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -25,7 +26,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -54,7 +56,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -66,7 +69,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, `name`, address, phone id, `name`, address, phone, managers
</sql> </sql>
<select id="selectByExample" parameterType="club.joylink.rtss.entity.CompanyExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="club.joylink.rtss.entity.CompanyExample" resultMap="BaseResultMap">
select select
@ -106,13 +109,15 @@
<include refid="Example_Where_Clause"/> <include refid="Example_Where_Clause"/>
</if> </if>
</delete> </delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.Company" useGeneratedKeys="true"> <insert id="insert" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.Company"
insert into company (`name`, address, phone useGeneratedKeys="true">
) insert into company (`name`, address, phone,
values (#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR} managers)
) values (#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
#{managers,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.Company" useGeneratedKeys="true"> <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.Company"
useGeneratedKeys="true">
insert into company insert into company
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null"> <if test="name != null">
@ -124,6 +129,9 @@
<if test="phone != null"> <if test="phone != null">
phone, phone,
</if> </if>
<if test="managers != null">
managers,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null"> <if test="name != null">
@ -135,6 +143,9 @@
<if test="phone != null"> <if test="phone != null">
#{phone,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
</if> </if>
<if test="managers != null">
#{managers,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="club.joylink.rtss.entity.CompanyExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="club.joylink.rtss.entity.CompanyExample" resultType="java.lang.Long">
@ -158,6 +169,9 @@
<if test="record.phone != null"> <if test="record.phone != null">
phone = #{record.phone,jdbcType=VARCHAR}, phone = #{record.phone,jdbcType=VARCHAR},
</if> </if>
<if test="record.managers != null">
managers = #{record.managers,jdbcType=VARCHAR},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/> <include refid="Update_By_Example_Where_Clause"/>
@ -168,7 +182,8 @@
set id = #{record.id,jdbcType=INTEGER}, set id = #{record.id,jdbcType=INTEGER},
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
address = #{record.address,jdbcType=VARCHAR}, address = #{record.address,jdbcType=VARCHAR},
phone = #{record.phone,jdbcType=VARCHAR} phone = #{record.phone,jdbcType=VARCHAR},
managers = #{record.managers,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/> <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
@ -185,6 +200,9 @@
<if test="phone != null"> <if test="phone != null">
phone = #{phone,jdbcType=VARCHAR}, phone = #{phone,jdbcType=VARCHAR},
</if> </if>
<if test="managers != null">
managers = #{managers,jdbcType=VARCHAR},
</if>
</set> </set>
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
@ -192,7 +210,8 @@
update company update company
set `name` = #{name,jdbcType=VARCHAR}, set `name` = #{name,jdbcType=VARCHAR},
address = #{address,jdbcType=VARCHAR}, address = #{address,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR} phone = #{phone,jdbcType=VARCHAR},
managers = #{managers,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
</mapper> </mapper>