GZMachinesWeb/.svn/pristine/b9/b9c46eae605b152e86986c064bb...

237 lines
6.3 KiB
Plaintext

package com.bonus.lease.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bonus.bm.service.subcontractorsService;
import com.bonus.lease.beans.AgreementBean;
import com.bonus.lease.beans.LeaseApplicationBean;
import com.bonus.lease.service.LeaseApplicationService;
import com.bonus.sys.AjaxRes;
import com.bonus.sys.BaseController;
import com.bonus.sys.GlobalConst;
import com.bonus.sys.Page;
import com.bonus.sys.UserShiroHelper;
import com.thoughtworks.xstream.alias.ClassMapper.Null;
@Controller
@RequestMapping("/backstage/lease/application/")
public class LeaseApplicationController extends BaseController<LeaseApplicationBean> {
@Autowired
private LeaseApplicationService service;
@Autowired
private subcontractorsService subService;
@RequestMapping("list")
public String index(Model model) {
return "/lease/leaseApplicationlist";
}
@RequestMapping(value = "findByPage", method = RequestMethod.POST)
@ResponseBody
public AjaxRes findByPage(Page<LeaseApplicationBean> page, LeaseApplicationBean o) {
AjaxRes ar = getAjaxRes();
try {
String companyId = UserShiroHelper.getRealCurrentUser().getCompanyId();
o.setCompanyId(companyId);
Page<LeaseApplicationBean> result = service.findByPage(o, page);
Map<String, Object> p = new HashMap<String, Object>();
p.put("list", result);
ar.setSucceed(p);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DATA_FAIL);
}
return ar;
}
/***
* 批量删除
* @param o
* @return
*/
@RequestMapping("deleteApply")
@ResponseBody
public AjaxRes deleteApply(LeaseApplicationBean o) {
Integer res = 0;
AjaxRes ar = getAjaxRes();
try {
String allId = o.getIds();
String[] ids = allId.split("-");
for(String id : ids) {
o.setId(id);
List<LeaseApplicationBean> list = service.getTaskDetails(o);
if (list.size() > 0) {
ar.setSucceedMsg("无法删除");
return ar;
}
res = service.deleteApply(o);
if (res == 1) {
ar.setSucceedMsg("删除成功");
} else {
ar.setFailMsg("删除失败");
}
}
} catch (Exception e) {
logger.error(e.toString(), e);
}
return ar;
}
@RequestMapping(value = "find", method = RequestMethod.POST)
@ResponseBody
public AjaxRes find(LeaseApplicationBean o) {
AjaxRes ar = getAjaxRes();
try {
List<LeaseApplicationBean> list = service.find(o);
LeaseApplicationBean station = list.get(0);
ar.setSucceed(station);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DATA_FAIL);
}
return ar;
}
//查询协议号
@RequestMapping(value = "findAgreeCode", method = RequestMethod.POST)
@ResponseBody
public AjaxRes findAgreeCode(AgreementBean o) {
AjaxRes ar = getAjaxRes();
try {
List<AgreementBean> list = service.findAgreeCode(o);
AgreementBean station = list.get(0);
ar.setSucceed(station);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DATA_FAIL);
}
return ar;
}
//根据协议获取最近一次领用方
@RequestMapping(value = "getSubInfo", method = RequestMethod.POST)
@ResponseBody
public AjaxRes getSubInfo(LeaseApplicationBean o) {
AjaxRes ar = getAjaxRes();
try {
List<LeaseApplicationBean> list = service.getSubInfo(o);
if(list!=null&&list.size()>0){
LeaseApplicationBean station = list.get(0);
ar.setSucceed(station);
}
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DATA_FAIL);
}
return ar;
}
//查询申请单号 和 分包商
@RequestMapping(value = "findApplyNumber", method = RequestMethod.POST)
@ResponseBody
public LeaseApplicationBean findApplyNumber(LeaseApplicationBean o) {
try {
o.setApplyNumber(service.findApplyNumber(o));
o.setSubcontractorsList(subService.findSubcontractors());
} catch (Exception e) {
logger.error(e.toString(), e);
}
return o;
}
@RequestMapping(value = "update", method = RequestMethod.POST)
@ResponseBody
public AjaxRes update(LeaseApplicationBean o) {
AjaxRes ar = getAjaxRes();
try {
/*String companyId = UserShiroHelper.getRealCurrentUser().getCompanyId();
o.setCompanyId(companyId);*/
service.update(o);
ar.setSucceedMsg(GlobalConst.UPDATE_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.UPDATE_FAIL);
}
return ar;
}
@RequestMapping(value = "addLeaseApply", method = RequestMethod.POST)
@ResponseBody
public AjaxRes add(HttpSession session,HttpServletRequest req,LeaseApplicationBean o) {
AjaxRes ar = getAjaxRes();
try {
service.addLeaseApply(o);
ar.setSucceedMsg(GlobalConst.SAVE_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(), e) ;
ar.setFailMsg(GlobalConst.SAVE_FAIL);
}
ar.setSucceed(o);
return ar;
}
//生成领料任务
@RequestMapping(value = "buildLeaseTask", method = RequestMethod.POST)
@ResponseBody
public AjaxRes buildLeaseTask(LeaseApplicationBean o) {
AjaxRes ar = getAjaxRes();
try {
service.buildLeaseTask(o);
ar.setSucceedMsg(GlobalConst.SAVE_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(), e) ;
ar.setFailMsg(GlobalConst.SAVE_FAIL);
}
ar.setSucceed(o);
return ar;
}
@RequestMapping(value = "del", method = RequestMethod.POST)
@ResponseBody
public AjaxRes del(LeaseApplicationBean o) {
AjaxRes ar = getAjaxRes();
try {
service.delete(o);
ar.setSucceedMsg(GlobalConst.DEL_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DEL_FAIL);
}
return ar;
}
@RequestMapping(value = "delBatch", method = RequestMethod.POST)
@ResponseBody
public AjaxRes delBatch(String chks) {
AjaxRes ar = getAjaxRes();
try {
// service.deleteBatch(chks);
ar.setSucceedMsg(GlobalConst.DEL_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DEL_FAIL);
}
return ar;
}
}