Commit a95c4f3d authored by 王夏晖's avatar 王夏晖

设备巡检功能修改完善

parent 785b568b
...@@ -181,4 +181,10 @@ public class BusDeviceController extends PaginationController<BusDevice> { ...@@ -181,4 +181,10 @@ public class BusDeviceController extends PaginationController<BusDevice> {
busDeviceServiceImpl.downloadExcel(response, list); busDeviceServiceImpl.downloadExcel(response, list);
} }
@ApiOperation(value="生成设备二维码", notes="生成设备二维码")
@RequestMapping("/generateCode")
public Result generateCode(@RequestParam String devNum) {
return Result.builder(busDeviceServiceImpl.generateCode(devNum));
}
} }
...@@ -25,7 +25,8 @@ public interface BusDeviceRepository extends BaseMapper<BusDevice> { ...@@ -25,7 +25,8 @@ public interface BusDeviceRepository extends BaseMapper<BusDevice> {
" where 1=1" + " where 1=1" +
"<if test='proId != null'> and a.pro_id = #{proId}</if>" + "<if test='proId != null'> and a.pro_id = #{proId}</if>" +
"<if test='devTpId != null'> and a.dev_tp_id = #{devTpId}</if>" + "<if test='devTpId != null'> and a.dev_tp_id = #{devTpId}</if>" +
"<if test='devNum != null'> and a.dev_num = #{devNum}</if>" "<if test='devNum != null'> and a.dev_num = #{devNum}</if>" +
"<if test='qrcodeUrl != null'> and a.qrcode_url is not null</if>"
+ "</script>") + "</script>")
List<Map<String,Object>> queryBusDevices(BusDevice busDevice); List<Map<String,Object>> queryBusDevices(BusDevice busDevice);
......
...@@ -90,4 +90,11 @@ public interface BusDeviceService { ...@@ -90,4 +90,11 @@ public interface BusDeviceService {
* @param response * @param response
*/ */
void downloadExcel(HttpServletResponse response, List<DeviceParamsVo> list); void downloadExcel(HttpServletResponse response, List<DeviceParamsVo> list);
/**
* 生成设备二维码
* @param devNum 设备编号
* @return
*/
PersistModel generateCode(String devNum);
} }
...@@ -259,6 +259,36 @@ public class BusDeviceServiceImpl implements BusDeviceService { ...@@ -259,6 +259,36 @@ public class BusDeviceServiceImpl implements BusDeviceService {
} }
} }
@Override
public PersistModel generateCode(String devNum) {
int line = 1;
String message = "";
boolean flag = busDeviceRepository.queryDeviceByDevNum(devNum)!=null && busDeviceRepository.queryDeviceByDevNum(devNum).size()>0;
if(!flag){
line = 0;
message = "设备编号不存在,生成失败";
}else{
// 保存二维码路径(配置的路径+项目编号)
String path = qrcodePath + "/";
try {
// 生成二维码(第一个参数(二维码数据):设备编号,第二个参数(保存的路径):保存的路径,第三个参数(文件名):设备id)
QRCodeUtils.createQRCodeFile(devNum, path,devNum);
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Example example = new Example(BusDevice.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("devNum",devNum);
BusDevice busDevice = new BusDevice();
busDevice.setDevNum(devNum);
busDevice.setQrcodeUrl( "/" + devNum + ".JPG");
line = busDeviceRepository.updateByExampleSelective(busDevice,example);
}
return new PersistModel(line,message);
}
private byte[] createExcel(List<DeviceParamsVo> list) throws IOException { private byte[] createExcel(List<DeviceParamsVo> list) throws IOException {
HSSFWorkbook workbook = null; HSSFWorkbook workbook = null;
try(ByteArrayOutputStream os = new ByteArrayOutputStream()) { try(ByteArrayOutputStream os = new ByteArrayOutputStream()) {
......
...@@ -6,6 +6,8 @@ package org.rcisoft.business.device.inspection.controller; ...@@ -6,6 +6,8 @@ package org.rcisoft.business.device.inspection.controller;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.*;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
import org.rcisoft.business.device.inspection.service.InspectionService; import org.rcisoft.business.device.inspection.service.InspectionService;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
...@@ -13,6 +15,16 @@ import org.rcisoft.core.result.Result; ...@@ -13,6 +15,16 @@ import org.rcisoft.core.result.Result;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/** /**
* Created by on 2018-4-18 15:41:54. * Created by on 2018-4-18 15:41:54.
*/ */
...@@ -38,14 +50,63 @@ public class InspectionController { ...@@ -38,14 +50,63 @@ public class InspectionController {
@ApiOperation(value = "查询该项目下某个设备的所有巡检记录") @ApiOperation(value = "查询该项目下某个设备的所有巡检记录")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "proId", value = "项目id", required = true,paramType = "path", dataType = "varvhar"), @ApiImplicitParam(name = "proId", value = "项目id", required = true,paramType = "path", dataType = "varvhar"),
@ApiImplicitParam(name = "devNum", value = "设备编号", required = true,paramType = "path", dataType = "varvhar") @ApiImplicitParam(name = "devNum", value = "设备编号", required = true,paramType = "path", dataType = "varvhar"),
@ApiImplicitParam(name = "mon", value = "年月", required = true,paramType = "path", dataType = "varvhar")
}) })
@ResponseBody @ResponseBody
@GetMapping(value = "/listAllInspection/{proId}/{devNum}") @GetMapping(value = "/listAllInspection/{proId}/{devNum}/{mon}")
public Result listAllInspection(@PathVariable("proId") String proId, @PathVariable("devNum") String devNum){ public Result listAllInspection(@PathVariable("proId") String proId, @PathVariable("devNum") String devNum, @PathVariable("mon") String mon){
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
inspectionService.listAllInspectionInfomatinByProIdAndDevNum(proId, devNum)); inspectionService.listAllInspectionInfomatinByProIdAndDevNum(proId, devNum,mon));
}
@ApiOperation(value = "导出单个设备的月巡检记录")
@ResponseBody
@RequestMapping(value = "/exportExcel",method = RequestMethod.GET)
public void exportExcel(HttpServletResponse response,
@RequestParam String proId, @RequestParam("devNum") String devNum, @RequestParam("mon") String mon) throws UnsupportedEncodingException {
List<Map<String, Object>> deviceList = new ArrayList<>();
//先获取数据库数据
deviceList = inspectionService.listAllInspectionInfomatinByProIdAndDevNum(proId, devNum,mon);
//通过项目id获取对应的名称组拼成文件名
String filename = devNum + "-"+ mon + "巡检记录.xls";
//创建excel生成对象
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(mon+"巡检记录表");
//表头内容
String[] headers = { "时间", "巡检人", "巡检结果"};
HSSFRow row = sheet.createRow(0);
//在excel表中添加表头
for(int i=0;i<headers.length;i++){
HSSFCell cell = row.createCell(i);
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text);
}
//日期类型格式化
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//在表中存放查询到的数据放入对应的列
int rowNum = 1;
for (Map<String,Object> temp :
deviceList) {
HSSFRow rowTemp = sheet.createRow(rowNum);
rowTemp.createCell(0).setCellValue(temp.get("INSP_TM").toString());
rowTemp.createCell(1).setCellValue(temp.get("USER_NICK_NAME").toString());
rowTemp.createCell(2).setCellValue(temp.get("INSP_CONTENT").toString());
rowNum++;
}
//设置响应头信息
response.setHeader("Content-disposition", "attachment;filename="+ URLEncoder.encode(filename, "utf-8"));
try {
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
...@@ -26,7 +26,7 @@ public interface InspectionRepository { ...@@ -26,7 +26,7 @@ public interface InspectionRepository {
* @param devNum * @param devNum
* @return * @return
*/ */
List<Map<String, Object>> listAllInspectionInfomatinByProIdAndDevNum(@Param("proId") String proId, @Param("devNum") String devNum); List<Map<String, Object>> listAllInspectionInfomatinByProIdAndDevNum(@Param("proId") String proId, @Param("devNum") String devNum,@Param("mon") String mon);
......
...@@ -20,7 +20,7 @@ public interface InspectionService { ...@@ -20,7 +20,7 @@ public interface InspectionService {
* @param devNum * @param devNum
* @return * @return
*/ */
List<Map<String, Object>> listAllInspectionInfomatinByProIdAndDevNum(String proId, String devNum); List<Map<String, Object>> listAllInspectionInfomatinByProIdAndDevNum(String proId, String devNum,String mon);
......
package org.rcisoft.business.device.inspection.service.impl; package org.rcisoft.business.device.inspection.service.impl;
import freemarker.template.SimpleDate;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.device.inspection.dao.InspectionRepository; import org.rcisoft.business.device.inspection.dao.InspectionRepository;
import org.rcisoft.business.device.inspection.service.InspectionService; import org.rcisoft.business.device.inspection.service.InspectionService;
...@@ -9,6 +10,8 @@ import org.springframework.stereotype.Service; ...@@ -9,6 +10,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -30,7 +33,11 @@ public class InspectionServiceImpl implements InspectionService { ...@@ -30,7 +33,11 @@ public class InspectionServiceImpl implements InspectionService {
} }
@Override @Override
public List<Map<String, Object>> listAllInspectionInfomatinByProIdAndDevNum(String proId, String devNum) { public List<Map<String, Object>> listAllInspectionInfomatinByProIdAndDevNum(String proId, String devNum,String mon) {
return inspectionRepository.listAllInspectionInfomatinByProIdAndDevNum(proId, devNum); if(mon==null || mon.equals("")){
SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM");
mon = simple.format(new Date());
}
return inspectionRepository.listAllInspectionInfomatinByProIdAndDevNum(proId, devNum,mon);
} }
} }
...@@ -36,5 +36,6 @@ ...@@ -36,5 +36,6 @@
LEFT JOIN sys_user su ON su.OPENID = bdi.INSPECTOR LEFT JOIN sys_user su ON su.OPENID = bdi.INSPECTOR
WHERE WHERE
bd.PRO_ID = #{proId} AND bd.DEV_NUM = #{devNum} bd.PRO_ID = #{proId} AND bd.DEV_NUM = #{devNum}
AND DATE_FORMAT (bdi.INSP_TM,'%Y-%m') = #{mon}
</select> </select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment