天津it审核需求
parent
d9ea9c63ee
commit
0beaca750a
@ -0,0 +1,17 @@
|
|||||||
|
package cn.estsh.i3plus.core.api.iservice.busi;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysLogRoleChange;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description : 用户登录日志
|
||||||
|
* @Reference :
|
||||||
|
* @Author : yunhao
|
||||||
|
* @CreateDate : 2020-08-31 11:47
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
public interface ISysLogRoleChangeService {
|
||||||
|
|
||||||
|
List<SysLogRoleChange> findLogsBetweenDatetime(String startDatetime, String endDatetime);
|
||||||
|
}
|
@ -0,0 +1,117 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogRoleChangeService;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
||||||
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||||
|
import cn.estsh.i3plus.platform.common.util.FileContentTypeTool;
|
||||||
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysLogRoleChange;
|
||||||
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
||||||
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
||||||
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||||
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
||||||
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference :
|
||||||
|
* @Author : yunhao
|
||||||
|
* @CreateDate : 2020-08-31 11:45
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
@RestController
|
||||||
|
@Api(tags = "用户登录日志")
|
||||||
|
@RequestMapping(PlatformConstWords.BASE_URL + "/sys-log-role-change")
|
||||||
|
public class SysLogRoleChangeController extends CoreBaseController {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(SysLogRoleChangeController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysLogRoleChangeService logRoleChangeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Resource(name = CommonConstWords.IMPP_REDIS_RES)
|
||||||
|
private ImppRedis redisRes;
|
||||||
|
|
||||||
|
@GetMapping(value = "/export/user-role-change")
|
||||||
|
@ApiOperation(value = "导出用户角色变更记录")
|
||||||
|
public ResultBean exportUserRoleChangedLog(HttpServletResponse response, String startDate, String endDate) {
|
||||||
|
try {
|
||||||
|
final String ZERO_TIME = " 00:00:00";
|
||||||
|
// 获取当月第一天和最后一天
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
String firstDay, nextMonthFirstDay;
|
||||||
|
// 获取前月的第一天
|
||||||
|
Calendar cale = Calendar.getInstance();
|
||||||
|
cale.setTime(format.parse(startDate));
|
||||||
|
cale.add(Calendar.MONTH, 0);
|
||||||
|
cale.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
firstDay = format.format(cale.getTime());
|
||||||
|
// 获取前月的最后一天
|
||||||
|
cale = Calendar.getInstance();
|
||||||
|
cale.setTime(format.parse(endDate));
|
||||||
|
cale.add(Calendar.MONTH, 1);
|
||||||
|
cale.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
nextMonthFirstDay = format.format(cale.getTime());
|
||||||
|
|
||||||
|
firstDay += ZERO_TIME;
|
||||||
|
nextMonthFirstDay += ZERO_TIME;
|
||||||
|
|
||||||
|
List<SysLogRoleChange> logRoleChanges = logRoleChangeService.findLogsBetweenDatetime(firstDay, nextMonthFirstDay);
|
||||||
|
|
||||||
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
||||||
|
String fileName = "user-role-changed-" + System.currentTimeMillis() + ".xls";
|
||||||
|
File file = new File(fileName);
|
||||||
|
file.createNewFile();
|
||||||
|
File excel = excelTool.exportData(file, logRoleChanges, SysLogRoleChange.class
|
||||||
|
, (LinkedHashMap<String, String>) ExcelTool.getColName(SysLogRoleChange.class));
|
||||||
|
|
||||||
|
response.setContentType("application/force-download"); // 设置强制下载不打开
|
||||||
|
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); // 设置文件名
|
||||||
|
response.addHeader("Content-type", FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(fileName, true)));
|
||||||
|
|
||||||
|
// 设置文件名
|
||||||
|
try (BufferedInputStream bis = new BufferedInputStream(new DataInputStream(new FileInputStream(excel)))) {
|
||||||
|
OutputStream os = response.getOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int i = bis.read(buffer);
|
||||||
|
while (i != -1) {
|
||||||
|
os.write(buffer, 0, i);
|
||||||
|
i = bis.read(buffer);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("用户权限变更日志导出异常", e);
|
||||||
|
}
|
||||||
|
return ResultBean.success().setResultList(logRoleChanges);
|
||||||
|
} catch (ImppBusiException busExcep) {
|
||||||
|
return ResultBean.fail(busExcep);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogRoleChangeService;
|
||||||
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
||||||
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysLogRoleChange;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.repository.SysLogRoleChangeRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description : 用户登录日志
|
||||||
|
* @Reference :
|
||||||
|
* @Author : yunhao
|
||||||
|
* @CreateDate : 2020-08-31 11:51
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class SysLogRoleChangeService implements ISysLogRoleChangeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysLogRoleChangeRepository logRoleChangeRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysLogRoleChange> findLogsBetweenDatetime(String startDatetime, String endDatetime) {
|
||||||
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean();
|
||||||
|
DdlPreparedPack.timeBuilder(startDatetime, endDatetime, "createDatetime", true, true, packBean);
|
||||||
|
return logRoleChangeRepository.findByHqlWhere(packBean);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue