|
|
|
@ -1,37 +1,45 @@
|
|
|
|
|
package jnpf.service.impl;
|
|
|
|
|
|
|
|
|
|
import jnpf.entity.*;
|
|
|
|
|
import jnpf.mapper.YysBillMaterialMapper;
|
|
|
|
|
import jnpf.service.*;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import jnpf.model.yysbillmaterial.*;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import jnpf.permission.model.authorize.AuthorizeConditionModel;
|
|
|
|
|
import jnpf.util.GeneraterSwapUtil;
|
|
|
|
|
import jnpf.database.model.superQuery.SuperQueryJsonModel;
|
|
|
|
|
import jnpf.database.model.superQuery.ConditionJsonModel;
|
|
|
|
|
import jnpf.database.model.superQuery.SuperQueryConditionModel;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import jnpf.model.QueryModel;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import jnpf.base.model.ColumnDataModel;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import jnpf.database.model.superQuery.SuperJsonModel;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import jnpf.util.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import jnpf.base.UserInfo;
|
|
|
|
|
import jnpf.base.model.ColumnDataModel;
|
|
|
|
|
import jnpf.database.model.superQuery.SuperJsonModel;
|
|
|
|
|
import jnpf.entity.YysBillMaterialEntity;
|
|
|
|
|
import jnpf.entity.YysSubsetMaterialEntity;
|
|
|
|
|
import jnpf.mapper.YysBillMaterialMapper;
|
|
|
|
|
import jnpf.model.QueryModel;
|
|
|
|
|
import jnpf.model.yysbillmaterial.*;
|
|
|
|
|
import jnpf.model.yysmaterialinformation.MaterialInformationSync;
|
|
|
|
|
import jnpf.permission.entity.UserEntity;
|
|
|
|
|
import jnpf.service.YysBillMaterialService;
|
|
|
|
|
import jnpf.service.YysSubsetMaterialService;
|
|
|
|
|
import jnpf.util.*;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
import org.springframework.jdbc.core.RowMapper;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* yysBillMaterial
|
|
|
|
|
* 版本: V3.5
|
|
|
|
|
* 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
|
|
|
|
@ -46,11 +54,20 @@ public class YysBillMaterialServiceImpl extends ServiceImpl<YysBillMaterialMappe
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserProvider userProvider;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private YysSubsetMaterialService yysSubsetMaterialService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<YysBillMaterialEntity> getList(YysBillMaterialPagination yysBillMaterialPagination) {
|
|
|
|
|
return getTypeList(yysBillMaterialPagination, yysBillMaterialPagination.getDataType());
|
|
|
|
|
}
|
|
|
|
|
/** 列表查询 */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表查询
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<YysBillMaterialEntity> getTypeList(YysBillMaterialPagination yysBillMaterialPagination, String dataType) {
|
|
|
|
|
String userId = userProvider.get().getUserId();
|
|
|
|
@ -229,27 +246,34 @@ public class YysBillMaterialServiceImpl extends ServiceImpl<YysBillMaterialMappe
|
|
|
|
|
return this.list(yysBillMaterialQueryWrapper);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public YysBillMaterialEntity getInfo(String id) {
|
|
|
|
|
QueryWrapper<YysBillMaterialEntity> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.lambda().eq(YysBillMaterialEntity::getId, id);
|
|
|
|
|
return this.getOne(queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void create(YysBillMaterialEntity entity) {
|
|
|
|
|
this.save(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean update(String id, YysBillMaterialEntity entity) {
|
|
|
|
|
return this.updateById(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(YysBillMaterialEntity entity) {
|
|
|
|
|
if (entity != null) {
|
|
|
|
|
this.removeById(entity.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** 验证表单唯一字段,正则,非空 i-0新增-1修改*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证表单唯一字段,正则,非空 i-0新增-1修改
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String checkForm(YysBillMaterialForm form, int i) {
|
|
|
|
|
boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0");
|
|
|
|
@ -261,8 +285,10 @@ public class YysBillMaterialServiceImpl extends ServiceImpl<YysBillMaterialMappe
|
|
|
|
|
//主表字段验证
|
|
|
|
|
return countRecover;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增修改数据(事务回滚)
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @param yysBillMaterialForm
|
|
|
|
|
* @return
|
|
|
|
@ -298,4 +324,84 @@ public class YysBillMaterialServiceImpl extends ServiceImpl<YysBillMaterialMappe
|
|
|
|
|
wrapper.lambda().in(YysBillMaterialEntity::getPieceId, id);
|
|
|
|
|
return this.list(wrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@DS("slave_2")
|
|
|
|
|
public String syncMaterial() {
|
|
|
|
|
List<String> syncList = this.list(new LambdaQueryWrapper<>(YysBillMaterialEntity.class).isNull(YysBillMaterialEntity::getDeleteMark))
|
|
|
|
|
.stream().map(YysBillMaterialEntity::getId).collect(Collectors.toList());
|
|
|
|
|
//母件物料
|
|
|
|
|
RowMapper<SyncMaterial> rowMapper = new BeanPropertyRowMapper<>(SyncMaterial.class);
|
|
|
|
|
String sql = "select * from v_bom_parent_rpt";
|
|
|
|
|
List<SyncMaterial> query = this.jdbcTemplate.query(sql, rowMapper);
|
|
|
|
|
if (CollectionUtils.isEmpty(query)) {
|
|
|
|
|
return "远程母件物料信息为空";
|
|
|
|
|
}
|
|
|
|
|
//过滤出同步过的
|
|
|
|
|
query = query.stream().filter(obj -> !syncList.contains(obj.getAutoId())).collect(Collectors.toList());
|
|
|
|
|
//子件物料
|
|
|
|
|
RowMapper<SyncSubsetMaterial> subMapper = new BeanPropertyRowMapper<>(SyncSubsetMaterial.class);
|
|
|
|
|
String subsetSql = "select * from v_bom_opcomponent_rpt";
|
|
|
|
|
List<SyncSubsetMaterial> subsetMaterials = this.jdbcTemplate.query(subsetSql, subMapper);
|
|
|
|
|
Map<String, List<SyncSubsetMaterial>> subsetCollect = Maps.newHashMap();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(subsetMaterials)) {
|
|
|
|
|
subsetCollect = subsetMaterials.stream().collect(Collectors.groupingBy(SyncSubsetMaterial::getBomId));
|
|
|
|
|
}
|
|
|
|
|
//物料表数据 不从自己库取数据,防止自己库未同步,从而取不到数据
|
|
|
|
|
RowMapper<MaterialInformationSync> materialMapper = new BeanPropertyRowMapper<>(MaterialInformationSync.class);
|
|
|
|
|
String materialSql = "select * from dbo.Inventory";
|
|
|
|
|
List<MaterialInformationSync> informationSyncs = this.jdbcTemplate.query(materialSql, materialMapper);
|
|
|
|
|
Map<String, MaterialInformationSync> materialCollect = Maps.newHashMap();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(informationSyncs)) {
|
|
|
|
|
materialCollect = informationSyncs.stream().collect(Collectors.toMap(MaterialInformationSync::getCInvCode, Function.identity()));
|
|
|
|
|
}
|
|
|
|
|
List<YysBillMaterialEntity> materialResult = Lists.newArrayList();
|
|
|
|
|
List<YysSubsetMaterialEntity> subsetResult = Lists.newArrayList();
|
|
|
|
|
for (SyncMaterial material : query) {
|
|
|
|
|
YysBillMaterialEntity yysBillMaterialEntity = new YysBillMaterialEntity();
|
|
|
|
|
yysBillMaterialEntity.setId(material.getAutoId());
|
|
|
|
|
yysBillMaterialEntity.setPieceId(material.getBomId());
|
|
|
|
|
if (MapUtils.isNotEmpty(materialCollect) && materialCollect.containsKey(material.getInvCode())) {
|
|
|
|
|
MaterialInformationSync sync = materialCollect.get(material.getInvCode());
|
|
|
|
|
yysBillMaterialEntity.setPieceName(sync.getCInvName());
|
|
|
|
|
yysBillMaterialEntity.setModels(sync.getEInvStd());
|
|
|
|
|
yysBillMaterialEntity.setUnit(sync.getCComUnitCode());
|
|
|
|
|
}
|
|
|
|
|
//处理子集
|
|
|
|
|
if (MapUtils.isNotEmpty(subsetCollect) && subsetCollect.containsKey(yysBillMaterialEntity.getPieceId())) {
|
|
|
|
|
List<SyncSubsetMaterial> list = subsetCollect.get(yysBillMaterialEntity.getPieceId());
|
|
|
|
|
for (SyncSubsetMaterial subsetMaterial : list) {
|
|
|
|
|
YysSubsetMaterialEntity yysSubsetMaterialEntity = new YysSubsetMaterialEntity();
|
|
|
|
|
yysSubsetMaterialEntity.setId(subsetMaterial.getOpComponentId());
|
|
|
|
|
yysSubsetMaterialEntity.setPieceId(yysBillMaterialEntity.getId());
|
|
|
|
|
yysSubsetMaterialEntity.setSubsetId(subsetMaterial.getBomId());
|
|
|
|
|
yysSubsetMaterialEntity.setBaseUse(subsetMaterial.getBaseQtyN());
|
|
|
|
|
yysSubsetMaterialEntity.setBaseNum(subsetMaterial.getBaseQtyD());
|
|
|
|
|
if (MapUtils.isNotEmpty(materialCollect) && materialCollect.containsKey(subsetMaterial.getInvCode())) {
|
|
|
|
|
MaterialInformationSync sync = materialCollect.get(subsetMaterial.getInvCode());
|
|
|
|
|
yysSubsetMaterialEntity.setSubsetName(sync.getCInvName());
|
|
|
|
|
yysSubsetMaterialEntity.setSubsetModel(sync.getEInvStd());
|
|
|
|
|
yysSubsetMaterialEntity.setUnit(sync.getCComUnitCode());
|
|
|
|
|
}
|
|
|
|
|
yysSubsetMaterialEntity.setCreatorTime(DateUtil.getNowDate());
|
|
|
|
|
//默认给个状态
|
|
|
|
|
yysSubsetMaterialEntity.setStatus("2");
|
|
|
|
|
subsetResult.add(yysSubsetMaterialEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//暂时默认单据状态为已审核
|
|
|
|
|
yysBillMaterialEntity.setDocumentStatus("2");
|
|
|
|
|
yysBillMaterialEntity.setCreatorTime(DateUtil.getNowDate());
|
|
|
|
|
materialResult.add(yysBillMaterialEntity);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isEmpty(materialResult)) {
|
|
|
|
|
return "没有需要同步的数据";
|
|
|
|
|
}
|
|
|
|
|
boolean material = this.saveBatch(materialResult);
|
|
|
|
|
boolean savedBatch = yysSubsetMaterialService.saveBatch(subsetResult);
|
|
|
|
|
if (material && savedBatch) {
|
|
|
|
|
return "同步成功";
|
|
|
|
|
}
|
|
|
|
|
return "同步失败";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|