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.
272 lines
9.6 KiB
272 lines
9.6 KiB
package com.ruoyi.tc.controller;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
import com.ruoyi.tc.entity.AssetApp;
|
|
import com.ruoyi.tc.entity.AssetEmail;
|
|
import com.ruoyi.tc.entity.po.*;
|
|
import com.ruoyi.tc.entity.request.AssetAuditPageRequest;
|
|
import com.ruoyi.tc.entity.request.AssetAuditRequest;
|
|
import com.ruoyi.tc.entity.request.AssetEmailPageRequest;
|
|
import com.ruoyi.tc.service.AssetEmailJyService;
|
|
import com.ruoyi.tc.service.AssetEmailService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
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.util.List;
|
|
|
|
/**
|
|
* 电子邮件资产表(asset_email)表控制层
|
|
*
|
|
* @author makejava
|
|
* @since 2024-11-28 17:13:05
|
|
*/
|
|
@Api(tags = "电子邮件资产")
|
|
@RestController
|
|
@RequestMapping("/tc/assetEmail")
|
|
public class AssetEmailController extends BaseController {
|
|
/**
|
|
* 服务对象
|
|
*/
|
|
@Resource
|
|
private AssetEmailService assetEmailService;
|
|
|
|
@Resource
|
|
private AssetEmailJyService assetEmailJyService;
|
|
/**
|
|
* 分页查询
|
|
*
|
|
* @param req 分页对象
|
|
* @return 查询结果
|
|
*/
|
|
@ApiOperation(value = "分页查询")
|
|
@GetMapping
|
|
public AjaxResult queryByPage(AssetEmailPageRequest req) {
|
|
Page<AssetEmail> page = new Page<>();
|
|
page.setCurrent(req.getCurrent());
|
|
page.setSize(req.getSize());
|
|
try {
|
|
if (!SecurityUtils.getLoginUser().getUser().isAdmin() && !SecurityUtils.hasRole("common")) {
|
|
req.setDwmc(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
}
|
|
} catch (Exception e) {
|
|
throw new ServiceException("获取用户信息异常");
|
|
}
|
|
return success(assetEmailService.page(page, req));
|
|
}
|
|
|
|
//=================================================
|
|
/**
|
|
* 单位自编辑进行校验
|
|
*/
|
|
@ApiOperation(value = "单位自编辑进行校验")
|
|
@PreAuthorize("@ss.hasAnyRoles('unit')")
|
|
@PostMapping("/unitEdit")
|
|
public AjaxResult unitEdit(@RequestBody @Valid AssetEmailJyPo assetEmailJyPo) {
|
|
AssetEmailJyPo one = assetEmailJyService.lambdaQuery().eq(AssetEmailJyPo::getSsdw,assetEmailJyPo.getSsdw())
|
|
.eq(AssetEmailJyPo::getDzyxhz,assetEmailJyPo.getDzyxhz()).isNull(AssetEmailJyPo::getTaskId).one();
|
|
assetEmailJyPo.setAuditState("1");
|
|
assetEmailJyPo.setAuditYy(null);
|
|
if (one != null) {
|
|
assetEmailJyPo.setEmailId(one.getEmailId());
|
|
assetEmailJyPo.setAssetId(one.getAssetId());
|
|
assetEmailJyService.updateById(assetEmailJyPo);
|
|
} else {
|
|
assetEmailJyPo.setAssetId(assetEmailService.lambdaQuery().eq(AssetEmail::getSsdw,assetEmailJyPo.getSsdw())
|
|
.eq(AssetEmail::getDzyxhz,assetEmailJyPo.getDzyxhz()).one().getId());
|
|
assetEmailJyService.save(assetEmailJyPo);
|
|
}
|
|
return success();
|
|
}
|
|
|
|
/**
|
|
* 分页查询管理端或者单位端审核列表
|
|
*
|
|
* @param as 查询实体
|
|
* @return 所有数据
|
|
*/
|
|
@ApiOperation(value = "分页查询管理端或者单位端审核列表", response = AssetEmailJyPo.class)
|
|
@GetMapping("/getAuditList")
|
|
public AjaxResult getAuditList(AssetAuditPageRequest as) {
|
|
Page<AssetEmailJyPo> page = new Page<>();
|
|
page.setSize(as.getSize());
|
|
page.setCurrent(as.getCurrent());
|
|
try {
|
|
if (!SecurityUtils.getLoginUser().getUser().isAdmin() && !SecurityUtils.hasRole("common")) {
|
|
as.setDwmc(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
}
|
|
} catch (Exception e) {
|
|
throw new ServiceException("获取用户信息异常");
|
|
}
|
|
return success(assetEmailJyService.getAuditList(page, as));
|
|
}
|
|
|
|
/**
|
|
* 查看中间数据详情
|
|
*/
|
|
@ApiOperation(value = "单位端查看中间数据详情", response = AssetEmailJyPo.class)
|
|
@GetMapping("/lookInfo/{id}")
|
|
public AjaxResult lookInfo(@PathVariable Long id) {
|
|
return success(assetEmailJyService.getById(id));
|
|
}
|
|
|
|
/**
|
|
* 管理端审核
|
|
*
|
|
* @param as 查询实体
|
|
* @return 所有数据
|
|
*/
|
|
@PreAuthorize("@ss.hasAnyRoles('admin,common')")
|
|
@ApiOperation(value = "管理端审核")
|
|
@PostMapping("/audit")
|
|
public AjaxResult audit(@Valid @RequestBody AssetAuditRequest as) {
|
|
AssetEmailJyPo ass = new AssetEmailJyPo();
|
|
BeanUtil.copyProperties(as, ass);
|
|
ass.setEmailId(as.getCurrentId());
|
|
assetEmailJyService.updateById(ass);
|
|
//通过数据同步
|
|
if ("2".equals(as.getAuditState())) {
|
|
AssetEmailJyPo byId = assetEmailJyService.getById(as.getCurrentId());
|
|
AssetEmail aa = new AssetEmail();
|
|
BeanUtil.copyProperties(byId, aa);
|
|
aa.setId(byId.getAssetId());
|
|
//修改主表
|
|
assetEmailService.updateById(aa);
|
|
//如果有任务也修改任务这边
|
|
AssetEmailJyPo one = assetEmailJyService.lambdaQuery()
|
|
.isNotNull(AssetEmailJyPo::getTaskId)
|
|
.eq(AssetEmailJyPo::getAssetId, byId.getAssetId()).one();
|
|
if(one!=null){
|
|
Integer taskId = one.getTaskId();
|
|
Long appId = one.getEmailId();
|
|
BeanUtil.copyProperties(byId, one);
|
|
one.setEmailId(appId);
|
|
one.setTaskId(taskId);
|
|
one.setAuditState(null);
|
|
one.setAuditYy(null);
|
|
assetEmailJyService.updateById(one);
|
|
}
|
|
}
|
|
return success();
|
|
}
|
|
//=================================================
|
|
|
|
/**
|
|
* 通过主键查询单条email数据
|
|
*
|
|
* @param id 主键
|
|
* @return 单条数据
|
|
*/
|
|
@ApiOperation(value = "通过主键查询单条email数据")
|
|
@GetMapping("/{id}")
|
|
public AjaxResult queryById(@PathVariable("id") Long id) {
|
|
return success(assetEmailService.getById(id));
|
|
}
|
|
|
|
/**
|
|
* 新增email数据
|
|
*
|
|
* @param assetEmail 实体
|
|
* @return 新增结果
|
|
*/
|
|
@ApiOperation(value = "新增email数据")
|
|
@PostMapping
|
|
@Log(title = "新增email数据", businessType = BusinessType.INSERT)
|
|
public AjaxResult add(@RequestBody AssetEmail assetEmail) {
|
|
return success(assetEmailService.add(assetEmail));
|
|
}
|
|
|
|
/**
|
|
* 编辑email数据
|
|
*
|
|
* @param assetEmail 实体
|
|
* @return 编辑结果
|
|
*/
|
|
@ApiOperation(value = "编辑email数据")
|
|
@Log(title = "编辑email数据", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
public AjaxResult edit(@RequestBody AssetEmail assetEmail) {
|
|
return success(assetEmailService.edit(assetEmail));
|
|
}
|
|
|
|
/**
|
|
* 删除email数据
|
|
*
|
|
* @param id 主键
|
|
* @return 删除是否成功
|
|
*/
|
|
@ApiOperation(value = "删除email数据")
|
|
@Log(title = "删除email数据", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/delete/{id}")
|
|
public AjaxResult deleteById(@PathVariable Long id) {
|
|
assetEmailService.deleteById(id);
|
|
return success();
|
|
}
|
|
|
|
/**
|
|
* 下载email导入模板
|
|
*/
|
|
@ApiOperation(value = "下载email导入模板")
|
|
@PostMapping("/importTemplate")
|
|
public void importTemplate(HttpServletResponse response) {
|
|
ExcelUtil<AssetEmail> util = new ExcelUtil<>(AssetEmail.class);
|
|
util.importTemplateExcel(response, "email导入模板");
|
|
}
|
|
|
|
/**
|
|
* email导出
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@ApiOperation(value = "email导出")
|
|
@Log(title = "email导出", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(HttpServletResponse response, AssetEmailPageRequest unit) {
|
|
List<AssetEmail> list = assetEmailService.getAllList(unit);
|
|
ExcelUtil<AssetEmail> util = new ExcelUtil<>(AssetEmail.class);
|
|
util.exportExcel(response, list, "email数据");
|
|
}
|
|
|
|
/**
|
|
* app导入
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@ApiOperation(value = "email导入")
|
|
@Log(title = "email导入", businessType = BusinessType.IMPORT)
|
|
@PostMapping("/importData")
|
|
public AjaxResult importData(MultipartFile file) throws Exception {
|
|
ExcelUtil<AssetEmail> util = new ExcelUtil<>(AssetEmail.class);
|
|
List<AssetEmail> list = util.importExcel(file.getInputStream());
|
|
if (list != null) {
|
|
list.forEach(x->{
|
|
AssetEmail one = assetEmailService.lambdaQuery().eq(AssetEmail::getDzyxhz, x.getDzyxhz())
|
|
.eq(AssetEmail::getSsdw, x.getSsdw()).one();
|
|
if(one!=null){
|
|
x.setId(one.getId());
|
|
assetEmailService.edit(x);
|
|
}else {
|
|
assetEmailService.add(x);
|
|
}
|
|
});
|
|
} else {
|
|
throw new ServiceException("email导入数据不能为空!");
|
|
}
|
|
return AjaxResult.success("导入成功");
|
|
}
|
|
}
|
|
|