/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2019-08-13
 * 描述            ：企业纪事附件表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Slm.CompanyNew.impl;

import java.util.List;

import market.Com.pb.SpeOptBaseService;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.CompanyNew.mapper.SlmCompanyNewAnnexMapper;
import market.Slm.CompanyNew.service.SlmCompanyNewAnnexService;
import market.Slm.CompanyNew.vo.SlmCompanyNewAnnex;

import org.springframework.transaction.annotation.Transactional;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.service.support.PageModel;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@RemoteService(path="SlmCompanyNewAnnexService")
public class SlmCompanyNewAnnexServiceImpl extends BaseServiceImpl<SlmCompanyNewAnnex,Object> implements SlmCompanyNewAnnexService {
	public ResultModel doQueryWeb(CommonPage<SlmCompanyNewAnnex> sum){
		ResultModel rm=new ResultModel();
		SlmCompanyNewAnnex annex=sum.getObject();
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize();
		try{
			if(annex.getCompany_new_no()!=null&&!"".equals(annex.getCompany_new_no())){
				List<SlmCompanyNewAnnex> list=this.getMapper(SlmCompanyNewAnnexMapper.class).findWithCondition(annex, null, " annex_no desc", (pageIndex-1)*pageSize, pageSize);
				int count=this.getMapper(SlmCompanyNewAnnexMapper.class).countWithCondition(annex, null);
				PageModel<SlmCompanyNewAnnex> pm=new PageModel<SlmCompanyNewAnnex>(pageIndex,pageSize);
				pm.setRows(list);
				pm.setTotal(count);
				rm.setData(pm);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	} 
	
	public ResultModel doQueryOneWeb(CommonPage<SlmCompanyNewAnnex> sum){
		ResultModel rm=new ResultModel();
		SlmCompanyNewAnnex annex=sum.getObject();
		try{
			if(annex.getAnnex_no()!=null&&!"".equals(annex.getAnnex_no())){
				SlmCompanyNewAnnex ssa=this.getMapper(SlmCompanyNewAnnexMapper.class).findById(annex.getAnnex_no());
				rm.setData(ssa);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doDeleteWeb(CommonPage<SlmCompanyNewAnnex> sum) throws Exception{
		ResultModel rm=new ResultModel();
		SlmCompanyNewAnnex annex=sum.getObject();
		try{
			//File file = new File(PropertiesUtils.getImageProperties().getProperty("FileUrl")+annex.getAnnex_path());
			//file.delete();
			
			annex=this.getMapper(SlmCompanyNewAnnexMapper.class).findById(annex.getAnnex_no());
			if(annex==null){
				rm.setState("500");
				rm.setMsgInfo("该附件已被删除");
				return rm;
			}
			if(annex!=null){
				this.getBean(SpeOptBaseService.class).doDelete(annex.getAnnex_path());
			}

			this.getMapper(SlmCompanyNewAnnexMapper.class).delete(annex.getAnnex_no());
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("删除失败"+e.getMessage());
			e.printStackTrace();
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	} 
}
