Commit e47d9d92 authored by licc's avatar licc

优化方案查询 新增用户uuid字段

parent c921ec7e
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<result column="user_name" property="userName"/> <result column="user_name" property="userName"/>
<result column="password" property="password"/> <result column="password" property="password"/>
<result column="phone" property="phone"/> <result column="phone" property="phone"/>
<result column="uuid" property="uuid"/>
<result column="head_image" property="headImage"/> <result column="head_image" property="headImage"/>
<result column="sex" property="sex"/> <result column="sex" property="sex"/>
<result column="school" property="school"/> <result column="school" property="school"/>
...@@ -27,11 +28,11 @@ ...@@ -27,11 +28,11 @@
</sql> </sql>
<sql id="cols_exclude_id"> <sql id="cols_exclude_id">
user_name,password, phone,head_image,sex,school, exam_type,source,is_delete,create_time,update_time user_name,password, phone,uuid,head_image,sex,school, exam_type,source,is_delete,create_time,update_time
</sql> </sql>
<sql id="vals"> <sql id="vals">
#{userName},#{password},#{phone},#{headImage},#{sex},#{school},#{examType}, #{source}, #{userName},#{password},#{phone},#{uuid},#{headImage},#{sex},#{school},#{examType}, #{source},
#{isDelete},now(),now() #{isDelete},now(),now()
</sql> </sql>
...@@ -39,6 +40,7 @@ ...@@ -39,6 +40,7 @@
<if test="userName != null">user_name = #{userName},</if> <if test="userName != null">user_name = #{userName},</if>
<if test="password != null">password =#{password},</if> <if test="password != null">password =#{password},</if>
<if test="phone != null">phone =#{phone},</if> <if test="phone != null">phone =#{phone},</if>
<if test="uuid != null">uuid =#{uuid},</if>
<if test="headImage != null">head_image =#{headImage},</if> <if test="headImage != null">head_image =#{headImage},</if>
<if test="sex != null">sex =#{sex},</if> <if test="sex != null">sex =#{sex},</if>
<if test="school != null">school =#{school},</if> <if test="school != null">school =#{school},</if>
...@@ -53,6 +55,7 @@ ...@@ -53,6 +55,7 @@
<if test="userName != null">and user_name = #{userName}</if> <if test="userName != null">and user_name = #{userName}</if>
<if test="password != null">and password =#{password}</if> <if test="password != null">and password =#{password}</if>
<if test="phone != null">and phone =#{phone}</if> <if test="phone != null">and phone =#{phone}</if>
<if test="uuid != null">and uuid =#{uuid}</if>
<if test="headImage != null">and head_image =#{headImage}</if> <if test="headImage != null">and head_image =#{headImage}</if>
<if test="sex != null">and sex =#{sex}</if> <if test="sex != null">and sex =#{sex}</if>
<if test="school != null">and school =#{school}</if> <if test="school != null">and school =#{school}</if>
......
...@@ -24,37 +24,43 @@ public class User implements Serializable { ...@@ -24,37 +24,43 @@ public class User implements Serializable {
/** /**
* 主键id * 主键id
*/ */
@ApiModelProperty(name ="id",value = "用户主键id") @ApiModelProperty(name = "id", value = "用户主键id")
private Integer id; private Integer id;
/** /**
* 用户名称 * 用户名称
*/ */
@ApiModelProperty(name = "name",value = "用户名") @ApiModelProperty(name = "name", value = "用户名")
private String userName; private String userName;
/** /**
* 密码 * 密码
*/ */
@ApiModelProperty(name="password",value = "用户密码") @ApiModelProperty(name = "password", value = "用户密码")
private String password; private String password;
/** /**
* 电话号码 * 电话号码
*/ */
@ApiModelProperty(name = "phone",value = "手机号") @ApiModelProperty(name = "phone", value = "手机号")
private String phone; private String phone;
/** /**
* 头像 * 头像
*/ */
@ApiModelProperty(name = "headImage",value = "头像") @ApiModelProperty(name = "headImage", value = "头像")
private String headImage; private String headImage;
/**
* 微信uuid
*/
@ApiModelProperty(name = "微信uuid", value = "uuid")
private String uuid;
/** /**
* 性别 * 性别
*/ */
@ApiModelProperty(name = "sex",value = "用户性别:0:男,1:女") @ApiModelProperty(name = "sex", value = "用户性别:0:男,1:女")
private Integer sex; private Integer sex;
/** /**
...@@ -66,29 +72,29 @@ public class User implements Serializable { ...@@ -66,29 +72,29 @@ public class User implements Serializable {
/** /**
* 学生类型 * 学生类型
*/ */
@ApiModelProperty(name = "examType",value = "考生类型 1:文化课考生 2:美术生 3:体育生 4:文学编导考生") @ApiModelProperty(name = "examType", value = "考生类型 1:文化课考生 2:美术生 3:体育生 4:文学编导考生")
private Integer examType; private Integer examType;
/** /**
* 来源 1:电脑端 2: 手机端 * 来源 1:电脑端 2: 手机端
*/ */
@ApiModelProperty(name = "source",value = "来源 1:电脑端 2: 手机端") @ApiModelProperty(name = "source", value = "来源 1:电脑端 2: 手机端")
private Integer source; private Integer source;
/** /**
* 是否删除 * 是否删除
*/ */
@ApiModelProperty(name = "isDelete",value = "是否删除 0:正常 1:删除") @ApiModelProperty(name = "isDelete", value = "是否删除 0:正常 1:删除")
private Integer isDelete; private Integer isDelete;
/** /**
* 创建时间 * 创建时间
*/ */
@ApiModelProperty(name = "createTime",value = "创建时间") @ApiModelProperty(name = "createTime", value = "创建时间")
private Date createTime; private Date createTime;
/** /**
* 修改时间 * 修改时间
*/ */
@ApiModelProperty(name = "updateTime",value = "修改时间") @ApiModelProperty(name = "updateTime", value = "修改时间")
private Date updateTime; private Date updateTime;
} }
...@@ -28,6 +28,12 @@ public class VolunteerVo { ...@@ -28,6 +28,12 @@ public class VolunteerVo {
@ApiModelProperty(value = "方案记录id", name = "recordId") @ApiModelProperty(value = "方案记录id", name = "recordId")
private Integer recordId; private Integer recordId;
/**
* 返回志愿总数
*/
@ApiModelProperty(value = "返回志愿总数", name = "total")
private Integer total;
/** /**
* 志愿信息列表 * 志愿信息列表
*/ */
......
...@@ -243,7 +243,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -243,7 +243,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
//6保存用户方案记录、志愿之间的关联关系,扣减查询次数 //6保存用户方案记录、志愿之间的关联关系,扣减查询次数
R<Integer> bool = volunteerManager.saveUserVolunteer(user, list, scoreInfo, queryVo.getBigMajorNames()); R<Integer> bool = volunteerManager.saveUserVolunteer(user, list, scoreInfo, queryVo.getBigMajorNames());
if (null != bool && bool.getCode() ==500 ) { if (null != bool && bool.getCode() == 500) {
return R.error("保存方案查询记录失败!"); return R.error("保存方案查询记录失败!");
} }
...@@ -253,6 +253,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -253,6 +253,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
assert bool != null; assert bool != null;
volunteerVo.setRecordId(bool.getData()); volunteerVo.setRecordId(bool.getData());
volunteerVo.setVolunteers(list); volunteerVo.setVolunteers(list);
volunteerVo.setTotal(list.size());
return R.ok(volunteerVo); return R.ok(volunteerVo);
} }
...@@ -714,16 +715,23 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -714,16 +715,23 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
private List<Volunteer> getVolunteerList(List<Volunteer> list, Integer total) { private List<Volunteer> getVolunteerList(List<Volunteer> list, Integer total) {
List<Volunteer> result = new ArrayList<>(); List<Volunteer> result = new ArrayList<>();
List<Volunteer> otherList = new ArrayList<>(); List<Volunteer> otherList = new ArrayList<>();
//分组,每组数量大于2的,取两条,小于等于则全取
Map<String, List<Volunteer>> map = list.stream().collect(Collectors.groupingBy(Volunteer::getLowestMark Map<String, List<Volunteer>> map = list.stream().collect(Collectors.groupingBy(Volunteer::getLowestMark
)); ));
for (Map.Entry<String, List<Volunteer>> entry : map.entrySet()) { for (Map.Entry<String, List<Volunteer>> entry : map.entrySet()) {
List<Volunteer> volunteerList = entry.getValue(); List<Volunteer> volunteers = entry.getValue();
if (volunteerList.size() > 2) { if (volunteers.size() > 2) {
result.addAll(volunteerList.subList(0, 2)); for (int i = 0; i < 2; i++) {
otherList.addAll(volunteerList.subList(2, volunteerList.size())); Random mRandom = new Random();
int number = mRandom.nextInt(volunteers.size());
result.add(volunteers.get(number));
volunteers.remove(number);
}
otherList.addAll(volunteers);
} else { } else {
result.addAll(volunteerList); result.addAll(volunteers);
} }
if (result.size() >= total) { if (result.size() >= total) {
...@@ -731,17 +739,22 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -731,17 +739,22 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
} }
} }
//从剩下来的数据中再重复上步操作
if (result.size() < total) { if (result.size() < total) {
List<Volunteer> otherListB = new ArrayList<>(); List<Volunteer> otherListB = new ArrayList<>();
Map<String, List<Volunteer>> mapB = otherList.stream().collect(Collectors.groupingBy(Volunteer::getLowestMark Map<String, List<Volunteer>> mapB = otherList.stream().collect(Collectors.groupingBy(Volunteer::getLowestMark
)); ));
for (Map.Entry<String, List<Volunteer>> entry : map.entrySet()) { for (Map.Entry<String, List<Volunteer>> entry : mapB.entrySet()) {
List<Volunteer> volunteerList = entry.getValue(); List<Volunteer> volunteerList = entry.getValue();
if (volunteerList.size() > 2) { if (volunteerList.size() > 2) {
result.addAll(volunteerList.subList(0, 2)); for (int i = 0; i < 2; i++) {
otherListB.addAll(volunteerList.subList(2, volunteerList.size())); Random mRandom = new Random();
int number = mRandom.nextInt(volunteerList.size());
result.add(volunteerList.get(number));
volunteerList.remove(number);
}
otherListB.addAll(volunteerList);
} else { } else {
result.addAll(volunteerList); result.addAll(volunteerList);
} }
...@@ -751,12 +764,20 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -751,12 +764,20 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
} }
} }
//从剩下的数据中随机抽取,添满数组
if (result.size() < total) { if (result.size() < total) {
int number = total - result.size(); int number = total - result.size();
List<Volunteer> volunteers = otherListB.subList(0, number); List<Volunteer> volunteers = new ArrayList<>();
for (int i = 0; i < number; i++) {
Random mRandom = new Random();
int count = mRandom.nextInt(otherListB.size());
volunteers.add(otherListB.get(count));
otherListB.remove(number);
}
result.addAll(volunteers); result.addAll(volunteers);
} }
} }
return result; return result;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment