commit
This commit is contained in:
+165
@@ -0,0 +1,165 @@
|
||||
package com.budwk.app.zhgh.staffbenefit.blessing.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.DateUtil;
|
||||
import com.budwk.app.sys.models.Sys_task;
|
||||
import com.budwk.app.sys.services.SysTaskService;
|
||||
import com.budwk.app.task.services.TaskPlatformService;
|
||||
import com.budwk.app.zhgh.staffbenefit.blessing.models.Blessing;
|
||||
import com.budwk.app.zhgh.staffbenefit.blessing.models.BlessingUser;
|
||||
import com.budwk.app.zhgh.staffbenefit.blessing.service.BlessingService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.trans.Trans;
|
||||
import org.quartz.CronExpression;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@IocBean
|
||||
@Ok("json")
|
||||
@ApiOperation("职工祝福")
|
||||
@At("/platform/blessing/applyList")
|
||||
public class BlessingController {
|
||||
|
||||
@Inject
|
||||
private BlessingService blessingService;
|
||||
|
||||
@Inject
|
||||
private TaskPlatformService taskPlatformService;
|
||||
|
||||
@Inject
|
||||
private SysTaskService sysTaskService;
|
||||
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhgh/staffbenefit/blessing/applyList.html")
|
||||
@SaCheckPermission("blessing.applyList")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@SaCheckPermission("blessing.applyList")
|
||||
public Result pageData(PageForm pageForm, String blessingName) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
bl.*,
|
||||
aus.groupName
|
||||
FROM
|
||||
`blessing` bl
|
||||
LEFT JOIN activity_user_scope aus ON aus.groupId = bl.activityGroupId
|
||||
$condition
|
||||
""");
|
||||
if (Strings.isNotBlank(blessingName)) {
|
||||
cnd.where().andLike("bl.blessingName", blessingName);
|
||||
}
|
||||
cnd.groupBy("aus.groupId");
|
||||
sql.setCondition(cnd);
|
||||
return Result.success(blessingService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql));
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("blessing.applyList")
|
||||
public Result doAdd(@Param("Blessing") Blessing blessing) {
|
||||
blessing.setApplyDate(DateUtil.getDate());
|
||||
blessingService.insert(blessing);
|
||||
if (blessing.getIsSend().equals("1")) {
|
||||
blessingService.addTask(blessing);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("blessing.applyList")
|
||||
public Result doEdit(@Param("Blessing") Blessing blessing) {
|
||||
if (Strings.isNotBlank(blessing.getBlessingCron()) && !blessing.getBlessingCron().equals("* * * * * ? *")) {
|
||||
blessing.setApplyDate(DateUtil.getDate());
|
||||
blessingService.updateIgnoreNull(blessing);
|
||||
if (blessing.getIsSend().equals("1")) {
|
||||
blessingService.editTask(blessing);
|
||||
}
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("blessing.applyList")
|
||||
public Result doDelete(String id) {
|
||||
blessingService.delete(id);
|
||||
Sys_task sysTask = sysTaskService.fetch(Cnd.where("name", "=", id));
|
||||
blessingService.dao().clear(BlessingUser.class, Cnd.where("blessingId", "=", id));
|
||||
if (sysTask != null) {
|
||||
taskPlatformService.delete(sysTask.getId(), sysTask.getId());
|
||||
sysTaskService.delete(sysTask.getId());
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("blessing.applyList")
|
||||
public Result findOne(String id) {
|
||||
try {
|
||||
Blessing blessing = blessingService.fetch(id);
|
||||
NutMap nutMap = NutMap.WRAP(JSON.parseObject(JSON.toJSONString(blessing)));
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
CronExpression cronExpression = new CronExpression(nutMap.getString("blessingCron"));
|
||||
Date lastTime = new Date();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
lastTime = cronExpression.getNextValidTimeAfter(lastTime);
|
||||
if (lastTime != null) {
|
||||
result.add(DateUtil.formatDateTime(lastTime));
|
||||
} else {
|
||||
String[] newStr = nutMap.getString("blessingCron").split(" ");
|
||||
String second = (newStr[0].equals("?") || newStr[0].equals("*")) ? "00" : newStr[0];
|
||||
String minute = (newStr[1].equals("?") || newStr[1].equals("*")) ? "00" : newStr[1];
|
||||
String hour = (newStr[2].equals("?") || newStr[2].equals("*")) ? "00" : newStr[2];
|
||||
String day = (newStr[3].equals("?") || newStr[3].equals("*")) ? "00" : newStr[3];
|
||||
String month = (newStr[4].equals("?") || newStr[4].equals("*")) ? "00" : newStr[4];
|
||||
String s6 = (newStr[5].equals("?") || newStr[5].equals("*")) ? "00" : newStr[5];
|
||||
String year = (newStr[6].equals("?") || newStr[6].equals("*")) ? "00" : newStr[6];
|
||||
String Time = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second;
|
||||
result.add(Time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
nutMap.setv("blessingDate", result);
|
||||
return Result.success(nutMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package com.budwk.app.zhgh.staffbenefit.blessing.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.zhgh.staffbenefit.blessing.service.BlessingService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
@At("/platform/blessing/userList")
|
||||
public class BlessingUserController {
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhgh/staffbenefit/blessing/blessingUser.html")
|
||||
@SaCheckPermission("blessing.user")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@Inject
|
||||
private BlessingService blessingService;
|
||||
|
||||
|
||||
@At
|
||||
@SaCheckPermission("blessing.user")
|
||||
public Result pageData(PageForm pageForm, String data, String unionId, String unitId, String personType, String userState, String sex, String blessingName) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.personType,
|
||||
u.userState,
|
||||
u.unionname,
|
||||
u.unitname,
|
||||
u.birthday,
|
||||
blu.*,
|
||||
bl.blessingName
|
||||
FROM
|
||||
blessing_user blu
|
||||
LEFT JOIN blessing bl ON bl.id = blu.blessingId
|
||||
LEFT JOIN `user` u ON u.id = blu.userId
|
||||
$condition
|
||||
""");
|
||||
if (Strings.isNotBlank(pageForm.getSearchKeyword()) && Strings.isNotBlank(pageForm.getSearchName())) {
|
||||
cnd.where().andLike(pageForm.getSearchName(), pageForm.getSearchKeyword());
|
||||
}
|
||||
if (Strings.isNotBlank(blessingName)) {
|
||||
cnd.where().andLike("bl.blessingName", blessingName);
|
||||
}
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("u.personType", "=", personType);
|
||||
cnd.andEX("u.userState", "=", userState);
|
||||
cnd.andEX("u.sex", "=", sex);
|
||||
cnd.andEX("blu.applyDate", "=", data);
|
||||
cnd.desc("blu.blessingId");
|
||||
cnd.desc("blu.applyDate");
|
||||
cnd.desc("u.unitid");
|
||||
sql.setCondition(cnd);
|
||||
return Result.success(blessingService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.budwk.app.zhgh.staffbenefit.blessing.models;
|
||||
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Table
|
||||
public class Blessing extends BaseModel {
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@Comment("id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Prev(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
|
||||
@Column
|
||||
@Comment("祝福名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String blessingName;
|
||||
|
||||
@Column
|
||||
@Comment("发送范围")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String activityGroupId;
|
||||
|
||||
@Column
|
||||
@Comment("祝福模式")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String blessingMode;
|
||||
|
||||
@Column
|
||||
@Comment("是否发送,0未开启,1 进行中,2,已完成")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 2)
|
||||
private String isSend;
|
||||
|
||||
@Column
|
||||
@Comment("发送方式")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<String> sendTypes;
|
||||
|
||||
@Column
|
||||
@Comment("祝福内容")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String blessingContent;
|
||||
|
||||
@Column
|
||||
@Comment("cron表达式")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String blessingCron;
|
||||
|
||||
@Column
|
||||
@Comment("创建时间")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 30)
|
||||
private String applyDate;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.budwk.app.zhgh.staffbenefit.blessing.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
@Data
|
||||
@Table
|
||||
public class BlessingUser extends BaseModel {
|
||||
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@Comment("id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Prev(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
|
||||
@Column
|
||||
@Comment("接收人ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String userId;
|
||||
|
||||
|
||||
@Column
|
||||
@Comment("祝福ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String blessingId;
|
||||
|
||||
@Column
|
||||
@Comment("发送时间")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String applyDate;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.budwk.app.zhgh.staffbenefit.blessing.service;
|
||||
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.staffbenefit.blessing.models.Blessing;
|
||||
|
||||
public interface BlessingService extends BaseService<Blessing> {
|
||||
|
||||
|
||||
/**
|
||||
* 添加任务
|
||||
*
|
||||
* @param blessing
|
||||
*/
|
||||
void addTask(Blessing blessing);
|
||||
|
||||
/**
|
||||
* 修改任务
|
||||
*
|
||||
* @param blessing
|
||||
*/
|
||||
void editTask(Blessing blessing);
|
||||
|
||||
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.budwk.app.zhgh.staffbenefit.blessing.service.impl;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_task;
|
||||
import com.budwk.app.sys.services.SysTaskService;
|
||||
import com.budwk.app.task.services.TaskPlatformService;
|
||||
import com.budwk.app.zhgh.staffbenefit.blessing.models.Blessing;
|
||||
import com.budwk.app.zhgh.staffbenefit.blessing.service.BlessingService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.trans.Trans;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class BlessingServiceImpl extends BaseServiceImpl<Blessing> implements BlessingService {
|
||||
public BlessingServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
private final String JOB_CLASS = "io.v.nutz.task.job.BlessingJob"; //调用类
|
||||
|
||||
@Inject
|
||||
private BaseService baseService;
|
||||
|
||||
@Inject
|
||||
private TaskPlatformService taskPlatformService;
|
||||
|
||||
@Inject
|
||||
private SysTaskService sysTaskService;
|
||||
|
||||
@Override
|
||||
public void addTask(Blessing blessing) {
|
||||
Trans.exec(() -> {
|
||||
Sys_task sys_task = new Sys_task();
|
||||
sys_task.setName(blessing.getId());
|
||||
|
||||
sys_task.setNote(blessing.getBlessingName());
|
||||
sys_task.setJobClass(JOB_CLASS);
|
||||
sys_task.setCron(blessing.getBlessingCron());
|
||||
sys_task.setData(Json.toJson(new HashMap<String, Object>() {{
|
||||
put("blessingId", blessing.getId());
|
||||
}}));
|
||||
sys_task.setDisabled(false);
|
||||
sys_task = sysTaskService.insert(sys_task);
|
||||
taskPlatformService.add(sys_task.getId(), sys_task.getId(), sys_task.getJobClass(), sys_task.getCron(), sys_task.getNote(), sys_task.getData());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editTask(Blessing blessing) {
|
||||
Sys_task sys_task = sysTaskService.fetch(Cnd.where("name", "=", blessing.getId()));
|
||||
sys_task.setCron(blessing.getBlessingCron());
|
||||
sysTaskService.updateIgnoreNull(sys_task);
|
||||
|
||||
taskPlatformService.delete(sys_task.getId(), sys_task.getId());
|
||||
taskPlatformService.add(sys_task.getId(), sys_task.getId(), sys_task.getJobClass(), sys_task.getCron(), sys_task.getNote(), sys_task.getData());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user