This commit is contained in:
磷叶 2024-11-09 18:04:21 +08:00
parent 2cd23d6b9c
commit 07dc59b3fe
20 changed files with 265 additions and 33 deletions

View File

@ -10,7 +10,7 @@ import com.ruoyi.common.enums.OperatorType;
/**
* 自定义操作日志记录注解
*
*
* @author ruoyi
*
*/
@ -48,4 +48,10 @@ public @interface Log
* 排除指定的请求参数
*/
public String[] excludeParamNames() default {};
/**
* 业务表ID
* @return
*/
long bizId() default -1;
}

View File

@ -69,4 +69,6 @@ public enum BusinessType
ENABLE,
// 取消提交
CANCEL,
// 提交
SUBMIT,
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.framework.aspectj;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@ -10,6 +12,7 @@ import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.NamedThreadLocal;
@ -33,7 +36,7 @@ import com.ruoyi.system.domain.SysOperLog;
/**
* 操作日志记录处理
*
*
* @author ruoyi
*/
@Aspect
@ -54,6 +57,43 @@ public class LogAspect
@Before(value = "@annotation(controllerLog)")
public void boBefore(JoinPoint joinPoint, Log controllerLog)
{
// MethodSignature signature = (MethodSignature) joinPoint.getSignature();
// Method method = signature.getMethod();
//
// // 获取方法的所有参数
// Parameter[] parameters = method.getParameters();
// Object[] args = joinPoint.getArgs();
//
// // 获取注解中的 paramName
// String paramName = myMethodAnnotation.paramName();
//
// // 查找参数名对应的参数值
// for (int i = 0; i < parameters.length; i++) {
// Parameter parameter = parameters[i];
// if (parameter.getName().equals(paramName.split("\\.")[0])) {
// Object paramValue = args[i];
//
// // 如果参数是复杂类型进一步获取属性值
// if (paramName.contains(".")) {
// String[] parts = paramName.split("\\.");
// Object currentObject = paramValue;
// for (int j = 1; j < parts.length; j++) {
// String part = parts[j];
// try {
// Field field = currentObject.getClass().getDeclaredField(part);
// field.setAccessible(true);
// currentObject = field.get(currentObject);
// } catch (NoSuchFieldException | IllegalAccessException e) {
// throw new RuntimeException("Failed to access field " + part, e);
// }
// }
// paramValue = currentObject;
// }
//
// System.out.println("Parameter value for " + paramName + ": " + paramValue);
// }
// }
TIME_THREADLOCAL.set(System.currentTimeMillis());
}
@ -70,7 +110,7 @@ public class LogAspect
/**
* 拦截异常操作
*
*
* @param joinPoint 切点
* @param e 异常
*/
@ -136,7 +176,7 @@ public class LogAspect
/**
* 获取注解中对方法的描述信息 用于Controller层注解
*
*
* @param log 日志
* @param operLog 操作日志
* @throws Exception
@ -164,7 +204,7 @@ public class LogAspect
/**
* 获取请求的参数放到log中
*
*
* @param operLog 操作日志
* @throws Exception 异常
*/
@ -220,7 +260,7 @@ public class LogAspect
/**
* 判断是否需要过滤的对象
*
*
* @param o 对象信息
* @return 如果是需要过滤的对象则返回true否则返回false
*/

View File

@ -34,9 +34,10 @@ public interface SysDeptMapper
* 根据部门ID查询信息
*
* @param deptId 部门ID
* @param scope
* @return 部门信息
*/
public SysDept selectDeptById(Long deptId);
public SysDept selectDeptById(@Param("deptId") Long deptId, @Param("scope") boolean scope);
/**
* 根据ID查询所有子部门

View File

@ -58,7 +58,18 @@ public interface ISysDeptService
* @param deptId 部门ID
* @return 部门信息
*/
public SysDept selectDeptById(Long deptId);
default SysDept selectDeptById(Long deptId) {
return selectDeptById(deptId, false);
}
/**
* 根据部门ID查询信息
*
* @param deptId 部门ID
* @param scope
* @return 部门信息
*/
public SysDept selectDeptById(Long deptId, boolean scope);
/**
* 根据ID查询所有子部门正常状态

View File

@ -122,12 +122,13 @@ public class SysDeptServiceImpl implements ISysDeptService
* 根据部门ID查询信息
*
* @param deptId 部门ID
* @param scope
* @return 部门信息
*/
@Override
public SysDept selectDeptById(Long deptId)
public SysDept selectDeptById(Long deptId, boolean scope)
{
return deptMapper.selectDeptById(deptId);
return deptMapper.selectDeptById(deptId, scope);
}
/**
@ -215,7 +216,7 @@ public class SysDeptServiceImpl implements ISysDeptService
@Override
public int insertDept(SysDept dept)
{
SysDept info = deptMapper.selectDeptById(dept.getParentId());
SysDept info = deptMapper.selectDeptById(dept.getParentId(), false);
// 如果父节点不为正常状态,则不允许新增子节点
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
{
@ -234,8 +235,8 @@ public class SysDeptServiceImpl implements ISysDeptService
@Override
public int updateDept(SysDept dept)
{
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId(), false);
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId(), false);
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
{
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();

View File

@ -69,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
from sys_dept d
where d.dept_id = #{deptId}
${@com.ruoyi.framework.util.DataScopeUtil@dataScope("d", null, scope)}
</select>
<select id="checkDeptExistUser" parameterType="Long" resultType="int">

View File

@ -12,14 +12,7 @@ import com.ruoyi.web.yh.report.service.ReportConverter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@ -81,11 +74,15 @@ public class ReportController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('yh:report:query')")
@GetMapping(value = "/{reportId}")
public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
{
public AjaxResult getInfo(@PathVariable("reportId") Long reportId,
@RequestParam(required = false, defaultValue = "true") Boolean needProductList,
@RequestParam(required = false, defaultValue = "true") Boolean needUserProd
) {
ReportVO report = reportService.selectReportByReportId(reportId);
List<ReportVO> list = Collections.singletonList(report);
reportAssembler.assembleProductList(list, true); // 拼接产量明细
if (needProductList) {
reportAssembler.assembleProductList(list, needUserProd); // 拼接产量明细
}
return success(report);
}
@ -129,4 +126,18 @@ public class ReportController extends BaseController
public AjaxResult verify(@RequestBody @Validated ReportVerifyDTO dto) {
return toAjax(reportService.verify(dto, getUserId()));
}
@PreAuthorize("@ss.hasPermi('yh:report:cancel')")
@Log(title = "车间报表取消提交", businessType = BusinessType.CANCEL)
@PutMapping("/{reportId}/cancel")
public AjaxResult cancel(@PathVariable Long reportId) {
return toAjax(reportService.cancel(reportId));
}
@PreAuthorize("@ss.hasPermi('yh:report:submit')")
@Log(title = "车间报表提交", businessType = BusinessType.SUBMIT)
@PutMapping("/{reportId}/submit")
public AjaxResult submit(@PathVariable Long reportId) {
return toAjax(reportService.submit(reportId));
}
}

View File

@ -13,6 +13,7 @@ import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
@ -71,5 +72,6 @@ public class Report extends BaseEntity
@Excel(name = "总金额", readConverterExp = "元=")
@ApiModelProperty("总金额")
@NotNull(message = "总金额不能为空")
@Min(value = 0, message = "总金额必须大于0")
private BigDecimal totalAmount;
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.web.yh.report.domain.bo;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.web.yh.report.domain.Report;
import com.ruoyi.web.yh.reportProd.domain.ReportProd;
@ -17,6 +18,9 @@ import java.util.List;
@Data
public class ReportBO extends Report {
// 部门信息
private SysDept dept;
// 产量列表
private List<ReportProdBO> productList;
}

View File

@ -3,6 +3,7 @@ package com.ruoyi.web.yh.report.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ -34,4 +35,24 @@ public enum ReportStatus {
return asList(WAIT_VERIFY);
}
/**
* 允许取消审核的状态
*/
public static List<String> canCancel() {
return asList(WAIT_VERIFY);
}
/**
* 允许提交的状态
*/
public static List<String> canSubmit() {
return asList(WAIT_SUBMIT);
}
/**
* 允许修改的状态
*/
public static List<String> canEdit() {
return asList(WAIT_SUBMIT, REJECT);
}
}

View File

@ -42,6 +42,12 @@
<if test="query.updateId != null "> and br.update_id = #{query.updateId}</if>
<if test="query.updateBy != null and query.updateBy != ''"> and br.update_by like concat('%', #{query.updateBy}, '%')</if>
<if test="query.remark != null and query.remark != ''"> and br.remark like concat('%', #{query.remark}, '%')</if>
<if test="query.statusList != null and query.statusList.size() > 0">
and br.status in
<foreach collection="query.statusList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
${query.params.dataScope}
</sql>
@ -104,7 +110,7 @@
</update>
<update id="updateByQuery">
update bst_report
update bst_report br
<trim prefix="SET" suffixOverrides=",">
<include refid="updateColumns"/>
</trim>

View File

@ -81,4 +81,14 @@ public interface ReportService
* @param verifyId 审核人ID
*/
int verify(ReportVerifyDTO dto, Long verifyId);
/**
* 取消提交
*/
int cancel(Long reportId);
/**
* 提交
*/
int submit(Long reportId);
}

View File

@ -2,6 +2,7 @@ package com.ruoyi.web.yh.report.service.impl;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.yh.price.domain.PriceQuery;
import com.ruoyi.web.yh.price.service.PriceService;
@ -37,6 +38,9 @@ public class ReportConverterImpl implements ReportConverter {
@Autowired
private ReportProdConverter reportProdConverter;
@Autowired
private ISysDeptService deptService;
@Override
public ReportBO toBoByCreate(ReportVO vo) {
if (vo == null) {
@ -65,6 +69,7 @@ public class ReportConverterImpl implements ReportConverter {
// 组装数据
bo.setProductList(productList);
bo.setDept(deptService.selectDeptById(bo.getDeptId(), true));
return bo;
}
@ -97,6 +102,7 @@ public class ReportConverterImpl implements ReportConverter {
// 组装数据
bo.setProductList(productList);
bo.setDept(deptService.selectDeptById(bo.getDeptId(), true));
return bo;
}
}

View File

@ -99,14 +99,19 @@ public class ReportServiceImpl implements ReportService
/**
* 修改报表
*
* @param report 报表
* @param data 报表
* @return 结果
*/
@Override
public int updateReport(Report report)
{
report.setUpdateTime(DateUtils.getNowDate());
return reportMapper.updateReport(report);
public int updateReport(Report data) {
if (data.getReportId() == null) {
return 0;
}
data.setUpdateTime(DateUtils.getNowDate());
ReportQuery query = new ReportQuery();
query.setReportId(data.getReportId());
query.setStatusList(ReportStatus.canEdit());
return this.updateByQuery(data, query);
}
/**
@ -265,6 +270,46 @@ public class ReportServiceImpl implements ReportService
return result == null ? 0 : result;
}
@Override
public int cancel(Long reportId) {
ReportVO old = this.selectReportByReportId(reportId);
ServiceUtil.assertion(old == null || old.getReportId() == null, "待取消的报表不存在");
ServiceUtil.assertion(!ReportStatus.canCancel().contains(old.getStatus()), "报表当前状态不允许取消,请刷新后重试");
Report data = new Report();
data.setStatus(ReportStatus.WAIT_SUBMIT.getStatus());
ReportQuery query = new ReportQuery();
query.setReportId(reportId);
query.setStatusList(ReportStatus.canCancel());
Integer result = transactionTemplate.execute(status -> {
int update = this.updateByQuery(data, query);
ServiceUtil.assertion(update != 1, "取消失败,当前报表状态已发生变化,请刷新后重试");
return update;
});
return result == null ? 0 : result;
}
@Override
public int submit(Long reportId) {
ReportVO old = this.selectReportByReportId(reportId);
ServiceUtil.assertion(old == null || old.getReportId() == null, "待提交的报表不存在");
ServiceUtil.assertion(!ReportStatus.canSubmit().contains(old.getStatus()), "报表当前状态不允许提交,请刷新后重试");
Report data = new Report();
data.setStatus(ReportStatus.WAIT_VERIFY.getStatus());
ReportQuery query = new ReportQuery();
query.setReportId(reportId);
query.setStatusList(ReportStatus.canSubmit());
Integer result = transactionTemplate.execute(status -> {
int update = this.updateByQuery(data, query);
ServiceUtil.assertion(update != 1, "提交失败,当前报表状态已发生变化,请刷新后重试");
return update;
});
return result == null ? 0 : result;
}
private int updateByQuery(Report data, ReportQuery query) {
return reportMapper.updateByQuery(data, query);
}

View File

@ -1,8 +1,12 @@
package com.ruoyi.web.yh.report.service.impl;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.web.yh.report.domain.ReportVO;
import com.ruoyi.web.yh.report.domain.bo.ReportBO;
import com.ruoyi.web.yh.report.domain.enums.ReportStatus;
import com.ruoyi.web.yh.report.service.ReportService;
import com.ruoyi.web.yh.report.service.ReportValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@ -11,9 +15,28 @@ import org.springframework.stereotype.Service;
*/
@Service
public class ReportValidatorImpl implements ReportValidator {
@Autowired
private ReportService reportService;
@Override
public void checkPreEdit(ReportBO bo) {
ServiceUtil.assertion(bo == null, "参数错误");
ServiceUtil.assertion(bo == null || bo.getReportId() == null, "参数错误");
ReportVO old = reportService.selectReportByReportId(bo.getReportId());
ServiceUtil.assertion(old == null || old.getReportId() == null, "待更新的报表不存在");
ServiceUtil.assertion(!ReportStatus.canEdit().contains(old.getStatus()), "报表当前状态不允许更新,请刷新后重试");
// TODO 业务表校验
// TODO 部门是否当前用户可选
// TODO 工序是否当前用户可选
// TODO 工序是否当前部门的工序
// TODO 员工是否当前用户可选
// TODO 员工是否当前部门的员工
}
}

View File

@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.BaseEntity;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* 报表产量对象 bst_report_prod
@ -94,4 +95,7 @@ public class ReportProd extends BaseEntity
@NotBlank(message = "工序类型不允许为空")
@DictValid(type = DictType.PRICE_TYPE, message = "非法的工序类型")
private String priceType;
@Size(max = 200, message = "备注长度不允许超过200个字符")
private String remark;
}

View File

@ -24,7 +24,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
brp.price_classify,
brp.price_quantity,
brp.deleted,
brp.price_type
brp.price_type,
brp.remark
from bst_report_prod brp
</sql>
@ -39,6 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.priceSpec != null and query.priceSpec != ''"> and brp.price_spec like concat('%', #{query.priceSpec}, '%')</if>
<if test="query.priceUnit != null and query.priceUnit != ''"> and brp.price_unit = #{query.priceUnit}</if>
<if test="query.priceClassify != null and query.priceClassify != ''"> and brp.price_classify like concat('%', #{query.priceClassify}, '%')</if>
<if test="query.remark != null and query.remark != ''"> and brp.remark like concat('%', #{query.remark}, '%')</if>
<if test="query.priceType != null and query.priceType != ''"> and price_type = #{query.priceType}</if>
<if test="query.deleted == null">and brp.deleted = false</if>
<if test="query.deleted != null">and brp.deleted = #{deleted}</if>
@ -81,6 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="priceClassify != null">price_classify,</if>
<if test="priceQuantity != null">price_quantity,</if>
<if test="priceType != null and priceType != ''">price_type,</if>
<if test="remark != null and remark != ''">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="reportId != null">#{reportId},</if>
@ -98,6 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="priceClassify != null">#{priceClassify},</if>
<if test="priceQuantity != null">#{priceQuantity},</if>
<if test="priceType != null and priceType != ''">#{priceType},</if>
<if test="remark != null and remark != ''">#{remark},</if>
</trim>
</insert>
@ -117,7 +121,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
price_unit,
price_classify,
price_quantity,
price_type
price_type,
remark
)
values
<foreach collection="list" item="i" separator=",">
@ -152,6 +157,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="i.priceQuantity == null">default,</if>
<if test="i.priceType != null">#{i.priceType},</if>
<if test="i.priceType == null">default,</if>
<if test="i.remark != null">#{i.remark},</if>
<if test="i.remark == null">default,</if>
</trim>
</foreach>
</insert>
@ -180,6 +187,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="data.priceClassify != null">price_classify = #{data.priceClassify},</if>
<if test="data.priceQuantity != null">price_quantity = #{data.priceQuantity},</if>
<if test="data.priceType != null and data.priceType != ''">price_type = #{data.priceType},</if>
<if test="data.remark != null and data.remark != ''">remark = #{data.remark},</if>
</sql>
<update id="batchUpdate">
@ -315,6 +323,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</otherwise>
</choose>
</foreach>
<foreach open="price_type = CASE id" collection="list" item="item" close="END,">
<choose>
<when test="item.priceType != null">
WHEN #{item.id} THEN #{item.priceType}
</when>
<otherwise>
WHEN #{item.id} THEN `price_type`
</otherwise>
</choose>
</foreach>
<foreach open="remark = CASE id" collection="list" item="item" close="END,">
<choose>
<when test="item.remark != null">
WHEN #{item.id} THEN #{item.remark}
</when>
<otherwise>
WHEN #{item.id} THEN `remark`
</otherwise>
</choose>
</foreach>
</trim>
where id in
<foreach item="item" collection="list" open="(" separator="," close=")">

View File

@ -42,6 +42,8 @@ public class ReportProdConverterImpl implements ReportProdConverter {
bo.setPriceUnit(vo.getPriceUnit());
bo.setPriceClassify(vo.getPriceClassify());
bo.setPriceQuantity(vo.getPriceQuantity());
bo.setPriceType(vo.getPriceType());
bo.setRemark(vo.getRemark());
// 用户产量明细
List<ReportUserProdBO> userProdList = new ArrayList<>();
@ -77,6 +79,8 @@ public class ReportProdConverterImpl implements ReportProdConverter {
bo.setPriceUnit(vo.getPriceUnit());
bo.setPriceClassify(vo.getPriceClassify());
bo.setPriceQuantity(vo.getPriceQuantity());
bo.setPriceType(vo.getPriceType());
bo.setRemark(vo.getRemark());
// 用户产量明细
List<ReportUserProdBO> userProdList = new ArrayList<>();

View File

@ -8,6 +8,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* 员工产量对象 bst_report_user_prod
*
@ -27,10 +30,13 @@ public class ReportUserProd extends BaseEntity
@Excel(name = "员工ID")
@ApiModelProperty("员工ID")
@NotNull(message = "员工不允许为空")
private Long userId;
@Excel(name = "产量")
@ApiModelProperty("产量")
@NotNull(message = "产量不允许为空")
@Min(value = 0, message = "产量不允许小于0")
private BigDecimal num;
}