!35 功能优化与部分Bug修复

Merge pull request !35 from 大熊/master
This commit is contained in:
1024创新实验室
2024-09-02 13:57:34 +00:00
committed by Gitee
78 changed files with 1010 additions and 721 deletions

View File

@@ -1,9 +1,11 @@
package net.lab1024.sa.admin.module.business.goods.domain.form;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.lab1024.sa.admin.module.business.goods.constant.GoodsStatusEnum;
import net.lab1024.sa.base.common.domain.PageParam;
import net.lab1024.sa.base.common.json.deserializer.DictValueVoDeserializer;
import net.lab1024.sa.base.common.swagger.SchemaEnum;
import net.lab1024.sa.base.common.validator.enumeration.CheckEnum;
import org.hibernate.validator.constraints.Length;
@@ -32,6 +34,7 @@ public class GoodsQueryForm extends PageParam {
private Integer goodsStatus;
@Schema(description = "产地")
@JsonDeserialize(using = DictValueVoDeserializer.class)
private String place;
@Schema(description = "上架状态")

View File

@@ -199,7 +199,7 @@ public class GoodsService {
GoodsExcelVO.builder()
.goodsStatus(SmartEnumUtil.getEnumDescByValue(e.getGoodsStatus(), GoodsStatusEnum.class))
.categoryName(categoryQueryService.queryCategoryName(e.getCategoryId()))
.place(dictCacheService.selectValueNameByValueCode(e.getPlace()))
.place(Arrays.stream(e.getPlace().split(",")).map(code -> dictCacheService.selectValueNameByValueCode(code)).collect(Collectors.joining(",")))
.price(e.getPrice())
.goodsName(e.getGoodsName())
.remark(e.getRemark())

View File

@@ -114,4 +114,14 @@ public interface NoticeDao extends BaseMapper<NoticeEntity> {
*/
void updateViewRecord(@Param("noticeId")Long noticeId, @Param("employeeId")Long requestEmployeeId,@Param("ip") String ip, @Param("userAgent")String userAgent);
/**
* 更新 浏览量
*
* @param noticeId 通知 id
* @param pageViewCountIncrement 页面浏览量的增量
* @param userViewCountIncrement 用户浏览量的增量
*/
void updateViewCount(@Param("noticeId")Long noticeId,@Param("pageViewCountIncrement") Integer pageViewCountIncrement, @Param("userViewCountIncrement")Integer userViewCountIncrement);
}

View File

@@ -52,10 +52,10 @@ public class NoticeEmployeeService {
public ResponseDTO<PageResult<NoticeEmployeeVO>> queryList(Long requestEmployeeId, NoticeEmployeeQueryForm noticeEmployeeQueryForm) {
Page<?> page = SmartPageUtil.convert2PageQuery(noticeEmployeeQueryForm);
//获取请求人的 部门及其子部门
List<Long> employeeDepartmentIdList = Lists.newArrayList();
EmployeeEntity employeeEntity = employeeService.getById(requestEmployeeId);
if (employeeEntity.getDepartmentId() != null) {
// 如果不是管理员 则获取请求人的 部门及其子部门
if (!employeeEntity.getAdministratorFlag() && employeeEntity.getDepartmentId() != null) {
employeeDepartmentIdList = departmentService.selfAndChildrenIdList(employeeEntity.getDepartmentId());
}
@@ -106,8 +106,15 @@ public class NoticeEmployeeService {
long viewCount = noticeDao.viewRecordCount(noticeId, requestEmployeeId);
if (viewCount == 0) {
noticeDao.insertViewRecord(noticeId, requestEmployeeId, ip, userAgent, 1);
// 该员工对于这个通知是第一次查看 页面浏览量+1 用户浏览量+1
noticeDao.updateViewCount(noticeId, 1, 1);
noticeDetailVO.setPageViewCount(noticeDetailVO.getPageViewCount() + 1);
noticeDetailVO.setUserViewCount(noticeDetailVO.getUserViewCount() + 1);
} else {
noticeDao.updateViewRecord(noticeId, requestEmployeeId, ip, userAgent);
// 该员工对于这个通知不是第一次查看 页面浏览量+1 用户浏览量+0
noticeDao.updateViewCount(noticeId, 1, 0);
noticeDetailVO.setPageViewCount(noticeDetailVO.getPageViewCount() + 1);
}
return ResponseDTO.ok(noticeDetailVO);

View File

@@ -60,8 +60,11 @@ public class EmployeeManager extends ServiceImpl<EmployeeDao, EmployeeEntity> {
// 保存员工 获得id
employeeDao.updateById(employee);
if (CollectionUtils.isNotEmpty(roleIdList)) {
List<RoleEmployeeEntity> roleEmployeeList = roleIdList.stream().map(e -> new RoleEmployeeEntity(e, employee.getEmployeeId())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(roleIdList)) {
// 删除员工角色
this.updateEmployeeRole(employee.getEmployeeId(), null);
} else {
List<RoleEmployeeEntity> roleEmployeeList = roleIdList.stream().map(roleId -> new RoleEmployeeEntity(roleId, employee.getEmployeeId())).collect(Collectors.toList());
this.updateEmployeeRole(employee.getEmployeeId(), roleEmployeeList);
}
}

View File

@@ -12,6 +12,7 @@ import net.lab1024.sa.admin.module.system.role.domain.form.RoleEmployeeQueryForm
import net.lab1024.sa.admin.module.system.role.domain.vo.RoleEmployeeVO;
import java.util.List;
import java.util.Set;
/**
@@ -50,7 +51,7 @@ public interface RoleEmployeeDao extends BaseMapper<RoleEmployeeEntity> {
/**
* 查询角色下的人员id
*/
List<Long> selectEmployeeIdByRoleIdList(@Param("roleIdList") List<Long> roleIdList);
Set<Long> selectEmployeeIdByRoleIdList(@Param("roleIdList") List<Long> roleIdList);
/**
*
@@ -79,5 +80,10 @@ public interface RoleEmployeeDao extends BaseMapper<RoleEmployeeEntity> {
/**
* 批量删除某个角色下的某批用户的关联关系
*/
void batchDeleteEmployeeRole(@Param("roleId") Long roleId,@Param("employeeIds")List<Long> employeeIds);
void batchDeleteEmployeeRole(@Param("roleId") Long roleId, @Param("employeeIds") Set<Long> employeeIds);
/**
* 判断某个角色下是否存在用户
*/
Integer existsByRoleId(@Param("roleId") Long roleId);
}

View File

@@ -5,7 +5,7 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;
/**
* 角色的员工更新
@@ -25,6 +25,6 @@ public class RoleEmployeeUpdateForm {
@Schema(description = "员工id集合")
@NotEmpty(message = "员工id不能为空")
protected List<Long> employeeIdList;
protected Set<Long> employeeIdList;
}

View File

@@ -3,11 +3,7 @@ package net.lab1024.sa.admin.module.system.role.manager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.lab1024.sa.admin.module.system.role.dao.RoleEmployeeDao;
import net.lab1024.sa.admin.module.system.role.domain.entity.RoleEmployeeEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 角色员工 manager
@@ -16,20 +12,9 @@ import java.util.List;
* @Date 2022-04-08 21:53:04
* @Wechat zhuoda1024
* @Email lab1024@163.com
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
*/
@Service
public class RoleEmployeeManager extends ServiceImpl<RoleEmployeeDao, RoleEmployeeEntity> {
/**
* 保存 角色员工
*
*/
@Transactional(rollbackFor = Throwable.class)
public void saveRoleEmployee(Long roleId, List<RoleEmployeeEntity> roleEmployeeList) {
this.getBaseMapper().deleteByRoleId(roleId);
if (CollectionUtils.isNotEmpty(roleEmployeeList)) {
this.saveBatch(roleEmployeeList);
}
}
}

View File

@@ -1,6 +1,7 @@
package net.lab1024.sa.admin.module.system.role.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import net.lab1024.sa.admin.module.system.department.dao.DepartmentDao;
import net.lab1024.sa.admin.module.system.department.domain.entity.DepartmentEntity;
import net.lab1024.sa.admin.module.system.employee.domain.vo.EmployeeVO;
@@ -20,12 +21,12 @@ import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -88,7 +89,6 @@ public class RoleEmployeeService {
* 移除员工角色
*
*/
@Transactional(rollbackFor = Exception.class)
public ResponseDTO<String> removeRoleEmployee(Long employeeId, Long roleId) {
if (null == employeeId || null == roleId) {
return ResponseDTO.userErrorParam();
@@ -112,16 +112,21 @@ public class RoleEmployeeService {
*/
public ResponseDTO<String> batchAddRoleEmployee(RoleEmployeeUpdateForm roleEmployeeUpdateForm) {
Long roleId = roleEmployeeUpdateForm.getRoleId();
List<Long> employeeIdList = roleEmployeeUpdateForm.getEmployeeIdList();
// 保存新的角色员工
List<RoleEmployeeEntity> roleEmployeeList = null;
if (CollectionUtils.isNotEmpty(employeeIdList)) {
roleEmployeeList = employeeIdList.stream()
// 已选择的员工id列表
Set<Long> selectedEmployeeIdList = roleEmployeeUpdateForm.getEmployeeIdList();
// 数据库里已有的员工id列表
Set<Long> dbEmployeeIdList = roleEmployeeDao.selectEmployeeIdByRoleIdList(Lists.newArrayList(roleId));
// 从已选择的员工id列表里 过滤数据库里不存在的 即需要添加的员工 id
Set<Long> addEmployeeIdList = selectedEmployeeIdList.stream().filter(id -> !dbEmployeeIdList.contains(id)).collect(Collectors.toSet());
// 添加角色员工
if (CollectionUtils.isNotEmpty(addEmployeeIdList)) {
List<RoleEmployeeEntity> roleEmployeeList = addEmployeeIdList.stream()
.map(employeeId -> new RoleEmployeeEntity(roleId, employeeId))
.collect(Collectors.toList());
roleEmployeeManager.saveBatch(roleEmployeeList);
}
// 保存数据
roleEmployeeManager.saveRoleEmployee(roleId, roleEmployeeList);
return ResponseDTO.ok();
}

View File

@@ -65,6 +65,11 @@ public class RoleService {
if (null == roleEntity) {
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
}
// 当没有员工绑定这个角色时才可以删除
Integer exists = roleEmployeeDao.existsByRoleId(roleId);
if (exists != null) {
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "该角色下存在员工,无法删除");
}
roleDao.deleteById(roleId);
roleMenuDao.deleteByRoleId(roleId);
roleEmployeeDao.deleteByRoleId(roleId);
@@ -86,7 +91,7 @@ public class RoleService {
}
existRoleEntity = roleDao.getByRoleCode(roleUpdateForm.getRoleCode());
if (null != existRoleEntity) {
if (null != existRoleEntity && !existRoleEntity.getRoleId().equals(roleUpdateForm.getRoleId())) {
return ResponseDTO.userErrorParam("角色编码重复,重复的角色为:" + existRoleEntity.getRoleName());
}

View File

@@ -18,7 +18,7 @@
INSTR(goods_name,#{query.searchWord})
</if>
<if test="query.place != null">
AND place = #{query.place}
AND INSTR(place,#{query.place})
</if>
<if test="query.goodsStatus != null">
AND goods_status = #{query.goodsStatus}

View File

@@ -1,69 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.lab1024.sa.admin.module.business.notice.NoticeDao">
<update id="updateWatchAmount">
UPDATE t_notice
SET watch_amount = watch_amount + 1
WHERE notice_id = #{noticeId}
</update>
<update id="batchDeleteNotice">
UPDATE t_notice
SET deleted_flag = #{deletedFlag}
WHERE notice_id IN
<foreach collection="noticeIdList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<update id="updateNotice">
UPDATE t_notice
SET notice_type = #{noticeType},
notice_belong_type = #{noticeBelongType},
notice_title = #{noticeTitle},
notice_content = #{noticeContent},
link_address = #{linkAddress},
cover_file_key = #{coverFileKey},
accessory_file_keys = #{accessoryFileKeys},
top_flag = #{topFlag},
publish_time = #{publishTime},
disabled_flag = #{disabledFlag}
WHERE notice_id = #{noticeId}
</update>
<select id="queryPage" resultType="net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeVO">
SELECT t_notice.*,
t_employee.actual_name AS createUserName
FROM t_notice
LEFT JOIN t_employee ON t_notice.create_user_id = t_employee.employee_id
<where>
t_notice.deleted_flag = #{queryForm.deletedFlag}
<if test="queryForm.keywords != null and queryForm.keywords != ''">
AND (INSTR(t_notice.notice_title,#{queryForm.keywords}) OR INSTR(t_employee.actual_name,#{queryForm.keywords}))
</if>
<if test="queryForm.noticeType != null">
AND t_notice.notice_type = #{queryForm.noticeType}
</if>
<if test="queryForm.noticeBelongType != null">
AND t_notice.notice_belong_type = #{queryForm.noticeBelongType}
</if>
<if test="queryForm.startTime != null">
AND DATE_FORMAT(t_notice.publish_time, '%Y-%m-%d') &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null">
AND DATE_FORMAT(t_notice.publish_time, '%Y-%m-%d') &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.disabledFlag != null">
AND t_notice.disabled_flag = #{queryForm.disabledFlag}
</if>
</where>
<if test="queryForm.sortItemList == null or queryForm.sortItemList.size == 0">
ORDER BY t_notice.top_flag DESC,t_notice.publish_time DESC
</if>
</select>
<select id="getDetail" resultType="net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeVO">
SELECT tn.*,
e.actual_name AS createUserName
FROM t_notice tn
LEFT JOIN t_employee e ON tn.create_user_id = e.employee_id
WHERE tn.notice_id = #{noticeId}
AND tn.deleted_flag = #{deletedFlag}
</select>
</mapper>

View File

@@ -242,5 +242,11 @@
where notice_id = #{noticeId}
and employee_id = #{employeeId}
</update>
<update id="updateViewCount">
update t_notice
set page_view_count = page_view_count + #{pageViewCountIncrement},
user_view_count = user_view_count + #{userViewCountIncrement}
where notice_id = #{noticeId}
</update>
</mapper>

View File

@@ -138,4 +138,12 @@
#{item}
</foreach>
</delete>
<select id="existsByRoleId" resultType="java.lang.Integer">
SELECT 1
FROM t_role_employee er
WHERE er.role_id = #{roleId}
LIMIT 1
</select>
</mapper>