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 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 files = (List) values.get("files"); for (String file:files){ HashMap 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 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 materials = materialMapper.materialList(values); PageInfo tMaterialPageInfo = new PageInfo<>(materials); return BasicResult.success(tMaterialPageInfo); } @Override public BasicResult materialInfo(Map values) { TMaterial material = materialMapper.materialInfo(values); List 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 values) { materialMapper.materialUpdate(values); String materialId = values.get("materialId").toString(); materialMapper.materialPathDel(materialId); List files = (List) values.get("files"); for (String file:files){ HashMap hashMap = new HashMap<>(); hashMap.put("materialId",materialId); hashMap.put("materialPath",file); hashMap.put("materialPathId",""); materialMapper.materialPathInsert(hashMap); } return BasicResult.success("修改成功"); } }