Search in sources :

Example 6 with SysRegion

use of com.itrus.portal.db.SysRegion 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();
}
Also used : SysRegion(com.itrus.portal.db.SysRegion) SysRegionExample(com.itrus.portal.db.SysRegionExample)

Example 7 with SysRegion

use of com.itrus.portal.db.SysRegion 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";
}
Also used : SysRegion(com.itrus.portal.db.SysRegion) SysRegionExample(com.itrus.portal.db.SysRegionExample)

Example 8 with SysRegion

use of com.itrus.portal.db.SysRegion in project portal by ixinportal.

the class SysRegionController method addView.

// 显示添加页面
@RequestMapping(value = "/addView")
public String addView(Long pid, Model uiModel) {
    SysRegion pSysRegion = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.selectByPrimaryKey", pid);
    uiModel.addAttribute("pSysRegion", pSysRegion);
    uiModel.addAttribute("type", pSysRegion.getType() + 1);
    return "sysRegion/add";
}
Also used : SysRegion(com.itrus.portal.db.SysRegion)

Example 9 with SysRegion

use of com.itrus.portal.db.SysRegion in project portal by ixinportal.

the class SysRegionController method showOrUpdateView.

private String showOrUpdateView(Long id, Model uiModel, boolean isUpdate) {
    // 查询是否存在
    SysRegion sysRegion = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.selectByPrimaryKey", id);
    SysRegion pSysRegion = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.selectByPrimaryKey", sysRegion.getParentId());
    uiModel.addAttribute("sysRegion", sysRegion);
    uiModel.addAttribute("pSysRegion", pSysRegion);
    // 若包含form参数,则显示修改页面
    if (isUpdate)
        return "sysRegion/update";
    else
        return "sysRegion/show";
}
Also used : SysRegion(com.itrus.portal.db.SysRegion)

Example 10 with SysRegion

use of com.itrus.portal.db.SysRegion in project portal by ixinportal.

the class SysRegionService method getCity.

public String getCity(String cityCode) {
    StringBuilder sBuilder = new StringBuilder();
    // 获得省份信息
    SysRegion region = getRegionByCode(cityCode);
    if (region != null)
        sBuilder.append(region.getNameCn());
    return sBuilder.toString();
}
Also used : SysRegion(com.itrus.portal.db.SysRegion)

Aggregations

SysRegion (com.itrus.portal.db.SysRegion)13 SysRegionExample (com.itrus.portal.db.SysRegionExample)7 ServiceDelException (com.itrus.portal.exception.ServiceDelException)2 ServiceNullException (com.itrus.portal.exception.ServiceNullException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)1