关于页面的排序问题

/**

*
* @param params
* @return
*/
@Transactional
public Map<String, Object> updatePhotoPicOrder(Map<String, Object> params) {
Map<String, Object> response = new HashMap<String, Object>();
//获取到两个的序号
String orderArr = params.get("orderArr").toString();
String[] arr = orderArr.split(",");
//一般都是2个进行排序的 如果第一个的序号大于第二个,
if (Integer.parseInt(arr[0]) > Integer.parseInt(arr[1])) {
params.put("one", Integer.parseInt(arr[1]));
params.put("two", Integer.parseInt(arr[0]));
//查询出两个序号对应的数据
List<PicJoinPhoto> listWall = interactMapper.selectPhotoOrder(params);
//循环两个数据
for (PicJoinPhoto wall : listWall) {
//如果数据的编号是一样的,就把编号写成第一个的编号
if (wall.getOrder() == Integer.parseInt(arr[0])) {
wall.setOrder(Integer.parseInt(arr[1]));
}
else {
//否则就加一个
wall.setOrder(wall.getOrder() + 1);
}
}
//修改编号
if (interactMapper.updatePhotoOrder(listWall) > 0) {
//展示出修改后的内容
response.put("photoHead", listWall);
response.put("status", true);
}
}
else {
params.put("one", Integer.parseInt(arr[0]));
params.put("two", Integer.parseInt(arr[1]));
List<PicJoinPhoto> listWall = interactMapper.selectPhotoOrder(params);
for (PicJoinPhoto wall : listWall) {
if (wall.getOrder() == Integer.parseInt(arr[0])) {
wall.setOrder(Integer.parseInt(arr[1]));
}
else {
wall.setOrder(wall.getOrder() - 1);
}
}
if (interactMapper.updatePhotoOrder(listWall) > 0) {
response.put("photoHead", listWall);
response.put("status", true);
}
}
return response;
}

public Map<String, Object> getActive(Map<String, Object> params) {
Integer pageNumber = Integer.valueOf((String) params.get("page"));
Integer pageSize = Integer.valueOf((String) params.get("rows"));
Map<String, Object> result = null;
int startRow = 0;
Integer total = null;
List<PicTitle> rows = null;
startRow = (pageNumber - 1) * pageSize;
total = interactMapper.countActive(params);
params.put("startRow", startRow);
params.put("pageSize", pageSize);
rows = interactMapper.getActive(params);
result = new HashMap<String, Object>();
result.put("total", total);
result.put("rows", rows);
return result;
}

public Map<String, Object> getOrderActive(Map<String, Object> params) {
Integer pageNumber = Integer.valueOf((String) params.get("page"));
Integer pageSize = Integer.valueOf((String) params.get("rows"));
Map<String, Object> result = null;
int startRow = 0;
Integer total = null;
List<PicTitle> rows = null;
startRow = (pageNumber - 1) * pageSize;
total = interactMapper.countOrderActive(params);
params.put("startRow", startRow);
params.put("pageSize", pageSize);
rows = interactMapper.getOrderActive(params);
result = new HashMap<String, Object>();
result.put("total", total);
result.put("rows", rows);
return result;
}

@Transactional
public Map<String, Object> updateActivePicOrder(Map<String, Object> params) {
Map<String, Object> response = new HashMap<String, Object>();
String orderArr = params.get("orderArr").toString();
String[] arr = orderArr.split(",");
if (Integer.parseInt(arr[0]) > Integer.parseInt(arr[1])) {
params.put("one", Integer.parseInt(arr[1]));
params.put("two", Integer.parseInt(arr[0]));
List<MemberArticle> listWall = interactMapper.selectActiveOrder(params);
for (MemberArticle wall : listWall) {
if (wall.getOrder() == Integer.parseInt(arr[0])) {
wall.setOrder(Integer.parseInt(arr[1]));
}
else {
wall.setOrder(wall.getOrder() + 1);
}
}
if (interactMapper.updateActiveOrder(listWall) > 0) {
response.put("activeList", listWall);
response.put("status", true);
}
}
else {
params.put("one", Integer.parseInt(arr[0]));
params.put("two", Integer.parseInt(arr[1]));
List<MemberArticle> listWall = interactMapper.selectActiveOrder(params);
for (MemberArticle wall : listWall) {
if (wall.getOrder() == Integer.parseInt(arr[0])) {
wall.setOrder(Integer.parseInt(arr[1]));
}
else {
wall.setOrder(wall.getOrder() - 1);
}
}
if (interactMapper.updateActiveOrder(listWall) > 0) {
response.put("activeList", listWall);
response.put("status", true);
}
}
return response;
}

<update id="updatePhotoOrder" parameterType="java.util.List">
<foreach collection="point" item="item" index="index" open=""
close="" separator=";">
UPDATE 表
<set>
`order` = #{item.order},
`updatedAt` = now(),
version = version+1
</set>
WHERE `key` = #{item.key}
</foreach>
</update>
posted @ 2021-08-05 16:36  夏之  阅读(51)  评论(0编辑  收藏  举报