package com.chuanghai.smartschool.tuitionpayment.controller; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.chuanghai.smartschool.tuitionpayment.anno.AdminLoginCheck; import com.chuanghai.smartschool.tuitionpayment.common.exception.BizCodeEnume; import com.chuanghai.smartschool.tuitionpayment.common.exception.RRException; import com.chuanghai.smartschool.tuitionpayment.common.utils.CommonResult; import com.chuanghai.smartschool.tuitionpayment.entity.PayDetailBank; import com.chuanghai.smartschool.tuitionpayment.entity.PayItem; import com.chuanghai.smartschool.tuitionpayment.service.PayItemService; import com.chuanghai.smartschool.tuitionpayment.vo.PayItemDetailVO; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; /** * @Author: bingo * @Date: 2022/6/22 星期三 14:36 * @Description: com.chuanghai.smartschool.tuitionpayment.controller * @version: 1.0 */ @RestController @RequestMapping("tuitionpayment/payitem") public class PayItemController { @Autowired private PayItemService payItemService; @Autowired private PayDetailBankController payDetailBankController; /** * 用于缴费项目的新增 * * @param adminToken 管理员token * @param jsonParam * @return */ @AdminLoginCheck @PostMapping("/insertPayItem") public CommonResult insertPayItem(@RequestHeader("admin_token") String adminToken, @RequestBody JSONObject jsonParam) { try { PayItem payItem = JSONObject.toJavaObject(jsonParam, PayItem.class); payItem.setItemAsk(Boolean.FALSE); payItem.setItemExcept(Boolean.FALSE); payItem.setItemAskDay("7"); payItem.setItemAskCount("2"); payItem.setRequestCount("0"); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("item_name", payItem.getItemName()); PayItem one = payItemService.getOne(wrapper); if (one != null) { throw new RRException(BizCodeEnume.PAY_ITEM_EXIST); } payItemService.saveOrUpdate(payItem); return CommonResult.ok(); } catch (NullPointerException n) { n.printStackTrace(); } return CommonResult.fail(); } /** * 查询所有缴费项目 * * @return */ @PostMapping("/queryPayItem") public CommonResult queryPayItem() { try { QueryWrapper wapper = new QueryWrapper<>(); wapper.eq("item_status", "1"); List payItemList = payItemService.list(wapper); return CommonResult.ok().setResult(payItemList); } catch (NullPointerException n) { n.printStackTrace(); } return CommonResult.fail(); } /** * 查询所有缴费项目 * * @return */ @PostMapping("/queryPayItemByName") public String queryPayItemByName(String name) { QueryWrapper wapper = new QueryWrapper<>(); wapper.eq("item_name", name); List list = payItemService.list(wapper); String itemAccount = ""; if (list.size() > 0) { PayItem payItem = list.get(0); itemAccount = payItem.getItemAccount(); String start = itemAccount.substring(0, 3); String end = itemAccount.substring(itemAccount.length() - 4); itemAccount = payItem.getItemBank() + " (" + start + "****" + end + ")"; } return itemAccount; } /** * 更新项目缴费配置 * adminToken 管理员token * * @param jsonObject 封装的缴费项目对象参数 * @return */ @AdminLoginCheck @PutMapping("/updatePayItem") public CommonResult updatePayItem(@RequestHeader("admin_token") String adminToken, @RequestBody JSONObject jsonObject) { PayItemDetailVO payItemDetailVO = JSONObject.toJavaObject(jsonObject, PayItemDetailVO.class); PayItem payItem = new PayItem(); PayDetailBank payDetailBank = new PayDetailBank(); BeanUtils.copyProperties(payItemDetailVO, payItem); BeanUtils.copyProperties(payItemDetailVO, payDetailBank); System.out.println(payDetailBank); System.out.println(payItem); //将催缴发送请求计数器归零 payItem.setRequestCount("0"); JSONObject payDetailBankJson = JSONObject.parseObject(payDetailBank.toString()); payDetailBankController.updatePayDetailBank(payDetailBankJson); boolean b = payItemService.updateById(payItem); return CommonResult.ok().setResult(b); } /** * 通过itemName 查询缴费项目的设置 * * @param itemName 缴费项目名称 * @return */ @GetMapping("/queryByItemNameSetting") public CommonResult queryByItemNameSetting( @RequestParam("itemName") String itemName) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("item_name", itemName); PayItem payItem = payItemService.getOne(wrapper); return CommonResult.ok().setResult(payItem); } }