SpmkServiceImpl.java 2.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
package cn.timer.api.controller.spmk.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Console;
import cn.timer.api.bean.spmk.SpmkApprovalG;
import cn.timer.api.bean.spmk.SpmkApprovalTemplate;
import cn.timer.api.bean.spmk.SpmkApprovalTemplateG;
import cn.timer.api.bean.spmk.SpmkCustomApproval;
import cn.timer.api.dao.spmk.SpmkCustomApprovalMapper;

@Service
public class SpmkServiceImpl implements SpmkService{

	@Autowired
	SpmkCustomApprovalMapper spmkCustomApprovalMapper;
	
	/**
	 * 根据orgCode查数据库 审批模板 生成 自定义模板
	 * orgCode 企业id
	 */
	@Override
	public boolean createCustomApproval(Integer orgCode) {
		// TODO Auto-generated method stub
		List<SpmkApprovalTemplateG> listAtg = SpmkApprovalTemplateG.builder().build()
				.selectList(new QueryWrapper<SpmkApprovalTemplateG>().lambda().orderByAsc(SpmkApprovalTemplateG::getId));
		List<SpmkApprovalG> listAG = new ArrayList<SpmkApprovalG>(listAtg.size());
		for (SpmkApprovalTemplateG spmkApprovalTemplateG : listAtg) {
			SpmkApprovalG saG = SpmkApprovalG.builder().build();
			BeanUtil.copyProperties(spmkApprovalTemplateG, saG, "id","update_time");
			saG.setOrgCode(orgCode);
			listAG.add(saG);
		}
		
		Console.log(listAG);
		SpmkCustomApproval sca = SpmkCustomApproval.builder().build();
		List<SpmkApprovalTemplate> listAt = new ArrayList<SpmkApprovalTemplate>();
		for (int i = 0,n = listAG.size(); i < n; i++) {
			boolean b = listAG.get(i).insert();
			if (b) {
				listAt = SpmkApprovalTemplate.builder().build().selectList(new QueryWrapper<SpmkApprovalTemplate>()
						.lambda()
						.eq(SpmkApprovalTemplate::getApprovalTemplateGId, listAtg.get(i).getId()).orderByAsc(SpmkApprovalTemplate::getId));
				for (SpmkApprovalTemplate spmkApprovalTemplate : listAt) {
					BeanUtil.copyProperties(spmkApprovalTemplate, sca, "id","approval_template_g_id","update_time","create_time");
					sca.setOrgCode(orgCode);
					sca.setApprovalGId(listAG.get(i).getId());
					sca.setIsAllvisible(1);
					
					sca.insert();
				}
			}
		}
		
		return true;
	}

}