| | |
| | | package com.billion.main.da.controller; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.billion.common.annotation.Log; |
| | | import com.billion.common.core.controller.BaseController; |
| | | import com.billion.common.core.domain.AjaxResult; |
| | | import com.billion.common.core.domain.R; |
| | | import com.billion.common.core.page.TableDataInfo; |
| | | import com.billion.common.enums.BusinessType; |
| | | import com.billion.common.exception.ServiceException; |
| | | import com.billion.common.utils.poi.ExcelUtil; |
| | | import com.billion.main.da.domain.DaStationCollection; |
| | | import com.billion.main.da.service.IDaStationCollectionService; |
| | | import com.billion.main.da.service.impl.DaStationCollectionServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.rmi.ServerError; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | public class DaStationCollectionController extends BaseController |
| | | { |
| | | @Autowired |
| | | private IDaStationCollectionService daStationCollectionService; |
| | | private DaStationCollectionServiceImpl daStationCollectionService; |
| | | |
| | | /** |
| | | * 查询过站采集列表 |
| | |
| | | startPage(); |
| | | List<DaStationCollection> list = daStationCollectionService.selectDaStationCollectionList(daStationCollection); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | @GetMapping("/printList") |
| | | public R printList() |
| | | { |
| | | List<DaStationCollection> list = daStationCollectionService.list(new LambdaQueryWrapper<DaStationCollection>().eq(DaStationCollection::getStatus,"0")); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('da:stationCollection:remove')") |
| | | @Log(title = "过站采集", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public AjaxResult remove(@PathVariable Long[] ids) |
| | | @DeleteMapping("/{id}") |
| | | public R remove(@PathVariable Long id) |
| | | { |
| | | return toAjax(daStationCollectionService.deleteDaStationCollectionByIds(ids)); |
| | | if (ObjUtil.isNull(id)){ |
| | | throw new ServiceException("id不能为空"); |
| | | } |
| | | List<DaStationCollection> list = daStationCollectionService.list(new LambdaQueryWrapper<DaStationCollection>().eq(DaStationCollection::getId, id)); |
| | | if (CollUtil.isEmpty(list)){ |
| | | throw new ServiceException("数据不存在,请刷新后重试"); |
| | | } |
| | | daStationCollectionService.removeById(id); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/crave") |
| | | public R crave(String sfcCode) throws IOException { |
| | | if (StrUtil.isBlank(sfcCode)){ |
| | | throw new ServiceException("序列号不能为空"); |
| | | } |
| | | if (!sfcCode.contains(StrUtil.SPACE)){ |
| | | throw new ServiceException("输入的序列号需要包含空格!"); |
| | | } |
| | | |
| | | List<DaStationCollection> list = daStationCollectionService.list(new LambdaQueryWrapper<DaStationCollection>() |
| | | .eq(DaStationCollection::getSfcCode, sfcCode) |
| | | .eq(DaStationCollection::getLocationCode,"OP001")); |
| | | if (CollUtil.isNotEmpty(list)){ |
| | | DaStationCollection daStationCollection = list.get(0); |
| | | //重复刻码 |
| | | return R.ok(303,"此序列号已刻码"); |
| | | } else { |
| | | // //首次刻码-发送刻码信号给下位机 |
| | | // TcpClient tcpClient = new TcpClient(); |
| | | // byte[] bytes = sfcCode.getBytes(StandardCharsets.UTF_8); |
| | | // tcpClient.sendData(bytes); |
| | | //查询数据中状态为0的数据 |
| | | List<DaStationCollection> collect = daStationCollectionService.list(new LambdaQueryWrapper<DaStationCollection>() |
| | | .eq(DaStationCollection::getStatus, "0")); |
| | | if (CollUtil.isNotEmpty(collect)) { |
| | | //清除 |
| | | daStationCollectionService.update(new LambdaUpdateWrapper<DaStationCollection>() |
| | | .eq(DaStationCollection::getStatus,"0") |
| | | .set(DaStationCollection::getStatus,"1")); |
| | | } |
| | | |
| | | //保存数据 |
| | | DaStationCollection daStationCollection = new DaStationCollection(); |
| | | Date date = new Date(); |
| | | daStationCollection.setSfcCode(sfcCode); |
| | | List<String> split = ListUtil.toList(sfcCode.split(StrUtil.SPACE)); |
| | | if (CollUtil.isNotEmpty(split)){ |
| | | if (split.size() > 1){ |
| | | daStationCollection.setPrintCode(split.get(1)); |
| | | } |
| | | } |
| | | daStationCollection.setLocationCode("OP001"); |
| | | daStationCollection.setCollectTime(date); |
| | | daStationCollection.setInboundTime(date); |
| | | daStationCollection.setOutboundTime(date); |
| | | daStationCollection.setStatus("0"); |
| | | daStationCollectionService.save(daStationCollection); |
| | | return R.ok(200); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @GetMapping("/reCrave") |
| | | public R reCrave(String sfcCode) throws IOException { |
| | | if (StrUtil.isBlank(sfcCode)){ |
| | | throw new ServiceException("序列号不能为空"); |
| | | } |
| | | if (!sfcCode.contains(StrUtil.SPACE)){ |
| | | throw new ServiceException("输入的序列号需要包含空格!"); |
| | | } |
| | | // //发送刻码信号给下位机 |
| | | // TcpClient tcpClient = new TcpClient(); |
| | | // byte[] bytes = sfcCode.getBytes(StandardCharsets.UTF_8); |
| | | // tcpClient.sendData(bytes); |
| | | |
| | | List<DaStationCollection> collect = daStationCollectionService.list(new LambdaQueryWrapper<DaStationCollection>() |
| | | .eq(DaStationCollection::getStatus, "0")); |
| | | if (CollUtil.isNotEmpty(collect)) { |
| | | //清除 |
| | | daStationCollectionService.update(new LambdaUpdateWrapper<DaStationCollection>() |
| | | .eq(DaStationCollection::getStatus,"0") |
| | | .set(DaStationCollection::getStatus,"1")); |
| | | } |
| | | |
| | | //保存数据 |
| | | DaStationCollection daStationCollection = new DaStationCollection(); |
| | | Date date = new Date(); |
| | | daStationCollection.setSfcCode(sfcCode); |
| | | List<String> split = ListUtil.toList(sfcCode.split(StrUtil.SPACE)); |
| | | if (CollUtil.isNotEmpty(split)){ |
| | | if (split.size() > 1){ |
| | | daStationCollection.setPrintCode(split.get(1)); |
| | | } |
| | | } |
| | | daStationCollection.setLocationCode("OP001"); |
| | | daStationCollection.setCollectTime(date); |
| | | daStationCollection.setInboundTime(date); |
| | | daStationCollection.setOutboundTime(date); |
| | | daStationCollection.setStatus("0"); |
| | | daStationCollectionService.save(daStationCollection); |
| | | return R.ok(200); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | // @GetMapping("/testSend") |
| | | // public void test(){ |
| | | // TcpClient tcpClient = new TcpClient(); |
| | | // tcpClient.receiveData(); |
| | | // } |
| | | } |