basic area

This commit is contained in:
sxu 2025-05-25 20:21:49 +08:00
parent 183989d1ac
commit 8e55d9158c
13 changed files with 173 additions and 8 deletions

View File

@ -49,6 +49,16 @@ public class BasicAreaController extends BaseController {
return getDataTable(list);
}
@GetMapping("/areaTree")
public AjaxResult deptTree(BasicArea area) {
try {
return success(basicAreaService.selectAreaTreeList(area));
} catch (Exception e) {
logger.error(e.toString(), e);
}
return error("系统异常,请联系管理员");
}
/**
* 导出区域列表
*/

View File

@ -6,6 +6,9 @@ import lombok.Data;
import lombok.ToString;
import com.bonus.common.core.web.domain.BaseEntity;
import java.util.ArrayList;
import java.util.List;
/**
* 区域对象 basic_area
*
@ -47,5 +50,6 @@ public class BasicArea extends BaseEntity {
@ApiModelProperty(value = "联系电话")
private String contactTel;
private List<BasicArea> children = new ArrayList();
}

View File

@ -26,6 +26,8 @@ public interface BasicAreaMapper {
*/
public List<BasicArea> selectBasicAreaList(BasicArea basicArea);
public BasicArea selectBasicAreaByAreaName(String areaName);
/**
* 新增区域
*

View File

@ -18,6 +18,8 @@ public interface BasicCanteenMapper {
*/
public BasicCanteen selectBasicCanteenByCanteenId(Long canteenId);
public int getBasicCanteenCountByAreaIds(Long[] areaIds);
/**
* 查询食堂信息列表
*

View File

@ -2,6 +2,7 @@ package com.bonus.canteen.core.basic.service;
import java.util.List;
import com.bonus.canteen.core.basic.domain.BasicArea;
import com.bonus.canteen.core.common.domain.TreeSelect;
/**
* 区域Service接口
@ -26,6 +27,8 @@ public interface IBasicAreaService {
*/
public List<BasicArea> selectBasicAreaList(BasicArea basicArea);
public List<TreeSelect> selectAreaTreeList(BasicArea area);
/**
* 新增区域
*

View File

@ -1,8 +1,18 @@
package com.bonus.canteen.core.basic.service.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.bonus.canteen.core.basic.mapper.BasicCanteenMapper;
import com.bonus.canteen.core.common.domain.TreeSelect;
import com.bonus.canteen.core.supermarket.mapper.SupermarketInfoMapper;
import com.bonus.canteen.core.supply.mapper.SupplyWarehouseInfoMapper;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.basic.mapper.BasicAreaMapper;
@ -19,6 +29,12 @@ import com.bonus.canteen.core.basic.service.IBasicAreaService;
public class BasicAreaServiceImpl implements IBasicAreaService {
@Autowired
private BasicAreaMapper basicAreaMapper;
@Autowired
private BasicCanteenMapper basicCanteenMapper;
@Autowired
private SupermarketInfoMapper supermarketInfoMapper;
@Autowired
SupplyWarehouseInfoMapper supplyWarehouseInfoMapper;
/**
* 查询区域
@ -42,6 +58,12 @@ public class BasicAreaServiceImpl implements IBasicAreaService {
return basicAreaMapper.selectBasicAreaList(basicArea);
}
@Override
public List<TreeSelect> selectAreaTreeList(BasicArea area) {
List<BasicArea> areas = selectBasicAreaList(area);
return buildAreaTreeSelect(areas);
}
/**
* 新增区域
*
@ -52,6 +74,10 @@ public class BasicAreaServiceImpl implements IBasicAreaService {
public int insertBasicArea(BasicArea basicArea) {
basicArea.setCreateTime(DateUtils.getNowDate());
try {
BasicArea checkResult = basicAreaMapper.selectBasicAreaByAreaName(basicArea.getAreaName());
if (Objects.nonNull(checkResult)) {
throw new ServiceException("区域名称已存在");
}
return basicAreaMapper.insertBasicArea(basicArea);
} catch (Exception e) {
throw new ServiceException(e.getMessage());
@ -68,6 +94,12 @@ public class BasicAreaServiceImpl implements IBasicAreaService {
public int updateBasicArea(BasicArea basicArea) {
basicArea.setUpdateTime(DateUtils.getNowDate());
try {
List<BasicArea> allAreaList = basicAreaMapper.selectBasicAreaList(new BasicArea());
List<String> otherAreaNameList = allAreaList.stream().filter(item -> !item.getAreaId().equals(basicArea.getAreaId()))
.map(BasicArea::getAreaName).collect(Collectors.toList());
if (otherAreaNameList.contains(basicArea.getAreaName())) {
throw new ServiceException("区域名称已存在");
}
return basicAreaMapper.updateBasicArea(basicArea);
} catch (Exception e) {
throw new ServiceException(e.getMessage());
@ -82,6 +114,18 @@ public class BasicAreaServiceImpl implements IBasicAreaService {
*/
@Override
public int deleteBasicAreaByAreaIds(Long[] areaIds) {
int count1 = basicCanteenMapper.getBasicCanteenCountByAreaIds(areaIds);
if (count1 > 0) {
throw new ServiceException("该区域含有食堂信息,不能删除");
}
int coun2 = supermarketInfoMapper.getSupermarketCountByAreaIds(areaIds);
if (coun2 > 0) {
throw new ServiceException("该区域含有超市信息,不能删除");
}
int coun3 = supplyWarehouseInfoMapper.getSupplyWarehouseCountByAreaIds(areaIds);
if (coun3 > 0) {
throw new ServiceException("该区域含有仓库信息,不能删除");
}
return basicAreaMapper.deleteBasicAreaByAreaIds(areaIds);
}
@ -95,4 +139,66 @@ public class BasicAreaServiceImpl implements IBasicAreaService {
public int deleteBasicAreaByAreaId(Long areaId) {
return basicAreaMapper.deleteBasicAreaByAreaId(areaId);
}
public List<TreeSelect> buildAreaTreeSelect(List<BasicArea> areas)
{
List<BasicArea> areaTrees = buildAreaTree(areas);
return areaTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
public List<BasicArea> buildAreaTree(List<BasicArea> areas) {
List<BasicArea> returnList = new ArrayList<BasicArea>();
List<Long> tempList = areas.stream().map(BasicArea::getAreaId).collect(Collectors.toList());
for (BasicArea area : areas)
{
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(area.getParentId()))
{
recursionFn(areas, area);
returnList.add(area);
}
}
if (returnList.isEmpty())
{
returnList = areas;
}
return returnList;
}
private void recursionFn(List<BasicArea> list, BasicArea t)
{
// 得到子节点列表
List<BasicArea> childList = getChildList(list, t);
t.setChildren(childList);
for (BasicArea tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
private List<BasicArea> getChildList(List<BasicArea> list, BasicArea t)
{
List<BasicArea> tlist = new ArrayList<BasicArea>();
Iterator<BasicArea> it = list.iterator();
while (it.hasNext())
{
BasicArea n = (BasicArea) it.next();
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getAreaId().longValue())
{
tlist.add(n);
}
}
return tlist;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<BasicArea> list, BasicArea t)
{
return getChildList(list, t).size() > 0 ? true : false;
}
}

View File

@ -1,5 +1,6 @@
package com.bonus.canteen.core.common.domain;
import com.bonus.canteen.core.basic.domain.BasicArea;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.List;
@ -41,13 +42,12 @@ public class TreeSelect implements Serializable {
}
// public TreeSelect(AllocArea area) {
// this.parentId = area.getParentId();
// this.id = area.getAreaId();
// this.label = area.getAreaName();
// this.status = area.getDelFlag();
// this.children = area.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
// }
public TreeSelect(BasicArea area) {
this.parentId = area.getParentId();
this.id = area.getAreaId();
this.label = area.getAreaName();
this.children = area.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public Integer getLevel() {
return level;

View File

@ -18,6 +18,8 @@ public interface SupermarketInfoMapper {
*/
public SupermarketInfo selectSupermarketInfoBySupermarketId(Long supermarketId);
public int getSupermarketCountByAreaIds(Long[] areaIds);
/**
* 查询超市列表
*

View File

@ -18,6 +18,8 @@ public interface SupplyWarehouseInfoMapper {
*/
public SupplyWarehouseInfo selectSupplyWarehouseInfoByWarehouseId(Long warehouseId);
public int getSupplyWarehouseCountByAreaIds(Long[] areaIds);
/**
* 查询仓库信息列表
*

View File

@ -17,7 +17,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectBasicAreaVo">
select area_id, area_name, parent_id, manager, description, contact_tel, create_by, create_time, update_by, update_time from basic_area
select area_id, area_name, parent_id, manager, description, contact_tel,
create_by, create_time, update_by, update_time
from basic_area
</sql>
<select id="selectBasicAreaList" parameterType="com.bonus.canteen.core.basic.domain.BasicArea" resultMap="BasicAreaResult">
@ -30,6 +32,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="contactTel != null and contactTel != ''"> and contact_tel = #{contactTel}</if>
</where>
</select>
<select id="selectBasicAreaByAreaName" parameterType="String" resultMap="BasicAreaResult">
<include refid="selectBasicAreaVo"/>
where area_name = #{areaName}
</select>
<select id="selectBasicAreaByAreaId" parameterType="Long" resultMap="BasicAreaResult">
<include refid="selectBasicAreaVo"/>

View File

@ -57,6 +57,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectBasicCanteenVo"/>
where canteen_id = #{canteenId}
</select>
<select id="getBasicCanteenCountByAreaIds" resultType="Integer">
select count(1)
from basic_canteen
where area_id in
<foreach item="areaId" collection="array" open="(" separator="," close=")">
#{areaId}
</foreach>
</select>
<insert id="insertBasicCanteen" parameterType="com.bonus.canteen.core.basic.domain.BasicCanteen" useGeneratedKeys="true" keyProperty="canteenId">
insert into basic_canteen

View File

@ -63,6 +63,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectSupermarketInfoVo"/>
where supermarket_id = #{supermarketId}
</select>
<select id="getSupermarketCountByAreaIds" resultType="Integer">
select count(1)
from supermarket_info
where area_id in
<foreach item="areaId" collection="array" open="(" separator="," close=")">
#{areaId}
</foreach>
</select>
<insert id="insertSupermarketInfo" parameterType="com.bonus.canteen.core.supermarket.domain.SupermarketInfo" useGeneratedKeys="true" keyProperty="supermarketId">
insert into supermarket_info

View File

@ -55,6 +55,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectSupplyWarehouseInfoVo"/>
where warehouse_id = #{warehouseId}
</select>
<select id="getSupplyWarehouseCountByAreaIds" resultType="Integer">
select count(1)
from supply_warehouse_info
where area_id in
<foreach item="areaId" collection="array" open="(" separator="," close=")">
#{areaId}
</foreach>
</select>
<insert id="insertSupplyWarehouseInfo" parameterType="com.bonus.canteen.core.supply.domain.SupplyWarehouseInfo" useGeneratedKeys="true" keyProperty="warehouseId">
insert into supply_warehouse_info