use of com.itrus.portal.db.SysRegionExample in project portal by ixinportal.
the class SysRegionController method addSysRegion.
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String addSysRegion(@Valid SysRegion sysRegion, BindingResult bindingResult, RedirectAttributesModelMap uiModel) {
if (bindingResult.hasErrors())
return "redirect:/sysregion/addView?pid=" + sysRegion.getParentId();
SysRegion pSysRegion = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.selectByPrimaryKey", sysRegion.getParentId());
// 判断行政区代码是否重复
SysRegionExample sysRegionExample = new SysRegionExample();
SysRegionExample.Criteria srCriteria = sysRegionExample.createCriteria();
srCriteria.andCodeEqualTo(sysRegion.getCode());
Integer num = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.countByExample", sysRegionExample);
if (num != null && num > 0) {
// 已经存在指定的code
uiModel.addFlashAttribute("errMsg", "已存在行政区代码【" + sysRegion.getCode() + "】");
return "redirect:/sysregion/addView?pid=" + sysRegion.getParentId();
}
// 不存在重复的code,保存行政区信息
sysRegion.setCreateTime(new Date());
sysRegion.setLastModify(new Date());
sysRegion.setType(pSysRegion.getType() + 1);
sysRegion.setParentIds(pSysRegion.getParentIds() + pSysRegion.getId() + ",");
sqlSession.insert("com.itrus.portal.db.SysRegionMapper.insert", sysRegion);
uiModel.addFlashAttribute("reNode", 1);
LogUtil.adminlog(sqlSession, "添加行政区", "添加行政区【" + sysRegion.getNameCn() + "】,代码为【" + sysRegion.getCode() + "】");
return "redirect:/sysregion/" + sysRegion.getId();
}
use of com.itrus.portal.db.SysRegionExample in project portal by ixinportal.
the class SysRegionController method list.
// 列表
@RequestMapping(value = "/list")
public String list(Long parentId, Integer type, @RequestParam(value = "srName", required = false) String srName, @RequestParam(value = "srCode", required = false) String srCode, @RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
if (page == null || page < 1)
page = 1;
if (size == null || size < 1)
size = 10;
uiModel.addAttribute("parentId", parentId);
uiModel.addAttribute("type", type);
uiModel.addAttribute("srName", srName);
uiModel.addAttribute("srCode", srCode);
uiModel.addAttribute("status", status);
uiModel.addAttribute("size", size);
if (parentId == null) {
uiModel.addAttribute("page", page);
uiModel.addAttribute("count", 0);
uiModel.addAttribute("pages", 0);
uiModel.addAttribute("itemcount", 0);
return "sysRegion/list";
}
SysRegionExample sysRegionExample = new SysRegionExample();
SysRegionExample.Criteria srCriteria = sysRegionExample.createCriteria();
if (StringUtils.isNotBlank(srName))
srCriteria.andNameCnLike("%" + srName + "%");
if (StringUtils.isNotBlank(srCode))
srCriteria.andCodeLike("%" + srCode + "%");
if (status != null && status >= 0)
// 页面上状态值教大
srCriteria.andStatusEqualTo(status);
srCriteria.andParentIdEqualTo(parentId);
// 查询下级行政区
srCriteria.andTypeEqualTo(type);
Integer count = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.countByExample", sysRegionExample);
uiModel.addAttribute("count", count);
uiModel.addAttribute("pages", (count + size - 1) / size);
// page
if (page > 1 && size * (page - 1) >= count) {
page = (count + size - 1) / size;
}
uiModel.addAttribute("page", page);
Integer offset = size * (page - 1);
sysRegionExample.setLimit(size);
sysRegionExample.setOffset(offset);
sysRegionExample.setOrderByClause("code asc");
List<SysRegion> sysRegionList = sqlSession.selectList("com.itrus.portal.db.SysRegionMapper.selectByExample", sysRegionExample);
uiModel.addAttribute("sysRegionList", sysRegionList);
// itemcount
uiModel.addAttribute("itemcount", sysRegionList.size());
return "sysRegion/list";
}
use of com.itrus.portal.db.SysRegionExample in project portal by ixinportal.
the class SysRegionService method getRegionsByCode.
/**
* 根据行政区代码,获取行政区子级信息
* @param code
* @param type
* @return
* @throws ServiceNullException
*/
public List<Region4t> getRegionsByCode(String code, Integer type) throws ServiceNullException {
List<Region4t> region4tList = new ArrayList<Region4t>();
SysRegion sysRegion = getRegionByCode(code);
// 指定代码不存在
if (sysRegion == null) {
throw new ServiceNullException("未知的行政区代码【" + code + "】");
}
// 查询指定代码的下层节点
SysRegionExample sysRegionExample = new SysRegionExample();
SysRegionExample.Criteria srCriteria = sysRegionExample.createCriteria();
srCriteria.andParentIdEqualTo(sysRegion.getId());
srCriteria.andTypeEqualTo(sysRegion.getType() + 1);
sysRegionExample.setOrderByClause("code asc");
Map<Long, SysRegion> childSR = sqlSession.selectMap("com.itrus.portal.db.SysRegionMapper.selectByExample", sysRegionExample, "id");
// 判断下级节点是否有子节点
sysRegionExample.clear();
sysRegionExample.setOrderByClause(null);
srCriteria = sysRegionExample.createCriteria();
srCriteria.andParentIdIn(new ArrayList<Long>(childSR.keySet()));
Map<Long, Object> childNumMap = new HashMap<Long, Object>();
if (!childSR.isEmpty())
childNumMap = sqlSession.selectMap("com.itrus.portal.db.SysRegionMapper.selectChildNumByExample", sysRegionExample, "parentId");
Iterator iter = childSR.entrySet().iterator();
while (iter.hasNext()) {
SysRegion sr = (SysRegion) ((Map.Entry) iter.next()).getValue();
region4tList.add(new Region4t(sr.getNameCn(), sr.getCode(), sr.getType(), childNumMap.containsKey(sr.getId()) ? 1 : 0));
}
return region4tList;
}
Aggregations