|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.config.mybatis.wrapper.NullFilterWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.ManageLog; | 
|---|
|  |  |  | import com.moral.api.entity.SysDictData; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageLogMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.SysDictDataMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.SysDictTypeMapper; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.manageLog.ManageLogQueryDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.form.manageLog.ManageLogQueryForm; | 
|---|
|  |  |  | import com.moral.api.service.ManageLogService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.util.ConvertUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | * @since 2021-04-12 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class ManageLogServiceImpl extends ServiceImpl<ManageLogMapper, ManageLog> implements ManageLogService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ManageLogMapper manageLogMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | SysDictTypeMapper sysDictTypeMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | SysDictDataMapper sysDictDataMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public ManageLogQueryDTO queryManageLog(ManageLogQueryForm form) { | 
|---|
|  |  |  | ManageLogQueryDTO dto = new ManageLogQueryDTO(); | 
|---|
|  |  |  | Integer pageCount = form.getPage(); | 
|---|
|  |  |  | Integer size = form.getSize(); | 
|---|
|  |  |  | String order = form.getOrder(); | 
|---|
|  |  |  | String orderType = form.getOrderType(); | 
|---|
|  |  |  | String account = form.getAccount(); | 
|---|
|  |  |  | String userName = form.getUserName(); | 
|---|
|  |  |  | String ip = form.getIp(); | 
|---|
|  |  |  | List<String> types = form.getType(); | 
|---|
|  |  |  | Date startTime = form.getStartTime(); | 
|---|
|  |  |  | Date endTime = form.getEndTime(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //构造查询条件 | 
|---|
|  |  |  | Page<ManageLog> page = new Page<>(pageCount, size); | 
|---|
|  |  |  | NullFilterWrapper<ManageLog> queryWrapper = new NullFilterWrapper<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | queryWrapper.like("account",account); | 
|---|
|  |  |  | queryWrapper.like("user_name",userName); | 
|---|
|  |  |  | queryWrapper.eq("ip",ip); | 
|---|
|  |  |  | queryWrapper.in("type",types); | 
|---|
|  |  |  | queryWrapper.between("create_time",startTime,endTime); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(order)) {//排序条件 | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(orderType)) { | 
|---|
|  |  |  | if (orderType.equals(Constants.ORDER_ASC)) | 
|---|
|  |  |  | queryWrapper.orderByAsc(ConvertUtils.toLine(order)); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | queryWrapper.orderByDesc(ConvertUtils.toLine(order)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询结果 | 
|---|
|  |  |  | Page<ManageLog> resultPage = manageLogMapper.selectPage(page, queryWrapper); | 
|---|
|  |  |  | List<ManageLog> manageLogs = resultPage.getRecords(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //根据字典表将Type转化为汉字 | 
|---|
|  |  |  | QueryWrapper<SysDictData> dataWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | dataWrapper.eq("dict_type_id",2); | 
|---|
|  |  |  | List<SysDictData> sysDictData = sysDictDataMapper.selectList(dataWrapper); | 
|---|
|  |  |  | Map<String,String> map = new HashMap<>(); | 
|---|
|  |  |  | for (SysDictData data : sysDictData) { | 
|---|
|  |  |  | map.put(data.getDataKey(),data.getDataValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (ManageLog manageLog : manageLogs) { | 
|---|
|  |  |  | String type = manageLog.getType(); | 
|---|
|  |  |  | String typeValue = map.get(type); | 
|---|
|  |  |  | manageLog.setType(typeValue); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | dto.setCurrent(page.getCurrent()); | 
|---|
|  |  |  | dto.setPage(page.getPages()); | 
|---|
|  |  |  | dto.setSize(page.getSize()); | 
|---|
|  |  |  | dto.setTotal(page.getTotal()); | 
|---|
|  |  |  | dto.setManageLogs(manageLogs); | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|