| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package cn.com.lzt.common.service.impl;
- import cn.com.lzt.common.entity.TSysFileEntity;
- import cn.com.lzt.common.service.TSysFileServiceI;
- import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
- import org.jeecgframework.core.util.ListUtils;
- import org.jeecgframework.core.util.ResourceUtil;
- import org.jeecgframework.core.util.StringUtil;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.io.File;
- import java.io.Serializable;
- import java.util.List;
- @Service("tSysFileService")
- @Transactional
- public class TSysFileServiceImpl extends CommonServiceImpl implements TSysFileServiceI {
-
- public void delete(TSysFileEntity entity) throws Exception{
- super.delete(entity);
- }
-
- public Serializable save(TSysFileEntity entity) throws Exception{
- List<TSysFileEntity> entities = getSysFileEntitiesByBusiId(entity.getBusiId(),entity.getTagetType());
- entity.setOrderNum((1+entities.size()));
- Serializable t = super.save(entity);
- return t;
- }
-
- public void saveOrUpdate(TSysFileEntity entity) throws Exception{
- super.saveOrUpdate(entity);
- }
- @Override
- public List<TSysFileEntity> getSysFileEntitiesByBusiId(String busiId,String tagetType) throws Exception {
- String hql = "from TSysFileEntity where 1=1 AND busiId =? AND tagetType =? ORDER BY createDate ";
- List<TSysFileEntity> entities = findHql(hql, new Object[] {busiId,tagetType});
- return entities;
- }
- @Override
- public void deleteByUrlPath(String urlpath) throws Exception {
- String hql = "from TSysFileEntity where 1=1 AND fileUrl =? ";
- List<TSysFileEntity> entities = findHql(hql, urlpath);
- deleteAllEntitie(entities);
- }
- @Override
- public void deleteByUrlPath(String urlpath, String busiId) throws Exception {
- String hql = "from TSysFileEntity where 1=1 AND fileUrl =? and busiId =? ";
- List<TSysFileEntity> entities = findHql(hql, urlpath, busiId);
- deleteAllEntitie(entities);
- }
-
- @Override
- public String getFileNameByurlPath(String urlpath) throws Exception {
- String hql = "from TSysFileEntity where 1=1 AND fileUrl =? ";
- List<TSysFileEntity> entities = findHql(hql, urlpath);
- if(ListUtils.isNullOrEmpty(entities))
- {
- return urlpath.substring(urlpath.lastIndexOf(File.separator)+1);
- }else{
- return entities.get(0).getFileName();
- }
- }
- @Override
- public void updateBusiId(String ids, String busiId) throws Exception {
- if (StringUtil.isNotEmpty(ids)&&StringUtil.isNotEmpty(busiId)) {
- String[] idlist = ids.split(",");
- for (int i = 0; i < idlist.length; i++) {
- TSysFileEntity tsysFileEntity = getEntity(TSysFileEntity.class, idlist[i]);
- tsysFileEntity.setBusiId(busiId);
- saveOrUpdate(tsysFileEntity);
- }
- }
- }
- @Override
- public void deleteByBusiId(String busiId, String tagetTypes) throws Exception {
- String[] tagetType = tagetTypes.split(",");
- String ctxPath = ResourceUtil.getConfigByName("webUploadpath");
- for (int j = 0; j < tagetType.length; j++) {
- List<TSysFileEntity> entities = getSysFileEntitiesByBusiId(busiId, tagetType[j]);
- for (int i = 0; i < entities.size(); i++) {
- TSysFileEntity entity = entities.get(i);
- String path = entity.getFileUrl();
- String delpath = ctxPath + File.separator + path;
- File fileDelete = new File(delpath);
- if (!fileDelete.exists() || !fileDelete.isFile()) {
- delete(entity);
- } else {
- if (fileDelete.delete()) {
- delete(entity);
- }
- }
- }
- }
- }
- @Override
- public void updateBusiIdWithTempBusiId(String tempBusiId, String busiId) throws Exception {
- String hql = "from TSysFileEntity where 1=1 AND busiId =? ";
- List<TSysFileEntity> entities = findHql(hql, tempBusiId);
- for (int i = 0; i < entities.size(); i++) {
- TSysFileEntity entity = entities.get(i);
- entity.setBusiId(busiId);
- saveOrUpdate(entity);
- }
- }
-
- }
|