Commit 0e466f24 authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge remote-tracking branch 'origin/master'

parents 7d5cb5cf 25e5d8db
...@@ -106,6 +106,13 @@ ...@@ -106,6 +106,13 @@
<artifactId>log</artifactId> <artifactId>log</artifactId>
<version>${acc.log.version}</version> <version>${acc.log.version}</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.22</version>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
......
...@@ -5,21 +5,21 @@ import io.swagger.annotations.ApiImplicitParam; ...@@ -5,21 +5,21 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.PmsUseLog; import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.entity.SysOperLog;
import iot.sixiang.license.log.BusinessType; import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog; import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult; import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.PmsUseService; import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.SysOperLogService; import iot.sixiang.license.util.CommonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -45,14 +45,23 @@ public class PmsUseLogController { ...@@ -45,14 +45,23 @@ public class PmsUseLogController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"), @ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "每页显示多少条", required = true, dataType = "int"), @ApiImplicitParam(name = "pageSize", value = "每页显示多少条", required = true, dataType = "int"),
@ApiImplicitParam(name = "startTime", value = "开始时间"),
@ApiImplicitParam(name = "endTime", value = "结束时间"),
@ApiImplicitParam(name = "sn", value = "设备编号"), @ApiImplicitParam(name = "sn", value = "设备编号"),
@ApiImplicitParam(name = "status", value = "状态 1:成功,0:失败", dataType = "int") @ApiImplicitParam(name = "status", value = "状态 1:成功,0:失败", dataType = "int")
}) })
public PageResult<PmsUseLog> getPmsUseLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, public PageResult<PmsUseLog> getPmsUseLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "sn", required = false) String sn, @RequestParam(value = "sn", required = false) String sn,
@RequestParam(value = "status", required = false) Integer status) { @RequestParam(value = "status", required = false) Integer status) throws ParseException {
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status); if (StringUtils.isEmpty(endTime)) {
endTime = CommonUtil.getDayByNum(1, CommonUtil.dateToString(new Date(), "yyyy-MM-dd"));
} else {
endTime = CommonUtil.getDayByNum(1, endTime);
}
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status, startTime, endTime);
int total = records.getTotal(); int total = records.getTotal();
int pages = total / pageSize;//pages为总页数 int pages = total / pageSize;//pages为总页数
int mod = total % pageSize; int mod = total % pageSize;
......
...@@ -10,12 +10,16 @@ import iot.sixiang.license.log.MyLog; ...@@ -10,12 +10,16 @@ import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult; import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.service.SysOperLogService; import iot.sixiang.license.service.SysOperLogService;
import iot.sixiang.license.util.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -31,6 +35,7 @@ public class SysOperLogController { ...@@ -31,6 +35,7 @@ public class SysOperLogController {
/** /**
* 分页查询所有的oper_log * 分页查询所有的oper_log
*
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @return * @return
...@@ -39,17 +44,26 @@ public class SysOperLogController { ...@@ -39,17 +44,26 @@ public class SysOperLogController {
@GetMapping("operate/list") @GetMapping("operate/list")
@MyLog(title = "获取日志列表", businessType = BusinessType.SELECT) @MyLog(title = "获取日志列表", businessType = BusinessType.SELECT)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo",value = "当前在第几页", required = true,dataType = "int"), @ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize",value = "每页显示多少条", required = true, dataType = "int") @ApiImplicitParam(name = "pageSize", value = "每页显示多少条", required = true, dataType = "int"),
@ApiImplicitParam(name = "startTime", value = "开始时间"),
@ApiImplicitParam(name = "endTime", value = "结束时间")
}) })
public PageResult<SysOperLog> getOperLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, public PageResult<SysOperLog> getOperLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize",defaultValue = "0") int pageSize) { @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
PageInfoModel<SysOperLog> records = sysOperLogService.getOperLogList(pageNo,pageSize); @RequestParam(value = "startTime", required = false, defaultValue = "") String startTime,
@RequestParam(value = "endTime", required = false, defaultValue = "") String endTime) throws ParseException {
if (StringUtils.isEmpty(endTime)) {
endTime = CommonUtil.getDayByNum(1, CommonUtil.dateToString(new Date(), "yyyy-MM-dd"));
} else {
endTime = CommonUtil.getDayByNum(1, endTime);
}
PageInfoModel<SysOperLog> records = sysOperLogService.getOperLogList(pageNo, pageSize, startTime, endTime);
int total = records.getTotal(); int total = records.getTotal();
int pages = total/pageSize;//pages为总页数 int pages = total / pageSize;//pages为总页数
int mod = total%pageSize; int mod = total % pageSize;
if(mod!=0){ if (mod != 0) {
pages = pages +1; pages = pages + 1;
} }
List<SysOperLog> result = records.getResult(); List<SysOperLog> result = records.getResult();
return new PageResult(200, "查找成功", pageNo, pages, total, result); return new PageResult(200, "查找成功", pageNo, pages, total, result);
......
...@@ -14,6 +14,7 @@ import iot.sixiang.license.log.MyLog; ...@@ -14,6 +14,7 @@ import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.BaseResult; import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult; import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserVo; import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService; import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil; import iot.sixiang.license.util.CommonUtil;
...@@ -24,7 +25,7 @@ import java.util.List; ...@@ -24,7 +25,7 @@ import java.util.List;
/** /**
* <p> * <p>
* 前端控制器 * 前端控制器
* </p> * </p>
* *
* @author m33 * @author m33
...@@ -40,15 +41,16 @@ public class UserController { ...@@ -40,15 +41,16 @@ public class UserController {
/** /**
* 添加user * 添加user
*
* @param jsonObject * @param jsonObject
* @return * @return
*/ */
@ApiOperation(value = "用户添加接口", notes = "用于添加用户") @ApiOperation(value = "用户添加接口", notes = "用于添加用户")
@PostMapping("add") @PostMapping("add")
@MyLog(title = "添加用户", optParam = "#{jsonObject}", businessType = BusinessType.INSERT) @MyLog(title = "添加用户", optParam = "#{jsonObject}", businessType = BusinessType.INSERT)
@ApiOperationSupport(params = @DynamicParameters(name = "jsonObject",properties = { @ApiOperationSupport(params = @DynamicParameters(name = "jsonObject", properties = {
@DynamicParameter(name = "userName",value = "账户名",required = true,dataTypeClass = String.class), @DynamicParameter(name = "userName", value = "账户名", required = true, dataTypeClass = String.class),
@DynamicParameter(name = "company",value = "公司名",required = true,dataTypeClass = String.class) @DynamicParameter(name = "company", value = "公司名", required = true, dataTypeClass = String.class)
})) }))
public BaseResult addUser(@RequestBody JSONObject jsonObject) { public BaseResult addUser(@RequestBody JSONObject jsonObject) {
String userName = (String) jsonObject.get("userName"); String userName = (String) jsonObject.get("userName");
...@@ -64,6 +66,7 @@ public class UserController { ...@@ -64,6 +66,7 @@ public class UserController {
/** /**
* 删除user * 删除user
*
* @param userId * @param userId
* @return * @return
*/ */
...@@ -81,15 +84,16 @@ public class UserController { ...@@ -81,15 +84,16 @@ public class UserController {
/** /**
* 修改user * 修改user
*
* @param jsonObject * @param jsonObject
* @return * @return
*/ */
@ApiOperation(value = "用户修改接口", notes = "修改用户") @ApiOperation(value = "用户修改接口", notes = "修改用户")
@PostMapping("update") @PostMapping("update")
@MyLog(title = "修改用户", optParam = "#{userId},#{password}", businessType = BusinessType.UPDATE) @MyLog(title = "修改用户", optParam = "#{userId},#{password}", businessType = BusinessType.UPDATE)
@ApiOperationSupport(params = @DynamicParameters(name = "jsonObject",properties = { @ApiOperationSupport(params = @DynamicParameters(name = "jsonObject", properties = {
@DynamicParameter(name = "userId",value = "用户Id",required = true,dataTypeClass = Integer.class), @DynamicParameter(name = "userId", value = "用户Id", required = true, dataTypeClass = Integer.class),
@DynamicParameter(name = "password",value = "密码",required = true,dataTypeClass = String.class) @DynamicParameter(name = "password", value = "密码", required = true, dataTypeClass = String.class)
})) }))
public BaseResult updateUser(@RequestBody JSONObject jsonObject) { public BaseResult updateUser(@RequestBody JSONObject jsonObject) {
int userId = jsonObject.getInteger("userId"); int userId = jsonObject.getInteger("userId");
...@@ -105,6 +109,7 @@ public class UserController { ...@@ -105,6 +109,7 @@ public class UserController {
/** /**
* 分页查询所有的user * 分页查询所有的user
*
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @return * @return
...@@ -113,24 +118,30 @@ public class UserController { ...@@ -113,24 +118,30 @@ public class UserController {
@GetMapping("list") @GetMapping("list")
@MyLog(title = "获取用户列表", optParam = "#{pageNo},#{pageSize},#{userName},#{company}", businessType = BusinessType.SELECT) @MyLog(title = "获取用户列表", optParam = "#{pageNo},#{pageSize},#{userName},#{company}", businessType = BusinessType.SELECT)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo",value = "当前在第几页", required = true,dataType = "int"), @ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize",value = "每页显示多少条", required = true, dataType = "int"), @ApiImplicitParam(name = "pageSize", value = "每页显示多少条", required = true, dataType = "int"),
@ApiImplicitParam(name = "userName",value = "用户名"), @ApiImplicitParam(name = "userName", value = "用户名"),
@ApiImplicitParam(name = "company",value = "公司名") @ApiImplicitParam(name = "company", value = "公司名")
}) })
public PageResult<UserVo> getUserList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, public PageResult<UserVo> getUserList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize",defaultValue = "0") int pageSize, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "userName",required = false) String userName, @RequestParam(value = "userName", required = false) String userName,
@RequestParam(value = "company",required = false) String company) { @RequestParam(value = "company", required = false) String company) {
PageInfoModel<UserVo> records = userService.getUserList(pageNo,pageSize,userName,company); PageInfoModel<UserVo> records = userService.getUserList(pageNo, pageSize, userName, company);
int total = records.getTotal(); int total = records.getTotal();
int pages = total/pageSize;//pages为总页数 int pages = total / pageSize;//pages为总页数
int mod = total%pageSize; int mod = total % pageSize;
if(mod!=0){ if (mod != 0) {
pages = pages + 1; pages = pages + 1;
} }
List<UserVo> result = records.getResult(); List<UserVo> result = records.getResult();
return new PageResult(200,"查找成功",pageNo,pages,total,result); return new PageResult(200, "查找成功", pageNo, pages, total, result);
}
@ApiOperation(value = "修改通知人接口", notes = "修改通知人邮箱")
@PostMapping("update_notify")
public BaseResult updateNotify(@RequestBody UpdateNotifyDTO updateNotifyDTO) {
return userService.updateNotify(updateNotifyDTO);
} }
} }
...@@ -17,7 +17,7 @@ public class GlobalExceptionHandler { ...@@ -17,7 +17,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseBody //为了返回数据 @ResponseBody //为了返回数据
public BaseResult error(Exception e){ public BaseResult error(Exception e){
log.error("出现自定义异常,{}" + e.getMessage()); log.error("出现自定义异常,{}", e.getMessage());
return BaseResult.serverException(); return BaseResult.serverException();
} }
...@@ -25,7 +25,7 @@ public class GlobalExceptionHandler { ...@@ -25,7 +25,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(IotLicenseException.class) @ExceptionHandler(IotLicenseException.class)
@ResponseBody//为了返回数据 @ResponseBody//为了返回数据
public BaseResult error(IotLicenseException e){ public BaseResult error(IotLicenseException e){
log.error("出现自定义异常,{}" + e.getMsg()); log.error("出现自定义异常,{}", e.getMsg());
return BaseResult.failed().msg(e.getMsg()).code(e.getCode()); return BaseResult.failed().msg(e.getMsg()).code(e.getCode());
} }
} }
...@@ -12,5 +12,5 @@ import java.util.List; ...@@ -12,5 +12,5 @@ import java.util.List;
* Description * Description
*/ */
public interface PmsUseLogMapper extends BaseMapper<PmsUseLog> { public interface PmsUseLogMapper extends BaseMapper<PmsUseLog> {
List<PmsUseLog> getPmsUseLogList(String sn, Integer status); List<PmsUseLog> getPmsUseLogList(String sn, Integer status, String startTime, String endTime);
} }
...@@ -18,5 +18,5 @@ public interface SysOperLogMapper extends BaseMapper<SysOperLog> { ...@@ -18,5 +18,5 @@ public interface SysOperLogMapper extends BaseMapper<SysOperLog> {
boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime); boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime);
List<SysOperLog> getOperLogList(); List<SysOperLog> getOperLogList(String startTime, String endTime);
} }
...@@ -19,7 +19,7 @@ public interface UserMapper extends BaseMapper<User> { ...@@ -19,7 +19,7 @@ public interface UserMapper extends BaseMapper<User> {
boolean deleteUser(int user); boolean deleteUser(int user);
boolean addUser(String userName, String company, String password); boolean addUser(String userName, String company, String password, String notify);
boolean updateUser(int userId, String password); boolean updateUser(int userId, String password);
......
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* Created by m33
* Date 2023/1/30 14:18
* Description
*/
@Data
public class UpdateNotifyDTO {
@ApiModelProperty("通知人邮箱")
private String notify;
}
...@@ -16,7 +16,7 @@ public interface PmsUseService { ...@@ -16,7 +16,7 @@ public interface PmsUseService {
void success(int useLogId); void success(int useLogId);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status); PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime);
boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO); boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
......
...@@ -17,5 +17,5 @@ import java.util.Date; ...@@ -17,5 +17,5 @@ import java.util.Date;
public interface SysOperLogService extends IService<SysOperLog> { public interface SysOperLogService extends IService<SysOperLog> {
boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime); boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime);
PageInfoModel<SysOperLog> getOperLogList(int pageNo, int pageSize); PageInfoModel<SysOperLog> getOperLogList(int pageNo, int pageSize, String startTime, String endTime);
} }
package iot.sixiang.license.service; package iot.sixiang.license.service;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserVo; import iot.sixiang.license.model.vo.UserVo;
/** /**
...@@ -20,4 +22,6 @@ public interface UserService{ ...@@ -20,4 +22,6 @@ public interface UserService{
boolean updateUser(int userId, String password); boolean updateUser(int userId, String password);
PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company); PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company);
BaseResult updateNotify(UpdateNotifyDTO updateNotifyDTO);
} }
...@@ -49,11 +49,11 @@ public class PmsUseServiceImpl implements PmsUseService { ...@@ -49,11 +49,11 @@ public class PmsUseServiceImpl implements PmsUseService {
} }
@Override @Override
public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status) { public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime) {
if (pageNo == 0 || pageSize == 0) { if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status); List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status, startTime, endTime);
List<PmsUseLog> result = new ArrayList<>(); List<PmsUseLog> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && pmsUseLogs.size() > 0) { if (begin >= 0 && pmsUseLogs.size() > 0) {
......
...@@ -37,11 +37,11 @@ public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOper ...@@ -37,11 +37,11 @@ public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOper
} }
@Override @Override
public PageInfoModel<SysOperLog> getOperLogList(int pageNo, int pageSize) { public PageInfoModel<SysOperLog> getOperLogList(int pageNo, int pageSize, String startTime, String endTime) {
if(pageNo == 0 || pageSize == 0) { if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
List<SysOperLog> records = sysOperLogMapper.getOperLogList(); List<SysOperLog> records = sysOperLogMapper.getOperLogList(startTime, endTime);
records = records.stream().sorted(Comparator.comparing(SysOperLog::getOperTime, Comparator.reverseOrder())).collect(Collectors.toList()); records = records.stream().sorted(Comparator.comparing(SysOperLog::getOperTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<SysOperLog> result = new ArrayList<>(); List<SysOperLog> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
......
package iot.sixiang.license.service.impl; package iot.sixiang.license.service.impl;
import cn.hutool.core.lang.Validator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.consts.ResultCode; import iot.sixiang.license.consts.ResultCode;
import iot.sixiang.license.entity.User; import iot.sixiang.license.entity.User;
import iot.sixiang.license.handler.IotLicenseException; import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.mapper.UserMapper; import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserVo; import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService; import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil; import iot.sixiang.license.util.CommonUtil;
...@@ -16,12 +21,13 @@ import org.springframework.stereotype.Service; ...@@ -16,12 +21,13 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* <p> * <p>
* 服务实现类 * 服务实现类
* </p> * </p>
* *
* @author m33 * @author m33
...@@ -34,11 +40,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -34,11 +40,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
UserMapper userMapper; UserMapper userMapper;
@Override @Override
public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize,String userName, String company) { public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company) {
if(pageNo == 0 || pageSize == 0) { if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
List<UserVo> records = userMapper.getUserList(userName,company); List<UserVo> records = userMapper.getUserList(userName, company);
records = records.stream().sorted(Comparator.comparing(UserVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList()); records = records.stream().sorted(Comparator.comparing(UserVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<UserVo> result = new ArrayList<>(); List<UserVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
...@@ -51,31 +57,59 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -51,31 +57,59 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
return objectPageInfoModel; return objectPageInfoModel;
} }
@Override
public BaseResult updateNotify(UpdateNotifyDTO updateNotifyDTO) {
String notify = updateNotifyDTO.getNotify();
String loginUserId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(notify) || !Validator.isEmail(notify)) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
if (StringUtils.isEmpty(loginUserId)) {
throw new IotLicenseException(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMsg());
}
int userId = Integer.parseInt(loginUserId);
User user = new User();
user.setNotify(notify);
user.setUpdateTime(new Date());
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getUserId, userId);
int res = userMapper.update(user, wrapper);
if (res > 0) {
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
@Override @Override
public boolean deleteUser(int userId) { public boolean deleteUser(int userId) {
if(userId == 0) { if (userId == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
return userMapper.deleteUser(userId); return userMapper.deleteUser(userId);
} }
@Override @Override
public boolean addUser(String userName, String company, String password) { public boolean addUser(String userName, String company, String password) {
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(company) || !CommonUtil.regularMessage(userName)) { String notify = null;
if (Validator.isEmail(userName)) {
notify = userName;
}
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(company) || (notify == null && !CommonUtil.regularMessage(userName))) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
User res = userMapper.getUserByUserName(userName); User res = userMapper.getUserByUserName(userName);
if (res != null) { if (res != null) {
throw new IotLicenseException(403, "用户名已存在"); throw new IotLicenseException(403, "用户名已存在");
} }
return userMapper.addUser(userName,company,password); return userMapper.addUser(userName, company, password, notify);
} }
@Override @Override
public boolean updateUser(int userId, String password) { public boolean updateUser(int userId, String password) {
if(userId == 0 || StringUtils.isEmpty(password)) { if (userId == 0 || StringUtils.isEmpty(password)) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
return userMapper.updateUser(userId,password); return userMapper.updateUser(userId, password);
} }
} }
...@@ -8,12 +8,41 @@ import java.io.File; ...@@ -8,12 +8,41 @@ import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
@Slf4j @Slf4j
public class CommonUtil { public class CommonUtil {
/**
* 获取指定日期前或后几天
*
* @return
*/
public static String getDayByNum(int num, String dateStr) throws ParseException {
//获取指定当前日期的前三天时间
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(dateStr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, num);
date = calendar.getTime();
return format.format(date);
}
/**
* date 转 字符串
* @param date
* @param pattern
* @return
*/
public static String dateToString(Date date, String pattern) {
SimpleDateFormat ft = new SimpleDateFormat(pattern);
return ft.format(date);
}
/** /**
* 随机生成指定长度的字符串 * 随机生成指定长度的字符串
* *
...@@ -55,7 +84,7 @@ public class CommonUtil { ...@@ -55,7 +84,7 @@ public class CommonUtil {
public static boolean regularMessage(String message) { public static boolean regularMessage(String message) {
String regex = "^[0-9a-zA-Z_]{1,}$"; String regex = "^[0-9a-zA-Z]{1,}$";
return message.matches(regex); return message.matches(regex);
} }
......
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
<if test="null != status"> <if test="null != status">
and status = #{status} and status = #{status}
</if> </if>
<if test="startTime != null and startTime != ''">
AND create_time &gt; #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND create_time &lt; #{endTime}
</if>
and deleted = 0 and deleted = 0
order by create_time desc order by create_time desc
</select> </select>
......
...@@ -7,5 +7,12 @@ ...@@ -7,5 +7,12 @@
<select id="getOperLogList" resultType="iot.sixiang.license.entity.SysOperLog"> <select id="getOperLogList" resultType="iot.sixiang.license.entity.SysOperLog">
select id, title, business_type, uri, status, opt_param, error_msg, oper_time from sys_oper_log select id, title, business_type, uri, status, opt_param, error_msg, oper_time from sys_oper_log
where 1=1
<if test="startTime != null and startTime != ''">
AND oper_time &gt; #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND oper_time &lt; #{endTime}
</if>
</select> </select>
</mapper> </mapper>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<mapper namespace="iot.sixiang.license.mapper.UserMapper"> <mapper namespace="iot.sixiang.license.mapper.UserMapper">
<insert id="addUser" parameterType="iot.sixiang.license.entity.User"> <insert id="addUser" parameterType="iot.sixiang.license.entity.User">
insert into user(user_name, company, password,create_time, update_time) values (#{userName},#{company}, #{password}, now(), now()) insert into user(user_name, company, password, notify, create_time, update_time) values (#{userName},#{company}, #{password}, #{notify, jdbcType=VARCHAR}, now(), now())
</insert> </insert>
<delete id="deleteUser" parameterType="iot.sixiang.license.entity.User"> <delete id="deleteUser" parameterType="iot.sixiang.license.entity.User">
...@@ -15,14 +15,15 @@ ...@@ -15,14 +15,15 @@
</update> </update>
<select id="getUserList" resultType="iot.sixiang.license.model.vo.UserVo"> <select id="getUserList" resultType="iot.sixiang.license.model.vo.UserVo">
SELECT user.user_id, user_name, password, company, user.create_time, user.update_time, SELECT user.user_id, user_name, password, company, user.create_time, user.update_time,
COUNT(device.`device_id`) totalDevice, COUNT(device.`device_id`) totalDevice,
COUNT(if(device.device_id is NOT NULL, if (device.`status` = 0 or device.`status` is NULL, 1, NULL), NULL)) unUseDevice, COUNT(if(device.device_id is NOT NULL, if (device.`status` = 0 or device.`status` is NULL, 1, NULL), NULL))
COUNT(if(device.device_id is NOT NULL and device.`status` = 1, 1, NULL)) inUseDevice, unUseDevice,
COUNT(if(device.device_id is NOT NULL and device.`status` = 2, 1, NULL)) failedDevice COUNT(if(device.device_id is NOT NULL and device.`status` = 1, 1, NULL)) inUseDevice,
FROM USER COUNT(if(device.device_id is NOT NULL and device.`status` = 2, 1, NULL)) failedDevice
LEFT JOIN apply ON user.user_id = apply.user_id FROM USER
LEFT JOIN device ON apply.app_id = device.app_id LEFT JOIN apply ON user.user_id = apply.user_id
LEFT JOIN device ON apply.app_id = device.app_id
where 1=1 where 1=1
<if test="null != userName and '' != userName"> <if test="null != userName and '' != userName">
and user_name like concat('%',#{userName},'%') and user_name like concat('%',#{userName},'%')
......
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