package com.thhy.secure.modules.biz.material.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.thhy.general.common.BasicResult;
|
import com.thhy.general.config.SysUserInfo;
|
import com.thhy.general.utils.UserInfoUtils;
|
import com.thhy.secure.modules.biz.file.service.FileService;
|
import com.thhy.secure.modules.biz.material.entity.TMaterial;
|
import com.thhy.secure.modules.biz.material.entity.TMaterialPath;
|
import com.thhy.secure.modules.biz.material.mapper.TMaterialMapper;
|
import com.thhy.secure.modules.biz.material.service.MaterialService;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
public class MaterialServiceImpl implements MaterialService {
|
|
@Resource
|
private TMaterialMapper materialMapper;
|
|
@Resource
|
private FileService fileService;
|
|
|
@Override
|
@Transactional
|
public BasicResult materialInsert(Map<String, Object> values) {
|
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
|
String companyId = sysUserInfo.getCompanyId();
|
String userId = sysUserInfo.getUserId();
|
values.put("companyId",companyId);
|
values.put("materialId","");
|
values.put("createUser",userId);
|
materialMapper.materialInsert(values);
|
//添加后的主键
|
String materialId = values.get("materialId").toString();
|
List<String> files = (List<String>) values.get("files");
|
for (String file:files){
|
HashMap<String, Object> hashMap = new HashMap<>();
|
hashMap.put("materialId",materialId);
|
hashMap.put("materialPath",file);
|
hashMap.put("materialPathId","");
|
materialMapper.materialPathInsert(hashMap);
|
}
|
return BasicResult.success("添加成功");
|
}
|
|
@Override
|
public BasicResult materialList(Map<String, Object> values) {
|
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
|
String companyId = sysUserInfo.getCompanyId();
|
values.put("companyId",companyId);
|
Integer pageSize = Integer.valueOf(values.get("pageSize").toString());
|
Integer pageNum = Integer.valueOf(values.get("pageNum").toString());
|
PageHelper.startPage(pageNum,pageSize);
|
List<TMaterial> materials = materialMapper.materialList(values);
|
PageInfo<TMaterial> tMaterialPageInfo = new PageInfo<>(materials);
|
return BasicResult.success(tMaterialPageInfo);
|
}
|
|
@Override
|
public BasicResult materialInfo(Map<String, Object> values) {
|
|
TMaterial material = materialMapper.materialInfo(values);
|
List<TMaterialPath> materialPaths = materialMapper.materialPathList(material.getMaterialId());
|
materialPaths.forEach(fl ->{
|
JSONObject json = new JSONObject();
|
json.put("fullpath",fl.getMaterialPath());
|
BasicResult basicResult = fileService.fileinfo(json.toJSONString());
|
if(basicResult.isSuccess()){
|
JSONArray jsonArray = JSONArray.parseArray(basicResult.getData().toString());
|
for(Object obj : jsonArray){
|
JSONObject j = JSON.parseObject(obj.toString());
|
if(j.containsKey("name")&&"name".equals(j.getString("name"))){
|
fl.setMaterialPathName(j.getString("value"));
|
}
|
}
|
}
|
});
|
material.setMaterialPaths(materialPaths);
|
return BasicResult.success(material);
|
}
|
|
@Override
|
public BasicResult materialUpdate(Map<String, Object> values) {
|
|
materialMapper.materialUpdate(values);
|
String materialId = values.get("materialId").toString();
|
materialMapper.materialPathDel(materialId);
|
|
List<String> files = (List<String>) values.get("files");
|
for (String file:files){
|
HashMap<String, Object> hashMap = new HashMap<>();
|
hashMap.put("materialId",materialId);
|
hashMap.put("materialPath",file);
|
hashMap.put("materialPathId","");
|
materialMapper.materialPathInsert(hashMap);
|
}
|
return BasicResult.success("修改成功");
|
}
|
}
|