ソースを参照

线路费用相关代码

chengang 4 年 前
コミット
6fc838fd71

+ 1 - 1
src/main/java/com/aoyang/tms/controller/TmsGasFeeController.java

@@ -30,7 +30,7 @@ import com.aoyang.common.param.PageParam;
 @RestController
 @Slf4j
 @Api(value = "tms_gas_feeCRUD接口")
-@RequestMapping("/strategy/tms_gas_fee")
+@RequestMapping("/tms/tms_gas_fee")
 public class TmsGasFeeController {
 
     @Resource

+ 99 - 15
src/main/java/com/aoyang/tms/controller/TmsLineCostController.java

@@ -1,7 +1,13 @@
 package com.aoyang.tms.controller;
 
 
+import com.alibaba.fastjson.JSON;
+import com.aoyang.tms.common.ErrCodeEnum;
+import com.aoyang.tms.controller.param.TmsLineCostAddParam;
 import com.aoyang.tms.entity.TmsLineCost;
+import com.aoyang.tms.entity.TmsLineCostOther;
+import com.aoyang.tms.entity.TruckDept;
+import com.aoyang.tms.entity.WorkSpot;
 import com.aoyang.tms.service.TmsLineCostService;
 import org.springframework.web.bind.annotation.*;
 
@@ -9,6 +15,10 @@ import org.springframework.web.bind.annotation.RestController;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.*;
 import lombok.extern.slf4j.Slf4j;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.time.LocalDateTime;
 import java.util.*;
 import javax.annotation.Resource;
 
@@ -21,8 +31,8 @@ import com.aoyang.common.param.PageParam;
 
 /**
  * <p>
-    * 线路费用表 控制器
-    * </p>
+ * 线路费用表 控制器
+ * </p>
  *
  * @author liujiren
  * @since 2022-04-23
@@ -30,31 +40,105 @@ import com.aoyang.common.param.PageParam;
 @RestController
 @Slf4j
 @Api(value = "tms_line_costCRUD接口")
-@RequestMapping("/strategy/tms_line_cost")
+@RequestMapping("/tms/tms_line_cost")
 public class TmsLineCostController {
 
     @Resource
     private TmsLineCostService tmsLineCostService;
 
-    @ApiOperation(value = "获取tms_line_cost列表",notes="")
-    @PostMapping("/list")
-    public Result list(@RequestBody PageParam<TmsLineCost> pageParam) {
+    @ApiOperation(value = "获取tms_line_cost分页列表", notes = "")
+    @PostMapping("/page_list")
+    public Result pageList(@RequestBody PageParam<TmsLineCost> pageParam) {
         Page<TmsLineCost> page = new Page<>(pageParam.getPage(), pageParam.getSize());
         IPage<TmsLineCost> records = tmsLineCostService.page(page, Wrappers.query(pageParam.getParam()));
         return new Result<>(records);
     }
 
-    @ApiOperation(value = "修改tms_line_cost",notes="根据id修改tms_line_cost")
-    @PostMapping("/update")
-    public Result update(@RequestBody TmsLineCost tmsLineCost) {
-        Boolean flag = tmsLineCostService.updateById(tmsLineCost);
-        return new Result<>(flag);
+    @ApiOperation(value = "获取线路费用列表", notes = "必传参数:CycleId,TruckId")
+    @PostMapping("/list")
+    public Result list(@RequestBody TmsLineCost param) {
+        log.info("获取线路费用列表,调用/tms/tms_line_cost/list,参数:{}", JSON.toJSONString(param));
+        if (param == null || param.getCycleId() == null || param.getTruckId() == null) {
+            return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
+        }
+        return new Result<>(tmsLineCostService.list(param));
     }
 
-    @ApiOperation(value = "添加tms_line_cost",notes="新增一条tms_line_cost")
+    @ApiOperation(value = "根据id获取线路费用详情", notes = "必传参数:Id")
+    @PostMapping("/get_one")
+    public Result getOne(@RequestBody TmsLineCost param) {
+        log.info("根据id获取线路费用详情,调用/tms/tms_line_cost/get_one,参数:{}", JSON.toJSONString(param));
+        if (param == null || param.getId() == null) {
+            return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
+        }
+        return new Result<>(tmsLineCostService.getOne(param));
+    }
+
+    @ApiOperation(value = "添加线路费用", notes = "必传参数:LineStart,LineEnd,Kilometre")
     @PostMapping("/add")
-    public Result add(@RequestBody TmsLineCost tmsLineCost) {
-        Boolean flag = tmsLineCostService.save(tmsLineCost);
-        return new Result<>(flag);
+    public Result add(@RequestHeader(value = "userId") Long userId,
+                      @RequestHeader(value = "userName") String userName,
+                      @RequestBody TmsLineCostAddParam param) {
+        log.info("添加线路费用,调用/tms/tms_line_cost/add,参数:{}", JSON.toJSONString(param));
+        if (param == null || param.getLineStart() == null || param.getLineEnd() == null || param.getKilometre() == null) {
+            return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
+        }
+        if (param.getList() != null && param.getList().size() > 0) {
+            for (TmsLineCostOther tmsLineCostOther : param.getList()) {
+                if (tmsLineCostOther.getCostName() == null || tmsLineCostOther.getCostName() == null) {
+                    return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
+                }
+            }
+        }
+
+        String utf8Name = userName;
+        try {
+            utf8Name = URLDecoder.decode(userName, "UTF-8");
+        } catch (UnsupportedEncodingException ignored) {
+        }
+        param.setCreater(userId);
+        param.setCreaterName(utf8Name);
+        param.setCreateDate(LocalDateTime.now());
+
+        return new Result<>(tmsLineCostService.add(param));
+    }
+
+    @ApiOperation(value = "修改线路费用", notes = "必传参数:id,tmsLineCostOther.id")
+    @PostMapping("/update")
+    public Result update(@RequestHeader(value = "userId") Long userId,
+                         @RequestHeader(value = "userName") String userName,
+                         @RequestBody TmsLineCostAddParam param) {
+        log.info("修改线路费用,调用/tms/tms_line_cost/update,参数:{}", JSON.toJSONString(param));
+        if (param == null || param.getId() == null) {
+            return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
+        }
+        if (param.getList() != null && param.getList().size() > 0) {
+            for (TmsLineCostOther tmsLineCostOther : param.getList()) {
+                if (tmsLineCostOther.getId() == null) {
+                    return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
+                }
+            }
+        }
+
+        String utf8Name = userName;
+        try {
+            utf8Name = URLDecoder.decode(userName, "UTF-8");
+        } catch (UnsupportedEncodingException ignored) {
+        }
+        param.setUpdater(userId);
+        param.setUpdaterName(utf8Name);
+        param.setUpdateDate(LocalDateTime.now());
+
+        return new Result<>(tmsLineCostService.update(param));
+    }
+
+    @ApiOperation(value = "删除线路费用", notes = "必传参数:id")
+    @PostMapping("/delete")
+    public Result delete(@RequestBody TmsLineCostAddParam param) {
+        log.info("删除线路费用,调用/tms/tms_line_cost/delete,参数:{}", JSON.toJSONString(param));
+        if (param == null || param.getId() == null) {
+            return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
+        }
+        return new Result<>(tmsLineCostService.delete(param));
     }
 }

+ 1 - 1
src/main/java/com/aoyang/tms/controller/TmsLineCostOtherController.java

@@ -30,7 +30,7 @@ import com.aoyang.common.param.PageParam;
 @RestController
 @Slf4j
 @Api(value = "tms_line_cost_otherCRUD接口")
-@RequestMapping("/strategy/tms_line_cost_other")
+@RequestMapping("/tms/tms_line_cost_other")
 public class TmsLineCostOtherController {
 
     @Resource

+ 1 - 1
src/main/java/com/aoyang/tms/controller/TmsOtherFeeController.java

@@ -30,7 +30,7 @@ import com.aoyang.common.param.PageParam;
 @RestController
 @Slf4j
 @Api(value = "tms_other_feeCRUD接口")
-@RequestMapping("/strategy/tms_other_fee")
+@RequestMapping("/tms/tms_other_fee")
 public class TmsOtherFeeController {
 
     @Resource

+ 15 - 0
src/main/java/com/aoyang/tms/controller/param/TmsLineCostAddParam.java

@@ -0,0 +1,15 @@
+package com.aoyang.tms.controller.param;
+
+import com.aoyang.tms.entity.TmsLineCost;
+import com.aoyang.tms.entity.TmsLineCostOther;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class TmsLineCostAddParam extends TmsLineCost implements Serializable {
+
+    private List<TmsLineCostOther> list;
+
+}

+ 14 - 0
src/main/java/com/aoyang/tms/controller/vo/TmsLineCostDetail.java

@@ -0,0 +1,14 @@
+package com.aoyang.tms.controller.vo;
+
+import com.aoyang.tms.entity.TmsLineCost;
+import com.aoyang.tms.entity.TmsLineCostOther;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class TmsLineCostDetail  extends TmsLineCost implements Serializable {
+
+    private List<TmsLineCostOther> list;
+}

+ 16 - 0
src/main/java/com/aoyang/tms/controller/vo/TmsLineCostListVO.java

@@ -0,0 +1,16 @@
+package com.aoyang.tms.controller.vo;
+
+import com.aoyang.tms.entity.TmsLineCost;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class TmsLineCostListVO extends TmsLineCost implements Serializable {
+
+    @ApiModelProperty(value = "线路费用总数")
+    private BigDecimal lineCostSum;
+
+}

+ 12 - 0
src/main/java/com/aoyang/tms/service/TmsLineCostOtherService.java

@@ -1,8 +1,12 @@
 package com.aoyang.tms.service;
 
+import com.aoyang.tms.controller.vo.TmsLineCostListVO;
+import com.aoyang.tms.entity.TmsLineCost;
 import com.aoyang.tms.entity.TmsLineCostOther;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +17,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface TmsLineCostOtherService extends IService<TmsLineCostOther> {
 
+    /**
+     * @return
+     * @Author chengang
+     * @Description 根据线路费用id获取线路费用其他费用列表
+     * @Date 2022/4/23
+     * @Param
+     **/
+    List<TmsLineCostOther> list(TmsLineCost param);
 }

+ 64 - 0
src/main/java/com/aoyang/tms/service/TmsLineCostService.java

@@ -1,8 +1,18 @@
 package com.aoyang.tms.service;
 
+import com.aoyang.common.param.PageParam;
+import com.aoyang.tms.controller.param.TmsLineCostAddParam;
+import com.aoyang.tms.controller.vo.TmsLineCostDetail;
+import com.aoyang.tms.controller.vo.TmsLineCostListVO;
+import com.aoyang.tms.controller.vo.TruckDeptListVO;
 import com.aoyang.tms.entity.TmsLineCost;
+import com.aoyang.tms.entity.TruckDept;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.math.BigDecimal;
+import java.util.List;
+
 /**
  * <p>
  * 线路费用表 服务类
@@ -13,4 +23,58 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface TmsLineCostService extends IService<TmsLineCost> {
 
+    /**
+     * @return
+     * @Author chengang
+     * @Description 获取线路费用列表
+     * @Date 2022/4/23
+     * @Param
+     **/
+    List<TmsLineCostListVO> list(TmsLineCost param);
+
+    /**
+     * @return
+     * @Author chengang
+     * @Description 获取线路费用总数
+     * @Date 2022/4/23
+     * @Param
+     **/
+    BigDecimal feeSum(TmsLineCost param);
+
+    /**
+     * @return
+     * @Author chengang
+     * @Description 获取单个线路费用
+     * @Date 2022/4/23
+     * @Param
+     **/
+    TmsLineCostDetail getOne(TmsLineCost param);
+
+    /**
+     * @return
+     * @Author chengang
+     * @Description 新增线路费用
+     * @Date 2022/4/23
+     * @Param
+     **/
+    boolean add(TmsLineCostAddParam param);
+
+    /**
+     * @return
+     * @Author chengang
+     * @Description 修改线路费用
+     * @Date 2022/4/23
+     * @Param
+     **/
+    boolean update(TmsLineCostAddParam param);
+
+    /**
+     * @return
+     * @Author chengang
+     * @Description 删除线路费用
+     * @Date 2022/4/23
+     * @Param
+     **/
+    boolean delete(TmsLineCostAddParam param);
+
 }

+ 13 - 0
src/main/java/com/aoyang/tms/service/impl/TmsLineCostOtherServiceImpl.java

@@ -1,12 +1,16 @@
 package com.aoyang.tms.service.impl;
 
 
+import com.aoyang.tms.entity.TmsLineCost;
 import com.aoyang.tms.entity.TmsLineCostOther;
 import com.aoyang.tms.mapper.TmsLineCostOtherMapper;
 import com.aoyang.tms.service.TmsLineCostOtherService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -18,4 +22,13 @@ import org.springframework.stereotype.Service;
 @Service
 public class TmsLineCostOtherServiceImpl extends ServiceImpl<TmsLineCostOtherMapper, TmsLineCostOther> implements TmsLineCostOtherService {
 
+    @Override
+    public List<TmsLineCostOther> list(TmsLineCost param) {
+        QueryWrapper<TmsLineCostOther> queryWrapper = new QueryWrapper<>();
+        if (param.getId() != null) {
+            queryWrapper.eq("line_cost_id", param.getId());
+        }
+        List<TmsLineCostOther> list = list(queryWrapper.orderByAsc("create_date"));
+        return list;
+    }
 }

+ 146 - 0
src/main/java/com/aoyang/tms/service/impl/TmsLineCostServiceImpl.java

@@ -1,11 +1,30 @@
 package com.aoyang.tms.service.impl;
 
 
+import com.alibaba.fastjson.JSON;
+import com.aoyang.common.result.Result;
+import com.aoyang.tms.common.ErrCodeEnum;
+import com.aoyang.tms.controller.param.TmsLineCostAddParam;
+import com.aoyang.tms.controller.vo.TmsLineCostDetail;
+import com.aoyang.tms.controller.vo.TmsLineCostListVO;
 import com.aoyang.tms.entity.TmsLineCost;
+import com.aoyang.tms.entity.TmsLineCostOther;
+import com.aoyang.tms.entity.TruckDept;
 import com.aoyang.tms.mapper.TmsLineCostMapper;
+import com.aoyang.tms.service.TmsLineCostOtherService;
 import com.aoyang.tms.service.TmsLineCostService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * <p>
@@ -16,6 +35,133 @@ import org.springframework.stereotype.Service;
  * @since 2022-04-23
  */
 @Service
+@Slf4j
 public class TmsLineCostServiceImpl extends ServiceImpl<TmsLineCostMapper, TmsLineCost> implements TmsLineCostService {
 
+    @Resource
+    private TmsLineCostOtherService tmsLineCostOtherService;
+
+    @Override
+    public List<TmsLineCostListVO> list(TmsLineCost param) {
+        QueryWrapper<TmsLineCost> queryWrapper = new QueryWrapper<>();
+        if (param.getCycleId() != null) {
+            queryWrapper.eq("cycle_id", param.getCycleId());
+        }
+        if (param.getTruckId() != null) {
+            queryWrapper.eq("truck_id", param.getTruckId());
+        }
+        List<TmsLineCost> list = list(queryWrapper.orderByAsc("create_date"));
+        List<TmsLineCostListVO> listVOS = new ArrayList<>();
+        for (TmsLineCost tmsLineCost : list) {
+            TmsLineCostListVO tmsLineCostListVO = new TmsLineCostListVO();
+            BeanUtils.copyProperties(tmsLineCost, tmsLineCostListVO);
+            tmsLineCostListVO.setLineCostSum(feeSum(tmsLineCost));
+
+            listVOS.add(tmsLineCostListVO);
+        }
+        return listVOS;
+    }
+
+    @Override
+    public BigDecimal feeSum(TmsLineCost param) {
+        BigDecimal feeSum = BigDecimal.ZERO;
+        if (param.getEtcFee() != null) {
+            feeSum = feeSum.add(param.getEtcFee());
+        }
+        if (param.getCash() != null) {
+            feeSum = feeSum.add(param.getCash());
+        }
+        if (param.getParkingFee() != null) {
+            feeSum = feeSum.add(param.getParkingFee());
+        }
+        List<TmsLineCostOther> list = tmsLineCostOtherService.list(param);
+        if (list != null && list.size() > 0) {
+            for (TmsLineCostOther tmsLineCostOther : list) {
+                if (tmsLineCostOther.getCostFee() != null) {
+                    feeSum = feeSum.add(tmsLineCostOther.getCostFee());
+                }
+            }
+        }
+        return feeSum;
+    }
+
+    @Override
+    public TmsLineCostDetail getOne(TmsLineCost param) {
+        TmsLineCostDetail tmsLineCostDetail = new TmsLineCostDetail();
+        TmsLineCost tmsLineCost = getById(param);
+        BeanUtils.copyProperties(tmsLineCost, tmsLineCostDetail);
+        List<TmsLineCostOther> list = tmsLineCostOtherService.list(param);
+        if (list != null && list.size() > 0) {
+            tmsLineCostDetail.setList(list);
+        }
+        return tmsLineCostDetail;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean add(TmsLineCostAddParam param) {
+        try {
+            TmsLineCost tmsLineCost = new TmsLineCost();
+            BeanUtils.copyProperties(param, tmsLineCost);
+            boolean flag = save(tmsLineCost);
+            if (param.getList() != null && param.getList().size() > 0) {
+                for (TmsLineCostOther tmsLineCostOther : param.getList()) {
+                    tmsLineCostOther.setLineCostId(tmsLineCost.getId());
+                    tmsLineCostOther.setCreater(tmsLineCost.getCreater());
+                    tmsLineCostOther.setCreaterName(tmsLineCost.getCreaterName());
+                    tmsLineCostOther.setCreateDate(tmsLineCost.getCreateDate());
+                    tmsLineCostOtherService.save(tmsLineCostOther);
+                }
+            }
+            return flag;
+        } catch (Exception e) {
+            log.error("新增线路费用失败,参数:{},错误信息:{}", JSON.toJSONString(param), e);
+            return false;
+        }
+
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean update(TmsLineCostAddParam param) {
+        try {
+            TmsLineCost tmsLineCost = new TmsLineCost();
+            BeanUtils.copyProperties(param, tmsLineCost);
+            boolean flag = updateById(tmsLineCost);
+            if (param.getList() != null && param.getList().size() > 0) {
+                for (TmsLineCostOther tmsLineCostOther : param.getList()) {
+                    tmsLineCostOther.setUpdater(param.getUpdater());
+                    tmsLineCostOther.setUpdaterName(param.getUpdaterName());
+                    tmsLineCostOther.setUpdateDate(param.getUpdateDate());
+                    tmsLineCostOtherService.updateById(tmsLineCostOther);
+                }
+            }
+            return flag;
+        } catch (Exception e) {
+            log.error("修改线路费用失败,参数:{},错误信息:{}", JSON.toJSONString(param), e);
+            return false;
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean delete(TmsLineCostAddParam param) {
+        try {
+            TmsLineCost tmsLineCost = new TmsLineCost();
+            BeanUtils.copyProperties(param, tmsLineCost);
+            boolean flag = removeById(tmsLineCost);
+
+            List<TmsLineCostOther> list = tmsLineCostOtherService.list(param);
+            if (list != null && list.size() > 0) {
+                for (TmsLineCostOther tmsLineCostOther : list) {
+                    tmsLineCostOtherService.removeById(tmsLineCostOther);
+                }
+            }
+            return flag;
+        } catch (Exception e) {
+            log.error("删除线路费用失败,参数:{},错误信息:{}", JSON.toJSONString(param), e);
+            return false;
+        }
+    }
+
 }