|
@@ -35,6 +35,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 产品的Service层
|
|
|
+ *
|
|
|
* @Author xiexiang
|
|
|
* @Date 2023/10/26
|
|
|
*/
|
|
@@ -69,8 +70,8 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
|
- List<String> sqls = formatQueryService.reSqls(queryRequest,"product");
|
|
|
- sqls= this.loadSearchSql(sqls);
|
|
|
+ List<String> sqls = formatQueryService.reSqls(queryRequest, "product");
|
|
|
+ sqls = this.loadSearchSql(sqls);
|
|
|
//根据sql查询产品信息
|
|
|
List<ProductVO> productVOS = productMapper.getProduct(sqls.get(0), sqls.get(1), sqls.get(2));
|
|
|
//查询总数
|
|
@@ -88,6 +89,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
|
* 新增产品
|
|
|
+ *
|
|
|
* @param object
|
|
|
* @param files
|
|
|
* @return
|
|
@@ -140,10 +142,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
}
|
|
|
//判断可见类型:
|
|
|
Integer showType = productDTO.getShowType();
|
|
|
- if(showType != 0 && showType != 1){
|
|
|
+ if (showType != 0 && showType != 1) {
|
|
|
List<String> showPersonIds = productDTO.getShowPersonIds();
|
|
|
//0所有人可见,1本人可见
|
|
|
- if(showPersonIds != null && showPersonIds.size() != 0){
|
|
|
+ if (showPersonIds != null && showPersonIds.size() != 0) {
|
|
|
for (String showPersonId : showPersonIds) {
|
|
|
AssoProductPerson assoProductPerson = new AssoProductPerson();
|
|
|
assoProductPerson.setProductId(product.getId());
|
|
@@ -161,11 +163,11 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(assoProductPeople != null && assoProductPeople.size() != 0){
|
|
|
+ if (assoProductPeople != null && assoProductPeople.size() != 0) {
|
|
|
assoProductPersonService.saveBatch(assoProductPeople);
|
|
|
}
|
|
|
//判断文件是否为空
|
|
|
- if(files != null && files.size() != 0) {
|
|
|
+ if (files != null && files.size() != 0) {
|
|
|
try {
|
|
|
//调用上传文件接口
|
|
|
List<String> guids = fileManagerService.uploadFileGetGuid(files);
|
|
@@ -190,6 +192,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
|
* 删除产品
|
|
|
+ *
|
|
|
* @param ids
|
|
|
* @return
|
|
|
*/
|
|
@@ -218,6 +221,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
|
* 更新产品
|
|
|
+ *
|
|
|
* @param object
|
|
|
* @param files
|
|
|
* @return
|
|
@@ -226,7 +230,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
|
//object to updateProductDTO
|
|
|
UpdateProductDTO updateProductDTO = (UpdateProductDTO) object;
|
|
|
- if(updateProductDTO == null || updateProductDTO.getId() == null){
|
|
|
+ if (updateProductDTO == null || updateProductDTO.getId() == null) {
|
|
|
throw new XiaoShiException("参数错误");
|
|
|
}
|
|
|
//获取登陆人信息 用于设置创建人
|
|
@@ -244,7 +248,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(Product::getName, name);
|
|
|
List<Product> products = this.list(queryWrapper);
|
|
|
- if(!updateProductDTO.getName().equals(product.getName()) && products.size() != 0){
|
|
|
+ if (!updateProductDTO.getName().equals(product.getName()) && products.size() != 0) {
|
|
|
throw new XiaoShiException("名称重复");
|
|
|
}
|
|
|
BeanUtils.copyProperties(updateProductDTO, product);
|
|
@@ -279,10 +283,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
}
|
|
|
//判断可见类型:
|
|
|
Integer showType = updateProductDTO.getShowType();
|
|
|
- if(showType != 0 && showType != 1){
|
|
|
+ if (showType != 0 && showType != 1) {
|
|
|
List<String> showPersonIds = updateProductDTO.getShowPersonIds();
|
|
|
//0所有人可见,1本人可见
|
|
|
- if(showPersonIds != null && showPersonIds.size() != 0){
|
|
|
+ if (showPersonIds != null && showPersonIds.size() != 0) {
|
|
|
for (String showPersonId : showPersonIds) {
|
|
|
AssoProductPerson assoProductPerson = new AssoProductPerson();
|
|
|
assoProductPerson.setProductId(product.getId());
|
|
@@ -300,7 +304,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(assoProductPeople != null && assoProductPeople.size() != 0){
|
|
|
+ if (assoProductPeople != null && assoProductPeople.size() != 0) {
|
|
|
assoProductPersonService.saveBatch(assoProductPeople);
|
|
|
}
|
|
|
/**
|
|
@@ -313,20 +317,20 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
List<String> fileGuIds = assoFiles.stream().map(AssoProductFile::getFileGuid).collect(Collectors.toList());
|
|
|
//获取更新后的附件ids
|
|
|
List<String> updateFileGuIds = new ArrayList<>();
|
|
|
- if(updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0){
|
|
|
+ if (updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0) {
|
|
|
updateFileGuIds = updateProductDTO.getGuids();
|
|
|
fileGuIds.retainAll(updateFileGuIds);
|
|
|
}
|
|
|
//做差获得被删除的文件id
|
|
|
- if(fileGuIds.size() != 0){
|
|
|
+ if (fileGuIds.size() != 0) {
|
|
|
//根据文件id删除产品与文件关联表记录
|
|
|
LambdaQueryWrapper<AssoProductFile> deleteWrapper = new LambdaQueryWrapper<>();
|
|
|
deleteWrapper.in(AssoProductFile::getFileGuid, fileGuIds);
|
|
|
assoProductFileService.remove(deleteWrapper);
|
|
|
//远程删除服务器上的文件
|
|
|
- try{
|
|
|
+ try {
|
|
|
fileManagerService.deleteFileFromFMS(fileGuIds);
|
|
|
- } catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -353,7 +357,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public GroupVO getGroup(GroupRequest groupRequest,String tableName) throws Exception {
|
|
|
+ public GroupVO getGroup(GroupRequest groupRequest, String tableName) throws Exception {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -369,6 +373,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
|
* 装载productVO
|
|
|
+ *
|
|
|
* @param productVOS
|
|
|
* @throws IOException
|
|
|
*/
|
|
@@ -377,7 +382,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
List<Integer> ids = new ArrayList<>();
|
|
|
productVOS.forEach(
|
|
|
item -> {
|
|
|
- if(item.getCreateId() != null){
|
|
|
+ if (item.getCreateId() != null) {
|
|
|
createIds.add(item.getCreateId());
|
|
|
}
|
|
|
if (item.getId() != null) {
|
|
@@ -409,8 +414,8 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
if (guids.size() != 0) {
|
|
|
String res = fileManagerService.getSystemFileFromFMS(guids);
|
|
|
systemFiles = JSONObject.parseArray(res, SystemFile.class);
|
|
|
- if(systemFiles==null){
|
|
|
- systemFiles=new ArrayList<>();
|
|
|
+ if (systemFiles == null) {
|
|
|
+ systemFiles = new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -418,7 +423,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
for (ProductVO productVO : productVOS) {
|
|
|
//装载人员信息
|
|
|
Personnel personnel = personnels.stream().filter(item -> item.getId().toString().equals(productVO.getCreateId())).findFirst().orElse(null);
|
|
|
- if(personnel != null){
|
|
|
+ if (personnel != null) {
|
|
|
productVO.setCreateName(personnel.getPersonnelName());
|
|
|
} else {
|
|
|
throw new XiaoShiException("未获取到当前登陆人信息");
|
|
@@ -497,21 +502,19 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
//装载查询语句
|
|
|
//装载查询语句
|
|
|
- private List<String> loadSearchSql(List<String> sqls){
|
|
|
- PersonnelVO personnelVO =cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
- String id =personnelVO.getId();
|
|
|
- Integer tenantId =personnelVO.getTenantId();
|
|
|
- String rootSql ="product.create_id="+id+" or(product.show_type =0 and product.tenant_id ="+tenantId+") or ( product.id in (select product_id from asso_product_person where" +
|
|
|
- " person_id="+id+" and role=0)) or (product.show_type=2 and product.id in (select product_id from asso_product_person where" +
|
|
|
- " person_id="+id+" and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
|
|
|
- " person_id="+id+" and role=2))";
|
|
|
- if(sqls.get(0)!=null&&!sqls.get(0).equals(""))
|
|
|
- {
|
|
|
- sqls.set(0,rootSql+" and"+"("+sqls.get(0)+")");
|
|
|
+ private List<String> loadSearchSql(List<String> sqls) {
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ String id = personnelVO.getId();
|
|
|
+ Integer tenantId = personnelVO.getTenantId();
|
|
|
+ String rootSql = "product.create_id=" + id + " or(product.show_type =0 and product.tenant_id =" + tenantId + ") or ( product.id in (select product_id from asso_product_person where" +
|
|
|
+ " person_id=" + id + " and role=0)) or (product.show_type=2 and product.id in (select product_id from asso_product_person where" +
|
|
|
+ " person_id=" + id + " and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
|
|
|
+ " person_id=" + id + " and role=2))";
|
|
|
+ if (sqls.get(0) != null && !sqls.get(0).equals("")) {
|
|
|
+ sqls.set(0, rootSql + " and" + "(" + sqls.get(0) + ")");
|
|
|
|
|
|
- }
|
|
|
- else {
|
|
|
- sqls.set(0,rootSql);
|
|
|
+ } else {
|
|
|
+ sqls.set(0, rootSql);
|
|
|
}
|
|
|
|
|
|
return sqls;
|