|
@@ -1,10 +1,25 @@
|
|
|
package com.huimv.farm.damsubsidy.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.huimv.farm.damsubsidy.common.utils.PageUtils;
|
|
|
+import com.huimv.farm.damsubsidy.common.utils.Result;
|
|
|
+import com.huimv.farm.damsubsidy.common.utils.ResultCode;
|
|
|
+import com.huimv.farm.damsubsidy.entity.BaseFarmerTypeInfo;
|
|
|
+import com.huimv.farm.damsubsidy.service.IBaseFarmerTypeInfoService;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 前端控制器
|
|
@@ -16,5 +31,76 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RestController
|
|
|
@RequestMapping("/base-farmer-type-info")
|
|
|
public class BaseFarmerTypeInfoController {
|
|
|
+ @Resource
|
|
|
+ private IBaseFarmerTypeInfoService baseFarmerTypeInfoService;
|
|
|
+
|
|
|
+ @PostMapping("/addType")
|
|
|
+ public Result addType(@RequestBody Map map){
|
|
|
+ String typeName = (String) map.get("typeName");
|
|
|
+ Integer farmerType = (Integer) map.get("farmerType");
|
|
|
+ Integer animalType = (Integer) map.get("animalType");
|
|
|
+ BigDecimal rewardMoney = (BigDecimal) map.get("rewardMoney");
|
|
|
+ BaseFarmerTypeInfo farmerTypeInfo = baseFarmerTypeInfoService.getOne(new QueryWrapper<BaseFarmerTypeInfo>().eq("farmer_type", farmerType).eq("animal_type", animalType));
|
|
|
+ if (ObjectUtil.isNotEmpty(farmerTypeInfo)){
|
|
|
+ return new Result(10001,"类别已存在!",false);
|
|
|
+ }
|
|
|
+ BaseFarmerTypeInfo baseFarmerTypeInfo = new BaseFarmerTypeInfo();
|
|
|
+ baseFarmerTypeInfo.setTypeName(typeName);
|
|
|
+ baseFarmerTypeInfo.setFarmerType(farmerType);
|
|
|
+ baseFarmerTypeInfo.setAnimalType(animalType);
|
|
|
+ baseFarmerTypeInfo.setRewardMoney(rewardMoney);
|
|
|
+ baseFarmerTypeInfoService.save(baseFarmerTypeInfo);
|
|
|
+ return Result.SUCCESS();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/listType")
|
|
|
+ public Result listType(@RequestBody Map map){
|
|
|
+ return new Result(ResultCode.SUCCESS,baseFarmerTypeInfoService.page(PageUtils.getPage(map)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/deleteType")
|
|
|
+ public Result deleteType(@RequestBody Map map){
|
|
|
+ String id = (String) map.get("id");
|
|
|
+ if (baseFarmerTypeInfoService.removeById(id)) {
|
|
|
+ return Result.SUCCESS();
|
|
|
+ }else {
|
|
|
+ return Result.ERROR();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/updateType")
|
|
|
+ public Result updateType(@RequestBody Map map){
|
|
|
+ String id = (String) map.get("id");
|
|
|
+ String typeName = (String) map.get("typeName");
|
|
|
+ Integer farmerType = (Integer) map.get("farmerType");
|
|
|
+ Integer animalType = (Integer) map.get("animalType");
|
|
|
+ BigDecimal rewardMoney = (BigDecimal) map.get("rewardMoney");
|
|
|
+ BaseFarmerTypeInfo farmerTypeInfo = baseFarmerTypeInfoService.getOne(new QueryWrapper<BaseFarmerTypeInfo>().eq("farmer_type", farmerType).eq("animal_type", animalType).ne("id",id));
|
|
|
+ if (ObjectUtil.isNotEmpty(farmerTypeInfo)){
|
|
|
+ return new Result(10001,"类别已存在!",false);
|
|
|
+ }
|
|
|
+ BaseFarmerTypeInfo editFarmerTypeInfo = baseFarmerTypeInfoService.getById(id);
|
|
|
+ editFarmerTypeInfo.setTypeName(typeName);
|
|
|
+ editFarmerTypeInfo.setAnimalType(animalType);
|
|
|
+ editFarmerTypeInfo.setFarmerType(farmerType);
|
|
|
+ editFarmerTypeInfo.setRewardMoney(rewardMoney);
|
|
|
+ if (baseFarmerTypeInfoService.updateById(editFarmerTypeInfo)) {
|
|
|
+ return Result.SUCCESS();
|
|
|
+ }else {
|
|
|
+ return Result.ERROR();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getRewardMoney")
|
|
|
+ public Result getRewardMoney(@RequestBody Map map){
|
|
|
+ Integer rewardNum = (Integer) map.get("rewardNum");
|
|
|
+ Integer farmerType = (Integer) map.get("farmerType");
|
|
|
+ Integer animalType = (Integer) map.get("animalType");
|
|
|
+ BaseFarmerTypeInfo baseFarmerTypeInfo = baseFarmerTypeInfoService.getOne(new QueryWrapper<BaseFarmerTypeInfo>().eq("farmer_type", farmerType).eq("animal_type", animalType));
|
|
|
+ if (ObjectUtil.isEmpty(baseFarmerTypeInfo)){
|
|
|
+ return new Result(10001,"奖补类型不存在",false);
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS,baseFarmerTypeInfo.getRewardMoney().multiply(BigDecimal.valueOf(rewardNum)));
|
|
|
+ }
|
|
|
|
|
|
}
|