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.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;
|
|
/**
|
* 过站采集Controller
|
*
|
* @author HDY
|
* @date 2025-02-12
|
*/
|
@RestController
|
@RequestMapping("/da/stationCollection")
|
public class DaStationCollectionController extends BaseController
|
{
|
@Autowired
|
private DaStationCollectionServiceImpl daStationCollectionService;
|
|
/**
|
* 查询过站采集列表
|
*/
|
@PreAuthorize("@ss.hasPermi('da:stationCollection:list')")
|
@GetMapping("/list")
|
public TableDataInfo list(DaStationCollection daStationCollection)
|
{
|
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:export')")
|
@Log(title = "过站采集", businessType = BusinessType.EXPORT)
|
@PostMapping("/export")
|
public void export(HttpServletResponse response, DaStationCollection daStationCollection)
|
{
|
List<DaStationCollection> list = daStationCollectionService.selectDaStationCollectionList(daStationCollection);
|
ExcelUtil<DaStationCollection> util = new ExcelUtil<DaStationCollection>(DaStationCollection.class);
|
util.exportExcel(response, list, "过站采集数据");
|
}
|
|
/**
|
* 获取过站采集详细信息
|
*/
|
@PreAuthorize("@ss.hasPermi('da:stationCollection:query')")
|
@GetMapping(value = "/{id}")
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
{
|
return success(daStationCollectionService.selectDaStationCollectionById(id));
|
}
|
|
/**
|
* 新增过站采集
|
*/
|
@PreAuthorize("@ss.hasPermi('da:stationCollection:add')")
|
@Log(title = "过站采集", businessType = BusinessType.INSERT)
|
@PostMapping
|
public AjaxResult add(@RequestBody DaStationCollection daStationCollection)
|
{
|
return toAjax(daStationCollectionService.insertDaStationCollection(daStationCollection));
|
}
|
|
/**
|
* 修改过站采集
|
*/
|
@PreAuthorize("@ss.hasPermi('da:stationCollection:edit')")
|
@Log(title = "过站采集", businessType = BusinessType.UPDATE)
|
@PutMapping
|
public AjaxResult edit(@RequestBody DaStationCollection daStationCollection)
|
{
|
return toAjax(daStationCollectionService.updateDaStationCollection(daStationCollection));
|
}
|
|
/**
|
* 删除过站采集
|
*/
|
@PreAuthorize("@ss.hasPermi('da:stationCollection:remove')")
|
@Log(title = "过站采集", businessType = BusinessType.DELETE)
|
@DeleteMapping("/{id}")
|
public R remove(@PathVariable Long id)
|
{
|
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();
|
// }
|
}
|