You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
13 KiB

package com.ruoyi.tc.controller;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
5 months ago
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tc.entity.*;
import com.ruoyi.tc.entity.request.AssetCurrentPageRequest;
5 months ago
import com.ruoyi.tc.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
5 months ago
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* (AssetCurrent)
*
* @author makejava
* @since 2024-11-15 10:03:56
*/
@Api(tags = "现有资产表")
@RestController
@RequestMapping("/tc/assetCurrent")
public class AssetCurrentController extends BaseController {
/**
*
*/
@Resource
private AssetCurrentService assetCurrentService;
@Resource
private AssetSupplyChainService assetSupplyChainService;
@Resource
private AssetBasicNetworkService assetBasicNetworkService;
5 months ago
@Resource
private AssetBusinessFormService assetBusinessFormService;
@Resource
private UnitOtherConcatService unitOtherConcatService;
/**
*
*
* @param as
* @return
*/
@ApiOperation(value = "分页查询所有数据", response = AssetCurrent.class)
@GetMapping
5 months ago
public AjaxResult selectAll(AssetCurrentPageRequest as) {
Page<AssetCurrent> page = new Page<>();
page.setSize(as.getSize());
page.setCurrent(as.getCurrent());
try {
5 months ago
if (!SecurityUtils.getLoginUser().getUser().isAdmin() && !SecurityUtils.hasRole("common")) {
as.setDwmc(SecurityUtils.getLoginUser().getUser().getNickName());
5 months ago
}
} catch (Exception e) {
throw new ServiceException("获取用户信息异常");
}
return success(assetCurrentService.page(page, as));
}
/**
*
*
* @param id
* @return
*/
@ApiOperation(value = "通过主键查询单条数据", response = AssetCurrent.class)
@GetMapping("{id}")
public AjaxResult selectOne(@PathVariable Serializable id) {
5 months ago
return success(assetCurrentService.selectOne(id));
}
/**
*
*
* @param assetCurrent
* @return
*/
@ApiOperation(value = "新增数据")
@PostMapping
5 months ago
@Transactional(rollbackFor = Exception.class)
5 months ago
public AjaxResult insert(@RequestBody AssetCurrent assetCurrent) {
5 months ago
StringBuilder a = new StringBuilder();
if(!assetCurrent.getGlymList().isEmpty()){
assetCurrent.getGlymList().forEach(x->{
a.append(x);
a.append(",");
});
}
assetCurrent.setGlym(a.toString());
StringBuilder b = new StringBuilder();
if(!assetCurrent.getGlIpList().isEmpty()){
assetCurrent.getGlymList().forEach(x->{
b.append(x);
b.append(",");
});
}
assetCurrent.setGlIp(b.toString());
5 months ago
assetCurrentService.save(assetCurrent);
//新增新监管业务形态
if (assetCurrent.getXjgywxt() != null) {
assetCurrent.getXjgywxt().setAssetId(assetCurrent.getId());
assetBusinessFormService.save(assetCurrent.getXjgywxt());
}
if (!assetCurrent.getGylxxList().isEmpty()) {
for (AssetSupplyChain items : assetCurrent.getGylxxList()) {
items.setAssetId(assetCurrent.getId());
}
//新增供应链
assetSupplyChainService.saveBatch(assetCurrent.getGylxxList());
}
if (!assetCurrent.getJcwlList().isEmpty()) {
for (AssetBasicNetwork items : assetCurrent.getJcwlList()) {
items.setAssetId(assetCurrent.getId());
}
//新增基础网络
assetBasicNetworkService.saveBatch(assetCurrent.getJcwlList());
}
if (!assetCurrent.getOtherConcat().isEmpty()) {
for (UnitOtherConcat items : assetCurrent.getOtherConcat()) {
items.setAssetId(assetCurrent.getId());
}
//新增其他联系人
unitOtherConcatService.saveBatch(assetCurrent.getOtherConcat());
}
return success();
}
/**
*
*
* @param assetCurrent
* @return
*/
@ApiOperation(value = "修改数据")
@PutMapping
public AjaxResult update(@RequestBody @Valid AssetCurrent assetCurrent) {
5 months ago
StringBuilder a = new StringBuilder();
if(!assetCurrent.getGlymList().isEmpty()){
assetCurrent.getGlymList().forEach(x->{
a.append(x);
a.append(",");
});
}
assetCurrent.setGlym(a.toString());
StringBuilder b = new StringBuilder();
if(!assetCurrent.getGlIpList().isEmpty()){
assetCurrent.getGlymList().forEach(x->{
b.append(x);
b.append(",");
});
}
assetCurrent.setGlIp(b.toString());
5 months ago
assetCurrentService.updateById(assetCurrent);
if (assetCurrent.getXjgywxt() != null) {
assetCurrent.getXjgywxt().setAssetId(assetCurrent.getId());
assetBusinessFormService.saveOrUpdate(assetCurrent.getXjgywxt());
}
if (!assetCurrent.getGylxxList().isEmpty()) {
for (AssetSupplyChain items : assetCurrent.getGylxxList()) {
items.setAssetId(assetCurrent.getId());
}
//新增供应链
assetSupplyChainService.saveOrUpdateBatch(assetCurrent.getGylxxList());
}
if (!assetCurrent.getJcwlList().isEmpty()) {
for (AssetBasicNetwork items : assetCurrent.getJcwlList()) {
items.setAssetId(assetCurrent.getId());
}
//新增基础网络
assetBasicNetworkService.saveOrUpdateBatch(assetCurrent.getJcwlList());
}
if (!assetCurrent.getOtherConcat().isEmpty()) {
for (UnitOtherConcat items : assetCurrent.getOtherConcat()) {
items.setAssetId(assetCurrent.getId());
}
//新增其他联系人
unitOtherConcatService.saveOrUpdateBatch(assetCurrent.getOtherConcat());
}
return success();
}
/**
*
*
5 months ago
* @param id
* @return
*/
@ApiOperation(value = "删除数据")
5 months ago
@DeleteMapping("/{id}")
public AjaxResult delete(@PathVariable Long id) {
assetSupplyChainService.deleteByAssetIds(id);
assetBasicNetworkService.deleteByAssetIds(id);
assetBusinessFormService.deleteByAssetIds(id);
unitOtherConcatService.deleteByAssetIds(id);
assetCurrentService.deleteByUnitIds(id);
5 months ago
return success();
}
/**
*
*/
@ApiOperation(value = "下载资产导入模板")
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) {
ExcelUtil<AssetExport> util = new ExcelUtil<>(AssetExport.class);
util.importTemplateExcel(response, "资产导入模板");
}
/**
*
*/
@ApiOperation(value = "导出现有资产")
@PostMapping("/export")
public void exportProject(HttpServletResponse response, AssetCurrentPageRequest as) {
List<AssetCurrent> list = assetCurrentService.page(as);
List<AssetExport> proList = new ArrayList<>();
for (AssetCurrent x : list) {
//对应的资产
AssetExport assetExport = new AssetExport();
5 months ago
BeanUtil.copyProperties(x, assetExport);
//查找对应的系统建设单位
AssetSupplyChain jsdw = assetSupplyChainService.getJsdw(x.getId());
5 months ago
BeanUtil.copyProperties(jsdw, assetExport);
5 months ago
//查找对应的系统运营单位
AssetSupplyChain yydw = assetSupplyChainService.getYydw(x.getId());
assetExport.setGyszcdz1(yydw.getGyszcdz());
assetExport.setLxr1(yydw.getLxr());
assetExport.setLxdh1(yydw.getLxdh());
assetExport.setSfwtc1(yydw.getSfwtc());
assetExport.setName1(yydw.getName());
assetExport.setTyshxydm1(yydw.getTyshxydm());
List<AssetBasicNetwork> byList = assetBasicNetworkService.getByAssetId(x.getId());
for (AssetBasicNetwork items : byList) {
5 months ago
if (items.getType() == 1) {
//查找对应的服务器信息
5 months ago
BeanUtil.copyProperties(items, assetExport);
}
5 months ago
if (items.getType() == 2) {
//查找对应网络设备
assetExport.setWlpp(items.getPp());
assetExport.setWlyjxh(items.getYjxh());
assetExport.setWlyjbsxx(items.getYjbsxx());
assetExport.setWlsblx(items.getSblx());
assetExport.setWlyjbbxx(items.getYjbbxx());
assetExport.setWlyjxlh(items.getYjxlh());
assetExport.setWlsbIp(items.getSbIp());
assetExport.setWlyjyt(items.getYjyt());
}
5 months ago
if (items.getType() == 3) {
//查找对应安全设备
assetExport.setAqwlpp(items.getPp());
assetExport.setAqwlsblx(items.getSblx());
assetExport.setAqwlsbIp(items.getSbIp());
}
}
proList.add(assetExport);
}
ExcelUtil<AssetExport> util = new ExcelUtil<>(AssetExport.class);
util.exportExcel(response, proList, "现有资产记录");
}
/**
*
*/
@ApiOperation(value = "导入现有资产")
@PostMapping(value = "/import", consumes = "multipart/form-data")
public AjaxResult export(@RequestPart("file") MultipartFile file) throws Exception {
//读取所有的字段
ExcelUtil<AssetExport> util = new ExcelUtil<>(AssetExport.class);
List<AssetExport> proList = util.importExcel(file.getInputStream());
for (AssetExport items : proList) {
AssetCurrent as = new AssetCurrent();
//copy新增到新的现有资产表里面
5 months ago
BeanUtil.copyProperties(items, as);
assetCurrentService.save(as);
//新增系统建设单位
AssetSupplyChain s1 = new AssetSupplyChain();
5 months ago
BeanUtil.copyProperties(items, s1);
s1.setType(5);
s1.setAssetId(as.getId());
assetSupplyChainService.save(s1);
5 months ago
//新增系统运营单位
AssetSupplyChain b6 = new AssetSupplyChain();
b6.setGyszcdz(items.getGyszcdz1());
b6.setLxr(items.getLxr1());
b6.setLxdh(items.getLxdh1());
b6.setSfwtc(items.getSfwtc1());
b6.setName(items.getName1());
b6.setTyshxydm(items.getTyshxydm1());
b6.setType(7);
b6.setAssetId(as.getId());
assetSupplyChainService.save(b6);
//新增服务器信息
AssetBasicNetwork a1 = new AssetBasicNetwork();
5 months ago
BeanUtil.copyProperties(items, a1);
a1.setType(1);
a1.setAssetId(as.getId());
assetBasicNetworkService.save(a1);
//新增网络设备
AssetBasicNetwork a2 = new AssetBasicNetwork();
a2.setSblx(items.getWlsblx());
a2.setPp(items.getWlpp());
a2.setSbIp(items.getWlsbIp());
a2.setYjxh(items.getWlyjxh());
a2.setYjxlh(items.getWlyjxlh());
a2.setYjbbxx(items.getWlyjbbxx());
a2.setYjyt(items.getWlyjyt());
a2.setYjbsxx(items.getWlyjbsxx());
a2.setType(2);
a2.setAssetId(as.getId());
assetBasicNetworkService.save(a2);
//新增安全设备
AssetBasicNetwork a3 = new AssetBasicNetwork();
a3.setSblx(items.getAqwlsblx());
a3.setPp(items.getAqwlpp());
a3.setSbIp(items.getAqwlsbIp());
a3.setType(3);
a3.setAssetId(as.getId());
assetBasicNetworkService.save(a3);
}
return AjaxResult.success();
}
}