package com.stylefeng.guns.modular.system.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.dao.CarRentalMapper; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.ResultUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class CarRentalServiceImpl extends ServiceImpl implements ICarRentalService { @Autowired private ITCarBrandService carBrandService; @Autowired private ITRegionService regionService; @Autowired private IMessNumService messNumService; @Autowired private ITSystemNoticeService systemNoticeService; @Override public Map list(String createTime, String title, Integer brandId, String insertUser, List status, Integer userType, Integer offset, Integer limit) throws Exception { Integer companyId = ShiroKit.getUser().getRoleType() == 1 ? null : ShiroKit.getUser().getObjectId(); String start = ""; String end = ""; if (ToolUtil.isNotEmpty(createTime)) { String[] split = createTime.split(" - "); start = split[0]; end = split[1]; } Map map = new HashMap<>(); List> list = this.baseMapper.list(companyId, start, end, title, brandId, insertUser, status, userType, offset, limit); int count = this.baseMapper.listCount(companyId, start, end, title, brandId, insertUser, status, userType); map.put("rows", list); map.put("total", count); return map; } @Override public ResultUtil addCarRental(CarRental carRental) throws Exception { carRental.setUserType(3); carRental.setUserId(ShiroKit.getUser().getObjectId()); TCarBrand tCarBrand = carBrandService.selectById(carRental.getBrandId()); carRental.setBrandName(tCarBrand.getName()); TRegion region = regionService.selectOne(new EntityWrapper().eq("code", carRental.getProvinceCode())); carRental.setProvinceName(region.getName()); region = regionService.selectOne(new EntityWrapper().eq("code", carRental.getCityCode())); carRental.setCityName(region.getName()); carRental.setCreateTime(new Date()); carRental.setFirstPageShow(2); carRental.setInsertUser(ShiroKit.getUser().getId()); if (ShiroKit.getUser().getRoleType() == 1 && carRental.getStatus() == 1) { carRental.setStatus(4); } this.insert(carRental); return ResultUtil.success(); } @Override public ResultUtil updateCarRental(CarRental carRental) throws Exception { TCarBrand tCarBrand = carBrandService.selectById(carRental.getBrandId()); carRental.setBrandName(tCarBrand.getName()); TRegion region = regionService.selectOne(new EntityWrapper().eq("code", carRental.getProvinceCode())); carRental.setProvinceName(region.getName()); region = regionService.selectOne(new EntityWrapper().eq("code", carRental.getCityCode())); carRental.setCityName(region.getName()); this.updateById(carRental); return ResultUtil.success(); } @Override public ResultUtil auditCarRental(Integer id, Integer status, String authRemark) throws Exception { CarRental carRental = this.selectById(id); if(carRental.getStatus() != 1){ return ResultUtil.error("不允许重复操作"); } carRental.setStatus(status); carRental.setAuthRemark(authRemark); this.updateById(carRental); MessNum messNum = messNumService.selectOne(new EntityWrapper().eq("userType", carRental.getUserType()) .eq("userId", carRental.getUserId())); if(null == messNum){ messNum = new MessNum(); messNum.setUserType(carRental.getUserType()); messNum.setUserId(carRental.getUserId()); messNum.setCarRental(1); messNumService.insert(messNum); }else{ messNum.setCarRental((null == messNum.getCarRental() ? 0 : messNum.getCarRental()) + 1); messNumService.updateById(messNum); } TSystemNotice systemNotice = new TSystemNotice(); systemNotice.setType(2); systemNotice.setUserType(carRental.getUserType()); systemNotice.setContent("您提交的租车申请审核" + (status == 4 ? "通过" : "拒绝")); systemNotice.setUserId(carRental.getUserId()); systemNotice.setInsertTime(new Date()); systemNotice.setRead(1); systemNoticeService.insert(systemNotice); return ResultUtil.success(); } }