package com.zcloud.service.mkmj.impl; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.mapper.datasource.mkmj.MkmjAreaGateMapper; import com.zcloud.mapper.datasource.mkmj.MkmjAreaMapper; import com.zcloud.service.map.util.ReturnMap; import com.zcloud.service.mkmj.MkmjAreaService; import com.zcloud.util.UuidUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 说明:门口门禁区域闸机 * 作者:zhaoyu * 时间:2024-01-16 * 官网:www.zcloudchina.com */ @Service @Transactional //开启事物 public class MkmjAreaServiceImpl implements MkmjAreaService { @Autowired private MkmjAreaMapper mkmjAreaMapper; @Autowired private MkmjAreaGateMapper mkmjAreaGateMapper; /**新增 * @param pd * @throws Exception */ public Object save(PageData pd)throws Exception{ Map map = new HashMap(); String errInfo = "success"; //保存校验名称不重复 PageData pageData = mkmjAreaMapper.findByOnly(pd); //查询不到重复数据 开始走业务 if(ObjectUtils.isEmpty(pageData)){ pd.put("AREA_ID", UuidUtil.get32UUID()); }else { map.put("result", "fail"); map.put("msg", "名称已存在,请修改后重新提交"); return map; } mkmjAreaMapper.save(pd); map.put("result", errInfo); map.put("msg", "保存成功"); return map; } /**删除 * @param pd * @throws Exception */ public Object delete(PageData pd)throws Exception{ Map map = new HashMap(); String errInfo = "success"; //校验区域下是否还存在区域 存在则不让删除 List childList = mkmjAreaMapper.findByChild(pd); if(childList.size()>0){ map.put("result", "fail"); map.put("msg", "当前区域还存在下级区域,请删除当前区域的所有下级区域后进行删除"); return map; } //校验区域下是否存在闸机,存在则不让删除 List gateList = mkmjAreaGateMapper.listAll(pd); if(gateList.size()>0){ map.put("result", "fail"); map.put("msg", "当前区域还存在闸机,请删除当前区域的所有闸机后进行删除"); return map; } //两个校验都不存在 则可以删除 mkmjAreaMapper.delete(pd); map.put("result", errInfo); map.put("msg", "删除成功"); return map; } /**修改 * @param pd * @throws Exception */ public Object edit(PageData pd)throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pageData = mkmjAreaMapper.findByOnly(pd); //查询不到重复数据 开始走业务 if(!ObjectUtils.isEmpty(pageData)){ map.put("result", "fail"); map.put("msg", "名称已存在,请修改后重新提交"); return map; } mkmjAreaMapper.edit(pd); map.put("result", errInfo); map.put("msg", "编辑成功"); return map; } /**列表 * @param page * @throws Exception */ public List list(Page page)throws Exception{ return mkmjAreaMapper.datalistPage(page); } /**列表(全部) * @param pd * @throws Exception */ public List listAll(PageData pd)throws Exception{ return mkmjAreaMapper.listAll(pd); } /**通过id获取数据 * @param pd * @throws Exception */ public PageData findById(PageData pd)throws Exception{ return mkmjAreaMapper.findById(pd); } }