New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.entity.Divisor; |
| | | import com.moral.api.entity.ManageAccount; |
| | | import com.moral.api.mapper.DivisorMapper; |
| | | import com.moral.api.pojo.redisBean.AccountInfoDTO; |
| | | import com.moral.api.service.DivisorService; |
| | | import com.moral.api.util.LogUtils; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.TokenUtils; |
| | | |
| | | |
| | | /** |
| | | * Description //todo |
| | | * |
| | | * @author swb |
| | | * @ClassName DivisorServiceimpl |
| | | * @date 2023.12.06 14:18 |
| | | */ |
| | | @Service |
| | | public class DivisorServiceImpl extends ServiceImpl<DivisorMapper, Divisor> implements DivisorService { |
| | | |
| | | @Autowired |
| | | private DivisorMapper divisorMapper; |
| | | |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param divisor |
| | | */ |
| | | @Override |
| | | public void insert(Divisor divisor) { |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String token = request.getHeader("token"); |
| | | AccountInfoDTO accountInfoDTO = (AccountInfoDTO) TokenUtils.getUserInfoByToken(token); |
| | | ManageAccount manageAccount = accountInfoDTO.getAccount(); |
| | | divisor.setIsDel(Constants.NOT_DELETE); |
| | | divisor.setCreateTime(new Date()); |
| | | divisor.setUpdateTime(new Date()); |
| | | divisor.setCreateName(manageAccount.getUserName()); |
| | | divisorMapper.insert(divisor); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改 |
| | | * @param divisor |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void update(Divisor divisor) { |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String token = request.getHeader("token"); |
| | | AccountInfoDTO accountInfoDTO = (AccountInfoDTO) TokenUtils.getUserInfoByToken(token); |
| | | ManageAccount manageAccount = accountInfoDTO.getAccount(); |
| | | Divisor divisor1 = divisorMapper.selectById(divisor.getId()); |
| | | divisor.setUpdateTime(new Date()); |
| | | divisor.setUpdateName(manageAccount.getUserName()); |
| | | divisorMapper.updateById(divisor); |
| | | //操作日志记录 |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("修改了"+divisor1.getOrganizationId()+"走航车高值范围"); |
| | | content.append(ObjectUtils.isEmpty(divisor.getDustld())?",尘负荷==>null":",尘负荷==>"+divisor.getDustld()); |
| | | content.append(ObjectUtils.isEmpty(divisor.getCo())?",co==>null":",co==>"+divisor.getCo()); |
| | | content.append(ObjectUtils.isEmpty(divisor.getSo2())?",so2==>null":",so2==>"+divisor.getSo2()); |
| | | content.append(ObjectUtils.isEmpty(divisor.getNo2())?",no2==>null":",no2==>"+divisor.getNo2()); |
| | | content.append(ObjectUtils.isEmpty(divisor.getPm25())?",pm2.5==>null":",pm2.5==>"+divisor.getPm25()); |
| | | content.append(ObjectUtils.isEmpty(divisor.getPm10())?",pm10==>null":",pm10==>"+divisor.getPm10()); |
| | | content.append(ObjectUtils.isEmpty(divisor.getTvoc())?",tvoc==>null":",tvoc==>"+divisor.getTvoc()); |
| | | content.append(ObjectUtils.isEmpty(divisor.getO3())?",o3==>null":",o3==>"+divisor.getO3()); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @param id |
| | | */ |
| | | @Override |
| | | public void delete(Integer id) { |
| | | Divisor divisor = divisorMapper.selectById(id); |
| | | divisor.setIsDel(Constants.DELETE); |
| | | divisorMapper.updateById(divisor); |
| | | } |
| | | |
| | | /** |
| | | * 详情 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Divisor queryById(Integer id) { |
| | | Divisor divisor = divisorMapper.selectById(id); |
| | | return divisor; |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | | * @param mac |
| | | * @param page |
| | | * @param size |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, Object> select(String mac, String page, String size) { |
| | | HashMap<String, Object> result = new HashMap<>(); |
| | | LambdaQueryWrapper<Divisor> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(Divisor::getIsDel,Constants.NOT_DELETE); |
| | | // if (!ObjectUtils.isEmpty(mac)){ |
| | | // wrapper.like(Divisor::getMac,mac); |
| | | // } |
| | | Page<Divisor> PageList = new Page<>(Integer.parseInt(page), Integer.parseInt(size)); |
| | | Page<Divisor> divisorPage = divisorMapper.selectPage(PageList, wrapper); |
| | | result.put("total", PageList.getTotal()); |
| | | result.put("totalPage", PageList.getPages()); |
| | | result.put("current", PageList.getCurrent()); |
| | | result.put("pageSize", PageList.getSize()); |
| | | result.put("item", divisorPage.getRecords()); |
| | | return result; |
| | | } |
| | | } |