123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package com.ruoyi.module.controller;
- import java.util.Date;
- import java.util.List;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.module.domain.*;
- import com.ruoyi.module.service.IBaseSettingService;
- import com.ruoyi.module.service.IIntegralBillService;
- import com.ruoyi.module.service.IUserService;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.enums.BusinessType;
- import com.ruoyi.module.service.IPunchCardService;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.common.core.page.TableDataInfo;
- /**
- * 打卡记录管理Controller
- *
- * @author zyl
- * @date 2021-10-08
- */
- @Controller
- @RequestMapping("/module/punchCard")
- public class PunchCardController extends BaseController {
- private String prefix = "module/punchCard";
- @Autowired
- private IPunchCardService punchCardService;
- @Autowired
- private IBaseSettingService baseSettingService;
- @Autowired
- private IUserService userService;
- @Autowired
- private IIntegralBillService integralBillService;
- @RequiresPermissions("module:punchCard:view")
- @GetMapping()
- public String punchCard() {
- return prefix + "/punchCard";
- }
- /**
- * 查询打卡记录管理列表
- */
- @RequiresPermissions("module:punchCard:list")
- @PostMapping("/list")
- @ResponseBody
- public TableDataInfo list(PunchCard punchCard) {
- startPage();
- List<PunchCard> list = punchCardService.selectPunchCardList(punchCard);
- return getDataTable(list);
- }
- /**
- * 导出打卡记录管理列表
- */
- @RequiresPermissions("module:punchCard:export")
- @Log(title = "打卡记录管理", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- @ResponseBody
- public AjaxResult export(PunchCard punchCard) {
- List<PunchCard> list = punchCardService.selectPunchCardList(punchCard);
- ExcelUtil<PunchCard> util = new ExcelUtil<PunchCard>(PunchCard.class);
- return util.exportExcel(list, "punchCard");
- }
- /**
- * 新增打卡记录管理
- */
- @GetMapping("/add")
- public String add() {
- return prefix + "/add";
- }
- /**
- * 新增保存打卡记录管理
- */
- @RequiresPermissions("module:punchCard:add")
- @Log(title = "打卡记录管理", businessType = BusinessType.INSERT)
- @PostMapping("/add")
- @ResponseBody
- public AjaxResult addSave(PunchCard punchCard) {
- return toAjax(punchCardService.insertPunchCard(punchCard));
- }
- /**
- * 修改打卡记录管理
- */
- @GetMapping("/edit/{id}")
- public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
- PunchCard punchCard = punchCardService.selectPunchCardById(id);
- mmap.put("punchCard", punchCard);
- return prefix + "/edit";
- }
- /**
- * 修改保存打卡记录管理
- */
- @RequiresPermissions("module:punchCard:edit")
- @Log(title = "打卡记录管理", businessType = BusinessType.UPDATE)
- @PostMapping("/edit")
- @ResponseBody
- public AjaxResult editSave(PunchCard punchCard) {
- return toAjax(punchCardService.updatePunchCard(punchCard));
- }
- /**
- * 删除打卡记录管理
- */
- @RequiresPermissions("module:punchCard:remove")
- @Log(title = "打卡记录管理", businessType = BusinessType.DELETE)
- @PostMapping("/remove")
- @ResponseBody
- public AjaxResult remove(String ids) {
- return toAjax(punchCardService.deletePunchCardByIds(ids));
- }
- @PostMapping(value = "/audit")
- @ResponseBody
- public AjaxResult audit(String id) {
- PunchCard punchCard = punchCardService.selectPunchCardById(Integer.valueOf(id));
- if (StringUtils.isNotNull(punchCard)) {
- punchCard.setAuditStatus(1);
- punchCardService.updatePunchCard(punchCard);
- BaseSetting baseSetting = baseSettingService.selectBaseSettingById(1);
- User user = userService.selectUserById(punchCard.getUserId());
- User bUser = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getCompanyId, punchCard.getCompanyId()));
- if (StringUtils.isNotNull(user) && StringUtils.isNotNull(bUser) && bUser.getIntegral() >= baseSetting.getClockIntegral()) {
- user.setIntegral(user.getIntegral() + baseSetting.getClockIntegral());
- userService.updateUser(user);
- bUser.setIntegral(bUser.getIntegral() - baseSetting.getClockIntegral());
- userService.updateUser(user);
- //用户增加积分,添加相应的打卡记录积分
- punchCard.setIntegral(baseSetting.getClockIntegral());
- punchCardService.updatePunchCard(punchCard);
- //积分记录
- IntegralBill integralBill = new IntegralBill();
- integralBill.setTitle("用户打卡奖励");
- integralBill.setAmount("+" + baseSetting.getClockIntegral());
- integralBill.setInOut(1);
- integralBill.setUid(user.getId());
- integralBill.setUname(user.getUserName());
- integralBill.setPhone(user.getPhone());
- integralBill.setCreateTime(new Date());
- integralBill.setType(4);
- integralBillService.save(integralBill);
- //企业消耗积分
- IntegralBill integralBills = new IntegralBill();
- integralBills.setTitle("用户打卡奖励消耗");
- integralBills.setAmount("-" + baseSetting.getClockIntegral());
- integralBills.setInOut(2);
- integralBills.setUid(bUser.getId());
- integralBills.setUname(bUser.getUserName());
- integralBills.setPhone(bUser.getPhone());
- integralBills.setCreateTime(new Date());
- integralBills.setType(4);
- integralBillService.save(integralBills);
- return AjaxResult.success();
- }
- }
- return AjaxResult.error();
- }
- @PostMapping(value = "/notAudit")
- @ResponseBody
- public AjaxResult notAudit(String id) {
- PunchCard punchCard = punchCardService.selectPunchCardById(Integer.valueOf(id));
- if (StringUtils.isNotNull(punchCard)) {
- punchCard.setAuditStatus(2);
- punchCardService.updatePunchCard(punchCard);
- return AjaxResult.success();
- }
- return AjaxResult.error();
- }
- }
|