统计功能
通过sql的count函数来获取总数 ,用于后期分析。
客户行业统计:
首先在客户列表,分组查询获取行业id和对应的客户数量,然后根据行业id去数据字典表找到对应的name。
问题来了,怎么保存呢,当然是写一个vo类(map也可以)
CountInfo(统计对象)
public class CountInfo {
private String fid;
private Integer count;
private String dictItemName;
业务流程:
控制层方法:
@RequestMapping("/industryCount.action")
public String industryCount(Model model){
List<CountInfo> list=cs.countIndustry();
model.addAttribute("list", list);
return "/jsp/statistic/industry.jsp";
}
业务逻辑层方法:
@Override
public List<CountInfo> countIndustry() {
List<CountInfo> list = customerMapper.groupByIndustry();
for (CountInfo countInfo : list) {
System.out.println(countInfo.getFid()+"countInfo.getFid");
BaseDict baseDict = baseDictMapper.selectByPrimaryKey(countInfo.getFid());
countInfo.setDictItemName(baseDict.getDictItemName());
}
return list;
}
sql语句:
<!-- 客户行业统计 -->
<select id="groupByIndustry" resultType="CountInfo">
SELECT cust_industry fid, COUNT(*) count
FROM cst_customer
GROUP BY cust_industry;
</select>
系统管理
角色管理
- 基于list.jsp修改
查看角色
增加角色
删除角色
扫描二维码关注公众号,回复:
4997476 查看本文章
![](/qrcode.jpg)
用户管理
- 基于list.jsp修改
查看用户
修改用户
重点:
查看用户(分页筛选功能不再赘述)
一个用户有多个角色,所以说设计的用户对象vo里成员属性里有一个list<role>
public class SysUserVo {
private Long userId;
private String userCode;
private String userName;
private String userPassword;
private String userState;
private List<SysRole> roleList;
控制层
@RequestMapping("/list.action")
public String list(QueryVo qvo,Model model){
PageBean<SysUserVo> pageBean=us.getUserList(qvo);
model.addAttribute("pageBean", pageBean);
model.addAttribute("queryVo", qvo);
System.out.println(pageBean);
return "/jsp/system/userlist.jsp";
}
业务逻辑层
@Override
public PageBean<SysUserVo> getUserList(QueryVo qvo) {
SysUserExample example = new SysUserExample();
if(qvo != null && qvo.getUser() != null && qvo.getUser().getUserCode() != null && qvo.getUser().getUserCode().length() > 0){
Criteria criteria = example.createCriteria();
criteria.andUserCodeLike("%" + qvo.getUser().getUserCode() + "%");
}
int count = sm.countByExample(example);
PageBean<SysUserVo> pageBean =new PageBean<>(qvo.getPageNum(),qvo.getPageSize(),count);
example.setOff(pageBean.getStartPage());
example.setLen(pageBean.getPageSize());
List<SysUser> userList = sm.selectByExample(example);
List<SysUserVo> vo=new ArrayList<>();
//遍历用户对象
for (SysUser sysUser : userList) {
SysUserRoleExample sure = new SysUserRoleExample();
com.wowowo.bean.SysUserRoleExample.Criteria urcriteria = sure.createCriteria();
urcriteria.andUserIdEqualTo(sysUser.getUserId());
//获取用户角色对象
List<SysUserRoleKey> userRoleList = surm.selectByExample(sure);
SysUserVo sysUserVo = new SysUserVo(sysUser);
List<SysRole> roleList= new ArrayList<>();
//po转vo,把角色列表放到vo对象中
for (SysUserRoleKey sysUserRoleKey : userRoleList) {
SysRole SysRole = srm.selectByPrimaryKey(sysUserRoleKey.getRoleId());
roleList.add(SysRole);
}
sysUserVo.setRoleList(roleList);
vo.add(sysUserVo);
}
pageBean.setList(vo);
return pageBean;
}
修改用户
重点在于修改用户的角色,首先点击修改按钮,发送请求到控制层:
@RequestMapping("/toEdit.action")
public String toEdit(Long userId,Model model){
//获取用户角色对象
SysUserVo uservo=us.selectByUserId(userId);
//获取所有的角色列表
List<SysRole> list=srs.getRoleList2();
model.addAttribute("user",uservo);
model.addAttribute("allRole", list);
System.out.println(uservo);
return "/jsp/system/useredit.jsp";
}
业务逻辑层方法:
@Override
public SysUserVo selectByUserId(Long userId) {
//获取用户对象
SysUser user = sm.selectByPrimaryKey(userId);
SysUserRoleExample sure = new SysUserRoleExample();
com.wowowo.bean.SysUserRoleExample.Criteria urcriteria = sure.createCriteria();
urcriteria.andUserIdEqualTo(user.getUserId());
//根据用户id查询用户角色列表
List<SysUserRoleKey> userRoleList = surm.selectByExample(sure);
//构造vo对象
SysUserVo sysUserVo = new SysUserVo(user);
List<SysRole> roleList= new ArrayList<>();
//po转vo,遍历用户角色列表,根据角色id获取角色信息,放到vo的list中
for (SysUserRoleKey sysUserRoleKey : userRoleList) {
SysRole SysRole = srm.selectByPrimaryKey(sysUserRoleKey.getRoleId());
roleList.add(SysRole);
}
sysUserVo.setRoleList(roleList);
return sysUserVo;
}
前端修改界面:
<td>
用户角色:
<!-- 遍历所有角色列表,如果列表中的角色id和该用户所属角色id一致,那么多选框选中-->
<c:forEach items="${allRole}" var="role"> <input type="checkbox"
<c:forEach items="${user.roleList}" var="myrole" >
<c:if test="${myrole.roleId==role.roleId }">checked="checked"
</c:if>
</c:forEach> name="rId" value="${role.roleId}" />
${role.roleName}
</c:forEach>
</td>
效果如下
用户点击保存按钮,发送表单到控制层,重点来了,如何保存呢?
我的做法是先删除该用户所有的角色,然后再保存!
@Override
public void updateUser(QueryVo qvo) {
System.out.println(qvo);
Long userId = qvo.getUser().getUserId();
//删除该用户所有角色
SysUserRoleExample example = new SysUserRoleExample();
com.wowowo.bean.SysUserRoleExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
surm.deleteByExample(example);
//插入选中的角色id,这里用户所属的角色id是长整型数组,如果是list的话,springmvc不太好接收
Long[] rId = qvo.getrId();
if(rId!=null){
for (Long long1 : rId) {
surm.insertSelective(new SysUserRoleKey(long1,userId));
}
}
//更新user,除了角色以外,别的信息
sm.updateByPrimaryKeySelective(qvo.getUser());
}
保存完成转发到用户列表