新增区域模块controller层
This commit is contained in:
parent
ac35ae92e2
commit
4dad73799e
|
|
@ -0,0 +1,121 @@
|
||||||
|
package com.ghy.web.controller.system;
|
||||||
|
|
||||||
|
import com.ghy.common.annotation.Log;
|
||||||
|
import com.ghy.common.constant.UserConstants;
|
||||||
|
import com.ghy.common.core.controller.BaseController;
|
||||||
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import com.ghy.common.enums.BusinessType;
|
||||||
|
import com.ghy.system.domain.SysArea;
|
||||||
|
import com.ghy.system.service.ISysAreaService;
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 区域信息
|
||||||
|
*
|
||||||
|
* @author clunt
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/system/area")
|
||||||
|
public class SysAreaController extends BaseController {
|
||||||
|
|
||||||
|
private String prefix = "system/area";
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysAreaService sysAreaService;
|
||||||
|
|
||||||
|
@RequiresPermissions("system:area:list")
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ResponseBody
|
||||||
|
public List<SysArea> list(SysArea sysArea)
|
||||||
|
{
|
||||||
|
List<SysArea> areaList = sysAreaService.selectSysAreaList(sysArea);
|
||||||
|
return areaList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增保存区域
|
||||||
|
*/
|
||||||
|
@Log(title = "区域管理", businessType = BusinessType.INSERT)
|
||||||
|
@RequiresPermissions("system:area:add")
|
||||||
|
@PostMapping("/add")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult addSave(@Validated SysArea sysArea)
|
||||||
|
{
|
||||||
|
if (UserConstants.AREA_CODE_NOT_UNIQUE.equals(sysAreaService.checkAreaCodeUnique(sysArea)))
|
||||||
|
{
|
||||||
|
return error("新增区域'" + sysArea.getAreaName() + "'失败,区域编码已存在");
|
||||||
|
}
|
||||||
|
sysArea.setCreateBy(getLoginName());
|
||||||
|
return toAjax(sysAreaService.insertSysArea(sysArea));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改保存区域
|
||||||
|
*/
|
||||||
|
@Log(title = "区域管理", businessType = BusinessType.UPDATE)
|
||||||
|
@RequiresPermissions("system:area:edit")
|
||||||
|
@PostMapping("/edit")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult editSave(@Validated SysArea sysArea)
|
||||||
|
{
|
||||||
|
if (UserConstants.AREA_CODE_NOT_UNIQUE.equals(sysAreaService.checkAreaCodeUnique(sysArea)))
|
||||||
|
{
|
||||||
|
return error("修改区域'" + sysArea.getAreaName() + "'失败,区域编码已存在");
|
||||||
|
}
|
||||||
|
sysArea.setUpdateBy(getLoginName());
|
||||||
|
return toAjax(sysAreaService.updateSysArea(sysArea));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@Log(title = "区域管理", businessType = BusinessType.DELETE)
|
||||||
|
@RequiresPermissions("system:area:remove")
|
||||||
|
@GetMapping("/remove/{areaId}")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult remove(@PathVariable("areaId") Long areaId)
|
||||||
|
{
|
||||||
|
if (sysAreaService.selectAreaCount(areaId) > 0)
|
||||||
|
{
|
||||||
|
return AjaxResult.warn("存在下级区域,不允许删除");
|
||||||
|
}
|
||||||
|
return toAjax(sysAreaService.deleteSysAreaByIds(areaId.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequiresPermissions("system:area:view")
|
||||||
|
@GetMapping()
|
||||||
|
public String area() {
|
||||||
|
return prefix + "/area";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增下级区域
|
||||||
|
*/
|
||||||
|
@GetMapping("/add/{parentCode}")
|
||||||
|
public String add(@PathVariable("parentCode") String parentCode, ModelMap mmap) {
|
||||||
|
mmap.put("sysCode", sysAreaService.selectByAreaCode(parentCode));
|
||||||
|
return prefix + "/add";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改区域
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("system:area:edit")
|
||||||
|
@GetMapping("/edit/{areaId}")
|
||||||
|
public String edit(@PathVariable("areaId") Long areaId, ModelMap mmap) {
|
||||||
|
SysArea sysArea = sysAreaService.selectById(areaId);
|
||||||
|
mmap.put("sysArea", sysArea);
|
||||||
|
return prefix + "/edit";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -61,6 +61,10 @@ public class UserConstants
|
||||||
public final static String DEPT_NAME_UNIQUE = "0";
|
public final static String DEPT_NAME_UNIQUE = "0";
|
||||||
public final static String DEPT_NAME_NOT_UNIQUE = "1";
|
public final static String DEPT_NAME_NOT_UNIQUE = "1";
|
||||||
|
|
||||||
|
/** 区域编码是否唯一的返回结果码 */
|
||||||
|
public final static String AREA_CODE_UNIQUE = "0";
|
||||||
|
public final static String AREA_CODE_NOT_UNIQUE = "1";
|
||||||
|
|
||||||
/** 角色名称是否唯一的返回结果码 */
|
/** 角色名称是否唯一的返回结果码 */
|
||||||
public final static String ROLE_NAME_UNIQUE = "0";
|
public final static String ROLE_NAME_UNIQUE = "0";
|
||||||
public final static String ROLE_NAME_NOT_UNIQUE = "1";
|
public final static String ROLE_NAME_NOT_UNIQUE = "1";
|
||||||
|
|
|
||||||
|
|
@ -46,4 +46,18 @@ public interface ISysAreaService {
|
||||||
*/
|
*/
|
||||||
public int insertSysArea(SysArea sysArea);
|
public int insertSysArea(SysArea sysArea);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sysArea 区域实体
|
||||||
|
* @return 校验结果
|
||||||
|
*/
|
||||||
|
String checkAreaCodeUnique(SysArea sysArea);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param areaId 区域id
|
||||||
|
* @return 下级区域条数
|
||||||
|
*/
|
||||||
|
int selectAreaCount(Long areaId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.ghy.system.service.impl;
|
package com.ghy.system.service.impl;
|
||||||
|
|
||||||
|
import com.ghy.common.constant.UserConstants;
|
||||||
import com.ghy.common.core.text.Convert;
|
import com.ghy.common.core.text.Convert;
|
||||||
import com.ghy.common.exception.ServiceException;
|
import com.ghy.common.exception.ServiceException;
|
||||||
|
import com.ghy.common.utils.StringUtils;
|
||||||
import com.ghy.system.domain.SysArea;
|
import com.ghy.system.domain.SysArea;
|
||||||
import com.ghy.system.mapper.SysAreaMapper;
|
import com.ghy.system.mapper.SysAreaMapper;
|
||||||
import com.ghy.system.service.ISysAreaService;
|
import com.ghy.system.service.ISysAreaService;
|
||||||
|
|
@ -59,6 +61,24 @@ public class SysAreaServiceImpl implements ISysAreaService {
|
||||||
return sysAreaMapper.insertSysArea(sysArea);
|
return sysAreaMapper.insertSysArea(sysArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String checkAreaCodeUnique(SysArea sysArea) {
|
||||||
|
Long areaId = StringUtils.isNull(sysArea.getAreaId()) ? -1L : sysArea.getAreaId();
|
||||||
|
SysArea info = sysAreaMapper.selectByAreaCode(sysArea.getAreaCode());
|
||||||
|
if(StringUtils.isNotNull(info) && info.getAreaId().longValue() != areaId){
|
||||||
|
return UserConstants.AREA_CODE_UNIQUE;
|
||||||
|
}
|
||||||
|
return UserConstants.AREA_CODE_NOT_UNIQUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int selectAreaCount(Long areaId) {
|
||||||
|
SysArea sysArea = sysAreaMapper.selectById(areaId);
|
||||||
|
SysArea info = new SysArea();
|
||||||
|
info.setParentCode(sysArea.getAreaCode());
|
||||||
|
return sysAreaMapper.selectSysAreaList(info).size();
|
||||||
|
}
|
||||||
|
|
||||||
public int countUseSysAreaById(SysArea sysArea){
|
public int countUseSysAreaById(SysArea sysArea){
|
||||||
//TODO 校验区域是否使用
|
//TODO 校验区域是否使用
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,9 @@
|
||||||
<if test="areaName != null and areaName != ''">
|
<if test="areaName != null and areaName != ''">
|
||||||
AND area_name like concat('%', #{areaName}, '%')
|
AND area_name like concat('%', #{areaName}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="parentCode != null and parentCode != ''">
|
||||||
|
AND parent_code = #{parentCode}
|
||||||
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue