@ -3,12 +3,16 @@ package com.ruoyi.system.service.impl;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.util.* ;
import java.util.stream.Collectors ;
import com.github.pagehelper.Page ;
import com.github.pagehelper.PageHelper ;
import com.github.pagehelper.PageInfo ;
import com.ruoyi.common.core.domain.entity.SysUser ;
import com.ruoyi.common.core.page.PageDomain ;
import com.ruoyi.common.core.page.TableSupport ;
import com.ruoyi.common.core.redis.RedisCache ;
import com.ruoyi.common.exception.BusinessException ;
import com.ruoyi.common.service.ICommonService ;
import com.ruoyi.common.utils.DateUtils ;
import com.ruoyi.common.utils.ShiroUtils ;
@ -25,9 +29,7 @@ import com.ruoyi.system.domain.BaseRequisitioningOrderChild;
import com.ruoyi.system.domain.Vo.BaseRequisitioningOrderVo ;
import com.ruoyi.system.mapper.BaseRequisitioningOrderChildMapper ;
import com.ruoyi.system.mapper.SysUserMapper ;
import com.ruoyi.system.service.ISysAttachFileService ;
import com.ruoyi.system.service.ISysAttachService ;
import com.ruoyi.system.service.ISysRoleService ;
import com.ruoyi.system.service.* ;
import org.activiti.engine.TaskService ;
import org.activiti.engine.impl.persistence.entity.TaskEntityImpl ;
import org.activiti.engine.runtime.ProcessInstance ;
@ -37,7 +39,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service ;
import com.ruoyi.system.mapper.BaseRequisitioningOrderMapper ;
import com.ruoyi.system.domain.BaseRequisitioningOrder ;
import com.ruoyi.system.service.IBaseRequisitioningOrderService ;
import com.ruoyi.common.core.text.Convert ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.CollectionUtils ;
@ -93,6 +94,9 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
@Autowired
private IPurchasePlanService purchasePlanService ;
@Autowired
private IBaseExpenseAccountService baseExpenseAccountService ;
/ * *
* 查询请购单
*
@ -119,13 +123,27 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
* @return 请购单
* /
@Override
public List < BaseRequisitioningOrderVo > selectBaseRequisitioningOrderList ( BaseRequisitioningOrderVo baseRequisitioningOrderVo1 )
{
public List < BaseRequisitioningOrderVo > selectBaseRequisitioningOrderList ( BaseRequisitioningOrderVo baseRequisitioningOrderVo1 ) throws Exception {
SysUser curUser = ShiroUtils . getSysUser ( ) ;
Long userId = curUser . getUserId ( ) ;
Set < String > roleKeys = roleService . selectRoleKeys ( userId ) ;
List < BaseRequisitioningOrderVo > Volist = baseRequisitioningOrderMapper . selectBaseRequisitioningOrderList ( baseRequisitioningOrderVo1 ) ;
// 获取当前登录名下可看用户列表
Set < String > users = baseExpenseAccountService . userLimitedList ( roleKeys , curUser ) ;
List < BaseRequisitioningOrderVo > matchedList = Volist . stream ( )
. filter ( requisitioningOrderVo - > users . contains ( requisitioningOrderVo . getApplyUser ( ) ) )
. collect ( Collectors . toList ( ) ) ;
PageDomain pageDomain = TableSupport . buildPageRequest ( ) ;
Integer pageNum = pageDomain . getPageNum ( ) ;
Integer pageSize = pageDomain . getPageSize ( ) ;
PageHelper . startPage ( pageNum , pageSize ) ;
//PageHelper 仅对第一List分页有效
Page < BaseRequisitioningOrderVo > list = ( Page < BaseRequisitioningOrderVo > ) baseRequisitioningOrderMapper . selectBaseRequisitioningOrderList ( baseRequisitioningOrderVo1 ) ;
PageInfo < BaseRequisitioningOrderVo > pageInfo = new PageInfo < > ( matchedList ) ;
// Page<BaseRequisitioningOrderVo> list = (Page<BaseRequisitioningOrderVo>) pageInfo.getList();
List < BaseRequisitioningOrderVo > list = pageInfo . getList ( ) ;
Page < BaseRequisitioningOrderVo > returnList = new Page < > ( ) ;
for ( BaseRequisitioningOrderVo baseRequisitioningOrderVo : list ) {
SysUser sysUser = userMapper . selectUserByLoginName ( baseRequisitioningOrderVo . getCreateBy ( ) ) ;
@ -166,9 +184,15 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
} else {
baseRequisitioningOrderVo . setTaskName ( "未启动" ) ;
}
baseRequisitioningOrderVo . setTaskStatus ( baseRequisitioningOrderVo . getTaskName ( ) ) ;
if ( baseRequisitioningOrderVo . getAuditStatus ( ) ! = null & & baseRequisitioningOrderVo . getAuditStatus ( ) . equals ( "1" ) ) {
baseRequisitioningOrderVo . setTaskStatus ( "审核通过" ) ;
} else if ( baseRequisitioningOrderVo . getAuditStatus ( ) ! = null & & baseRequisitioningOrderVo . getAuditStatus ( ) . equals ( "2" ) ) {
baseRequisitioningOrderVo . setTaskStatus ( "审核拒绝" ) ;
}
returnList . add ( baseRequisitioningOrderVo ) ;
}
returnList . setTotal ( CollectionUtils . isEmpty ( list ) ? 0 : list . getTotal ( ) ) ;
returnList . setTotal ( CollectionUtils . isEmpty ( list ) ? 0 : list . size ( ) ) ;
returnList . setPageNum ( pageNum ) ;
returnList . setPageSize ( pageSize ) ;
return returnList ;
@ -181,45 +205,51 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
* @return 结果
* /
@Override
@Transactional ( rollbackFor = NullPointer Exception. class )
@Transactional ( rollbackFor = Exception . class )
public int insertBaseRequisitioningOrder ( BaseRequisitioningOrder baseRequisitioningOrder )
{
String loginName = ShiroUtils . getLoginName ( ) ;
baseRequisitioningOrder . setCreateBy ( loginName ) ;
baseRequisitioningOrder . setCreateTime ( DateUtils . getNowDate ( ) ) ;
if ( baseRequisitioningOrder . getRequisitioningCode ( ) = = null ) {
baseRequisitioningOrder . setRequisitioningCode ( redisCache . generateBillNo ( "QG" ) ) ;
}
baseRequisitioningOrder . setRequisitioningCode ( redisCache . generateBillNo ( "QG" ) ) ;
List < BaseRequisitioningOrderChild > childList = baseRequisitioningOrder . getBaseRequisitioningOrderChildList ( ) ;
Long materialSum = 0L ;
BigDecimal materialRmbSum = new BigDecimal ( 0 ) ;
BigDecimal materialNoRmbSum = new BigDecimal ( 0 ) ;
// 预估单价合计
BigDecimal estimatePrice = new BigDecimal ( 0 ) ;
// BigDecimal materialNoRmbSum = new BigDecimal(0);
//物料合计
if ( CollectionUtils . isEmpty ( childList ) ) {
throw new BusinessException ( "请购物料为空!" ) ;
}
Integer childSize = childList . size ( ) ;
if ( childSize > 0 ) {
for ( BaseRequisitioningOrderChild child : childList ) {
//物料数量
materialSum + = child . getMaterialNum ( ) ;
if ( child . getMaterialRmbSum ( ) = = null ) {
child . setMaterialRmbSum ( new BigDecimal ( 0 ) ) ;
}
if ( child . getMaterialNoRmbSum ( ) = = null ) {
child . setMaterialNoRmbSum ( new BigDecimal ( 0 ) ) ;
}
//物料不含税总价(RMB)
materialRmbSum = child . getMaterialRmbSum ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( materialNoRmbSum ) ;
//物料含税总价(RMB)
materialNoRmbSum = child . getMaterialNoRmbSum ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( materialNoRmbSum ) ;
child . setRequisitioningCode ( baseRequisitioningOrder . getRequisitioningCode ( ) ) ;
child . setCreateBy ( loginName ) ;
child . setCreateTime ( DateUtils . getNowDate ( ) ) ;
baseRequisitioningOrderChildMapper . insertBaseRequisitioningOrderChild ( child ) ;
for ( BaseRequisitioningOrderChild child : childList ) {
//物料数量
if ( child . getMaterialNum ( ) = = null ) {
throw new BusinessException ( "存在物料数为空,请检查" ) ;
}
materialSum + = child . getMaterialNum ( ) ;
if ( child . getMaterialRmbSum ( ) = = null ) {
child . setMaterialRmbSum ( new BigDecimal ( 0 ) ) ;
}
if ( child . getMaterialRmb ( ) = = null ) {
throw new BusinessException ( "存在预估金额为空,请检查" ) ;
}
//物料预估总价(RMB)
materialRmbSum = child . getMaterialRmbSum ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( materialRmbSum ) ;
// 物料预估单价合计
estimatePrice = child . getMaterialRmb ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( estimatePrice ) ;
//物料不含税总价(RMB)
child . setRequisitioningCode ( baseRequisitioningOrder . getRequisitioningCode ( ) ) ;
child . setCreateBy ( loginName ) ;
child . setCreateTime ( DateUtils . getNowDate ( ) ) ;
baseRequisitioningOrderChildMapper . insertBaseRequisitioningOrderChild ( child ) ;
}
baseRequisitioningOrder . setMaterialAmount ( childSize ) ;
baseRequisitioningOrder . setMaterialSum ( materialSum ) ;
baseRequisitioningOrder . setRmbSum ( materialRmbSum ) ;
baseRequisitioningOrder . setNoRmbSum ( materialNoRmbSum ) ;
baseRequisitioningOrder . setEstimatePrice ( estimatePrice ) ;
// baseRequisitioningOrder.setNoRmbSum(materialNoRmbSum);
int result = baseRequisitioningOrderMapper . insertBaseRequisitioningOrder ( baseRequisitioningOrder ) ;
//如要获取请购单ID,作为key
baseRequisitioningOrder . getRequisitioningId ( ) ;
@ -233,7 +263,7 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
* @return 结果
* /
@Override
@Transactional ( rollbackFor = NullPointer Exception. class )
@Transactional ( rollbackFor = Exception . class )
public int updateBaseRequisitioningOrder ( BaseRequisitioningOrder baseRequisitioningOrder )
{
String loginName = ShiroUtils . getLoginName ( ) ;
@ -243,14 +273,29 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
List < BaseRequisitioningOrderChild > childList = baseRequisitioningOrder . getBaseRequisitioningOrderChildList ( ) ;
Long materialSum = 0L ;
BigDecimal materialRmbSum = new BigDecimal ( 0 ) ;
BigDecimal materialNoRmbSum = new BigDecimal ( 0 ) ;
// BigDecimal materialNoRmbSum = new BigDecimal(0);
// 物料预估单价合计
BigDecimal estimatePrice = new BigDecimal ( 0 ) ;
// Integer childSize = childList.size();
if ( ! StringUtils . isEmpty ( childList ) ) {
baseRequisitioningOrderChildMapper . deleteBaseRequisitioningOrderChildByRequisitioningCode ( baseRequisitioningOrder . getRequisitioningCode ( ) ) ;
for ( BaseRequisitioningOrderChild child : childList ) {
//物料数量
if ( child . getMaterialNum ( ) = = null ) {
throw new BusinessException ( "存在物料数为空,请检查" ) ;
}
materialSum + = child . getMaterialNum ( ) ;
materialRmbSum = child . getMaterialRmbSum ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( materialNoRmbSum ) ;
materialNoRmbSum = child . getMaterialNoRmbSum ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( materialNoRmbSum ) ;
if ( child . getMaterialRmbSum ( ) = = null ) {
child . setMaterialRmbSum ( new BigDecimal ( 0 ) ) ;
}
if ( child . getMaterialRmb ( ) = = null ) {
throw new BusinessException ( "存在预估金额为空,请检查" ) ;
}
//物料预估总价(RMB)
materialRmbSum = child . getMaterialRmbSum ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( materialRmbSum ) ;
// 物料预估单价合计
estimatePrice = child . getMaterialRmb ( ) . setScale ( 2 , RoundingMode . HALF_UP ) . add ( estimatePrice ) ;
child . setRequisitioningCode ( requisitioningCode ) ;
child . setCreateBy ( loginName ) ;
child . setCreateTime ( DateUtils . getNowDate ( ) ) ;
@ -262,12 +307,13 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
}
baseRequisitioningOrder . setMaterialSum ( materialSum ) ;
baseRequisitioningOrder . setRmbSum ( materialRmbSum ) ;
baseRequisitioningOrder . setNoRmbSum ( materialNoRmbSum ) ;
baseRequisitioningOrder . setEstimatePrice ( estimatePrice ) ;
// baseRequisitioningOrder.setNoRmbSum(materialNoRmbSum);
return baseRequisitioningOrderMapper . updateBaseRequisitioningOrder ( baseRequisitioningOrder ) ;
}
@Override
@Transactional ( rollbackFor = NullPointer Exception. class )
@Transactional ( rollbackFor = Exception . class )
public int updateVerifyBaseRequisitioningOrder ( BaseRequisitioningOrder baseRequisitioningOrder ) {
baseRequisitioningOrder . setUpdateBy ( ShiroUtils . getLoginName ( ) ) ;
baseRequisitioningOrder . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
@ -461,8 +507,8 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
}
private void buildAuthority ( SysUser user , Map < String , Object > variables ) {
System . out . println ( "请购单启动流程" ) ;
System . out . println ( "user = " + user + ", variables = " + variables ) ;
// System.out.println("请购单启动流程");
// System.out.println("user = " + user + ", variables = " + variables);
//查询当前请购人的角色
Set < String > roleKeys = roleService . selectRoleKeys ( user . getUserId ( ) ) ;
@ -488,7 +534,7 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
}
else if ( roleKeys . contains ( "scyRole" ) | | roleKeys . contains ( "scjlRole" ) | | roleKeys . contains ( "sczgRole" ) ) {
// 生产经理
variables . put ( "qgjlRole" , "scjlRoe" ) ;
variables . put ( "qgjlRole" , "scjlRol e" ) ;
// 生产主管
variables . put ( "qgzgRole" , "sczgRole" ) ;
}
@ -498,15 +544,15 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
// 售后主管
variables . put ( "qgzgRole" , "shzgRole" ) ;
}
else if ( roleKeys . contains ( "cgyyRole" ) | | roleKeys . contains ( "ckzgRole" ) ) {
variables . put ( "qgjlRole" , "shzgRole" ) ;
// 售后主管
variables . put ( "qgzgRole" , "shzgRole" ) ;
else if ( roleKeys . contains ( "cgyyRole" ) | | roleKeys . contains ( "cgzgRole" ) ) {
// 仓管员、仓管主管
variables . put ( "qgjlRole" , "cgzgRole" ) ;
variables . put ( "qgzgRole" , "cgzgRole" ) ;
}
else if ( roleKeys . contains ( "cwRole" ) | | roleKeys . contains ( "cwjlRole" ) ) {
variables . put ( "qgjlRole" , "cwjlRole" ) ;
// 售后主管
variables . put ( "qgzgRole" , "cwJlRole" ) ;
// 财务
}
else {
variables . put ( "authority" , 2 ) ;
@ -547,11 +593,12 @@ public class BaseRequisitioningOrderServiceImpl implements IBaseRequisitioningOr
purchasePlanChild . setBrand ( requisitioningOrderDetail . getBrand ( ) ) ;
purchasePlanChild . setUnit ( requisitioningOrderDetail . getUnit ( ) ) ;
purchasePlanChild . setPhotoUrl ( requisitioningOrderDetail . getPhotoUrl ( ) ) ;
purchasePlanChild . setProcessMethod ( requisitioningOrderDetail . getProcessMethod ( ) ) ;
purchasePlanChild . setMaterialNum ( Double . valueOf ( requisitioningOrderDetail . getMaterialNum ( ) ) ) ;
purchasePlanChild . setMaterialType ( requisitioningOrderDetail . getMaterialType ( ) ) ;
purchasePlanChild . setMaterialNoRmb ( requisitioningOrderDetail . getMaterialNoRmb ( ) ) ;
purchasePlanChild . setMaterialRmb ( requisitioningOrderDetail . getMaterialRmb ( ) ) ;
noRmbSum = noRmbSum . add ( requisitioningOrderDetail . getMaterialNoRmb ( ) ) ;
// noRmbSum = noRmbSum.add(requisitioningOrderDetail.getMaterialNoRmb());
rmbSum = rmbSum . add ( requisitioningOrderDetail . getMaterialRmbSum ( ) ) ;
materialSum + = requisitioningOrderDetail . getMaterialNum ( ) ;
planChildMapper . insertPurchasePlanChild ( purchasePlanChild ) ;