|
@@ -0,0 +1,257 @@
|
|
|
+package com.szwl.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.szwl.model.bo.R;
|
|
|
+import com.szwl.model.bo.ResponseModel;
|
|
|
+import com.szwl.model.entity.*;
|
|
|
+import com.szwl.service.TAdminService;
|
|
|
+import com.szwl.service.TEquipmentService;
|
|
|
+import com.szwl.service.TProportionCheckService;
|
|
|
+import com.szwl.service.TProportionService;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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 java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 分账表 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author wuhs
|
|
|
+ * @since 2022-05-10
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/tProportion")
|
|
|
+public class TProportionController {
|
|
|
+ @Autowired
|
|
|
+ TProportionCheckService tProportionCheckService;
|
|
|
+ @Autowired
|
|
|
+ TProportionService tProportionService;
|
|
|
+ @Autowired
|
|
|
+ TEquipmentService tEquipmentService;
|
|
|
+ @Autowired
|
|
|
+ TAdminService adminService;
|
|
|
+ @ApiOperation(value = "查找机器分销信息信息")
|
|
|
+ @PostMapping("/getOne")
|
|
|
+ public ResponseModel<?> findById(Long adminid, String clientId) {
|
|
|
+ TAdmin admin = adminService.getById(adminid);
|
|
|
+// if(!admin.getUsername().equals(username)){
|
|
|
+// return R.fail("username不符合!");
|
|
|
+// }
|
|
|
+ LambdaQueryWrapper<TProportion> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TProportion::getAdminId,adminid);
|
|
|
+ query.eq(TProportion::getClientId,clientId);
|
|
|
+ List<TProportion> list = tProportionService.list(query);
|
|
|
+ if(list.size()>0){
|
|
|
+ //已经注册,就要查看是否有提交审核的
|
|
|
+// LambdaQueryWrapper<TProportionCheck> query1 = Wrappers.lambdaQuery();
|
|
|
+// query1.eq(TProportionCheck::getAdminId,adminid);
|
|
|
+// query1.eq(TProportionCheck::getClientId,clientId);
|
|
|
+// List<TProportionCheck> list1 = tProportionCheckService.list(query1);
|
|
|
+// if(list1.size()>0){
|
|
|
+// int i = 0;
|
|
|
+// for(TProportionCheck tProportionCheck:list1){
|
|
|
+// if(tProportionCheck.getCheckType().equals("0")||tProportionCheck.getCheckType().equals("3")){
|
|
|
+// i++;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if(i==0){
|
|
|
+// return R.ok(list.get(0));
|
|
|
+// }else {
|
|
|
+// for(int j=list1.size()-1;j>=0;j--){
|
|
|
+// if(!list1.get(j).getCheckType().equals("2")&!list1.get(j).getCheckType().equals("1")){
|
|
|
+// if(list1.get(j).getCheckType().equals("3")){
|
|
|
+// Date data = new Date();
|
|
|
+// long time = data.getTime();
|
|
|
+// long updateTime = list1.get(j).getModifyDate().getTime();
|
|
|
+// if(3*24*60*60*1000l>time-updateTime){
|
|
|
+// //拒绝的审核,超过3天后不显示
|
|
|
+// return R.ok(list.get(0));
|
|
|
+// }else {
|
|
|
+// return R.ok(list.get(j));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return R.ok(list.get(j));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }else {
|
|
|
+// return R.ok(list.get(0));
|
|
|
+// }
|
|
|
+ TProportion tProportion = list.get(0);
|
|
|
+ if(tProportion.getAgencyId()!=null){
|
|
|
+ TAdmin admin1 = adminService.getById(tProportion.getAgencyId());
|
|
|
+ tProportion.setAgencyName(admin1.getUsername());
|
|
|
+ }
|
|
|
+ if(tProportion.getMerchantId()!=null){
|
|
|
+ TAdmin admin2 = adminService.getById(tProportion.getMerchantId());
|
|
|
+ tProportion.setAgencyName(admin2.getUsername());
|
|
|
+ }
|
|
|
+ if(tProportion.getPersonageId()!=null){
|
|
|
+ TAdmin admin3 = adminService.getById(tProportion.getId());
|
|
|
+ tProportion.setAgencyName(admin3.getUsername());
|
|
|
+ }
|
|
|
+ return R.ok(tProportion);
|
|
|
+ }else {
|
|
|
+ return R.fail("尚未注册!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "保存或提交审核")
|
|
|
+ @PostMapping("/save")
|
|
|
+ public ResponseModel<?> save(@RequestBody TProportion tProportion) {
|
|
|
+ if(tProportion.getAdminId()==null||StringUtils.isEmpty(tProportion.getClientId())){
|
|
|
+ R.fail("信息有空!");
|
|
|
+ }
|
|
|
+ TAdmin admin = adminService.getById(tProportion.getAdminId());
|
|
|
+ //查找机器,看改商家是否有该机器
|
|
|
+ LambdaQueryWrapper<TEquipment> query1 = Wrappers.lambdaQuery();
|
|
|
+ query1.eq(TEquipment::getAdminId,tProportion.getAdminId());
|
|
|
+ query1.eq(TEquipment::getClientId,tProportion.getClientId());
|
|
|
+ List<TEquipment> equipmentList = tEquipmentService.list(query1);
|
|
|
+ if(equipmentList.size()<=0){
|
|
|
+ R.fail("找不到该机器!");
|
|
|
+ }
|
|
|
+ TEquipment equipment = equipmentList.get(0);
|
|
|
+ //查看是否有审核中的
|
|
|
+ LambdaQueryWrapper<TProportionCheck> queryCheck = Wrappers.lambdaQuery();
|
|
|
+ queryCheck.eq(TProportionCheck::getAdminId,tProportion.getAdminId());
|
|
|
+ queryCheck.eq(TProportionCheck::getClientId,tProportion.getClientId());
|
|
|
+ queryCheck.eq(TProportionCheck::getCheckType,"0");
|
|
|
+ List<TProportionCheck> listCheck = tProportionCheckService.list(queryCheck);
|
|
|
+ if(listCheck.size()>0){
|
|
|
+ R.fail("已有审核,如需修改请先取消原来的审核!");
|
|
|
+ }
|
|
|
+ Long agencyId = null;
|
|
|
+ Long merchantId = null;
|
|
|
+ Long personageId = null;
|
|
|
+ //查找个分账人的id
|
|
|
+ if(tProportion.getType()>0){
|
|
|
+ //1个
|
|
|
+ LambdaQueryWrapper<TAdmin> queryTAdmin = Wrappers.lambdaQuery();
|
|
|
+ queryTAdmin.eq(TAdmin::getUsername,tProportion.getAgencyName());
|
|
|
+ List<TAdmin> admins = adminService.list(queryTAdmin);
|
|
|
+ if(admins.size()>0){
|
|
|
+ TAdmin tAdmin = admins.get(0);
|
|
|
+ agencyId = tAdmin.getAreaId();
|
|
|
+ }else {
|
|
|
+ R.fail("找不到第一个分账人!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(tProportion.getType()>1){
|
|
|
+ //2个
|
|
|
+ LambdaQueryWrapper<TAdmin> queryTAdmin1 = Wrappers.lambdaQuery();
|
|
|
+ queryTAdmin1.eq(TAdmin::getUsername,tProportion.getMerchantName());
|
|
|
+ List<TAdmin> admins1 = adminService.list(queryTAdmin1);
|
|
|
+ if(admins1.size()>0){
|
|
|
+ TAdmin tAdmin = admins1.get(0);
|
|
|
+ merchantId = tAdmin.getAreaId();
|
|
|
+ }else {
|
|
|
+ R.fail("找不到第二个分账人!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(tProportion.getType()>3){
|
|
|
+ //3个
|
|
|
+ LambdaQueryWrapper<TAdmin> queryTAdmin2 = Wrappers.lambdaQuery();
|
|
|
+ queryTAdmin2.eq(TAdmin::getUsername,tProportion.getPersonageId());
|
|
|
+ List<TAdmin> admins2 = adminService.list(queryTAdmin2);
|
|
|
+ if(admins2.size()>0){
|
|
|
+ TAdmin tAdmin = admins2.get(0);
|
|
|
+ personageId = tAdmin.getAreaId();
|
|
|
+ }else {
|
|
|
+ R.fail("找不到第三个分账人!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<TProportion> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TProportion::getAdminId,tProportion.getAdminId());
|
|
|
+ query.eq(TProportion::getClientId,tProportion.getClientId());
|
|
|
+ List<TProportion> list = tProportionService.list(query);
|
|
|
+ if(list.size()>0){
|
|
|
+ //已有,属于第二次提交信息,需要审核
|
|
|
+ TProportion oldProportion = list.get(0);
|
|
|
+ //已有,判断是否为99%和1%组合
|
|
|
+// if(tProportion.getProportion().compareTo(new BigDecimal("99"))==0&&tProportion.getAdminProportion().compareTo(new BigDecimal("1"))==0){
|
|
|
+// oldProportion.setAgencyId(agencyId);
|
|
|
+// oldProportion.setMerchantId(merchantId);
|
|
|
+// oldProportion.setPersonageId(personageId);
|
|
|
+// oldProportion.setAgencyProportion(BigDecimal.valueOf(0.00));
|
|
|
+// oldProportion.setMerchantProportion(BigDecimal.valueOf(0.00));
|
|
|
+// oldProportion.setPersonageProportion(BigDecimal.valueOf(0.00));
|
|
|
+// oldProportion.setModifyDate(new Date());
|
|
|
+// tProportionService.updateById(tProportion);
|
|
|
+// return R.ok("修改成功");
|
|
|
+// }else {
|
|
|
+ //提交审核
|
|
|
+ TProportionCheck proportionCheck = new TProportionCheck();
|
|
|
+ proportionCheck.setAdminId(tProportion.getAdminId());
|
|
|
+ proportionCheck.setEquipmentId(equipment.getId());
|
|
|
+ proportionCheck.setClientId(tProportion.getClientId());
|
|
|
+ proportionCheck.setType(tProportion.getType());
|
|
|
+ proportionCheck.setProportion(tProportion.getProportion());
|
|
|
+ proportionCheck.setAdminProportion(tProportion.getAdminProportion());
|
|
|
+ proportionCheck.setAgencyId(agencyId);
|
|
|
+ proportionCheck.setMerchantId(merchantId);
|
|
|
+ proportionCheck.setPersonageId(personageId);
|
|
|
+ proportionCheck.setAgencyProportion(tProportion.getAgencyProportion());
|
|
|
+ proportionCheck.setMerchantProportion(tProportion.getMerchantProportion());
|
|
|
+ proportionCheck.setPersonageProportion(tProportion.getPersonageProportion());
|
|
|
+ proportionCheck.setCreateDate(new Date());
|
|
|
+ proportionCheck.setModifyDate(new Date());
|
|
|
+ proportionCheck.setCheckType("0");
|
|
|
+ tProportionCheckService.save(proportionCheck);
|
|
|
+ return R.ok("已提交审核");
|
|
|
+// }
|
|
|
+ }else {
|
|
|
+ //没有,判断是否为99%和1%组合
|
|
|
+ if(tProportion.getProportion().compareTo(new BigDecimal("99"))==0&&tProportion.getAdminProportion().compareTo(new BigDecimal("1"))==0){
|
|
|
+ tProportion.setAgencyId(agencyId);
|
|
|
+ tProportion.setMerchantId(merchantId);
|
|
|
+ tProportion.setPersonageId(personageId);
|
|
|
+ tProportion.setAgencyProportion(BigDecimal.valueOf(0.00));
|
|
|
+ tProportion.setMerchantProportion(BigDecimal.valueOf(0.00));
|
|
|
+ tProportion.setPersonageProportion(BigDecimal.valueOf(0.00));
|
|
|
+ tProportion.setCreateDate(new Date());
|
|
|
+ tProportion.setModifyDate(new Date());
|
|
|
+ tProportionService.save(tProportion);
|
|
|
+ return R.ok("添加成功");
|
|
|
+ }else {
|
|
|
+ //提交审核
|
|
|
+ TProportionCheck proportionCheck = new TProportionCheck();
|
|
|
+ proportionCheck.setAdminId(tProportion.getAdminId());
|
|
|
+ proportionCheck.setEquipmentId(equipment.getId());
|
|
|
+ proportionCheck.setClientId(tProportion.getClientId());
|
|
|
+ proportionCheck.setType(tProportion.getType());
|
|
|
+ proportionCheck.setProportion(tProportion.getProportion());
|
|
|
+ proportionCheck.setAdminProportion(tProportion.getAdminProportion());
|
|
|
+ proportionCheck.setAgencyId(agencyId);
|
|
|
+ proportionCheck.setMerchantId(merchantId);
|
|
|
+ proportionCheck.setPersonageId(personageId);
|
|
|
+ proportionCheck.setAgencyProportion(tProportion.getAgencyProportion());
|
|
|
+ proportionCheck.setMerchantProportion(tProportion.getMerchantProportion());
|
|
|
+ proportionCheck.setPersonageProportion(tProportion.getPersonageProportion());
|
|
|
+ proportionCheck.setCreateDate(new Date());
|
|
|
+ proportionCheck.setModifyDate(new Date());
|
|
|
+ proportionCheck.setCheckType("0");
|
|
|
+ tProportionCheckService.save(proportionCheck);
|
|
|
+ return R.ok("已提交审核");
|
|
|
+ }
|
|
|
+// tProportion.setSettleableBalance(BigDecimal.valueOf(0.00));
|
|
|
+// tProportion.setCreateDate(new Date());
|
|
|
+// tProportion.setModifyDate(new Date());
|
|
|
+// tProportionService.save(tProportion);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|