考勤配置增加默认选项

dev_xd
lj7788 2026-03-30 14:15:17 +08:00
parent 70de0ffc14
commit fdc8f217d9
12 changed files with 5848 additions and 3 deletions

View File

@ -0,0 +1,16 @@
### 1.给attendance_cfg表中增加is_default int 1-默认0-非默认
更新历史数据
UPDATE attendance_cfg set is_default=1
更新历史数据
UPDATE pro_mobile_attendance_data pmad
INNER JOIN (
SELECT ac.project_id, ac.id AS cfg_id
FROM attendance_cfg ac
WHERE ac.is_default = 1 AND ac.enabled = 1
) ac ON pmad.project_id = ac.project_id
SET pmad.cfg_id = ac.cfg_id
WHERE pmad.att_device = 'device' AND pmad.cfg_id = 0;

View File

@ -0,0 +1,30 @@
-- 更新pro_mobile_attendance_data表的cfg_id根据project_id从attendance_cfg中找到默认配置ID
UPDATE pro_mobile_attendance_data pmad
INNER JOIN (
SELECT ac.project_id, ac.id AS cfg_id
FROM attendance_cfg ac
WHERE ac.is_default = 1 AND ac.enabled = 1
) ac ON pmad.project_id = ac.project_id
SET pmad.cfg_id = ac.cfg_id
WHERE pmad.att_device = 'device' AND pmad.cfg_id = 0;
-- 测试查询:查看更新效果
SELECT pmad.id, pmad.project_id, pmad.cfg_id, ac.id AS new_cfg_id
FROM pro_mobile_attendance_data pmad
LEFT JOIN (
SELECT ac.project_id, ac.id
FROM attendance_cfg ac
WHERE ac.is_default = 1 AND ac.enabled = 1
) ac ON pmad.project_id = ac.project_id
WHERE pmad.att_device = 'device' AND pmad.cfg_id = 0;
-- 分批更新(可选,适用于大数据量)
UPDATE pro_mobile_attendance_data pmad
INNER JOIN (
SELECT ac.project_id, ac.id AS cfg_id
FROM attendance_cfg ac
WHERE ac.is_default = 1 AND ac.enabled = 1
) ac ON pmad.project_id = ac.project_id
SET pmad.cfg_id = ac.cfg_id
WHERE pmad.att_device = 'device' AND pmad.cfg_id = 0
LIMIT 1000;

File diff suppressed because one or more lines are too long

View File

@ -37,6 +37,10 @@ public class AttendanceCfg extends BaseEntity
@Excel(name = "1-启用,0-停用") @Excel(name = "1-启用,0-停用")
private Long enabled; private Long enabled;
/** 1-默认0-非默认 */
@Excel(name = "1-默认0-非默认")
private Long isDefault;
/** 状态 */ /** 状态 */
@Excel(name = "状态") @Excel(name = "状态")
private Long state; private Long state;
@ -118,6 +122,15 @@ public class AttendanceCfg extends BaseEntity
{ {
return enabled; return enabled;
} }
public void setIsDefault(Long isDefault)
{
this.isDefault = isDefault;
}
public Long getIsDefault()
{
return isDefault;
}
public void setState(Long state) public void setState(Long state)
{ {
this.state = state; this.state = state;
@ -174,6 +187,7 @@ public class AttendanceCfg extends BaseEntity
.append("vendorsCode", getVendorsCode()) .append("vendorsCode", getVendorsCode())
.append("vendorsParameter", getVendorsParameter()) .append("vendorsParameter", getVendorsParameter())
.append("enabled", getEnabled()) .append("enabled", getEnabled())
.append("isDefault", getIsDefault())
.append("state", getState()) .append("state", getState())
.append("remark", getRemark()) .append("remark", getRemark())
.append("isDel", getIsDel()) .append("isDel", getIsDel())

View File

@ -64,4 +64,14 @@ public interface AttendanceCfgMapper
* *
*/ */
String getMachMaterCfg(@Param("projectId") Long projectId,@Param("cfgType") String cfgType); String getMachMaterCfg(@Param("projectId") Long projectId,@Param("cfgType") String cfgType);
/**
* IDID
*/
AttendanceCfg selectDefaultCfgByProjectAndCom(@Param("projectId") Long projectId, @Param("comId") Long comId);
/**
*
*/
AttendanceCfg selectDefaultCfgByDeviceNo(@Param("deviceNo") String deviceNo);
} }

View File

@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="vendorsCode" column="vendors_code" /> <result property="vendorsCode" column="vendors_code" />
<result property="vendorsParameter" column="vendors_parameter" /> <result property="vendorsParameter" column="vendors_parameter" />
<result property="enabled" column="enabled" /> <result property="enabled" column="enabled" />
<result property="isDefault" column="is_default" />
<result property="state" column="state" /> <result property="state" column="state" />
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<result property="isDel" column="is_del" /> <result property="isDel" column="is_del" />
@ -26,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectAttendanceCfgVo"> <sql id="selectAttendanceCfgVo">
SELECT ac.id, ac.com_id, ac.project_id, ac.vendors_code, ac.vendors_parameter, ac.enabled, ac.state, ac.remark, ac.is_del, ac.create_by, ac.create_time, ac.update_by SELECT ac.id, ac.com_id, ac.project_id, ac.vendors_code, ac.vendors_parameter, ac.enabled, ac.is_default, ac.state, ac.remark, ac.is_del, ac.create_by, ac.create_time, ac.update_by
, ac.update_time,dp.`dept_name` comp_name,pp.`project_name`,dic.`dict_label` vendors_name,sd.sub_dept_name dept_name,ac.dept_id , ac.update_time,dp.`dept_name` comp_name,pp.`project_name`,dic.`dict_label` vendors_name,sd.sub_dept_name dept_name,ac.dept_id
FROM attendance_cfg ac FROM attendance_cfg ac
LEFT JOIN sys_dept dp ON ac.`com_id`=dp.`dept_id` LEFT JOIN sys_dept dp ON ac.`com_id`=dp.`dept_id`
@ -62,6 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="vendorsCode != null">vendors_code,</if> <if test="vendorsCode != null">vendors_code,</if>
<if test="vendorsParameter != null">vendors_parameter,</if> <if test="vendorsParameter != null">vendors_parameter,</if>
<if test="enabled != null">enabled,</if> <if test="enabled != null">enabled,</if>
<if test="isDefault != null">is_default,</if>
<if test="state != null">state,</if> <if test="state != null">state,</if>
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
<if test="isDel != null">is_del,</if> <if test="isDel != null">is_del,</if>
@ -77,6 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="vendorsCode != null">#{vendorsCode},</if> <if test="vendorsCode != null">#{vendorsCode},</if>
<if test="vendorsParameter != null">#{vendorsParameter},</if> <if test="vendorsParameter != null">#{vendorsParameter},</if>
<if test="enabled != null">#{enabled},</if> <if test="enabled != null">#{enabled},</if>
<if test="isDefault != null">#{isDefault},</if>
<if test="state != null">#{state},</if> <if test="state != null">#{state},</if>
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
<if test="isDel != null">#{isDel},</if> <if test="isDel != null">#{isDel},</if>
@ -96,6 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="vendorsCode != null">vendors_code = #{vendorsCode},</if> <if test="vendorsCode != null">vendors_code = #{vendorsCode},</if>
<if test="vendorsParameter != null">vendors_parameter = #{vendorsParameter},</if> <if test="vendorsParameter != null">vendors_parameter = #{vendorsParameter},</if>
<if test="enabled != null">enabled = #{enabled},</if> <if test="enabled != null">enabled = #{enabled},</if>
<if test="isDefault != null">is_default = #{isDefault},</if>
<if test="state != null">state = #{state},</if> <if test="state != null">state = #{state},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="isDel != null">is_del = #{isDel},</if> <if test="isDel != null">is_del = #{isDel},</if>
@ -120,4 +124,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getMachMaterCfg" resultType="String"> <select id="getMachMaterCfg" resultType="String">
select param_data from pro_machmater_config where project_id=#{projectId} and cfg_type=#{cfgType} LIMIT 1 select param_data from pro_machmater_config where project_id=#{projectId} and cfg_type=#{cfgType} LIMIT 1
</select> </select>
<select id="selectDefaultCfgByProjectAndCom" resultMap="AttendanceCfgResult">
<include refid="selectAttendanceCfgVo"/>
where ac.project_id = #{projectId} and ac.com_id = #{comId} and ac.is_default = 1 and ac.enabled = 1
limit 1
</select>
<select id="selectDefaultCfgByDeviceNo" resultMap="AttendanceCfgResult">
<include refid="selectAttendanceCfgVo"/>
where exists (
select 1 from attendance_ubi_device ad
where ad.device_no = #{deviceNo}
and ad.project_id = ac.project_id
and ad.com_id = ac.com_id
)
and ac.is_default = 1 and ac.enabled = 1
limit 1
</select>
</mapper> </mapper>

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.yanzhu.common.core.utils.DateUtils; import com.yanzhu.common.core.utils.DateUtils;
import com.yanzhu.common.core.utils.StringUtils; import com.yanzhu.common.core.utils.StringUtils;
import com.yanzhu.common.core.web.domain.AjaxResult; import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.manage.domain.AttendanceCfg;
import com.yanzhu.manage.domain.AttendanceUbiData; import com.yanzhu.manage.domain.AttendanceUbiData;
import com.yanzhu.manage.domain.AttendanceUbiDevice; import com.yanzhu.manage.domain.AttendanceUbiDevice;
import com.yanzhu.manage.domain.ProMobileAttendanceData; import com.yanzhu.manage.domain.ProMobileAttendanceData;
@ -36,6 +37,9 @@ public class UniCallBackController {
@Autowired @Autowired
private IProMobileAttendanceDataService proMobileAttendanceDataService; private IProMobileAttendanceDataService proMobileAttendanceDataService;
@Autowired
private IAttendanceCfgService attendanceCfgService;
/** /**
* *
* @return * @return
@ -123,7 +127,11 @@ public class UniCallBackController {
if(device==null){ if(device==null){
return AjaxResult.error("没有查询到设备No"); return AjaxResult.error("没有查询到设备No");
} }
AttendanceCfg cfg = attendanceCfgService.selectDefaultCfgByDeviceNo(deviceNo);
Long cfgId = (cfg != null && cfg.getId() != null) ? cfg.getId() : 0L;
ProMobileAttendanceData attendanceData=new ProMobileAttendanceData(); ProMobileAttendanceData attendanceData=new ProMobileAttendanceData();
attendanceData.setCfgId(cfgId);
if(list.size()==0){ if(list.size()==0){
//增加操作 //增加操作
ProProjectInfoSubdeptsUsers userWhere=new ProProjectInfoSubdeptsUsers(); ProProjectInfoSubdeptsUsers userWhere=new ProProjectInfoSubdeptsUsers();
@ -153,6 +161,7 @@ public class UniCallBackController {
attendanceData.setAttDate(showTime); attendanceData.setAttDate(showTime);
attendanceData.setAttImg(filePath); attendanceData.setAttImg(filePath);
attendanceData.setWorkAreaId(device.getWorkAreaId()); attendanceData.setWorkAreaId(device.getWorkAreaId());
attendanceData.setCfgId(cfgId);
if(device.getDirection()==0) { if(device.getDirection()==0) {
addData.setInTime(showTime); addData.setInTime(showTime);
addData.setInData(data); addData.setInData(data);
@ -184,6 +193,7 @@ public class UniCallBackController {
attendanceData.setProjectId(projectId); attendanceData.setProjectId(projectId);
attendanceData.setAttDate(showTime); attendanceData.setAttDate(showTime);
attendanceData.setAttImg(filePath); attendanceData.setAttImg(filePath);
attendanceData.setCfgId(cfgId);
if(device.getDirection()==0){ if(device.getDirection()==0){
attendanceData.setInOut("in"); attendanceData.setInOut("in");
proMobileAttendanceDataService.addAttendanceData(attendanceData); proMobileAttendanceDataService.addAttendanceData(attendanceData);

View File

@ -63,4 +63,14 @@ public interface IAttendanceCfgService
* *
*/ */
String getMachMaterCfg(Long projectId, String cfgType); String getMachMaterCfg(Long projectId, String cfgType);
/**
* IDID
*/
AttendanceCfg selectDefaultCfgByProjectAndCom(Long projectId, Long comId);
/**
*
*/
AttendanceCfg selectDefaultCfgByDeviceNo(String deviceNo);
} }

View File

@ -59,9 +59,17 @@ public class AttendanceCfgServiceImpl implements IAttendanceCfgService
AttendanceCfg query = new AttendanceCfg(); AttendanceCfg query = new AttendanceCfg();
query.setProjectId(attendanceCfg.getProjectId()); query.setProjectId(attendanceCfg.getProjectId());
List<AttendanceCfg> cfgs = attendanceCfgMapper.selectAttendanceCfgList(query); List<AttendanceCfg> cfgs = attendanceCfgMapper.selectAttendanceCfgList(query);
if(cfgs.size()>0){ if(cfgs.size()>0){
throw new ServiceException("当前项目已配置考勤信息..."); throw new ServiceException("当前项目已配置考勤信息...");
} }
if(attendanceCfg.getEnabled() != null || attendanceCfg.getEnabled() == 0L){
attendanceCfg.setIsDefault(0L);
} else if(attendanceCfg.getIsDefault() == null){
attendanceCfg.setIsDefault(1L);
}
attendanceCfg.setCreateBy(SecurityContextHolder.getUserName()); attendanceCfg.setCreateBy(SecurityContextHolder.getUserName());
attendanceCfg.setCreateTime(DateUtils.getNowDate()); attendanceCfg.setCreateTime(DateUtils.getNowDate());
return attendanceCfgMapper.insertAttendanceCfg(attendanceCfg); return attendanceCfgMapper.insertAttendanceCfg(attendanceCfg);
@ -76,6 +84,26 @@ public class AttendanceCfgServiceImpl implements IAttendanceCfgService
@Override @Override
public int updateAttendanceCfg(AttendanceCfg attendanceCfg) public int updateAttendanceCfg(AttendanceCfg attendanceCfg)
{ {
if(attendanceCfg.getIsDefault() != null && attendanceCfg.getIsDefault() == 1L){
AttendanceCfg currentCfg = attendanceCfgMapper.selectAttendanceCfgById(attendanceCfg.getId());
if(currentCfg != null && currentCfg.getProjectId() != null){
AttendanceCfg query = new AttendanceCfg();
query.setProjectId(currentCfg.getProjectId());
List<AttendanceCfg> cfgs = attendanceCfgMapper.selectAttendanceCfgList(query);
for(AttendanceCfg cfg : cfgs){
if(!cfg.getId().equals(attendanceCfg.getId()) && cfg.getIsDefault() != null && cfg.getIsDefault() == 1L){
cfg.setIsDefault(0L);
attendanceCfgMapper.updateAttendanceCfg(cfg);
}
}
}
}
AttendanceCfg currentCfg = attendanceCfgMapper.selectAttendanceCfgById(attendanceCfg.getId());
if(currentCfg != null && currentCfg.getIsDefault() != null && currentCfg.getIsDefault() == 1L && attendanceCfg.getIsDefault() != null){
throw new ServiceException("不能修改唯一默认配置为非默认");
}
attendanceCfg.setUpdateBy(SecurityContextHolder.getUserName()); attendanceCfg.setUpdateBy(SecurityContextHolder.getUserName());
attendanceCfg.setUpdateTime(DateUtils.getNowDate()); attendanceCfg.setUpdateTime(DateUtils.getNowDate());
return attendanceCfgMapper.updateAttendanceCfg(attendanceCfg); return attendanceCfgMapper.updateAttendanceCfg(attendanceCfg);
@ -90,6 +118,21 @@ public class AttendanceCfgServiceImpl implements IAttendanceCfgService
@Override @Override
public int deleteAttendanceCfgByIds(Long[] ids) public int deleteAttendanceCfgByIds(Long[] ids)
{ {
for(Long id : ids){
AttendanceCfg cfg = attendanceCfgMapper.selectAttendanceCfgById(id);
if(cfg != null && cfg.getIsDefault() != null && cfg.getIsDefault() == 1L && cfg.getProjectId() != null){
AttendanceCfg query = new AttendanceCfg();
query.setProjectId(cfg.getProjectId());
List<AttendanceCfg> cfgs = attendanceCfgMapper.selectAttendanceCfgList(query);
for(AttendanceCfg c : cfgs){
if(!c.getId().equals(id) && c.getIsDefault() != null && c.getIsDefault() == 0L){
c.setIsDefault(1L);
attendanceCfgMapper.updateAttendanceCfg(c);
break;
}
}
}
}
return attendanceCfgMapper.deleteAttendanceCfgByIds(ids); return attendanceCfgMapper.deleteAttendanceCfgByIds(ids);
} }
@ -102,6 +145,19 @@ public class AttendanceCfgServiceImpl implements IAttendanceCfgService
@Override @Override
public int deleteAttendanceCfgById(Long id) public int deleteAttendanceCfgById(Long id)
{ {
AttendanceCfg cfg = attendanceCfgMapper.selectAttendanceCfgById(id);
if(cfg != null && cfg.getIsDefault() != null && cfg.getIsDefault() == 1L && cfg.getProjectId() != null){
AttendanceCfg query = new AttendanceCfg();
query.setProjectId(cfg.getProjectId());
List<AttendanceCfg> cfgs = attendanceCfgMapper.selectAttendanceCfgList(query);
for(AttendanceCfg c : cfgs){
if(!c.getId().equals(id) && c.getIsDefault() != null && c.getIsDefault() == 0L){
c.setIsDefault(1L);
attendanceCfgMapper.updateAttendanceCfg(c);
break;
}
}
}
return attendanceCfgMapper.deleteAttendanceCfgById(id); return attendanceCfgMapper.deleteAttendanceCfgById(id);
} }
@ -112,4 +168,20 @@ public class AttendanceCfgServiceImpl implements IAttendanceCfgService
public String getMachMaterCfg(Long projectId, String cfgType) { public String getMachMaterCfg(Long projectId, String cfgType) {
return attendanceCfgMapper.getMachMaterCfg(projectId,cfgType); return attendanceCfgMapper.getMachMaterCfg(projectId,cfgType);
} }
/**
* IDID
*/
@Override
public AttendanceCfg selectDefaultCfgByProjectAndCom(Long projectId, Long comId) {
return attendanceCfgMapper.selectDefaultCfgByProjectAndCom(projectId, comId);
}
/**
*
*/
@Override
public AttendanceCfg selectDefaultCfgByDeviceNo(String deviceNo) {
return attendanceCfgMapper.selectDefaultCfgByDeviceNo(deviceNo);
}
} }

View File

@ -102,7 +102,9 @@ public class ProMobileAttendanceDataServiceImpl implements IProMobileAttendanceD
public int addAttendanceData(ProMobileAttendanceData attendanceData) { public int addAttendanceData(ProMobileAttendanceData attendanceData) {
attendanceData.setIsDel(0L); attendanceData.setIsDel(0L);
attendanceData.setRemark(""); attendanceData.setRemark("");
attendanceData.setCfgId(0L); if(attendanceData.getCfgId() == null){
attendanceData.setCfgId(0L);
}
attendanceData.setState(0L); attendanceData.setState(0L);
attendanceData.setAttDevice("device"); attendanceData.setAttDevice("device");
return insertProMobileAttendanceData(attendanceData); return insertProMobileAttendanceData(attendanceData);

View File

@ -139,7 +139,7 @@ function getCookie() {
getCode() getCode()
getCookie() getCookie()
setTimeout(() => { setTimeout(() => {
if (translate && translate.execute) { if (typeof translate !== 'undefined' && translate && translate.execute) {
translate.execute(); translate.execute();
} }
}, 1000); }, 1000);

View File

@ -70,6 +70,13 @@
<el-switch v-model="scope.row.enabled" :active-value="1" @change="doUpdateRow(scope.row)" :inactive-value="0"></el-switch> <el-switch v-model="scope.row.enabled" :active-value="1" @change="doUpdateRow(scope.row)" :inactive-value="0"></el-switch>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="是否默认" align="center" prop="isDefault">
<template #default="scope">
<el-tag :type="scope.row.isDefault === 1 ? 'success' : 'info'">
{{ scope.row.isDefault === 1 ? '是' : '否' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180"> <el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template #default="scope"> <template #default="scope">
<span>{{ parseTime(scope.row.createTime) }}</span> <span>{{ parseTime(scope.row.createTime) }}</span>
@ -139,6 +146,12 @@
<el-form-item label="已启用" prop="enabled"> <el-form-item label="已启用" prop="enabled">
<el-switch v-model="form.enabled" :active-value="1" :inactive-value="0" /> <el-switch v-model="form.enabled" :active-value="1" :inactive-value="0" />
</el-form-item> </el-form-item>
<el-form-item label="是否默认" prop="isDefault">
<el-tag :type="form.isDefault === 1 ? 'success' : 'info'" v-if="form.id">
{{ form.isDefault === 1 ? '是' : '否' }}
</el-tag>
<el-switch v-model="form.isDefault" :active-value="1" :inactive-value="0" v-if="!form.id" />
</el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
@ -188,6 +201,7 @@ const data = reactive({
vendorsCode: null, vendorsCode: null,
vendorsParameter: null, vendorsParameter: null,
enabled: null, enabled: null,
isDefault: null,
state: null, state: null,
isDel: null, isDel: null,
}, },
@ -306,6 +320,7 @@ function reset() {
projectGuid: '', projectGuid: '',
vendorsParameter: null, vendorsParameter: null,
enabled: 1, enabled: 1,
isDefault: 0,
state: null, state: null,
remark: null, remark: null,
isDel: null, isDel: null,