|
|
|
@ -1,11 +1,13 @@
|
|
|
|
|
package com.hnac.hzims.spare.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ch.qos.logback.classic.jmx.MBeanUtil; |
|
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
|
import com.alibaba.excel.converters.longconverter.LongStringConverter; |
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle; |
|
|
|
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; |
|
|
|
|
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
@ -17,6 +19,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.hnac.hzims.common.logs.utils.StringUtils; |
|
|
|
|
import com.hnac.hzims.equipment.feign.IEmInfoClient; |
|
|
|
|
import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO; |
|
|
|
|
import com.hnac.hzims.spare.dto.WtSpBasicDto; |
|
|
|
|
import com.hnac.hzims.spare.entity.*; |
|
|
|
|
import com.hnac.hzims.spare.enume.WarehouseInType; |
|
|
|
|
import com.hnac.hzims.spare.enume.WarehouseOutType; |
|
|
|
@ -33,16 +37,20 @@ import com.hnac.hzims.spare.utils.SheetWriteStyleHandler;
|
|
|
|
|
import com.hnac.hzims.spare.vo.SparePartVO; |
|
|
|
|
import com.hnac.hzims.spare.vo.WtSpBasicVO; |
|
|
|
|
import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; |
|
|
|
|
import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO; |
|
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.poi.ss.usermodel.BorderStyle; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.api.IResultCode; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.api.ResultCode; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
@ -57,10 +65,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.io.*; |
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -171,7 +176,6 @@ public class WtSpBasicServiceImpl extends ServiceImpl<WtSpBasicMapper, WtSpBasic
|
|
|
|
|
List<WtSpBasicVO> voList = new ArrayList<>(); |
|
|
|
|
IPage<WtSpBasicVO> voPages = new Page<>(); |
|
|
|
|
if (Func.isNotEmpty(spBasicEntity.getName()) && "工具".equals(spBasicEntity.getName())) { |
|
|
|
|
// if(Func.isNotEmpty(spBasicEntity.getName())){
|
|
|
|
|
List<WtSpManagementEntity> list = managementService.list(Wrappers.<WtSpManagementEntity>query().lambda(). |
|
|
|
|
eq(WtSpManagementEntity::getName, spBasicEntity.getName())); |
|
|
|
|
if (list.size() == 0) { |
|
|
|
@ -218,13 +222,6 @@ public class WtSpBasicServiceImpl extends ServiceImpl<WtSpBasicMapper, WtSpBasic
|
|
|
|
|
basicVO.setStock(0L); |
|
|
|
|
} |
|
|
|
|
BeanUtils.copyProperties(basicEntity, basicVO); |
|
|
|
|
|
|
|
|
|
List<TicketInfoStatisticVO> ticketVOS = ticketInfoAllClient.getTicketStatistic("2022-02"); |
|
|
|
|
|
|
|
|
|
// R<Dept> deptR = sysClient.getDept(basicEntity.getWaterPlantId());
|
|
|
|
|
// if(Func.isNotEmpty(deptR.getData())){
|
|
|
|
|
// basicVO.setWaterPlantName(deptR.getData().getDeptName());
|
|
|
|
|
// }
|
|
|
|
|
voList.add(basicVO); |
|
|
|
|
} else { |
|
|
|
|
WtSpBasicVO basicVO = new WtSpBasicVO(); |
|
|
|
@ -240,16 +237,11 @@ public class WtSpBasicServiceImpl extends ServiceImpl<WtSpBasicMapper, WtSpBasic
|
|
|
|
|
if (null != totalEntity) { |
|
|
|
|
List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); |
|
|
|
|
if (totalList.size() > 0) { |
|
|
|
|
// basicVO.setStock(totalList.get(0).getStock());
|
|
|
|
|
basicVO.setStock(totalEntity.getStock()); |
|
|
|
|
} else { |
|
|
|
|
basicVO.setStock(0L); |
|
|
|
|
} |
|
|
|
|
BeanUtils.copyProperties(basicEntity, basicVO); |
|
|
|
|
// R<Dept> deptR = sysClient.getDept(basicEntity.getWaterPlantId());
|
|
|
|
|
// if(Func.isNotEmpty(deptR.getData())){
|
|
|
|
|
// basicVO.setWaterPlantName(deptR.getData().getDeptName());
|
|
|
|
|
// }
|
|
|
|
|
voList.add(basicVO); |
|
|
|
|
} |
|
|
|
|
List<WtSpTotalEntity> totalEntities = totalMapper.selectByWarehouseId(warehouseId); |
|
|
|
@ -274,6 +266,61 @@ public class WtSpBasicServiceImpl extends ServiceImpl<WtSpBasicMapper, WtSpBasic
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void export(WtSpBasicDto request, HttpServletResponse response) { |
|
|
|
|
LambdaQueryWrapper<WtSpBasicEntity> basicWrapper = Wrappers.<WtSpBasicEntity>lambdaQuery() |
|
|
|
|
.like(StringUtils.isNotEmpty(request.getNameQuery()),WtSpBasicEntity::getName, request.getNameQuery()); |
|
|
|
|
List<WtSpBasicEntity> wtBasicList = this.list(basicWrapper); |
|
|
|
|
Assert.isTrue(CollectionUtil.isNotEmpty(wtBasicList),() -> { |
|
|
|
|
throw new HzServiceException(ResultCode.FAILURE,"暂无数据!"); |
|
|
|
|
}); |
|
|
|
|
List<WtSpBasicVO> basicVOList = wtBasicList.stream().map(b -> this.getBasicVO(b, request.getWarehouseId())).collect(Collectors.toList()); |
|
|
|
|
String fileName; |
|
|
|
|
try { |
|
|
|
|
fileName = URLEncoder.encode("工具台账报表", "UTF-8"); |
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
|
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
|
|
|
|
contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); |
|
|
|
|
contentWriteCellStyle.setBorderTop(BorderStyle.THIN); |
|
|
|
|
contentWriteCellStyle.setBorderRight(BorderStyle.THIN); |
|
|
|
|
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); |
|
|
|
|
contentWriteCellStyle.setWrapped(true); |
|
|
|
|
try { |
|
|
|
|
EasyExcel.write(response.getOutputStream(), WtSpBasicVO.class) |
|
|
|
|
.registerWriteHandler(new HorizontalCellStyleStrategy(new WriteCellStyle(), contentWriteCellStyle)) |
|
|
|
|
.autoCloseStream(Boolean.FALSE).sheet("工具台账") |
|
|
|
|
.doWrite(basicVOList); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private WtSpBasicVO getBasicVO(WtSpBasicEntity basicEntity,Long warehouseId) { |
|
|
|
|
WtSpBasicVO basicVO = BeanUtil.copy(basicEntity,WtSpBasicVO.class); |
|
|
|
|
if(Func.isEmpty(warehouseId)) { |
|
|
|
|
WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); |
|
|
|
|
basicVO.setSparePartsName(Optional.ofNullable(managementEntity).map(WtSpManagementEntity::getName).orElse(null)); |
|
|
|
|
List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); |
|
|
|
|
basicVO.setStock(CollectionUtil.isNotEmpty(totalList) ? totalList.get(0).getStock() : 0L); |
|
|
|
|
} else { |
|
|
|
|
WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); |
|
|
|
|
basicVO.setSparePartsName(Optional.ofNullable(managementEntity).map(WtSpManagementEntity::getName).orElse(null)); |
|
|
|
|
LambdaQueryWrapper<WtSpTotalEntity> totalWrapper = Wrappers.<WtSpTotalEntity>lambdaQuery() |
|
|
|
|
.eq(Func.isNotEmpty(basicEntity.getId()), WtSpTotalEntity::getSpBasicId, basicEntity.getId()) |
|
|
|
|
.eq(WtSpTotalEntity::getWarehouseId, warehouseId); |
|
|
|
|
if(CollectionUtil.isNotEmpty(totalMapper.selectList(totalWrapper))) { |
|
|
|
|
List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); |
|
|
|
|
basicVO.setStock(CollectionUtil.isNotEmpty(totalList) ? totalList.get(0).getStock() : 0L); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return basicVO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Integer selectTotal(Map<String, Object> params) { |
|
|
|
|
return baseMapper.selectTotal(params); |
|
|
|
|
} |
|
|
|
@ -508,7 +555,6 @@ public class WtSpBasicServiceImpl extends ServiceImpl<WtSpBasicMapper, WtSpBasic
|
|
|
|
|
// .doWrite(list);
|
|
|
|
|
// response.getOutputStream().close();
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
System.out.println("exportExcel = " + e); |
|
|
|
|
// 重置response
|
|
|
|
|
response.reset(); |
|
|
|
|
response.setContentType("application/json"); |
|
|
|
|