Authored by LiQZ

列表提交

package com.yoho.unions.channel.restapi;
import com.yoho.service.model.response.PageResponseBO;
import com.yoho.service.model.union.request.ChannelUserBO;
import com.yoho.service.model.union.request.ChannelUserRequest;
import com.yoho.unions.channel.service.IChannelUserService;
import com.yoho.unions.common.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* 渠道用户管理
... ... @@ -11,6 +19,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("channel")
public class ChannelUserController {
@Autowired
private IChannelUserService channelUserService;
/**
* 列表
*/
@RequestMapping("user_list")
public ApiResponse userList(@RequestBody ChannelUserRequest request) {
PageResponseBO<ChannelUserBO> page = channelUserService.list(request);
return new ApiResponse.ApiResponseBuilder().data(page).build();
}
}
... ...
package com.yoho.unions.channel.service;
import com.yoho.service.model.response.PageResponseBO;
import com.yoho.service.model.union.request.ChannelUserBO;
import com.yoho.service.model.union.request.ChannelUserRequest;
/**
* 渠道用户管理
* Created by LiQZ on 2017/2/15.
*/
public interface IChannelUserService {
/**
* 渠道用户列表
*/
PageResponseBO<ChannelUserBO> list(ChannelUserRequest request);
}
... ...
package com.yoho.unions.channel.service.impl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yoho.service.model.response.PageResponseBO;
import com.yoho.service.model.union.request.ChannelUserBO;
import com.yoho.service.model.union.request.ChannelUserRequest;
import com.yoho.unions.channel.service.IChannelUserService;
import com.yoho.unions.dal.IChannelUserDAO;
import com.yoho.unions.dal.model.ChannelUser;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* 范渠道用户管理
* Created by LiQZ on 2017/2/15.
... ... @@ -15,6 +26,35 @@ public class ChannelUserServiceImpl implements IChannelUserService {
@Autowired
private IChannelUserDAO channelUserDAO;
@Override
public PageResponseBO<ChannelUserBO> list(ChannelUserRequest request) {
// 设置查询参数
Map<String, Object> condition = Maps.newHashMap();
// condition.put("status", request.getStatus());
// 统计数量
int count = channelUserDAO.selectCount(condition);
request.checkCurrentPage(count);
// 查询列表
List<ChannelUser> users = Collections.emptyList();
if (count > 0) {
users = channelUserDAO.selectPage(condition, request.getStart(), request.getSize());
}
List<ChannelUserBO> list = Lists.transform(users, input -> {
ChannelUserBO output = new ChannelUserBO();
BeanUtils.copyProperties(input, output);
return output;
});
// 设置返回参数
PageResponseBO<ChannelUserBO> page = new PageResponseBO<>();
page.setPage(request.getPage());
page.setPageSize(request.getSize());
page.setTotal(count);
page.setList(list);
return page;
}
}
... ...
package com.yoho.unions.dal;
import com.yoho.unions.dal.model.ChannelUser;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface IChannelUserDAO {
int deleteByPrimaryKey(Integer id);
int insert(ChannelUser record);
... ... @@ -14,4 +19,9 @@ public interface IChannelUserDAO {
int updateByPrimaryKeySelective(ChannelUser record);
int updateByPrimaryKey(ChannelUser record);
int selectCount(@Param("condition") Map<String, Object> condition);
List<ChannelUser> selectPage(@Param("condition") Map<String, Object> condition, @Param("offset") int offset, @Param("rows") int rows);
}
\ No newline at end of file
... ...
... ... @@ -245,4 +245,28 @@
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectCount" resultType="java.lang.Integer">
SELECT count(*) FROM channel_user c
<include refid="WHERE_CONDITION"/>
</select>
<select id="selectPage" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM channel_user c
<include refid="WHERE_CONDITION"/>
ORDER BY create_time DESC
limit #{offset}, #{rows}
</select>
<sql id="WHERE_CONDITION">
<if test="condition != null">
<trim prefix="where" prefixOverrides="and | or">
1 = 1
<!--<if test="condition.status != null">-->
<!--AND status = #{condition.status}-->
<!--</if>-->
</trim>
</if>
</sql>
</mapper>
\ No newline at end of file
... ...