package com.huimv.receive.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.receive.common.token.TokenSign;
import com.huimv.receive.common.utils.Result;
import com.huimv.receive.common.utils.ResultCode;
import com.huimv.receive.entity.BaseProcess;
import com.huimv.receive.entity.BaseVisitingMid;
import com.huimv.receive.entity.BaseWashoutPoint;
import com.huimv.receive.entity.dto.GetWashoutPointDto;
import com.huimv.receive.entity.dto.WashListDto;
import com.huimv.receive.entity.vo.DestVo;
import com.huimv.receive.entity.vo.WashOutVo;
import com.huimv.receive.mapper.*;
import com.huimv.receive.service.IBaseWashoutPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
*
* 服务实现类
*
*
* @author author
* @since 2024-03-06
*/
@Service
public class BaseWashoutPointServiceImpl extends ServiceImpl implements IBaseWashoutPointService {
@Autowired
private BaseWashoutPointMapper washoutPointMapper;
@Autowired
private BaseVisitingMapper visitingMapper;
@Autowired
private SysAccountMultilevelMapper accountMultilevelMapper;
@Autowired
private BaseProcessMapper processMapper;
@Autowired
private BaseVisitingMidMapper midMapper;
@Override
public Result list(HttpServletRequest httpServletRequest, Map paramsMap) {
String farmId = paramsMap.get("farmId");
List midList = midMapper.selectList(new QueryWrapper().eq("farm_id", farmId));
// List visitings = visitingMapper.selectList(new QueryWrapper<>());
List washoutPointDtos = new ArrayList<>();
if (ObjectUtil.isEmpty(midList)) {
return new Result(ResultCode.SUCCESS, washoutPointDtos);
} else {
for (BaseVisitingMid visiting : midList) {
Integer type = visiting.getId();
List list = washoutPointMapper.selectList(new QueryWrapper()
.eq("farm_ids", farmId).eq("mid_id", type));
List washListDtos = new ArrayList<>();
if (list.size() != 0) {
for (BaseWashoutPoint point : list) {
WashListDto washListDto = new WashListDto();
washListDto.setAddressId(point.getLocationId());
washListDto.setFlowLists(point.getFlowList());
washListDto.setNextName(point.getTailLocationName());
washListDto.setPcrTime(point.getPcrTime());
washListDtos.add(washListDto);
}
GetWashoutPointDto getWashoutPointDto = new GetWashoutPointDto();
getWashoutPointDto.setFarmIds(farmId);
getWashoutPointDto.setNumber(list.size());
getWashoutPointDto.setVisitingType(visiting.getVisitingType());
getWashoutPointDto.setMidId(visiting.getId());
getWashoutPointDto.setMidName(visiting.getVisitingName());
getWashoutPointDto.setWashListDtos(washListDtos);
washoutPointDtos.add(getWashoutPointDto);
}
}
}
return new Result(ResultCode.SUCCESS, washoutPointDtos);
}
@Override
public Result add(HttpServletRequest httpServletRequest, WashOutVo washOutVo) {
List washoutPointDtos = washOutVo.getWashoutPointDtos();
String farmId = washOutVo.getFarmId();
//如果当前存在进行中流程,则初始化流程配置不能修改或删除
QueryWrapper processQueryWrapper = new QueryWrapper<>();
processQueryWrapper.eq("farm_id", farmId).eq("process_type",0);
List processes = processMapper.selectList(processQueryWrapper);
if (processes.size() > 0) {
return new Result(10001, "当前存在进行中流程,无法修改", true);
}
//访问类型集合
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("farm_ids",farmId);
washoutPointMapper.delete(queryWrapper);
for (GetWashoutPointDto washoutPointDto : washoutPointDtos) {
//流程集合
List washListDtos = washoutPointDto.getWashListDtos();
int i = 1;
for (WashListDto washListDto : washListDtos) {
BaseWashoutPoint washoutPoint = new BaseWashoutPoint();
washoutPoint.setCreateTime(new Date());
washoutPoint.setCreateUser(TokenSign.getMemberIdByJwtToken(httpServletRequest));
washoutPoint.setFlowList(washListDto.getFlowLists());
washoutPoint.setLocationId(washListDto.getAddressId());
washoutPoint.setPcrTime(washListDto.getPcrTime());
washoutPoint.setVisitingType(washoutPointDto.getVisitingType());
washoutPoint.setTailLocationName(washListDto.getNextName());
washoutPoint.setFarmIds(farmId);
washoutPoint.setPointLevel(i);
washoutPoint.setMidName(washoutPointDto.getMidName());
washoutPoint.setMidId(washoutPointDto.getMidId());
washoutPointMapper.insert(washoutPoint);
i++;
}
}
return new Result(10000, "添加成功!", true);
}
@Override
public Result delete(HttpServletRequest httpServletRequest, Map paramsMap) {
String farmId = paramsMap.get("farmId");
String type = paramsMap.get("type");//访问类型
String level = paramsMap.get("level");//洗消站等级
washoutPointMapper.delete(new QueryWrapper().like("farm_ids", farmId)
.eq("visiting_type", type).eq("point_level", level));
return new Result(10000, "删除成功!", true);
}
@Override
public Result listDest(Map paramsMap) {
String farmId = paramsMap.get("farmId");
String vistitType = paramsMap.get("midId");
// if ("0".equals(vistitType)){
// vistitType= "7";
// }
List baseWashoutPointList = washoutPointMapper.listDest(farmId,vistitType);
List destVoList = new ArrayList<>();
for (BaseWashoutPoint baseWashoutPoint : baseWashoutPointList) {
DestVo destVo2 = new DestVo();
destVo2.setId(baseWashoutPoint.getLocationId());
destVo2.setLocationName(baseWashoutPoint.getTailLocationName());
destVoList.add(destVo2);
}
return new Result(ResultCode.SUCCESS,destVoList);
}
@Override
public Result listWash(Map paramsMap) {
String farmId = paramsMap.get("farmId");
String vistitType = paramsMap.get("midId");
List points = washoutPointMapper.listWash(farmId, vistitType);
List destVoList = new ArrayList<>();
for (BaseWashoutPoint baseWashoutPoint : points) {
DestVo destVo = new DestVo();
destVo.setId(baseWashoutPoint.getLocationId());
destVo.setLocationName(baseWashoutPoint.getLocationName());
destVoList.add(destVo);
}
return new Result(ResultCode.SUCCESS,destVoList);
}
}