package com.dy.pmsProduct.taskPlan;
|
|
import com.alibaba.excel.converters.Converter;
|
import com.dy.common.aop.SsoPowerAop;
|
import com.dy.common.webUtil.BaseResponse;
|
import com.dy.common.webUtil.BaseResponseUtils;
|
import com.dy.common.webUtil.QueryResultVo;
|
import com.dy.pmsGlobal.aop.Log;
|
import com.dy.pmsGlobal.pojoPr.PrAssemblyPlan;
|
import com.dy.pmsGlobal.pojoPr.PrDevice;
|
import com.dy.pmsGlobal.util.QrCodeUtil;
|
import com.google.zxing.WriterException;
|
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.validation.Valid;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 组装任务计划
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping(path="assembly")
|
public class AssemblyPlanCtrl {
|
private static final String fileName = "设备号信息" ;
|
private static final String sheetName = "设备号信息" ;
|
private AssemblySv sv;
|
@Autowired
|
public void setAssemblySv(AssemblySv assemblySv) {
|
this.sv = assemblySv;
|
}
|
|
@PostMapping(path="save")
|
@SsoPowerAop(power = "10200001")
|
@Log("保存组装任务计划")
|
public BaseResponse<Boolean> save(@RequestBody @Valid PrAssemblyPlan plan){
|
int count = sv.save(plan);
|
if (count <= 0) {
|
return BaseResponseUtils.buildFail("数据库存储失败");
|
} else {
|
return BaseResponseUtils.buildSuccess(true);
|
}
|
}
|
|
/**
|
* 更新
|
* @param plan
|
* @return
|
*/
|
@PostMapping(path="update")
|
@SsoPowerAop(power = "10200001")
|
@Log("更新组装任务计划")
|
public BaseResponse<Boolean> update(@RequestBody @Valid PrAssemblyPlan plan){
|
int count = sv.update(plan);
|
if (count <= 0) {
|
return BaseResponseUtils.buildFail("数据库存储失败");
|
} else {
|
return BaseResponseUtils.buildSuccess(true);
|
}
|
}
|
|
@PostMapping(path="updateStatus")
|
@SsoPowerAop(power = "10200001")
|
@Log("更新任务计划状态")
|
public BaseResponse<Boolean> updateStatus(@RequestBody PrAssemblyPlan plan){
|
int count = sv.updateStatus(plan);
|
if (count <= 0) {
|
return BaseResponseUtils.buildFail("数据库存储失败");
|
} else {
|
return BaseResponseUtils.buildSuccess(true);
|
}
|
}
|
/**
|
* 根据ID查询
|
* @return
|
*/
|
@GetMapping(path="one")
|
@SsoPowerAop(power = "10200000")
|
@Log("根据ID查询组装任务计划")
|
public BaseResponse<PrAssemblyPlan> one(Long id){
|
PrAssemblyPlan plan=sv.selectById(id);
|
return BaseResponseUtils.buildSuccess(plan);
|
}
|
|
/**
|
* 分页查询
|
* @param vo
|
* @return
|
*/
|
@PostMapping(path="some")
|
@SsoPowerAop(power = "10200000")
|
@Log("分页查询组装任务计划")
|
public BaseResponse<QueryResultVo<List<PrAssemblyPlan>>> some(@RequestBody QueryVo vo){
|
QueryResultVo<List<PrAssemblyPlan>> list = sv.selectSome(vo) ;
|
return BaseResponseUtils.buildSuccess(list);
|
}
|
|
/**
|
* 增加设备号
|
*/
|
@PostMapping(path="addDevice")
|
@SsoPowerAop(power = "10200001")
|
@Log("增加设备号")
|
public BaseResponse<?> addDevice(@RequestBody QueryVo vo){
|
if(vo.addNum == null || vo.addNum <= 0 || vo.planId == null){
|
return BaseResponseUtils.buildFail("参数错误");
|
}
|
int count = sv.addDevice(vo.planId,vo.addNum);
|
if (count <= 0) {
|
return BaseResponseUtils.buildFail("数据库存储失败");
|
} else {
|
return BaseResponseUtils.buildSuccess(true);
|
}
|
}
|
|
@PostMapping(path="someDevice")
|
@SsoPowerAop(power = "10200000")
|
@Log("分页查询设备号")
|
public BaseResponse<QueryResultVo<List<PrDevice>>> someDevice(@RequestBody QueryVo queryVo){
|
QueryResultVo<List<PrDevice>> list = sv.selectSomeDevice(queryVo) ;
|
return BaseResponseUtils.buildSuccess(list);
|
}
|
|
@GetMapping(path="exportDevice")
|
@SsoPowerAop(power = "10200001")
|
@Log("导出设备号")
|
public void exportDevice(Long batchId, HttpServletResponse response){
|
Date start = new Date() ;
|
List<Converter> list = new ArrayList<>();
|
|
List<PrDevice> deviceList = sv.selectDeviceByBatchId(batchId) ;
|
// 使用并行流提高性能
|
deviceList.parallelStream().forEach(device -> {
|
ExcelVo vo = new ExcelVo();
|
vo.deviceNo = device.deviceNo;
|
try {
|
vo.qrCode = QrCodeUtil.genQrCode(vo.deviceNo);
|
} catch (IOException | WriterException e) {
|
e.printStackTrace();
|
}
|
list.add(vo);
|
});
|
log.info("导出设备号耗时:"+(new Date().getTime()-start.getTime())+"ms");
|
QrCodeUtil.downloadExcel(response, fileName,sheetName,list);
|
log.info("导出设备号耗时:"+(new Date().getTime()-start.getTime())+"ms");
|
}
|
}
|