package com.jsecode.esb.web.action;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jsecode.esb.common.BaseBusinessTool;
import com.jsecode.esb.model.protocol.hostEscrowVehicle.HostEscrowVehicleReq;
import com.jsecode.esb.service.HostEscrowVehicleService;
import com.jsecode.esb.util.DictionaryUtil;
import com.jsecode.platform.entity.BaseResp;
import com.jsecode.platform.util.Asserts;
/**
*
* 【代管车辆】
*
*
* @author jsecode01
* @date 2016年11月18日 上午11:15:09
* @version 1.0
*/
@Controller
@RequestMapping(value = "/clgl/host")
public class HostEscrowVehicleController extends BaseBusinessTool{
@Autowired
private HostEscrowVehicleService hostEscrowVehicleService;
/*
* 代管车辆新增接口
*/
@RequestMapping(value="/escrowVehicleAdd", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public BaseResp hostEscrowVehiclAdd(@RequestBody HostEscrowVehicleReq req) throws Exception {
return hostEscrowVehicleService.addHostEscrowVehicle(req);
}
/*
* 代管车辆查询接口
*/
@RequestMapping(value="/escrowVehicleSearch", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public BaseResp queryHostEscrowVehiclList(@RequestBody HostEscrowVehicleReq req) throws Exception {
ifNoSysDeptThenSetLoginUserSysDept(req);
return hostEscrowVehicleService.queryHostEscrowVehicleList(req);
}
/*
* 代管车辆修改接口
*/
@RequestMapping(value="/escrowVehicleUpdate", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public BaseResp updateHostEscrowVehicl(@RequestBody HostEscrowVehicleReq vehicle) throws Exception {
Asserts.notEmpty(vehicle.getVehicleid(), "修改失败:代管车辆主键编号(Vehicleid)参数值不能为空");
return hostEscrowVehicleService.updateHostEscrowVehicl(vehicle);
}
/*
* 代管车辆删除接口
*/
@RequestMapping(value="/escrowVehicleDelete", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public BaseResp deleteHostEscrowVehicle(@RequestBody List<String> idList) throws Exception {
Asserts.notEmpty(idList, "没有提供需要删除的数据");
return hostEscrowVehicleService.deleteHostEscrowVehicleList(idList);
}
/*
* 代管车辆详情接口
*/
@RequestMapping(value="/escrowVehicle/{vehicleid}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public BaseResp queryHostEscrowVehicle(@PathVariable String vehicleid) throws Exception {
return hostEscrowVehicleService.queryHostEscrowVehicle(vehicleid);
}
/*
* 代管车辆导入接口
*/
@RequestMapping(value="/escrowVehicleExcelImport", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public BaseResp hostEscrowVehicleExcelImport(@RequestBody List<HostEscrowVehicleReq> veList) throws Exception {
Asserts.notEmpty(veList, "没有提供导入数据");
DictionaryUtil.invertTranslate(veList);
return hostEscrowVehicleService.addHostEscrowVehicleExcelList(veList);
}
}
package com.jsecode.esb.service;
import java.util.List;
import com.jsecode.esb.model.protocol.hostEscrowVehicle.HostEscrowVehicleReq;
import com.jsecode.platform.entity.BaseResp;
public interface HostEscrowVehicleService {
BaseResp addHostEscrowVehicle(HostEscrowVehicleReq req);
BaseResp queryHostEscrowVehicleList(HostEscrowVehicleReq req);
BaseResp updateHostEscrowVehicl(HostEscrowVehicleReq vehicle);
BaseResp deleteHostEscrowVehicleList(List<String> idList);
BaseResp queryHostEscrowVehicle(String vehicleid);
BaseResp addHostEscrowVehicleExcelList(List<HostEscrowVehicleReq> veList);
}
package com.jsecode.esb.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jsecode.esb.common.Constant;
import com.jsecode.esb.db.dao.HostEscrowVehicleDao;
import com.jsecode.esb.db.dao.impl.SysConfigDAO;
import com.jsecode.esb.model.po.vm.ClglHostEscrowVehicle;
import com.jsecode.esb.model.protocol.hostEscrowVehicle.HostEscrowVehicleReq;
import com.jsecode.esb.model.protocol.po.login.LoginInfo;
import com.jsecode.esb.service.HostEscrowVehicleService;
import com.jsecode.esb.util.Common;
import com.jsecode.esb.util.DictionaryUtil;
import com.jsecode.esb.util.MemoryTable;
import com.jsecode.esb.util.PageQueryTemplet;
import com.jsecode.platform.entity.BaseResp;
import com.jsecode.platform.entity.DetailResp;
import com.jsecode.platform.entity.EcodeServiceException;
import com.jsecode.platform.util.Asserts;
import com.jsecode.platform.util.DateUtil;
import com.jsecode.platform.util.TypeUtil;
import com.jsecode.platform.util.Util;
@Service("hostEscrowVehicleService")
public class HostEscrowVehicleServiceImpl implements HostEscrowVehicleService {
@Autowired
private HostEscrowVehicleDao hostEscrowVehicleDao;
@Override
public BaseResp addHostEscrowVehicle(HostEscrowVehicleReq req){
Asserts.notEmpty(req.getAppSysId(), "车辆使用单位不能为空");
Asserts.notEmpty(req.getAppDeptId(), "车辆使用单位不能为空");
Asserts.notEmpty(req.getHostno(), "车辆号码不能为空");
if(haveSameHostId(req)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆编号["+req.getHostid()+"]不能重复");
}
if(haveSameHostno(req)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆号码["+req.getHostno()+"]不能重复");
}
if(haveSameXszh(req)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆行驶登记证["+req.getXszh()+"]不能重复");
}
if(haveSameEngineId(req)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆发动机号["+req.getEngineId()+"]不能重复");
}
if(haveSameHostVin(req)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆车架号["+req.getHostVin()+"]不能重复");
}
try{
if(!Util.isEmpty(req.getDisplacement())){
TypeUtil.toTargetTypeValue(req.getDisplacement(), Float.class);
}
} catch(Exception e) {
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "排量必须是数字");
}
//获取登录用户相关信息
MemoryTable memoryTable = MemoryTable.getInstance();
LoginInfo loginInfo = Common.getLoginInfo();
int createUserId = loginInfo.getAppUserInfo().getIntAppUserId();
String createUserName = loginInfo.getAppUserInfo().getUserName();
int createOrgId = loginInfo.getUserSysDept().getAppSysId();
int createDeptId = loginInfo.getUserSysDept().getAppDeptId();
String createOrgDeptName = memoryTable.getOrgDeptFullName(createOrgId, createDeptId);
ClglHostEscrowVehicle vehicel = new ClglHostEscrowVehicle();
vehicel.setHostid(req.getHostid());
vehicel.setHostno(req.getHostno());
vehicel.setAppSysId(req.getAppSysId());
vehicel.setAppDeptId(req.getAppDeptId());
vehicel.setXszh(req.getXszh());
vehicel.setHostVehType(req.getHostVehType());
vehicel.setHostBrand(req.getHostBrand());
vehicel.setDisplacement(req.getDisplacement());
vehicel.setVehiclearea(req.getVehiclearea());
vehicel.setVehicleproperty(req.getVehicleproperty());
vehicel.setEngineId(req.getEngineId());
vehicel.setHostVin(req.getHostVin());
vehicel.setYearlyinspectiontime(req.getYearlyinspectiontime());
vehicel.setRemark(req.getRemark());
vehicel.setCreateUserId(createUserId);
vehicel.setCreateUserName(createUserName);
vehicel.setCreateOrgId(createOrgId);
vehicel.setCreateDeptId(createDeptId);
vehicel.setCreateOrgDeptName(createOrgDeptName);
vehicel.setCreateTime(DateUtil.parseStrDateTime(SysConfigDAO.getSysConfigDAO().getOracleSysDate(true)));
hostEscrowVehicleDao.addHostEscrowVehicle(vehicel);
return BaseResp.success();
}
private boolean haveSameHostId(HostEscrowVehicleReq veh){
List<ClglHostEscrowVehicle> vehicelList = hostEscrowVehicleDao.findHostEscrowVehicleByHostId(veh.getHostid());
return Util.isNotEmpty(vehicelList);
}
private boolean haveSameHostno(HostEscrowVehicleReq veh){
List<ClglHostEscrowVehicle> vehicelList = hostEscrowVehicleDao.findHostEscrowVehicleByHostno(veh.getHostno());
return Util.isNotEmpty(vehicelList);
}
private boolean haveSameXszh(HostEscrowVehicleReq veh){
List<ClglHostEscrowVehicle> vehicelList = hostEscrowVehicleDao.findHostEscrowVehicleByXszh(veh.getXszh());
return Util.isNotEmpty(vehicelList);
}
private boolean haveSameEngineId(HostEscrowVehicleReq veh){
List<ClglHostEscrowVehicle> vehicelList = hostEscrowVehicleDao.findHostEscrowVehicleByEngineId(veh.getEngineId());
return Util.isNotEmpty(vehicelList);
}
private boolean haveSameHostVin(HostEscrowVehicleReq veh){
List<ClglHostEscrowVehicle> vehicelList = hostEscrowVehicleDao.findHostEscrowVehicleByHostVin(veh.getHostVin());
return Util.isNotEmpty(vehicelList);
}
@Override
public BaseResp queryHostEscrowVehicleList(final HostEscrowVehicleReq req){
return new PageQueryTemplet() {
@Override
protected List<?> list() throws Exception{
List<ClglHostEscrowVehicle> list = hostEscrowVehicleDao.queryHostEscrowVehicleList(req);
DictionaryUtil.translate(list);
return list;
}
@Override
protected long totalNum() throws Exception{
return hostEscrowVehicleDao.countHostEscrowVehicleListWhereSql(req);
}
}.query(req);
}
@Override
public BaseResp updateHostEscrowVehicl(HostEscrowVehicleReq vehicle){
Asserts.notEmpty(vehicle.getAppSysId(), "车辆使用单位不能为空");
Asserts.notEmpty(vehicle.getAppDeptId(), "车辆使用单位不能为空");
Asserts.notEmpty(vehicle.getHostno(), "车辆号码不能为空");
ClglHostEscrowVehicle oldVehicle = hostEscrowVehicleDao.findHostEscrowVehicleById(vehicle.getVehicleid());
Asserts.notEmpty(oldVehicle, "修改失败:查不到车辆维修记录");
if(Util.isNotEmpty(vehicle.getHostid()) && !vehicle.getHostid().equals(oldVehicle.getHostid()) && haveSameHostId(vehicle)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "["+vehicle.getHostid()+"]车辆编号不能重复");
}
if(!vehicle.getHostno().equals(oldVehicle.getHostno()) && haveSameHostno(vehicle)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆号码["+vehicle.getHostno()+"]不能重复");
}
if(Util.isNotEmpty(vehicle.getXszh()) &&!vehicle.getXszh().equals(oldVehicle.getXszh()) && haveSameXszh(vehicle)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆行驶登记证["+vehicle.getXszh()+"]不能重复");
}
if(Util.isNotEmpty(vehicle.getEngineId()) &&!vehicle.getEngineId().equals(oldVehicle.getEngineId()) &&haveSameEngineId(vehicle)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆发动机号["+vehicle.getEngineId()+"]不能重复");
}
if(Util.isNotEmpty(vehicle.getHostVin()) &&!vehicle.getHostVin().equals(oldVehicle.getHostVin()) && haveSameHostVin(vehicle)){
throw new EcodeServiceException(Constant.DATA_DUPLICUTE, "车辆车架号["+vehicle.getHostVin()+"]不能重复");
}
oldVehicle.setHostid(vehicle.getHostid());
oldVehicle.setHostno(vehicle.getHostno());
oldVehicle.setAppSysId(vehicle.getAppSysId());
oldVehicle.setAppDeptId(vehicle.getAppDeptId());
oldVehicle.setXszh(vehicle.getXszh());
oldVehicle.setHostVehType(vehicle.getHostVehType());
oldVehicle.setHostBrand(vehicle.getHostBrand());
oldVehicle.setDisplacement(vehicle.getDisplacement());
oldVehicle.setVehiclearea(vehicle.getVehiclearea());
oldVehicle.setVehicleproperty(vehicle.getVehicleproperty());
oldVehicle.setEngineId(vehicle.getEngineId());
oldVehicle.setHostVin(vehicle.getHostVin());
oldVehicle.setYearlyinspectiontime(vehicle.getYearlyinspectiontime());
oldVehicle.setRemark(vehicle.getRemark());
hostEscrowVehicleDao.updateHostEscrowVehicle(oldVehicle);
return BaseResp.success();
}
@Override
public BaseResp deleteHostEscrowVehicleList(List<String> idList){
hostEscrowVehicleDao.deleteHostEscrowVehicleList(idList);
return BaseResp.success();
}
@Override
public BaseResp queryHostEscrowVehicle(String vehicleid){
ClglHostEscrowVehicle ve = hostEscrowVehicleDao.findHostEscrowVehicleById(vehicleid);
if(!Util.isEmpty(ve)){
MemoryTable mem = MemoryTable.getInstance();
String sysName = mem.getSysDeptMap(ve.getAppSysId(), 0).getName();
String deptName = mem.getSysDeptMap(ve.getAppSysId(), ve.getAppDeptId()).getName();
ve.setAppSysName(sysName);
ve.setAppDeptName(deptName);
}
return DetailResp.build(ve);
}
@Override
public BaseResp addHostEscrowVehicleExcelList(List<HostEscrowVehicleReq> veList){
int reocrdRow = 0;
try {
for(HostEscrowVehicleReq req : veList){
reocrdRow++;
this.addHostEscrowVehicle(req);
}
}catch(Exception e) {
throw new RuntimeException("第["+reocrdRow+"]条记录,"+e.getMessage());
}
return BaseResp.success();
}
}
package com.jsecode.esb.db.dao;
import java.util.List;
import com.jsecode.esb.model.po.vm.ClglHostEscrowVehicle;
import com.jsecode.esb.model.protocol.hostEscrowVehicle.HostEscrowVehicleReq;
import com.jsecode.platform.spring3.hibernate3.dao.IBaseDao;
public interface HostEscrowVehicleDao extends IBaseDao<ClglHostEscrowVehicle, String> {
List<ClglHostEscrowVehicle> findHostEscrowVehicleByHostId(String hostid);
List<ClglHostEscrowVehicle> findHostEscrowVehicleByHostno(String hostno);
List<ClglHostEscrowVehicle> findHostEscrowVehicleByXszh(String xszh);
List<ClglHostEscrowVehicle> findHostEscrowVehicleByEngineId(String engineId);
List<ClglHostEscrowVehicle> findHostEscrowVehicleByHostVin(String hostVin);
void addHostEscrowVehicle(ClglHostEscrowVehicle vehicel);
List<ClglHostEscrowVehicle> queryHostEscrowVehicleList(HostEscrowVehicleReq req) throws Exception;
long countHostEscrowVehicleListWhereSql(HostEscrowVehicleReq req) throws Exception;
ClglHostEscrowVehicle findHostEscrowVehicleById(String vehicleid);
void updateHostEscrowVehicle(ClglHostEscrowVehicle oldVehicle);
void deleteHostEscrowVehicleList(List<String> idList);
}
package com.jsecode.esb.db.dao.impl;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.jsecode.esb.db.OrgDeptSearchFilter;
import com.jsecode.esb.db.dao.HostEscrowVehicleDao;
import com.jsecode.esb.model.po.vm.ClglHostEscrowVehicle;
import com.jsecode.esb.model.protocol.hostEscrowVehicle.HostEscrowVehicleReq;
import com.jsecode.platform.spring3.hibernate3.HibernateParams;
import com.jsecode.platform.spring3.hibernate3.dao.BaseHibernateDao;
import com.jsecode.platform.util.Util;
@Repository("hostEscrowVehicleDao")
public class HostEscrowVehicleDaoImpl extends BaseHibernateDao<ClglHostEscrowVehicle, String> implements HostEscrowVehicleDao {
@Override
public List<ClglHostEscrowVehicle> findHostEscrowVehicleByHostId(String hostid){
return findByProperty("hostid", hostid);
}
@Override
public List<ClglHostEscrowVehicle> findHostEscrowVehicleByHostno(String hostno){
return findByProperty("hostno", hostno);
}
@Override
public List<ClglHostEscrowVehicle> findHostEscrowVehicleByXszh(String xszh){
return findByProperty("xszh", xszh);
}
@Override
public List<ClglHostEscrowVehicle> findHostEscrowVehicleByEngineId(String engineId){
return findByProperty("engineId", engineId);
}
@Override
public List<ClglHostEscrowVehicle> findHostEscrowVehicleByHostVin(String hostVin){
return findByProperty("hostVin", hostVin);
}
@Override
public void addHostEscrowVehicle(ClglHostEscrowVehicle vehicel){
saveOrUpdate(vehicel);
}
@Override
public void updateHostEscrowVehicle(ClglHostEscrowVehicle oldVehicle){
saveOrUpdate(oldVehicle);
}
@Override
public List<ClglHostEscrowVehicle> queryHostEscrowVehicleList(HostEscrowVehicleReq req) throws Exception{
StringBuilder hql = new StringBuilder();
HibernateParams params = new HibernateParams();
hql.append("select * ");
hql.append("from CLGL_HOST_ESCROW_VEHICLE a ");
hql.append(getQueryHostEscrowVehicleListWhereSql(req, params));
hql.append("order by a.CREATE_TIME desc ");
return findBySql(hql.toString(), params.getParamObj(), req.getStartRow().intValue(), req.getMaxSize().intValue(), ClglHostEscrowVehicle.class);
}
@Override
public long countHostEscrowVehicleListWhereSql(HostEscrowVehicleReq req) throws Exception{
StringBuilder hql = new StringBuilder();
HibernateParams params = new HibernateParams();
hql.append("select count(1) ");
hql.append("from CLGL_HOST_ESCROW_VEHICLE a ");
hql.append(getQueryHostEscrowVehicleListWhereSql(req, params));
return findCountBySql(hql.toString(), params.getParamObj());
}
private Object getQueryHostEscrowVehicleListWhereSql(HostEscrowVehicleReq req, HibernateParams params) throws Exception{
StringBuilder sqlBuilder = new StringBuilder();
//使用单位
OrgDeptSearchFilter helper = createOrgDeptSearchFilter();
sqlBuilder.append(" and (a.APPSYSID, a.APPDEPTID) in (").append(helper.getMyViewSubDeptSql(req.getAppSysId(), req.getAppDeptId(), params)).append(") ");
//车牌号码
if (!Util.isEmpty(req.getHostno())) {
sqlBuilder.append(" and a.HOSTNO like ? ");
params.addParamObj("%"+req.getHostno().trim()+"%");
}
//编号
if (!Util.isEmpty(req.getHostid())) {
sqlBuilder.append(" and a.HOSTID like ? ");
params.addParamObj("%"+req.getHostid().trim()+"%");
}
//车辆性质
if (!Util.isEmpty(req.getVehicleproperty())) {
sqlBuilder.append(" and a.VEHICLEPROPERTY = ? ");
params.addParamObj(req.getVehicleproperty().trim());
}
/*//使用单位
if (Util.isIntGT(req.getAppSysId(), 0) || Util.isIntGT(req.getAppDeptId(), 0)) {
sqlBuilder.append(" and (a.APPSYSID = ? and a.APPDEPTID = ?) ");
params.addParamObj(req.getAppSysId());
params.addParamObj(req.getAppDeptId());
}*/
return sqlBuilder.toString().replaceFirst("and", "where");
}
protected OrgDeptSearchFilter createOrgDeptSearchFilter() {
return new OrgDeptSearchFilter();
}
@Override
public ClglHostEscrowVehicle findHostEscrowVehicleById(String vehicleid){
return findById(ClglHostEscrowVehicle.class, vehicleid);
}
@Override
public void deleteHostEscrowVehicleList(List<String> idList){
for(String id : idList){
StringBuilder hql = new StringBuilder();
hql.append("delete from CLGL_HOST_ESCROW_VEHICLE ");
hql.append("where VEHICLEID = ? ");
executeBySql(hql.toString(),new String[]{id} );
}
}
}