package market.Lms.FixedAssets.impl;


import java.util.ArrayList;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.FixedAssets.mapper.LmsFixedAssetsInfoMapper;
import market.Lms.FixedAssets.service.LmsFixedAssetsInfoService;
import market.Lms.FixedAssets.vo.LmsFixedAssetsInfo;

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

@RemoteService(path="LmsFixedAssetsInfo")
public class LmsFixedAssetsInfoServiceImpl extends BaseServiceImpl<LmsFixedAssetsInfo,Object> implements LmsFixedAssetsInfoService{

	//==========================================逻辑方法==============================================
	//新增
	public String doAdd(LmsFixedAssetsInfo ofai){
		String snCode = ofai.getSn_code();
		//新增时将产品的状态设置为1空闲
		ofai.setValid_flag("1");
		this.getMapper(LmsFixedAssetsInfoMapper.class).insert(ofai);
		return snCode;
	}

	//删除
	public void doDelete(LmsFixedAssetsInfo ofai){
		this.getMapper(LmsFixedAssetsInfoMapper.class).delete(ofai.getSn_code());
	}

	//修改
	public void doUpdate(LmsFixedAssetsInfo ofai){
		this.getMapper(LmsFixedAssetsInfoMapper.class).update(ofai);
	}

	//查询
	public LmsFixedAssetsInfo doQuery(String snCode){
		LmsFixedAssetsInfo ofai = new LmsFixedAssetsInfo();
		ofai = this.getMapper(LmsFixedAssetsInfoMapper.class).findById(snCode);
		return ofai;
	}
	//==========================================逻辑方法==============================================

	//===========================================web端==============================================
	//资产列表查询根据（资产类别）
	public ResultModel doQueryWeb(CommonPage<LmsFixedAssetsInfo> sum){
		ResultModel rm = new ResultModel();
		String flag = sum.getMemo1();
		int pageIndex = sum.getPageIndex();
		int pageSize = sum.getPageSize();
		List<LmsFixedAssetsInfo> assetsList = new ArrayList<LmsFixedAssetsInfo>();
		PageModel<LmsFixedAssetsInfo> pm=new PageModel<LmsFixedAssetsInfo>(pageIndex, pageSize);
		int count = 0;
		String sWhere = "";
		try{
			if(flag != null && !flag.isEmpty()){
				switch (Integer.parseInt(flag)) {
				case 1: //1代表领用 查询空闲状态
					sWhere = "valid_flag = '1'";
					break;
				case 2://2代表退库 查询使用状态
					sWhere = "valid_flag = '2'";
					break;
				case 3://3代表借用 查询使用状态
					sWhere = "valid_flag = '2'";
					break;
				case 4://4代表归还 查询借用状态
					sWhere = "valid_flag = '4'";
					break;
				case 5://5代表维修 查询不是报废与维修的都能维修
					sWhere = "valid_flag not in ('3','5')";
					break;
				case 6://6代表报废  查询不是报废状态的都能报废
					sWhere = "valid_flag not in ('3')";
					break;
				case 7://7代表变更 查询空闲状态下的资产列表
					sWhere = "valid_flag = '1'";
					break;
				default:
					break;
				}
			}else{
				sWhere = null;
			}
			assetsList = this.getMapper(LmsFixedAssetsInfoMapper.class).findWithCondition(sum.getObject(), sWhere, null, (pageIndex-1)*pageSize, pageSize);
			count = this.getMapper(LmsFixedAssetsInfoMapper.class).countWithCondition(sum.getObject(), sWhere);
			pm.setRows(assetsList);
			pm.setTotal(count);
			rm.setData(pm);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
		}
		return rm;
	}

	//===========================================app端==============================================
	//资产列表查询根据（资产类别）
	public List<LmsFixedAssetsInfo> doQueryApp(CommonPage<LmsFixedAssetsInfo> sum){
		String flag = sum.getMemo1();
		int pageIndex = sum.getPageIndex();
		int pageSize = sum.getPageSize();
		List<LmsFixedAssetsInfo> assetsList = new ArrayList<LmsFixedAssetsInfo>();
		String sWhere = "";
		try{
			if(flag != null && !flag.isEmpty()){
				switch (Integer.parseInt(flag)) {
				case 1: //1代表领用 查询空闲状态
					sWhere = "valid_flag = '1'";
					break;
				case 2://2代表退库 查询使用状态
					sWhere = "valid_flag = '2'";
					break;
				case 3://3代表借用 查询使用状态
					sWhere = "valid_flag = '2'";
					break;
				case 4://4代表归还 查询借用状态
					sWhere = "valid_flag = '4'";
					break;
				case 5://5代表维修 查询不是报废与维修的都能维修
					sWhere = "valid_flag not in ('3','5')";
					break;
				case 6://6代表报废  查询不是报废状态的都能报废
					sWhere = "valid_flag not in ('3')";
					break;
				case 7://7代表变更 查询空闲状态下的资产列表
					sWhere = "valid_flag = '1'";
					break;
				default:
					break;
				}
			}else{
				sWhere = null;
			}
			assetsList = this.getMapper(LmsFixedAssetsInfoMapper.class).findWithCondition(sum.getObject(), sWhere, null, pageIndex, pageSize);
		}catch(Exception e){
			return new ArrayList<LmsFixedAssetsInfo>();
		}
		return assetsList;
	}

}
