package doumeemes.service.ext.impl;
|
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import doumeemes.core.constants.ResponseStatus;
|
import doumeemes.core.exception.BusinessException;
|
import doumeemes.core.model.LoginUserInfo;
|
import doumeemes.core.model.PageData;
|
import doumeemes.core.model.PageWrap;
|
import doumeemes.core.utils.Constants;
|
import doumeemes.core.utils.excel.EasyExcelUtil;
|
import doumeemes.core.utils.redis.RedisUtil;
|
import doumeemes.dao.business.MaterialMapper;
|
import doumeemes.dao.business.dto.QueryUnitExtDTO;
|
import doumeemes.dao.business.model.BarcodeParam;
|
import doumeemes.dao.business.model.Material;
|
import doumeemes.dao.business.vo.UnitExtListVO;
|
import doumeemes.dao.ext.MaterialExtMapper;
|
import doumeemes.dao.ext.bean.MaterialDetailBean;
|
import doumeemes.dao.ext.dto.QueryCategoryUnionExtDTO;
|
import doumeemes.dao.ext.dto.QueryMaterialDistributeExtDTO;
|
import doumeemes.dao.ext.dto.QueryMaterialExtDTO;
|
import doumeemes.dao.ext.vo.CategoryExtListVO;
|
import doumeemes.dao.ext.vo.CategoryUnionExtListVO;
|
import doumeemes.dao.ext.vo.MaterialDistributeExtListVO;
|
import doumeemes.dao.ext.vo.MaterialExtListVO;
|
import doumeemes.service.business.BarcodeParamService;
|
import doumeemes.service.business.UnitExtService;
|
import doumeemes.service.business.impl.MaterialDistributeServiceImpl;
|
import doumeemes.service.business.impl.MaterialServiceImpl;
|
import doumeemes.service.ext.CategoryUnionExtService;
|
import doumeemes.service.ext.MaterialDistributeExtService;
|
import doumeemes.service.ext.MaterialExtService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.util.*;
|
|
/**
|
* 物料基本信息Service实现
|
* @author 江蹄蹄
|
* @date 2022/04/20 10:59
|
*/
|
@Service
|
public class MaterialExtServiceImpl implements MaterialExtService {
|
|
@Autowired
|
private MaterialExtMapper materialExtMapper;
|
|
@Autowired
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
@Autowired
|
private MaterialDistributeExtService materialDistributeExtService;
|
@Autowired
|
private MaterialServiceImpl materialServiceimpl;
|
|
@Autowired
|
private MaterialMapper materialMapper;
|
|
@Autowired
|
private MaterialDistributeServiceImpl materialDistributeServiceimpl;
|
|
@Autowired
|
private UnitExtService unitExtService;
|
|
@Autowired
|
private CategoryUnionExtService categoryUnionExtService;
|
|
|
@Autowired
|
private BarcodeParamService barcodeParamService;
|
|
|
@Override
|
public PageData<MaterialExtListVO> findPage(PageWrap<QueryMaterialExtDTO> pageWrap) {
|
PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
|
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
pageWrap.getModel().setDeleted(Constants.ZERO);
|
pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId());
|
|
List<MaterialExtListVO> result = materialExtMapper.getListByCondition(pageWrap.getModel());
|
|
List<CategoryExtListVO> clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+user.getCompany().getId(), ArrayList.class);
|
|
for(int i=0;i<result.size();i++){
|
MaterialExtListVO materialExtListVO=result.get(i);
|
for(int j=0;j<clist.size();j++){
|
CategoryExtListVO categoryExtListVO=clist.get(j);
|
if(StringUtils.isNotEmpty(materialExtListVO.getCumodelCateBigId())){
|
if(Constants.equalsInteger(Integer.valueOf(materialExtListVO.getCumodelCateBigId()),categoryExtListVO.getId())){
|
materialExtListVO.setCmodelName(categoryExtListVO.getName());
|
}
|
}
|
|
if(StringUtils.isNotEmpty(materialExtListVO.getCumodelCateMiddleId())){
|
if(Constants.equalsInteger(Integer.valueOf(materialExtListVO.getCumodelCateMiddleId()),categoryExtListVO.getId())){
|
materialExtListVO.setCmodel1Name(categoryExtListVO.getName());
|
|
}
|
}
|
|
if(StringUtils.isNotEmpty(materialExtListVO.getCumodelCateSmallId())){
|
if(Constants.equalsInteger(Integer.valueOf(materialExtListVO.getCumodelCateSmallId()),categoryExtListVO.getId())){
|
materialExtListVO.setCmodel2Name(categoryExtListVO.getName());
|
|
}
|
}
|
if(StringUtils.isNotEmpty(materialExtListVO.getCmodelName())){
|
if(StringUtils.isNotEmpty(materialExtListVO.getCmodel1Name())){
|
if(StringUtils.isNotEmpty(materialExtListVO.getCmodel2Name())){
|
materialExtListVO.setUnionCategoryName(materialExtListVO.getCmodelName()+"-"+materialExtListVO.getCmodel1Name()+"-"+materialExtListVO.getCmodel2Name());
|
}else{
|
materialExtListVO.setUnionCategoryName(materialExtListVO.getCmodelName()+"-"+materialExtListVO.getCmodel1Name());
|
}
|
}else{
|
materialExtListVO.setUnionCategoryName(materialExtListVO.getCmodelName());
|
}
|
}
|
|
}
|
}
|
/*for(int i=0;i<result.size();i++){
|
MaterialExtListVO mev=result.get(i);
|
if(StringUtils.isNotEmpty(mev.getCmodelName())){
|
if(StringUtils.isNotEmpty(mev.getCmodel1Name())){
|
if(StringUtils.isNotEmpty(mev.getCmodel2Name())){
|
mev.setUnionCategoryName(mev.getCmodelName()+"-"+mev.getCmodel1Name()+"-"+mev.getCmodel2Name());
|
}else{
|
mev.setUnionCategoryName(mev.getCmodelName()+"-"+mev.getCmodel1Name());
|
}
|
}else{
|
mev.setUnionCategoryName(mev.getCmodelName());
|
}
|
}
|
|
}*/
|
return PageData.from(new PageInfo<>(result));
|
}
|
|
|
|
@Override
|
public MaterialDetailBean findDetailById(Integer id) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
MaterialDetailBean materialDetailBean=new MaterialDetailBean();
|
QueryMaterialExtDTO query=new QueryMaterialExtDTO();
|
query.setId(id);
|
List<MaterialExtListVO> result = materialExtMapper.getListByCondition(query);
|
|
List<CategoryExtListVO> clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+user.getCompany().getId(), ArrayList.class);
|
for(int i=0;i<result.size();i++){
|
MaterialExtListVO materialExtListVO=result.get(i);
|
for(int j=0;j<clist.size();j++){
|
CategoryExtListVO categoryExtListVO=clist.get(j);
|
if(StringUtils.isNotEmpty(materialExtListVO.getCumodelCateBigId())){
|
if(Constants.equalsInteger(Integer.valueOf(materialExtListVO.getCumodelCateBigId()),categoryExtListVO.getId())){
|
materialExtListVO.setCmodelName(categoryExtListVO.getName());
|
}
|
}
|
|
if(StringUtils.isNotEmpty(materialExtListVO.getCumodelCateMiddleId())){
|
if(Constants.equalsInteger(Integer.valueOf(materialExtListVO.getCumodelCateMiddleId()),categoryExtListVO.getId())){
|
materialExtListVO.setCmodel1Name(categoryExtListVO.getName());
|
|
}
|
}
|
|
if(StringUtils.isNotEmpty(materialExtListVO.getCumodelCateSmallId())){
|
if(Constants.equalsInteger(Integer.valueOf(materialExtListVO.getCumodelCateSmallId()),categoryExtListVO.getId())){
|
materialExtListVO.setCmodel2Name(categoryExtListVO.getName());
|
|
}
|
}
|
if(StringUtils.isNotEmpty(materialExtListVO.getCmodelName())){
|
if(StringUtils.isNotEmpty(materialExtListVO.getCmodel1Name())){
|
if(StringUtils.isNotEmpty(materialExtListVO.getCmodel2Name())){
|
materialExtListVO.setUnionCategoryName(materialExtListVO.getCmodelName()+"-"+materialExtListVO.getCmodel1Name()+"-"+materialExtListVO.getCmodel2Name());
|
}else{
|
materialExtListVO.setUnionCategoryName(materialExtListVO.getCmodelName()+"-"+materialExtListVO.getCmodel1Name());
|
}
|
}else{
|
materialExtListVO.setUnionCategoryName(materialExtListVO.getCmodelName());
|
}
|
}
|
|
}
|
}
|
if(result!=null&&result.size()>0){
|
MaterialExtListVO mev=result.get(0);
|
|
materialDetailBean=new MaterialDetailBean().toMaterialDetail(mev);
|
|
//获取分配公司级组织信息
|
QueryMaterialDistributeExtDTO que=new QueryMaterialDistributeExtDTO();
|
que.setRootDepartId(user.getRootDepartment().getId());
|
que.setMaterialId(id);
|
que.setDeleted(Constants.ZERO);
|
List<MaterialDistributeExtListVO> mdList= materialDistributeExtService.findListByCondition(que);
|
List<Map<String ,Object>> res=new ArrayList<>();
|
if(mdList.size()>0){
|
for(int i=0;i<mdList.size();i++){
|
MaterialDistributeExtListVO mdev=mdList.get(i);
|
Map<String ,Object> map=new HashMap<>();
|
map.put("id",mdev.getId());
|
System.out.println(mdev.getDmodelName());
|
map.put("dmodelName",mdev.getDmodelName());
|
if(mdev.getStatus()!=null){
|
if(mdev.getStatus()==0){
|
map.put("status","无效");
|
}else if(mdev.getStatus()==1){
|
map.put("status","有效");
|
}
|
}else{
|
map.put("status",null);
|
}
|
|
map.put("createTime",mdev.getCreateTime());
|
res.add(map);
|
}
|
}
|
materialDetailBean.setMdlist(res);
|
return materialDetailBean;
|
}else{
|
return materialDetailBean;
|
}
|
}
|
|
|
@Override
|
public List<MaterialExtListVO> getListByCondition(QueryMaterialExtDTO pageWrap) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
pageWrap.setDeleted(Constants.ZERO);
|
pageWrap.setRootDepartId(user.getRootDepartment().getId());
|
List<MaterialExtListVO> result = materialExtMapper.getListByCondition(pageWrap);
|
for(int i=0;i<result.size();i++){
|
MaterialExtListVO mev=result.get(i);
|
if(StringUtils.isNotEmpty(mev.getCmodelName())){
|
if(StringUtils.isNotEmpty(mev.getCmodel1Name())){
|
if(StringUtils.isNotEmpty(mev.getCmodel2Name())){
|
mev.setUnionCategoryName(mev.getCmodelName()+"-"+mev.getCmodel1Name()+"-"+mev.getCmodel2Name());
|
}else{
|
mev.setUnionCategoryName(mev.getCmodelName()+"-"+mev.getCmodel1Name());
|
}
|
}else{
|
mev.setUnionCategoryName(mev.getCmodelName());
|
}
|
}
|
|
}
|
return result;
|
}
|
|
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
@Override
|
public void importmaterial(MultipartFile file) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
|
}
|
//解析excel
|
List<Material> materialList = EasyExcelUtil.importExcel(file, 1, 1, Material.class);
|
if(materialList == null || materialList.size()==0){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "导入数据内容有误!");
|
}
|
|
for(int i=0;i<materialList.size();i++){
|
Integer counter=i+2;
|
Material material=materialList.get(i);
|
if(StringUtils.isEmpty(material.getName())
|
||StringUtils.isEmpty(material.getCode())
|
||StringUtils.isEmpty(material.getUnitname())
|
||StringUtils.isEmpty(material.getFormationname())
|
||StringUtils.isEmpty(material.getAttr())
|
||StringUtils.isEmpty(material.getCateUnionName())){
|
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "第"+counter+"行:导入数据内容不能为空!");
|
}
|
material.setDeleted(Constants.ZERO);
|
material.setRootDepartId(user.getRootDepartment().getId());
|
material.setCreateTime(new Date());
|
material.setCreateUser(user.getId());
|
|
Material findMi=new Material();
|
findMi.setDeleted(Constants.ZERO);
|
findMi.setRootDepartId(user.getRootDepartment().getId());
|
findMi.setCode(material.getCode());
|
List<Material> list=materialServiceimpl.findList(findMi);
|
if(list.size()>0){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "第"+counter+"行:主组织内编码不能重复!");
|
}
|
|
Material findMi1=new Material();
|
findMi1.setDeleted(Constants.ZERO);
|
findMi1.setRootDepartId(user.getRootDepartment().getId());
|
findMi1.setName(material.getName());
|
List<Material> list1=materialServiceimpl.findList(findMi1);
|
if(list1.size()>0){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"第"+counter+"行:主组织内名称不能重复!");
|
}
|
|
QueryUnitExtDTO pageWrap=new QueryUnitExtDTO();
|
pageWrap.setDeleted(Constants.ZERO);
|
pageWrap.setRootDepartId(user.getRootDepartment().getId());
|
pageWrap.setType(Constants.ZERO);
|
pageWrap.setStatus(Constants.ONE);
|
pageWrap.setName(material.getUnitname().trim());
|
List<UnitExtListVO> unitlist=unitExtService.getUnitListByOrg(pageWrap);
|
if(unitlist!=null&&unitlist.size()>0){
|
material.setUnitId(unitlist.get(0).getId());
|
}else{
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"第"+counter+"行:单位不存在/没有有效的单位!");
|
}
|
|
if(StringUtils.equals(material.getFormationname().trim(),"生产")){
|
material.setFormation(0);
|
}else if(StringUtils.equals(material.getFormationname().trim(),"采购")){
|
material.setFormation(1);
|
}else{
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"第"+counter+"行:形成方式类型错误!");
|
}
|
|
|
QueryCategoryUnionExtDTO categoryUnion=new QueryCategoryUnionExtDTO();
|
categoryUnion.setDeleted(Constants.ZERO);
|
categoryUnion.setRootDepartId(user.getRootDepartment().getId());
|
categoryUnion.setBmodelCateType("0");
|
List<CategoryUnionExtListVO> catelist= categoryUnionExtService.getCategoryUnionListByOrg(categoryUnion);
|
if(catelist!=null&&catelist.size()>0){
|
for(int j=0;j<catelist.size();j++){
|
CategoryUnionExtListVO cuev=catelist.get(j);
|
if(StringUtils.equals(cuev.getCombinationName(),material.getCateUnionName().trim())){
|
material.setCateUnionId(cuev.getId());
|
}
|
|
}
|
}else{
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"第"+counter+"行:物料分类(组合名称)不存在!");
|
}
|
|
if(material.getCateUnionId()==null||material.getCateUnionId()==0){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"第"+counter+"行:物料分类(组合名称)不存在!");
|
}
|
|
material.setStatus(Constants.ONE);
|
material.setUnionName(material.getName()+material.getAttr());
|
material.setValidTime(new Date());
|
|
|
//获取二维码规则
|
BarcodeParam queryparam=new BarcodeParam();
|
queryparam.setDepartId(user.getCurComDepartment().getId());
|
queryparam.setRootDepartId(user.getRootDepartment().getId());
|
queryparam.setType(Constants.BARCODEPARAM_TYPE.material);
|
BarcodeParam barcodeParam =barcodeParamService.findOne(queryparam);
|
|
if(barcodeParam!=null){
|
material.setQrcodeId(barcodeParam.getId()+"");
|
}
|
Integer maid= materialMapper.insert(material);
|
|
materialDistributeServiceimpl.insert(material.getId()+"",user.getRootDepartment().getId()+"");
|
|
}
|
|
}
|
}
|