first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package io.v.nutz.welfare.service;
|
||||
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.welfare.model.WelfareList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Todo
|
||||
*
|
||||
* @author: 1V
|
||||
* @date: 2021/1/25
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface WelfareListService extends ViService<WelfareList> {
|
||||
/**
|
||||
* 生成名单
|
||||
*
|
||||
* @param projectId
|
||||
*/
|
||||
void createList(String projectId);
|
||||
|
||||
/**
|
||||
* 加入福利名单
|
||||
*
|
||||
* @param projectId
|
||||
* @param userIds
|
||||
*/
|
||||
void joinWelfareList(String projectId, List<String> userIds);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package io.v.nutz.welfare.service;
|
||||
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.service.ViService;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* 发放名单汇总
|
||||
*/
|
||||
public interface WelfareListSummaryService extends ViService {
|
||||
|
||||
/**
|
||||
* 部门工会/福利单位,集中发放
|
||||
*
|
||||
* @param pageForm
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
NutMap togetherPageData(PageForm pageForm, String projectId);
|
||||
|
||||
|
||||
/**
|
||||
* 个人
|
||||
*
|
||||
* @param pageForm
|
||||
* @param projectId
|
||||
* @param unionId
|
||||
* @return
|
||||
*/
|
||||
NutMap singlePageData(PageForm pageForm, String projectId, String unionId);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.v.nutz.welfare.service;
|
||||
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.welfare.model.WelfareMemberRecord;
|
||||
|
||||
/**
|
||||
* Todo
|
||||
*
|
||||
* @author: 1V
|
||||
* @date: 2021/1/25
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface WelfareMemberRecordService extends ViService<WelfareMemberRecord> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.v.nutz.welfare.service;
|
||||
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
|
||||
/**
|
||||
* Todo
|
||||
*
|
||||
* @author: 1V
|
||||
* @date: 2021/1/25
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface WelfareMemberService extends ViService<Sys_user> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.v.nutz.welfare.service;
|
||||
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.welfare.model.WelfareProject;
|
||||
|
||||
/**
|
||||
* Todo
|
||||
*
|
||||
* @author: 1V
|
||||
* @date: 2021/1/25
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface WelfareProjectService extends ViService<WelfareProject> {
|
||||
|
||||
/**
|
||||
* 获取项目的信息
|
||||
*
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
WelfareProject projectInfo(String projectId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package io.v.nutz.welfare.service;
|
||||
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.welfare.model.WelfareProject;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zxy
|
||||
* @Description 意向选择 邮寄到家类的统计
|
||||
* @createTime 2022年01月25日 13:58:00
|
||||
*/
|
||||
public interface WelfareSingleService extends ViService<WelfareProject> {
|
||||
|
||||
/**
|
||||
* 某年的福利信息 (弹性)
|
||||
*
|
||||
* @param year
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> welfareProjectList(Integer year);
|
||||
|
||||
/**
|
||||
* 部门工会信息
|
||||
*
|
||||
* @param unionId 部门工会id
|
||||
* @param projectId 福利id
|
||||
* @return 每个部门工会信息 及 该福利项目下部门工会的福利会员人数
|
||||
*/
|
||||
List<NutMap> getUnionData(String unionId, String projectId);
|
||||
|
||||
/**
|
||||
* 获取某个福利下的题目 这个福利必然是弹性福利
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> getOptionByProjectId(String projectId);
|
||||
|
||||
/**
|
||||
* 某个福利下以后选择的数据
|
||||
*
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> getUserSelectionByProjectId(String projectId);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param projectId 福利id
|
||||
* @return
|
||||
*/
|
||||
NutMap pageData(String projectId, String welfareUnitCode);
|
||||
|
||||
|
||||
/**
|
||||
* 领取详情
|
||||
*
|
||||
* @param projectId 福利id
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> receivePageData(String projectId, String welfareUnitCode);
|
||||
|
||||
/**
|
||||
* 导出发放详细表
|
||||
*
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> receivePageDataColumns(String projectId);
|
||||
|
||||
/**
|
||||
* 未领取人员信息
|
||||
*
|
||||
* @param projectId
|
||||
* @param welfareUnitCode
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> unclaimedData(String projectId, String welfareUnitCode);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package io.v.nutz.welfare.service;
|
||||
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.welfare.mode.voucher.WelfareVoucherDonateReceiveResult;
|
||||
import io.v.nutz.welfare.model.WelfareVoucher;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Todo
|
||||
*
|
||||
* @author: 1V
|
||||
* @date: 2021/1/25
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface WelfareVoucherService extends ViService<WelfareVoucher> {
|
||||
|
||||
/**
|
||||
* 发放礼品
|
||||
*
|
||||
* @param voucherId 券id
|
||||
* @param userid 发放人id
|
||||
* @return 持券人信息
|
||||
*/
|
||||
Map<String, Object> grantGift(String voucherId, String userid);
|
||||
|
||||
/**
|
||||
* 获取礼品券详细信息
|
||||
*
|
||||
* @param voucherId 券id
|
||||
* @return 礼品券详细信息
|
||||
*/
|
||||
Map<String, Object> voucherInfo(String voucherId);
|
||||
|
||||
/**
|
||||
* 转赠领取
|
||||
*
|
||||
* @param voucherId 券id
|
||||
* @param userid 被转赠人id
|
||||
* @return 领取结果
|
||||
*/
|
||||
WelfareVoucherDonateReceiveResult donateReceive(String voucherId, String userid);
|
||||
|
||||
/**
|
||||
* 获取礼品券详细信息
|
||||
*
|
||||
* @param voucherId 券id
|
||||
* @return 礼品券详细信息
|
||||
*/
|
||||
Map<String, Object> donateVoucherInfo(String voucherId);
|
||||
|
||||
/**
|
||||
* 将礼品券的状态改为已赠但是未领
|
||||
*
|
||||
* @param voucherId 券id
|
||||
*/
|
||||
void voucherDonating(String voucherId);
|
||||
|
||||
/**
|
||||
* 领取礼品券
|
||||
*
|
||||
* @param projectId 项目
|
||||
* @param userid 用户
|
||||
* @return
|
||||
*/
|
||||
WelfareVoucher grantVoucher(String projectId, String userid);
|
||||
|
||||
/**
|
||||
* 该用户待领取的礼品券
|
||||
*
|
||||
* @param userid
|
||||
* @return
|
||||
*/
|
||||
List unclaimedVoucher(String userid);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package io.v.nutz.welfare.service.impl;
|
||||
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.dao.CndPlus;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.welfare.mode.WelfareUnitMode;
|
||||
import io.v.nutz.welfare.model.*;
|
||||
import io.v.nutz.welfare.service.WelfareListService;
|
||||
import io.v.nutz.welfare.service.WelfareProjectService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
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.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author 1V
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "welfare_list")
|
||||
public class WelfareListServiceImpl extends ViServiceImpl<WelfareList> implements WelfareListService {
|
||||
public WelfareListServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private WelfareProjectService projectService;
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void createList(String projectId) {
|
||||
clear(Cnd.where("projectId", "=", projectId));
|
||||
|
||||
WelfareProject project = projectService.projectInfo(projectId);
|
||||
|
||||
CndPlus cnd = CndPlus.create();
|
||||
if (project.getConditionStructure() != null) {
|
||||
project.getConditionStructure().join(cnd);
|
||||
}
|
||||
|
||||
Sql sql = Sqls.create("SELECT * from `welfare_member` $condition");
|
||||
sql.setCondition(cnd);
|
||||
joinWelfareList(listMap(sql), projectId);
|
||||
addflUser(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void joinWelfareList(String projectId, List<String> userIds) {
|
||||
Sql sql = Sqls.create("SELECT * from `user` $condition");
|
||||
CndPlus cnd = CndPlus.create();
|
||||
cnd.and("id", "in", userIds);
|
||||
sql.setCondition(cnd);
|
||||
joinWelfareList(listMap(sql), projectId);
|
||||
}
|
||||
|
||||
private void joinWelfareList(List<NutMap> users, String projectId) {
|
||||
String field = WelfareUnitMode.getMode().getField();
|
||||
List<WelfareList> lists = new ArrayList<>();
|
||||
for (NutMap user : users) {
|
||||
WelfareList list = new WelfareList();
|
||||
list.setProjectId(projectId);
|
||||
list.setUserId(user.getString("id"));
|
||||
list.setWelfareUnitId(user.getString(field));
|
||||
lists.add(list);
|
||||
}
|
||||
dao().insert(lists);
|
||||
}
|
||||
|
||||
private void addflUser(String id) {
|
||||
dao().clear(WelfareUserSelection.class, Cnd.where("welfareId", "=", id));
|
||||
WelfareProject project = projectService.fetchLinks(projectService.fetch(Cnd.where("year", "=", DateUtil.getYear()).asc("createdAt")), "welfareProjectSubjects");
|
||||
|
||||
if (!project.getIsRoutine()) {
|
||||
|
||||
//首先找出今年最新一条的福利选项
|
||||
List<WelfareProjectSubject> welfareProjectSubjects = project.getWelfareProjectSubjects();
|
||||
List<WelfareProjectSubjectOption> options = projectService.dao().query(WelfareProjectSubjectOption.class, Cnd.where("subjectId", "=", welfareProjectSubjects.get(0).getId()));
|
||||
//过滤出福利卡
|
||||
List<WelfareProjectSubjectOption> subjectOptions = options.stream().filter(vi -> vi.getOptionType().equals("福利卡")).collect(Collectors.toList());
|
||||
|
||||
List<String> ids = subjectOptions.stream().map(vi -> vi.getId()).collect(Collectors.toList());
|
||||
|
||||
//找出原来选福利卡的人
|
||||
List<WelfareUserSelection> userSelections = projectService.dao().query(WelfareUserSelection.class, Cnd.where("selectOptionId", "in", ids));
|
||||
|
||||
List<WelfareUserSelection> users = new ArrayList<>();
|
||||
|
||||
|
||||
//新的福利选项
|
||||
WelfareProjectSubject subject = projectService.dao().fetch(WelfareProjectSubject.class, Cnd.where("projectId", "=", id));
|
||||
userSelections.forEach(v -> {
|
||||
//原来的福利
|
||||
WelfareProjectSubjectOption yld = projectService.dao().fetch(WelfareProjectSubjectOption.class, v.getSelectOptionId());
|
||||
//新的
|
||||
WelfareProjectSubjectOption subjectOption = projectService.dao().fetch(WelfareProjectSubjectOption.class,
|
||||
Cnd.where("subjectId", "=", subject.getId())
|
||||
.and("optionNameId", "=", yld.getOptionNameId()));
|
||||
|
||||
|
||||
WelfareUserSelection userSelection = new WelfareUserSelection();
|
||||
userSelection.setWelfareId(id);
|
||||
userSelection.setSubjectId(subject.getId());
|
||||
userSelection.setSelectOptionId(subjectOption.getId());
|
||||
userSelection.setSelectUserId(v.getSelectUserId());
|
||||
userSelection.setSelectTime(new Date());
|
||||
users.add(userSelection);
|
||||
|
||||
});
|
||||
projectService.insert(users);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package io.v.nutz.welfare.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import io.v.nutz.dao.CndPlus;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.sys.models.Sys_dict;
|
||||
import io.v.nutz.welfare.mode.WelfareUnitMode;
|
||||
import io.v.nutz.welfare.service.WelfareListSummaryService;
|
||||
import io.v.nutz.welfare.service.WelfareSingleService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
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.lang.util.NutMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class WelfareListSummaryServiceImpl extends ViServiceImpl implements WelfareListSummaryService {
|
||||
|
||||
@Inject
|
||||
private WelfareSingleService welfareSingleService;
|
||||
|
||||
public WelfareListSummaryServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap togetherPageData(PageForm pageForm, String projectId) {
|
||||
//获取所有人员类型
|
||||
Sys_dict dict = dao().fetch(Sys_dict.class, Cnd.where("code", "=", "UserType"));
|
||||
List<Sys_dict> userTypeDictList = dict == null ? new ArrayList<>() : dao().query(Sys_dict.class, Cnd.where("parentId", "=", Strings.sNull(dict.getId())).and("disabled", "=", false).asc("location"));
|
||||
List<String> userTypeList = userTypeDictList.stream().map(Sys_dict::getCode).collect(Collectors.toList());
|
||||
List<NutMap> labelList = userTypeDictList.stream().map(v -> NutMap.NEW().addv("prop", v.getCode()).addv("label", v.getName())).collect(Collectors.toList());
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
unit.*,
|
||||
sum( 1 ) number,
|
||||
$temp_sql
|
||||
FROM
|
||||
welfare_unit unit
|
||||
LEFT JOIN welfare_list list ON unit.welfareUnitId = list.welfareUnitId
|
||||
LEFT JOIN `user` su ON su.id = list.userId
|
||||
$condition
|
||||
""");
|
||||
StringBuffer temp_sql_str = new StringBuffer();
|
||||
userTypeList.forEach(v -> {
|
||||
temp_sql_str.append("COUNT( CASE WHEN ( su.personType = '%s' ) THEN 1 ELSE NULL END ) AS '%s',".formatted(v, v));
|
||||
});
|
||||
|
||||
String totalUserType = CollUtil.join(userTypeList, ",", "'", "'");
|
||||
|
||||
temp_sql_str.append("COUNT( CASE WHEN ( su.personType in (%s) ) THEN 1 ELSE NULL END ) AS totalNum".formatted(totalUserType));
|
||||
sql.setVar("temp_sql", temp_sql_str);
|
||||
|
||||
CndPlus cnd = CndPlus.create();
|
||||
cnd.and("unit.welfareUnitMode", "=", WelfareUnitMode.getMode().name());
|
||||
pageForm.defaultSortAsc("unit.welfareUnitCode");
|
||||
cnd.and(pageForm);
|
||||
cnd.and("list.projectId", "=", projectId);
|
||||
cnd.groupBy("unit.welfareUnitId");
|
||||
sql.setCondition(cnd);
|
||||
labelList.add(NutMap.NEW().addv("prop", "totalNum").addv("label", "合计"));
|
||||
return NutMap.WRAP(Map.of("tableList", listMap(sql), "tableColumn", labelList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap singlePageData(PageForm pageForm, String projectId, String unionId) {
|
||||
Sql welfareUnitSql = Sqls.create("""
|
||||
SELECT
|
||||
unit.*,
|
||||
( SELECT count( 1 ) FROM view_welfare_list WHERE unioncode = unit.welfareUnitCode AND projectId = @projectId ) AS teacherSum\s
|
||||
FROM
|
||||
welfare_unit unit
|
||||
$condition
|
||||
""");
|
||||
CndPlus cnd = CndPlus.create();
|
||||
cnd.and("unit.welfareUnitMode", "=", WelfareUnitMode.getMode().name());
|
||||
pageForm.defaultSortAsc("unit.welfareUnitCode");
|
||||
cnd.and(pageForm);
|
||||
cnd.groupBy("unit.welfareUnitId");
|
||||
welfareUnitSql.setCondition(cnd);
|
||||
welfareUnitSql.setParam("projectId", projectId);
|
||||
List<NutMap> welfareUnitList = listMap(welfareUnitSql);
|
||||
|
||||
//选项数据
|
||||
List<NutMap> optionList = welfareSingleService.getOptionByProjectId(projectId);
|
||||
//选择数据
|
||||
List<NutMap> userSelectionList = welfareSingleService.getUserSelectionByProjectId(projectId);
|
||||
for (NutMap wUnit : welfareUnitList) {
|
||||
//该部门工会选择数据
|
||||
List<NutMap> thisUnionSelectionList = userSelectionList.stream().filter(x -> x.getString("unionCode").equals(wUnit.getString("welfareUnitCode")) && x.getString("welfareId").equals(projectId)).collect(Collectors.toList());
|
||||
optionList.forEach(o -> {
|
||||
//每一项选择的人数
|
||||
long count = thisUnionSelectionList.stream().filter(z -> z.getString("selectOptionId").equals(o.getString("id"))).count();
|
||||
wUnit.put(o.getString("optionName"), count);
|
||||
});
|
||||
//已选人数
|
||||
wUnit.put("totalCount", thisUnionSelectionList.size());
|
||||
//未选人数
|
||||
wUnit.put("unselectedTeacherSum", wUnit.getInt("teacherSum") - wUnit.getInt("totalCount"));
|
||||
}
|
||||
//表格列数据
|
||||
List<NutMap> labelList = new ArrayList<>();
|
||||
labelList.add(NutMap.NEW().addv("label", "本次福利会员人数").addv("prop", "teacherSum"));
|
||||
optionList.forEach(v -> {
|
||||
labelList.add(NutMap.NEW().addv("label", v.getString("optionName")).addv("prop", v.getString("optionName")));
|
||||
});
|
||||
labelList.add(NutMap.NEW().addv("label", "参加人数").addv("prop", "totalCount"));
|
||||
labelList.add(NutMap.NEW().addv("label", "未选人数").addv("prop", "unselectedTeacherSum"));
|
||||
|
||||
return NutMap.NEW().addv("tableList", welfareUnitList).addv("tableColumn", labelList);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.v.nutz.welfare.service.impl;
|
||||
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.welfare.model.WelfareMemberRecord;
|
||||
import io.v.nutz.welfare.service.WelfareMemberRecordService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
|
||||
/**
|
||||
* @author 1V
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "member")
|
||||
public class WelfareMemberRecordServiceImpl extends ViServiceImpl<WelfareMemberRecord> implements WelfareMemberRecordService {
|
||||
public WelfareMemberRecordServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.v.nutz.welfare.service.impl;
|
||||
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.welfare.service.WelfareMemberService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
|
||||
/**
|
||||
* @author 1V
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "welfare_member")
|
||||
public class WelfareMemberServiceImpl extends ViServiceImpl<Sys_user> implements WelfareMemberService {
|
||||
public WelfareMemberServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.v.nutz.welfare.service.impl;
|
||||
|
||||
import io.v.nutz.base.service.BaseService;
|
||||
import io.v.nutz.data.model.MatchConditionStructure;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.welfare.model.WelfareProject;
|
||||
import io.v.nutz.welfare.model.WelfareProjectSubject;
|
||||
import io.v.nutz.welfare.service.WelfareProjectService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
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.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author 1V
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "welfare_project")
|
||||
public class WelfareProjectServiceImpl extends ViServiceImpl<WelfareProject> implements WelfareProjectService {
|
||||
public WelfareProjectServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private BaseService baseService;
|
||||
|
||||
@Override
|
||||
public WelfareProject projectInfo(String projectId) {
|
||||
// WelfareProject project = fetchLinks(projectId);
|
||||
WelfareProject project = fetchLinks(dao().fetch(WelfareProject.class, Cnd.where("id", "=", projectId)), "welfareProjectSubjects");
|
||||
List<WelfareProjectSubject> welfareProjectSubjects = project.getWelfareProjectSubjects();
|
||||
Sql sqlo = Sqls.create("""
|
||||
SELECT
|
||||
optionName
|
||||
FROM
|
||||
welfare_project_subject_option
|
||||
WHERE
|
||||
id IN ( SELECT selectOptionId FROM welfare_project_user_selection WHERE selectUserId = @userid AND welfareId = @welfareId )
|
||||
ORDER BY
|
||||
optionSort ASC
|
||||
""");
|
||||
sqlo.setParam("userid", ShiroUtil.getPrincipalProperty("id"));
|
||||
sqlo.setParam("welfareId", project.getId());
|
||||
List<NutMap> optionNameList = baseService.listMap(sqlo);
|
||||
if (Lang.isNotEmpty(optionNameList)) {
|
||||
project.setGift(optionNameList.stream().map(x -> x.getString("optionName")).collect(Collectors.joining("、")));
|
||||
}
|
||||
if (Lang.isNotEmpty(welfareProjectSubjects)) {
|
||||
fetchLinks(welfareProjectSubjects, "options", Cnd.NEW().asc("optionSort"));
|
||||
}
|
||||
if (Strings.isNotBlank(project.getConditionStructureId())) {
|
||||
MatchConditionStructure conditionStructure = fetchLinks(dao().fetch(MatchConditionStructure.class, project.getConditionStructureId()), "conditions");
|
||||
project.setConditionStructure(conditionStructure);
|
||||
}
|
||||
return project;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
package io.v.nutz.welfare.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.base.utils.Vi;
|
||||
import io.v.nutz.dao.CndPlus;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.welfare.mode.WelfareProvideMode;
|
||||
import io.v.nutz.welfare.mode.WelfareUnitMode;
|
||||
import io.v.nutz.welfare.model.WelfareProject;
|
||||
import io.v.nutz.welfare.service.WelfareSingleService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author zxy
|
||||
* @Description 意向选择 邮寄到家类的统计
|
||||
* @createTime 2022年01月25日 13:58:00
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class WelfareSingleServiceImpl extends ViServiceImpl<WelfareProject> implements WelfareSingleService {
|
||||
|
||||
public WelfareSingleServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 某年的福利信息 (弹性)
|
||||
*
|
||||
* @param year
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> welfareProjectList(Integer year) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
id,
|
||||
`year`,
|
||||
`name`,
|
||||
provideMode
|
||||
FROM
|
||||
welfare_project
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.where("flexible", "=", 1);
|
||||
cnd.andEX("year", "=", year);
|
||||
sql.setCondition(cnd);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 部门工会信息
|
||||
*
|
||||
* @param unionId 部门工会id
|
||||
* @param projectId 福利id
|
||||
* @return 每个部门工会信息 及 该福利项目下部门工会的福利会员人数
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> getUnionData(String unionId, String projectId) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
un.id unionId,
|
||||
un.unionName,
|
||||
( SELECT count( 1 ) FROM view_welfare_list WHERE unionid = un.id AND projectId = @projectId ) AS teacherSum
|
||||
FROM
|
||||
sys_union un
|
||||
$condition
|
||||
""");
|
||||
if (!ShiroUtil.hasAnyRoles("sysadmin,A06")) {
|
||||
if (ShiroUtil.hasAnyRoles("H04")) {
|
||||
cnd.and("un.id", "=", Vi.getUnionId());
|
||||
}
|
||||
}
|
||||
sql.setParam("projectId", projectId);
|
||||
|
||||
if (StrUtil.isNotBlank(unionId)) {
|
||||
cnd.and("un.id", "=", unionId);
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个福利下的题目 这个福利必然是弹性福利
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> getOptionByProjectId(String projectId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
wpso.id,
|
||||
wpso.optionName
|
||||
FROM
|
||||
welfare_project_subject_option wpso
|
||||
LEFT JOIN welfare_project_subject wps ON wps.id = wpso.subjectId
|
||||
WHERE
|
||||
wps.projectId = @projectId
|
||||
""");
|
||||
sql.setParam("projectId", projectId);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 某个福利下以后选择的数据
|
||||
*
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> getUserSelectionByProjectId(String projectId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
wpus.selectOptionId,
|
||||
wpus.selectTime,
|
||||
wpus.userSign,
|
||||
wpus.receiveAddress,
|
||||
wpus.welfareId,
|
||||
u.unionid AS unionId,
|
||||
u.unioncode AS unionCode,
|
||||
u.unitcode AS unitCode
|
||||
FROM
|
||||
`welfare_project_user_selection` wpus
|
||||
LEFT JOIN `user` u ON u.id = wpus.selectUserId
|
||||
where u.unionid is not null
|
||||
AND wpus.welfareId=@projectId
|
||||
GROUP BY wpus.selectUserId
|
||||
""").setParam("projectId", projectId);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param projectId 福利id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public NutMap pageData(String projectId, String welfareUnitCode) {
|
||||
// //部门工会数据
|
||||
// List<NutMap> unionData = getUnionData(unionId, projectId);
|
||||
// //选项数据
|
||||
// List<NutMap> optionList = getOptionByProjectId(projectId);
|
||||
// //选择数据
|
||||
// List<NutMap> userSelectionList = getUserSelectionByProjectId(projectId);
|
||||
// unionData.forEach(v -> {
|
||||
// //该部门工会选择数据
|
||||
// List<NutMap> thisUnionSelectionList = userSelectionList.stream().filter(x -> x.getString("unionId").equals(v.getString("unionId")) && x.getString("welfareId").equals(projectId)).collect(Collectors.toList());
|
||||
// optionList.forEach(o -> {
|
||||
// //每一项选择的人数
|
||||
// long count = thisUnionSelectionList.stream().filter(z -> z.getString("selectOptionId").equals(o.getString("id"))).count();
|
||||
// v.put(o.getString("optionName"), count);
|
||||
// });
|
||||
// //已选人数
|
||||
// v.put("totalCount", thisUnionSelectionList.size());
|
||||
// //未选人数
|
||||
// v.put("unselectedTeacherSum", v.getInt("teacherSum") - v.getInt("totalCount"));
|
||||
// });
|
||||
//
|
||||
// //表格列数据
|
||||
// List<NutMap> labelList = new ArrayList<>();
|
||||
// labelList.add(NutMap.NEW().addv("label", "基层工会名称").addv("prop", "unionName"));
|
||||
// labelList.add(NutMap.NEW().addv("label", "基层工会名称").addv("prop", "welfareUnitName"));
|
||||
// labelList.add(NutMap.NEW().addv("label", "本次福利会员人数").addv("prop", "teacherSum"));
|
||||
// optionList.forEach(v -> {
|
||||
// labelList.add(NutMap.NEW().addv("label", v.getString("optionName")).addv("prop", v.getString("optionName")));
|
||||
// });
|
||||
// labelList.add(NutMap.NEW().addv("label", "参加人数").addv("prop", "totalCount"));
|
||||
// labelList.add(NutMap.NEW().addv("label", "未选人数").addv("prop", "unselectedTeacherSum"));
|
||||
//
|
||||
//
|
||||
// return NutMap.NEW().addv("tableList", unionData).addv("tableColumn", labelList);
|
||||
|
||||
Sql welfareUnitSql = Sqls.create("""
|
||||
SELECT
|
||||
unit.*,
|
||||
( SELECT count( 1 ) FROM view_welfare_list WHERE unioncode = unit.welfareUnitCode AND projectId = @projectId ) AS teacherSum\s
|
||||
FROM
|
||||
welfare_unit unit
|
||||
$condition
|
||||
""");
|
||||
CndPlus cnd = CndPlus.create();
|
||||
cnd.and("unit.welfareUnitMode", "=", WelfareUnitMode.getMode().name());
|
||||
cnd.asc("unit.welfareUnitCode");
|
||||
cnd.andEX("unit.welfareUnitCode", "=", welfareUnitCode);
|
||||
cnd.groupBy("unit.welfareUnitId");
|
||||
welfareUnitSql.setCondition(cnd);
|
||||
welfareUnitSql.setParam("projectId", projectId);
|
||||
List<NutMap> welfareUnitList = listMap(welfareUnitSql);
|
||||
|
||||
//选项数据
|
||||
List<NutMap> optionList = this.getOptionByProjectId(projectId);
|
||||
//选择数据
|
||||
List<NutMap> userSelectionList = this.getUserSelectionByProjectId(projectId);
|
||||
for (NutMap wUnit : welfareUnitList) {
|
||||
//该部门工会选择数据
|
||||
List<NutMap> thisUnionSelectionList = userSelectionList.stream().filter(x -> x.getString("unionCode").equals(wUnit.getString("welfareUnitCode")) && x.getString("welfareId").equals(projectId)).collect(Collectors.toList());
|
||||
optionList.forEach(o -> {
|
||||
//每一项选择的人数
|
||||
Sql optionCountSql = Sqls.create("""
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
`welfare_project_user_selection` wpus
|
||||
LEFT JOIN `user` u ON u.id = wpus.selectUserId
|
||||
WHERE
|
||||
u.unionCode = @unionCode
|
||||
AND wpus.welfareId = @welfareId
|
||||
AND wpus.selectOptionId = @selectOptionId
|
||||
""")
|
||||
.setParam("unionCode", wUnit.getString("welfareUnitCode"))
|
||||
.setParam("welfareId", projectId)
|
||||
.setParam("selectOptionId", o.getString("id"));
|
||||
int count = count(optionCountSql);
|
||||
// long count = thisUnionSelectionList.stream().filter(z -> z.getString("selectOptionId").equals(o.getString("id"))).count();
|
||||
wUnit.put(o.getString("optionName"), count);
|
||||
});
|
||||
//已选人数
|
||||
wUnit.put("totalCount", thisUnionSelectionList.size());
|
||||
//未选人数
|
||||
wUnit.put("unselectedTeacherSum", wUnit.getInt("teacherSum") - wUnit.getInt("totalCount"));
|
||||
}
|
||||
//表格列数据
|
||||
List<NutMap> labelList = new ArrayList<>();
|
||||
labelList.add(NutMap.NEW().addv("label", "本次福利会员人数").addv("prop", "teacherSum"));
|
||||
optionList.forEach(v -> {
|
||||
labelList.add(NutMap.NEW().addv("label", v.getString("optionName")).addv("prop", v.getString("optionName")));
|
||||
});
|
||||
labelList.add(NutMap.NEW().addv("label", "参加人数").addv("prop", "totalCount"));
|
||||
labelList.add(NutMap.NEW().addv("label", "未选人数").addv("prop", "unselectedTeacherSum"));
|
||||
|
||||
return NutMap.NEW().addv("tableList", welfareUnitList).addv("tableColumn", labelList);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取详情
|
||||
*
|
||||
* @param projectId 福利id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> receivePageData(String projectId, String welfareUnitCode) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.loginname AS loginName,
|
||||
u.username AS userName,
|
||||
u.unitname AS unitName,
|
||||
u.unionname AS unionName,
|
||||
u.mobile,
|
||||
wpus.receiveAddress,
|
||||
(
|
||||
SELECT
|
||||
GROUP_CONCAT( wpso.optionName )
|
||||
FROM
|
||||
welfare_project_user_selection wpus
|
||||
LEFT JOIN welfare_project_subject_option wpso ON wpso.id = wpus.selectOptionId
|
||||
WHERE
|
||||
wpus.welfareId = @welfareId
|
||||
AND wpus.selectUserId = u.id
|
||||
) optionName,
|
||||
wpus.courierNumber
|
||||
FROM
|
||||
welfare_project_user_selection wpus
|
||||
LEFT JOIN `user` u ON u.id = wpus.selectUserId
|
||||
LEFT JOIN welfare_project_subject_option wpso ON wpso.id = wpus.selectOptionId
|
||||
$condition
|
||||
""").setParam("welfareId", projectId);
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("u.loginname ");
|
||||
switch (WelfareUnitMode.getMode().name()) {
|
||||
case "UNION" -> {
|
||||
cnd.andEX("u.unioncode", "=", welfareUnitCode);
|
||||
cnd.asc("u.unioncode");
|
||||
}
|
||||
case "UNIT" -> {
|
||||
cnd.andEX("u.unitcode", "=", welfareUnitCode);
|
||||
cnd.asc("u.unitcode");
|
||||
}
|
||||
}
|
||||
cnd.and("wpus.welfareId", "=", projectId);
|
||||
|
||||
sql.setCondition(cnd);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出发放详细表
|
||||
*
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> receivePageDataColumns(String projectId) {
|
||||
List<NutMap> labelList = new ArrayList<>();
|
||||
labelList.add(NutMap.NEW().addv("label", "工号").addv("prop", "loginName"));
|
||||
labelList.add(NutMap.NEW().addv("label", "姓名").addv("prop", "userName"));
|
||||
labelList.add(NutMap.NEW().addv("label", "单位").addv("prop", "unitName"));
|
||||
labelList.add(NutMap.NEW().addv("label", "工会").addv("prop", "unionName"));
|
||||
labelList.add(NutMap.NEW().addv("label", "所选福利").addv("prop", "optionName"));
|
||||
|
||||
WelfareProject project = dao().fetch(WelfareProject.class, Cnd.where("id", "=", projectId));
|
||||
if (project.getProvideMode().equals(WelfareProvideMode.PERSONAL.getCode())) {
|
||||
labelList.add(NutMap.NEW().addv("label", "收货信息").addv("prop", "receiveAddress").addv("width", 50));
|
||||
labelList.add(NutMap.NEW().addv("label", "快递单号").addv("prop", "courierNumber").addv("width", 50));
|
||||
}
|
||||
|
||||
return labelList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未领取人员信息
|
||||
*
|
||||
* @param projectId
|
||||
* @param welfareUnitCode
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> unclaimedData(String projectId, String welfareUnitCode) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
loginname loginName,
|
||||
username userName,
|
||||
unitname unitName,
|
||||
unionname unionName,
|
||||
mobile
|
||||
FROM
|
||||
view_welfare_list
|
||||
WHERE
|
||||
projectId = @projectId
|
||||
AND id NOT IN
|
||||
(
|
||||
SELECT selectUserId FROM welfare_project_user_selection WHERE welfareId = @projectId AND selectUserId IS NOT NULL
|
||||
)
|
||||
$modeCnd
|
||||
""");
|
||||
if (Strings.isNotBlank(welfareUnitCode)) {
|
||||
if ("UNION".equals(WelfareUnitMode.getMode().name())) {
|
||||
sql.setVar("modeCnd", "AND unioncode = '%s'".formatted(welfareUnitCode));
|
||||
} else if ("UNIT".equals(WelfareUnitMode.getMode().name())) {
|
||||
sql.setVar("modeCnd", "AND unitcode = '%s'".formatted(welfareUnitCode));
|
||||
}
|
||||
}
|
||||
|
||||
// sql.setParam("unionId", welfareUnitCode);
|
||||
sql.setParam("projectId", projectId);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
package io.v.nutz.welfare.service.impl;
|
||||
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.welfare.mode.WelfareProvideMode;
|
||||
import io.v.nutz.welfare.mode.WelfareSignMode;
|
||||
import io.v.nutz.welfare.mode.WelfareVoucherOrigin;
|
||||
import io.v.nutz.welfare.mode.WelfareVoucherStatus;
|
||||
import io.v.nutz.welfare.mode.voucher.WelfareGiftGrantResult;
|
||||
import io.v.nutz.welfare.mode.voucher.WelfareVoucherDonateReceiveResult;
|
||||
import io.v.nutz.welfare.model.WelfareProject;
|
||||
import io.v.nutz.welfare.model.WelfareVoucher;
|
||||
import io.v.nutz.welfare.service.WelfareProjectService;
|
||||
import io.v.nutz.welfare.service.WelfareVoucherService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.Static;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author 1V
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "welfare_voucher")
|
||||
public class WelfareVoucherServiceImpl extends ViServiceImpl<WelfareVoucher> implements WelfareVoucherService {
|
||||
public WelfareVoucherServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private WelfareProjectService projectService;
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Map<String, Object> grantGift(String voucherId, String userid) {
|
||||
|
||||
WelfareVoucher voucher = fetch(voucherId);
|
||||
|
||||
if (voucher == null) {
|
||||
return Map.of("result", WelfareGiftGrantResult.NotFound.map());
|
||||
}
|
||||
|
||||
WelfareProject project = projectService.fetch(voucher.getProjectId());
|
||||
|
||||
Date now = new Date();
|
||||
if (!(project.getProvideTimeStart().compareTo(now) < 0 && project.getProvideTimeEnd().compareTo(now) > 0)) {
|
||||
return Map.of("result", WelfareGiftGrantResult.TIMEOUT.map());
|
||||
}
|
||||
|
||||
Chain chain = Chain.make("status", WelfareVoucherStatus.USED.getCode())
|
||||
.add("useTime", System.currentTimeMillis())
|
||||
.add("issuedBy", userid);
|
||||
boolean success = update(chain, Cnd.where("id", "=", voucherId).and("status", "=", WelfareVoucherStatus.NORMAL.getCode())) > 0;
|
||||
|
||||
if (success) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
`user`.username,
|
||||
`user`.loginname,
|
||||
`user`.unitname,
|
||||
`user`.unionname
|
||||
FROM
|
||||
welfare_voucher voucher
|
||||
LEFT JOIN `user` ON voucher.userId = `user`.id
|
||||
WHERE
|
||||
voucher.id = @id
|
||||
""").setParam("id", voucherId);
|
||||
|
||||
return Map.of("user", fetch(sql), "result", WelfareGiftGrantResult.SUCCESS.map());
|
||||
}
|
||||
|
||||
return Map.of("result", WelfareGiftGrantResult.GRANTED.map());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> voucherInfo(String voucherId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
voucher.id,
|
||||
voucher.`status`,
|
||||
project.`id` projectId,
|
||||
project.`name`,
|
||||
project.festival,
|
||||
project.provideAddress,
|
||||
project.gift,
|
||||
project.flexibleGifts,
|
||||
project.provideTimeStart,
|
||||
project.provideTimeEnd,
|
||||
`user`.username,
|
||||
`user`.loginname,
|
||||
`user`.unitname,
|
||||
`user`.unionname
|
||||
FROM
|
||||
welfare_voucher voucher
|
||||
LEFT JOIN welfare_project project ON voucher.projectId = project.id
|
||||
LEFT JOIN `user` ON voucher.userId = `user`.id
|
||||
WHERE
|
||||
voucher.id = @id
|
||||
""").setParam("id", voucherId);
|
||||
|
||||
NutMap result = fetch(sql);
|
||||
|
||||
result.setv("canget", result.getInt("status") == WelfareVoucherStatus.NORMAL.getCode());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public WelfareVoucherDonateReceiveResult donateReceive(String voucherId, String userid) {
|
||||
WelfareVoucher voucher = fetch(voucherId);
|
||||
|
||||
WelfareVoucherDonateReceiveResult receiveResult = donateReceiveResult(voucher);
|
||||
if (receiveResult != null) {
|
||||
return receiveResult;
|
||||
}
|
||||
|
||||
int update = update(Chain.make("status", WelfareVoucherStatus.DONATE.getCode()),
|
||||
Cnd.where("id", "=", voucherId).and("status", "=", WelfareVoucherStatus.DONATING.getCode()));
|
||||
if (update < 1) {
|
||||
return WelfareVoucherDonateReceiveResult.FAIL;
|
||||
}
|
||||
|
||||
WelfareVoucher welfareVoucher = new WelfareVoucher()
|
||||
.setOrigin(WelfareVoucherOrigin.DONATE.getCode())
|
||||
.setProjectId(voucher.getProjectId())
|
||||
.setUserId(userid)
|
||||
.setDonateUserId(voucher.getUserId())
|
||||
.setGrantTime(System.currentTimeMillis())
|
||||
.setStatus(WelfareVoucherStatus.NORMAL.getCode());
|
||||
|
||||
insert(welfareVoucher);
|
||||
|
||||
return WelfareVoucherDonateReceiveResult.SUCCESS;
|
||||
}
|
||||
|
||||
private WelfareVoucherDonateReceiveResult donateReceiveResult(WelfareVoucher voucher) {
|
||||
if (voucher == null) {
|
||||
return WelfareVoucherDonateReceiveResult.FAIL;
|
||||
}
|
||||
|
||||
WelfareProject project = projectService.fetch(voucher.getProjectId());
|
||||
|
||||
if (voucher.getStatus() == WelfareVoucherStatus.DONATE.getCode()) {
|
||||
return WelfareVoucherDonateReceiveResult.DONATED;
|
||||
}
|
||||
|
||||
if (voucher.getStatus() == WelfareVoucherStatus.INVALID.getCode()) {
|
||||
return WelfareVoucherDonateReceiveResult.INVALID;
|
||||
}
|
||||
|
||||
if (project.getProvideTimeStart().compareTo(new Date()) <= 0) {
|
||||
return WelfareVoucherDonateReceiveResult.TIMEOUT;
|
||||
}
|
||||
|
||||
if (voucher.getStatus() != WelfareVoucherStatus.DONATING.getCode()) {
|
||||
return WelfareVoucherDonateReceiveResult.FAIL;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> donateVoucherInfo(String voucherId) {
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
voucher.id,
|
||||
voucher.`status`,
|
||||
project.`id` projectId,
|
||||
project.`name`,
|
||||
project.festival,
|
||||
project.provideAddress,
|
||||
project.gift,
|
||||
project.flexibleGifts,
|
||||
project.provideTimeStart,
|
||||
project.provideTimeEnd,
|
||||
`user`.username donors
|
||||
FROM
|
||||
welfare_voucher voucher
|
||||
LEFT JOIN welfare_project project ON voucher.projectId = project.id
|
||||
LEFT JOIN sys_user `user` ON voucher.userId = `user`.id
|
||||
WHERE
|
||||
voucher.id = @id
|
||||
""").setParam("id", voucherId);
|
||||
|
||||
NutMap result = fetch(sql);
|
||||
|
||||
WelfareVoucherDonateReceiveResult receiveResult = donateReceiveResult(fetch(voucherId));
|
||||
result.put("result", receiveResult == null ? null : receiveResult.map());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void voucherDonating(String voucherId) {
|
||||
update(Chain.make("status", WelfareVoucherStatus.DONATING.getCode()), Cnd.where("id", "=", voucherId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public WelfareVoucher grantVoucher(String projectId, String userid) {
|
||||
return insert(new WelfareVoucher()
|
||||
.setOrigin(WelfareVoucherOrigin.RECEIVE.getCode())
|
||||
.setProjectId(projectId)
|
||||
.setUserId(userid)
|
||||
.setGrantTime(System.currentTimeMillis())
|
||||
.setStatus(WelfareVoucherStatus.NORMAL.getCode())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List unclaimedVoucher(String userid) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
project.`id` projectId,
|
||||
project.`name`,
|
||||
project.festival,
|
||||
project.provideAddress,
|
||||
project.gift,
|
||||
project.flexibleGifts,
|
||||
project.provideTimeStart,
|
||||
project.provideTimeEnd
|
||||
FROM
|
||||
welfare_project project
|
||||
LEFT JOIN welfare_list list ON project.id = list.projectId
|
||||
LEFT JOIN welfare_voucher voucher ON (voucher.projectId = project.id AND voucher.userId = list.userId)
|
||||
$condition
|
||||
""");
|
||||
|
||||
Cnd cnd = Cnd.where("project.provideMode", "=", WelfareProvideMode.PERSONAL.getCode())
|
||||
.and("project.signMode", "in", List.of(WelfareSignMode.QRCODE.getCode(), WelfareSignMode.QRCODE_SIGNATURE.getCode()))
|
||||
.and("list.userId", "=", userid)
|
||||
.and(new Static("now() < project.provideTimeStart"))
|
||||
.and("voucher.id", "is", null);
|
||||
|
||||
cnd.desc("project.provideTimeStart");
|
||||
|
||||
sql.setCondition(cnd);
|
||||
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Date date = new Date();
|
||||
Thread.sleep(3000);
|
||||
Date date1 = new Date();
|
||||
System.err.println(date1.compareTo(date));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user