package com.huaheng.pc.config.zone.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.huaheng.common.utils.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huaheng.common.exception.service.ServiceException; import com.huaheng.common.utils.StringUtils; import com.huaheng.common.utils.security.ShiroUtils; import com.huaheng.pc.config.company.domain.Company; import com.huaheng.pc.config.zone.domain.Zone; import com.huaheng.pc.config.zone.mapper.ZoneMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; import java.util.Map; @Service("zone") public class ZoneServiceImpl extends ServiceImpl<ZoneMapper, Zone> implements ZoneService { @Resource private ZoneMapper zoneMapper; @Override public List<Map<String, Object>> getZoneCodeList() { LambdaQueryWrapper<Zone> lambda = Wrappers.lambdaQuery(); lambda.select(Zone::getId, Zone::getCode, Zone::getName, Zone::getArea) .eq(Zone::getWarehouseCode, ShiroUtils.getWarehouseCode()); return this.listMaps(lambda); } @Override @Transactional public boolean zoneCopy(String warehouseCode, String newWarehouseCode) { int i = 0; //复制流程主表 i = zoneMapper.zoneCopy(warehouseCode,newWarehouseCode); if(i < 1){ throw new ServiceException("复制菜单数据失败"); } return true; } @Override public boolean exists(String code,String warehouseCode) { LambdaQueryWrapper<Zone> lambda = Wrappers.lambdaQuery(); lambda.eq(Zone::getCode,code) .eq(Zone::getWarehouseCode, warehouseCode); return this.listMaps(lambda).size() != 0; } @Override public List<Map<String, Object>> getCode() { LambdaQueryWrapper<Zone> lambda = Wrappers.lambdaQuery(); lambda.select(Zone::getCode, Zone::getId, Zone::getName) .eq(Zone::getWarehouseCode, ShiroUtils.getWarehouseCode()); return this.listMaps(lambda); } public List<Map<String, Object>> getCodeAll() { LambdaQueryWrapper<Zone> lambda = Wrappers.lambdaQueryNoWarehouse(); lambda.select(Zone::getCode, Zone::getId, Zone::getName); return this.listMaps(lambda); } @Override public Zone getZoneByArea(String area) { LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery(); zoneLambdaQueryWrapper.eq(Zone::getArea, area); Zone zone = getOne(zoneLambdaQueryWrapper); return zone; } @Override public void dataValidation(Zone zone) throws Exception { if (StringUtils.isEmpty(zone.getCode())){ throw new Exception("库区编码不能为空值!"); } if (StringUtils.isEmpty(zone.getWarehouseCode())){ throw new Exception("仓库编码不能为空值!"); } LambdaQueryWrapper<Zone> query = Wrappers.lambdaQuery(); query.eq(Zone::getCode, zone.getCode()). eq(Zone::getWarehouseCode, zone.getWarehouseCode()); if (this.getOne(query) != null){ throw new Exception("库区编码已存在!"); } } public Zone getByArea(String area,String warehouseCode){ LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery(); zoneLambdaQueryWrapper.eq(Zone::getArea, area); zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode,warehouseCode); zoneLambdaQueryWrapper.last("limit 1"); return this.getOne(zoneLambdaQueryWrapper); } }