xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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<CarRentalMapper, CarRental> implements ICarRentalService {
 
    @Autowired
    private ITCarBrandService carBrandService;
 
    @Autowired
    private ITRegionService regionService;
 
    @Autowired
    private IMessNumService messNumService;
 
    @Autowired
    private ITSystemNoticeService systemNoticeService;
 
 
 
    @Override
    public Map<String, Object> list(String createTime, String title, Integer brandId, String insertUser, List<Integer> 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<String, Object> map = new HashMap<>();
        List<Map<String, Object>> 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<TRegion>().eq("code", carRental.getProvinceCode()));
        carRental.setProvinceName(region.getName());
        region = regionService.selectOne(new EntityWrapper<TRegion>().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<TRegion>().eq("code", carRental.getProvinceCode()));
        carRental.setProvinceName(region.getName());
        region = regionService.selectOne(new EntityWrapper<TRegion>().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<MessNum>().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();
    }
 
}