package com.jcdm.main.bs.batchInfo.service.impl; import java.text.SimpleDateFormat; import java.time.Instant; import java.util.*; import java.util.concurrent.CompletableFuture; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jcdm.common.utils.DateUtils; import com.jcdm.main.bs.beatSetting.domain.BsBeatSetting; import com.jcdm.main.bs.beatSetting.mapper.BsBeatSettingMapper; import com.jcdm.main.bs.beatSetting.service.IBsBeatSettingService; import com.jcdm.main.constant.Constants; import com.jcdm.main.restful.qingYan.doman.ChildVO; import com.jcdm.main.restful.qingYan.doman.ParentVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.jcdm.main.bs.batchInfo.mapper.BsBatchInfoMapper; import com.jcdm.main.bs.batchInfo.domain.BsBatchInfo; import com.jcdm.main.bs.batchInfo.service.IBsBatchInfoService; /** * 批次信息录入Service业务层处理 * * @author Yi * @date 2024-10-15 */ @Service public class BsBatchInfoServiceImpl extends ServiceImpl implements IBsBatchInfoService { @Autowired private BsBatchInfoMapper bsBatchInfoMapper; /** * 查询批次信息录入 * * @param id 批次信息录入主键 * @return 批次信息录入 */ @Override public BsBatchInfo selectBsBatchInfoById(Long id) { return bsBatchInfoMapper.selectBsBatchInfoById(id); } /** * 查询批次信息录入列表 * * @param bsBatchInfo 批次信息录入 * @return 批次信息录入 */ @Override public List selectBsBatchInfoList(BsBatchInfo bsBatchInfo) { return bsBatchInfoMapper.selectBsBatchInfoList(bsBatchInfo); } /** * 新增批次信息录入 * * @param bsBatchInfo 批次信息录入 * @return 结果 */ @Override public int insertBsBatchInfo(BsBatchInfo bsBatchInfo) { bsBatchInfo.setChangeTime(DateUtils.getNowDate()); bsBatchInfo.setCreateTime(DateUtils.getNowDate()); return bsBatchInfoMapper.insertBsBatchInfo(bsBatchInfo); } /** * 修改批次信息录入 * * @param bsBatchInfo 批次信息录入 * @return 结果 */ @Override public int updateBsBatchInfo(BsBatchInfo bsBatchInfo) { bsBatchInfo.setUpdateTime(DateUtils.getNowDate()); return bsBatchInfoMapper.updateBsBatchInfo(bsBatchInfo); } /** * 批量删除批次信息录入 * * @param ids 需要删除的批次信息录入主键 * @return 结果 */ @Override public int deleteBsBatchInfoByIds(Long[] ids) { return bsBatchInfoMapper.deleteBsBatchInfoByIds(ids); } /** * 删除批次信息录入信息 * * @param id 批次信息录入主键 * @return 结果 */ @Override public int deleteBsBatchInfoById(Long id) { return bsBatchInfoMapper.deleteBsBatchInfoById(id); } @Override public int bacthInput(Long[] ids) { Integer sendData = 0; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Set idSet = new HashSet<>(Arrays.asList(ids)); List bsBatchInfos = this.listByIds(idSet); for (BsBatchInfo bsBatchInfo : bsBatchInfos) { ParentVO parentVO = new ParentVO(); parentVO.setSiteCode("3983"); parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli())); parentVO.setStationCode(bsBatchInfo.getStationCode()); parentVO.setProductNum(format.format(new Date())); parentVO.setTotalResult("1"); List listChildVo = new ArrayList<>(); ChildVO childVO = new ChildVO(); childVO.setItemCode(bsBatchInfo.getMaterialCode()); childVO.setItemType("3"); childVO.setItemText(bsBatchInfo.getMaterialName()); childVO.setItemValue(bsBatchInfo.getBatch()); childVO.setCheckResult("1"); childVO.setCheckTime(format.format(new Date())); listChildVo.add(childVO); parentVO.setCheckList(listChildVo); try{ CompletableFuture cp1 = CompletableFuture.runAsync(() -> { HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute(); System.out.println(execute.body()); bsBatchInfo.setFlag("Y"); this.saveOrUpdate(bsBatchInfo); }); }catch (Exception e){ System.out.println(e.getMessage()); } sendData = sendData+1; } return sendData; } }