Commit 04491f4a authored by gaoliwei's avatar gaoliwei

资产统计页面查询 excel导出

parent ac81e991
package org.rcisoft.business.device.controller;
/*固定导入*/
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.*;
import org.rcisoft.business.device.entity.BusDevice;
import org.rcisoft.business.device.service.BusDeviceService;
import org.rcisoft.business.device.vo.DeviceAssetStatisticVo;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.controller.PaginationController;
import org.rcisoft.core.model.GridModel;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
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;
/**
* Created by on 2018-4-12 15:33:23.
*/
@RestController
@RequestMapping("busdevice")
public class BusDeviceController extends PaginationController<BusDevice> {
@Autowired
private BusDeviceService busDeviceServiceImpl;
@ApiOperation(value="添加", notes="添加")
//@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar")})
@PostMapping(value = "/add")
public Result add(@Valid BusDevice busDevice, BindingResult bindingResult) {
PersistModel data = busDeviceServiceImpl.save(busDevice);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
busDevice);
}
@ApiOperation(value="逻辑删除", notes="逻辑删除")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "id", required = false, dataType = "varchar")})
@DeleteMapping("/delete/{id:\\w+}")
public Result delete(@PathVariable String id) {
BusDevice busDevice = new BusDevice();
PersistModel data = busDeviceServiceImpl.remove(busDevice);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
@ApiOperation(value="修改", notes="修改")
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar")})
@PutMapping("/update/{id:\\w+}")
public Result update(@Valid BusDevice busDevice, BindingResult bindingResult) {
PersistModel data = busDeviceServiceImpl.merge(busDevice);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
busDevice);
}
@ApiOperation(value="查看单 ", notes="查看单 ")
@GetMapping("/detail/{id:\\w+}")
public Result detail(@PathVariable String id) {
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
busDeviceServiceImpl.findById(id));
}
@ApiOperation(value="查看 集合", notes="查看 集合")
@GetMapping(value = "/queryBusDeviceByPagination")
public GridModel listByPagination(BusDevice busDevice) {
// busDevice.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
busDeviceServiceImpl.findAllByPagination(getPaginationUtility(), busDevice);
return getGridModelResponse();
}
/**
* 通过项目id和系统id获取该子系统中的所有设备信息
* @param sysId 系统id
* @param proId 项目id
* @return
*/
@ApiOperation(value = "通过项目id与子系统id获取子系统下所有的设备")
@ApiImplicitParams({
@ApiImplicitParam(name = "sysId", value = "sysId", required = true,paramType = "query", dataType = "varchar"),
@ApiImplicitParam(name = "proId", value = "proId", required = true,paramType = "query", dataType = "varchar")
})
@ResponseBody
@RequestMapping(value = "/getDeviceBySysId",method = RequestMethod.GET)
public Result getDeviceBySysId(@RequestParam("sysId") String sysId,
@RequestParam("proId") String proId)
{
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
busDeviceServiceImpl.getDevicesBySysId(sysId, proId));
}
@ApiOperation(value = "通过项目id与子系统id导出子系统的设备清单excel文件")
@ApiImplicitParams({
@ApiImplicitParam(name = "sysId", value = "sysId", required = true,paramType = "path", dataType = "varchar"),
@ApiImplicitParam(name = "proId", value = "proId", required = true,paramType = "path", dataType = "varvhar")
})
@ResponseBody
@RequestMapping(value = "/exportExcel/{proId}/{sysId}",method = RequestMethod.GET)
public void exportExcel(HttpServletResponse response,@PathVariable("sysId") String sysId,
@PathVariable("proId") String proId) throws UnsupportedEncodingException {
System.out.println("参数:"+sysId+" "+proId);
List<DeviceAssetStatisticVo> deviceList = new ArrayList<>();
//先获取数据库数据
deviceList = busDeviceServiceImpl.getDevicesBySysId(sysId, proId);
//通过项目id与系统id获取对应的名称组拼成文件名
String filename = busDeviceServiceImpl.getProNameByProId(proId) + busDeviceServiceImpl.getSysNameBySysId(sysId)+"设备统计报表.xls";
//创建excel生成对象
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("设备统计表");
//表头内容
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 (DeviceAssetStatisticVo temp :
deviceList) {
HSSFRow rowTemp = sheet.createRow(rowNum);
rowTemp.createCell(0).setCellValue(temp.getDevNm());
rowTemp.createCell(1).setCellValue(temp.getDevTpNm());
rowTemp.createCell(2).setCellValue(temp.getModel());
rowTemp.createCell(3).setCellValue(temp.getFacNm());
rowTemp.createCell(4).setCellValue(temp.getParam());
rowTemp.createCell(5).setCellValue(sdf.format(temp.getInstallDate()));
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();
}
}
}
package org.rcisoft.business.device.dao;
import org.apache.ibatis.annotations.Param;
import org.rcisoft.business.device.vo.DeviceAssetStatisticVo;
import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.business.device.entity.BusDevice;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import springfox.documentation.service.ApiListing;
import java.util.List;
/**
* Created with on 2018-4-12 15:33:23.
*/
@Repository
public interface BusDeviceRepository extends BaseMapper<BusDevice> {
/**
* 分页查询 busDevice
*
*/
@Select("<script>select * from bus_device where 1=1 "
+ "<if test=\"delFlag !=null and delFlag != '' \">and del_flag = #{delFlag} </if> "
+ "<if test=\"flag !=null and flag != '' \">and flag = #{flag} </if> "
+ "</script>")
@ResultMap(value = "BaseResultMap" )
List<BusDevice> queryBusDevices(BusDevice busDevice);
/*
通过项目id与子系统id获取子系统中的所有设备
@param sysId 子系统id
@param proId 项目id
*/
List<DeviceAssetStatisticVo> getBusDevicesBySysId(@Param("sysId") String sysId, @Param("proId") String proId);
/**
* 通过项目id获取项目名称
* @param proId
* @return
*/
String getProNameByProId(@Param("proId") String proId);
/**
* 通过系统id获取系统名称
* @param sysId
* @return
*/
String getSysNameBySysId(@Param("sysId") String sysId);
}
package org.rcisoft.business.device.entity;
import lombok.*;
import org.rcisoft.core.entity.IdNotDataEntity;
import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* Created with on 2018-4-12 15:33:22.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "bus_device")
public class BusDevice implements Serializable{
@Id
private String devId;
private String devNm;
private String devTpId;
private String devNum;
private String devLocal;
private String model;
private String facId;
private String param;
private Date installDate;
//项目id
private String proId;
//系统id
private String sysId;
private String ownId;
public String getDevId() {
return devId;
}
public void setDevId(String devId) {
this.devId = devId;
}
public String getDevNm() {
return devNm;
}
public void setDevNm(String devNm) {
this.devNm = devNm;
}
public String getDevTpId() {
return devTpId;
}
public void setDevTpId(String devTpId) {
this.devTpId = devTpId;
}
public String getDevNum() {
return devNum;
}
public void setDevNum(String devNum) {
this.devNum = devNum;
}
public String getDevLocal() {
return devLocal;
}
public void setDevLocal(String devLocal) {
this.devLocal = devLocal;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getFacId() {
return facId;
}
public void setFacId(String facId) {
this.facId = facId;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
public Date getInstallDate() {
return installDate;
}
public void setInstallDate(Date installDate) {
this.installDate = installDate;
}
public String getProId() {
return proId;
}
public void setProId(String proId) {
this.proId = proId;
}
public String getSysId() {
return sysId;
}
public void setSysId(String sysId) {
this.sysId = sysId;
}
public String getOwnId() {
return ownId;
}
public void setOwnId(String ownId) {
this.ownId = ownId;
}
}
package org.rcisoft.business.device.service;
import org.apache.ibatis.annotations.Param;
import org.rcisoft.business.device.entity.BusDevice;
import org.rcisoft.business.device.vo.DeviceAssetStatisticVo;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.aop.PageUtil;
import java.util.List;
/**
* Created by on 2018-4-12 15:33:23.
*/
public interface BusDeviceService {
/**
* 保存
* @param busDevice
* @return
*/
PersistModel save(BusDevice busDevice);
/**
* 逻辑删除
* @param busDevice
* @return
*/
PersistModel remove(BusDevice busDevice);
/**
* 修改
* @param busDevice
* @return
*/
PersistModel merge(BusDevice busDevice);
/**
* 根据id查询
* @param id
* @return
*/
BusDevice findById(String id);
/**
* 分页查询
* @param busDevice
* @return
*/
List<BusDevice> findAllByPagination(PageUtil<BusDevice> paginationUtility,
BusDevice busDevice);
/**
*通过项目id与子系统id获取系统中所有的设备
* @param proId 项目id
* @param sysId 系统id
*/
List<DeviceAssetStatisticVo> getDevicesBySysId(String sysId, String proId);
/**
* 通过项目id获取项目名称
* @param proId
* @return
*/
String getProNameByProId(String proId);
/**
* 通过系统id获取系统名称
* @param sysId
* @return
*/
String getSysNameBySysId(String sysId);
}
package org.rcisoft.business.device.service.impl;
import org.rcisoft.business.device.dao.BusDeviceRepository;
import org.rcisoft.business.device.service.BusDeviceService;
import org.rcisoft.business.device.vo.DeviceAssetStatisticVo;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.business.device.entity.BusDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
/**
* Created by on 2018-4-12 15:33:23.
*/
@Service
@Transactional(readOnly = true,propagation = Propagation.NOT_SUPPORTED)
@Slf4j
public class BusDeviceServiceImpl implements BusDeviceService {
@Autowired
private BusDeviceRepository busDeviceRepository;
/**
* 保存 busDevice
* @param busDevice
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public PersistModel save(BusDevice busDevice){
//增加操作
// UserUtil.setCurrentPersistOperation(busDevice);
int line = busDeviceRepository.insertSelective(busDevice);
return new PersistModel(line);
}
/**
* 逻辑删除
* @param busDevice
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public PersistModel remove(BusDevice busDevice){
// UserUtil.setCurrentMergeOperation(busDevice);
// busDevice.setDeleted();
int line = busDeviceRepository.logicalDelete(busDevice);
return new PersistModel(line);
}
/**
* 修改 busDevice
* @param busDevice
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public PersistModel merge(BusDevice busDevice){
// UserUtil.setCurrentMergeOperation(busDevice);
int line = busDeviceRepository.updateByPrimaryKeySelective(busDevice);
return new PersistModel(line);
}
/**
* 根据id查询 busDevice
* @param id
* @return
*/
@Override
public BusDevice findById(String id)
{
return busDeviceRepository.selectByPrimaryKey(id);
}
/**
* 分页查询 busDevice
* @param busDevice
* @return
*/
@Override
public List<BusDevice> findAllByPagination(PageUtil<BusDevice> paginationUtility,
BusDevice busDevice){
// busDevice.setStart();
// busDevice.setNotDeleted();
return busDeviceRepository.queryBusDevices(busDevice);
}
/*
通过项目id与子系统id获取子系统中的所有设备
@param sysId 子系统id
@param proId 项目id
*/
@Override
public List<DeviceAssetStatisticVo> getDevicesBySysId(String sysId, String proId) {
return busDeviceRepository.getBusDevicesBySysId(sysId,proId);
}
@Override
public String getProNameByProId(String proId) {
return busDeviceRepository.getProNameByProId(proId);
}
@Override
public String getSysNameBySysId(String sysId) {
return busDeviceRepository.getSysNameBySysId(sysId);
}
}
package org.rcisoft.business.device.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.rcisoft.business.device.entity.BusDevice;
import javax.persistence.Entity;
import java.io.Serializable;
import java.util.Date;
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeviceAssetStatisticVo implements Serializable {
//设备名称
private String devNm;
//设备类型
private String devTpNm;
//设备型号
private String model;
//厂家名称
private String facNm;
//设备参数
private String param;
//安装时间
private Date installDate;
public String getDevNm() {
return devNm;
}
public void setDevNm(String devNm) {
this.devNm = devNm;
}
public String getDevTpNm() {
return devTpNm;
}
public void setDevTpNm(String devTpNm) {
this.devTpNm = devTpNm;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getFacNm() {
return facNm;
}
public void setFacNm(String facNm) {
this.facNm = facNm;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
public Date getInstallDate() {
return installDate;
}
public void setInstallDate(Date installDate) {
this.installDate = installDate;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.business.device.dao.BusDeviceRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.device.entity.BusDevice">
<id column="DEV_ID" jdbcType="VARCHAR" property="devId"/>
<result column="DEV_NM" jdbcType="VARCHAR" property="devNm"/>
<result column="DEV_TP_ID" jdbcType="VARCHAR" property="devTpId"/>
<result column="DEV_NUM" jdbcType="VARCHAR" property="devNum"/>
<result column="DEV_LOCAL" jdbcType="VARCHAR" property="devLocal"/>
<result column="MODEL" jdbcType="VARCHAR" property="model"/>
<result column="FAC_ID" jdbcType="VARCHAR" property="facId"/>
<result column="PARAM" jdbcType="VARCHAR" property="param"/>
<result column="INSTALL_DATE" jdbcType="TIMESTAMP" property="installDate"/>
<result column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="SYS_ID" jdbcType="VARCHAR" property="sysId"/>
<result column="OWN_ID" jdbcType="VARCHAR" property="ownId"/>
</resultMap>
<resultMap id="DeviceAssetStatistics" type="org.rcisoft.business.device.vo.DeviceAssetStatisticVo">
<result column="DEV_NM" jdbcType="VARCHAR" property="devNm"></result>
<result column="DEV_TP_NM" jdbcType="VARCHAR" property="devTpNm"></result>
<result column="MODEL" jdbcType="VARCHAR" property="model"></result>
<result column="FAC_NM" jdbcType="VARCHAR" property="facNm"></result>
<result column="PARAM" jdbcType="VARCHAR" property="param"></result>
<result column="INSTALL_DATE" jdbcType="VARCHAR" property="installDate"></result>
</resultMap>
<select id="getBusDevicesBySysId" parameterType="string" resultMap="DeviceAssetStatistics">
select dev.DEV_NM, dev.MODEL,dev.PARAM,dev.INSTALL_DATE,devtp.DEV_TP_NM,fac.FAC_NM
from bus_device as dev,bus_device_tp as devtp,bus_factory as fac
where dev.DEV_TP_ID=devtp.DEV_TP_ID and dev.FAC_ID=fac.FAC_ID
AND
<if test="proId !='' and proId != null">
dev.PRO_ID = #{proId,jdbcType=VARCHAR}
</if>
AND
<if test="sysId !='' and sysId != null">
dev.SYS_ID = #{sysId,jdbcType=VARCHAR}
</if>
ORDER BY INSTALL_DATE
</select>
<select id="getProNameByProId" parameterType="string" resultType="string">
select PRO_NM from bus_project where PRO_ID =#{proId,jdbcType=VARCHAR}
</select>
<select id="getSysNameBySysId" parameterType="string" resultType="string">
select SYS_NM from bus_system where SYS_ID =#{sysId,jdbcType=VARCHAR}
</select>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
</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