HtzzController.java 10.3 KB
Newer Older
yuquan.zhu committed
1 2 3 4 5 6 7
package cn.timer.api.controller.htzz;

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

import org.springframework.beans.factory.annotation.Autowired;
ilal committed
8
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.transaction.annotation.Transactional;
yuquan.zhu committed
10 11 12 13 14 15 16 17 18
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

19
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
yuquan.zhu committed
20 21 22 23
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
ilal committed
24
import com.google.common.collect.Lists;
yuquan.zhu committed
25 26 27 28

import cn.hutool.core.util.StrUtil;
import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
ilal committed
29
import cn.timer.api.bean.admin.AdminAssoTxjlb;
yuquan.zhu committed
30 31
import cn.timer.api.bean.htzz.HtzzAdminZzda;
import cn.timer.api.bean.htzz.HtzzAssoHtgx;
ilal committed
32
import cn.timer.api.bean.htzz.HtzzAssoZztx;
33
import cn.timer.api.bean.qyzx.businessService.QyzxRemainingQuantity;
yuquan.zhu committed
34 35 36 37 38
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.dao.htzz.HtzzAdminZzdaMapper;
import cn.timer.api.dto.htzz.HtzzQueryDto;
ilal committed
39
import cn.timer.api.dto.htzz.NotifyPersonDto;
ilal committed
40
import cn.timer.api.dto.htzz.QueryNoReadingDto;
yuquan.zhu committed
41 42 43 44 45 46 47
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "7.0合同证照")
@RestController
48
@Transactional
yuquan.zhu committed
49 50 51 52 53 54 55 56
@RequestMapping(value = "/htzz", produces = { "application/json" })
public class HtzzController {

	@Autowired
	private HtzzAdminZzdaMapper htzzAdminZzdaMapper;


	/**
ilal committed
57
	 * 新增证件
yuquan.zhu committed
58 59 60 61 62 63 64 65
	 * 
	 * @param userBean
	 * @param htzzAdminZzda 证照档案实体
	 * @return 新增证件结果
	 */
	@PostMapping("/addzj")
	@ApiOperation(value = "新增合同证件", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> addzj(@CurrentUser UserBean userBean, @RequestBody HtzzAdminZzda zzda) {
66
		Integer orgCode = userBean.getOrgCode();
67

68 69 70 71 72 73 74 75
		QyzxRemainingQuantity quantity = QyzxRemainingQuantity.builder().build().selectOne(
				new LambdaQueryWrapper<QyzxRemainingQuantity>().eq(QyzxRemainingQuantity::getOrgCode, orgCode)
						.eq(QyzxRemainingQuantity::getPmid, 1).gt(QyzxRemainingQuantity::getRemainder, 0));
		Date date = null;
		Integer remainder = null;
		if (quantity != null) {
			remainder = quantity.getRemainder();
			date = quantity.getExpireDate();
76
		}
77 78 79 80
		if (quantity == null || remainder == null || remainder <= 0) { // 判断充了钱没
			return ResultUtil.error("请充值后使用短信功能!");
		}
		if (date != null && date.getTime() <= new Date().getTime()) {
ilal committed
81
			Logoutput("企业 " + orgCode + " :短信套餐已过期");
82 83
			return ResultUtil.error("短信套餐已到期!");
		}
mobh committed
84 85 86
		if (zzda.getId() == null) {
			zzda.setTxkgType(1);//默认开启提醒
		}
yuquan.zhu committed
87 88
		zzda.setLrrid(userBean.getEmpNum());
		zzda.setLrsjTime(new Date());
89
		zzda.setOrgCode(orgCode);
ilal committed
90 91 92
		
		zzda.setSendingStatus(0);//0:未发;1:已发
		zzda.setTemplateId(zzda.getTemplateId());//消息模板id
ilal committed
93 94
//		zzda.insert();
		zzda.insertOrUpdate();
yuquan.zhu committed
95 96 97 98

		/**
		 * 新增通知关系表,每人一个
		 */
ilal committed
99
		List<NotifyPersonDto> ids = zzda.getIds();//通知人    用户id+手机号码
mobh committed
100
		List<HtzzAssoHtgx> htgxs = Lists.newArrayList();
ilal committed
101
		for (NotifyPersonDto pre : ids) {
ilal committed
102
			HtzzAssoHtgx.builder().build().delete(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getOrgCode, orgCode).eq(HtzzAssoHtgx::getTzrid, pre.getEmpNum())
ilal committed
103
					.eq(HtzzAssoHtgx::getPhone, pre.getPhone()));
yuquan.zhu committed
104 105 106

			HtzzAssoHtgx htgx = HtzzAssoHtgx.builder().build();
			htgx.setHtid(zzda.getId());
ilal committed
107 108
			htgx.setTzrid(pre.getEmpNum());
			htgx.setName(pre.getEmpName());
ilal committed
109
			htgx.setPhone(pre.getPhone());
110
			htgx.setOrgCode(orgCode);
yuquan.zhu committed
111 112 113
			htgx.insert();
			htgxs.add(htgx);
		}
mobh committed
114 115 116 117 118 119
		HtzzAssoZztx zztx = zzda.getZztx();
		zztx.setZzdaId(zzda.getId());
		zztx.setOrgCode(orgCode);
		zztx.setLrrid(userBean.getEmpNum());
		zztx.setLrsjTime(new Date());
		zztx.insertOrUpdate();
yuquan.zhu committed
120 121 122

		return ResultUtil.datas(zzda, htgxs, "新增证件成功!");
	}
ilal committed
123
	
mobh committed
124
	@GetMapping("/modifytx/{id}")
ilal committed
125 126 127
	@ApiOperation(value = "修改提醒数据", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> modifytx(@CurrentUser UserBean userBean, @PathVariable Integer id) {
		
ilal committed
128

ilal committed
129
		List<NotifyPersonDto> tzids = new ArrayList<NotifyPersonDto>();
mobh committed
130
		List<HtzzAssoHtgx> httxs = HtzzAssoHtgx.builder().build().selectList(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getHtid, id));
ilal committed
131 132
		for(HtzzAssoHtgx gx : httxs) {
			NotifyPersonDto predto = NotifyPersonDto.builder().build();
mobh committed
133 134 135
			predto.setEmpName(gx.getName());
			predto.setEmpNum(gx.getTzrid());
			predto.setPhone(gx.getPhone());
ilal committed
136 137 138
			tzids.add(predto);
		}
		
ilal committed
139 140 141 142
		HtzzAdminZzda zzda = HtzzAdminZzda.builder().id(id).build().selectById();
		HtzzAssoZztx zztx = HtzzAssoZztx.builder().build().selectOne(new QueryWrapper<HtzzAssoZztx>().lambda().eq(HtzzAssoZztx::getZzdaId, id));
		zzda.setZztx(zztx);
		zzda.setIds(tzids);
ilal committed
143
		
ilal committed
144
		return ResultUtil.data(zzda, "新增成功");
ilal committed
145 146
	}
	
yuquan.zhu committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160

	/**
	 * 按条件搜索(关键字、到期时间)
	 * 
	 * @param userBean
	 * @return
	 */
	@GetMapping("/queryht")
	@ApiOperation(value = "按条件搜索(关键字、到期时间)", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryht(@CurrentUser UserBean userBean, HtzzQueryDto htzzQueryDto) {
		String e = htzzQueryDto.getEndTime();
		String q = htzzQueryDto.getQuery();
		Page<HtzzAdminZzda> page = new Page<HtzzAdminZzda>(
				htzzQueryDto.getCurrentPage() == null ? 1 : htzzQueryDto.getCurrentPage(),
161
				htzzQueryDto.getTotalPage() == null ? 10 : htzzQueryDto.getTotalPage());
yuquan.zhu committed
162 163

		QueryWrapper<HtzzAdminZzda> queryWrapper = new QueryWrapper<>();
邓实川 committed
164
		queryWrapper.eq("org_code", userBean.getOrgCode())
ilal committed
165
				.select("id", "zjmc", "czry", "fzjg", "fzrq", "yxdqr", "txkg_type").eq("is_delete", 0).eq("document_type", htzzQueryDto.getDocumentType())
166 167
				.gt(!StrUtil.hasBlank(e), "yxdqr", !StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
				.and(!StrUtil.hasBlank(q), wq -> wq.like("zjmc", q).or().like("czry", q)).orderByDesc("lrsj_time");
yuquan.zhu committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

		IPage<HtzzAdminZzda> zPage = HtzzAdminZzda.builder().build().selectPage(page, queryWrapper);
		List<HtzzAdminZzda> zccrkgls = zPage.getRecords();
		zPage.getCurrent();
		zPage.getPages();
		zPage.getTotal();
		zPage.getSize();
		return ResultUtil.data(zPage, zccrkgls, "搜索成功");
	}

	/**
	 * 根据id查合同
	 * 
	 * @param id
	 * @return
	 */
	@PostMapping(value = "/queryHt/{id}")
	@ApiOperation(value = "根据id查合同", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> queryHt(@CurrentUser UserBean userBean, @PathVariable Integer id) {
		List<Object> list = new ArrayList<Object>();
		list.add(HtzzAdminZzda.builder().build().selectOne(new QueryWrapper<HtzzAdminZzda>()
				.eq("org_code", userBean.getOrgCode()).eq("is_delete", 0).eq("id", id)));
		QueryWrapper<HtzzAssoHtgx> q = new QueryWrapper<HtzzAssoHtgx>();
		q.select("id", "name").eq("htid", id);
		List<HtzzAssoHtgx> htgx = HtzzAssoHtgx.builder().build().selectList(q);
		for (HtzzAssoHtgx gx : htgx) {
			String name = gx.getName();
			list.add(name);
		}
		return ResultUtil.data(list);
	}

	/**
	 * 根据id删除合同
	 * 
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delHt")
	@ApiOperation(value = "根据id删除合同", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Object> delHt(@CurrentUser UserBean userBean, @RequestParam Integer htid) {
		// 删除提醒关系
ilal committed
210 211 212 213 214
		HtzzAssoHtgx.builder().build().delete(new QueryWrapper<HtzzAssoHtgx>().eq("org_code", userBean.getOrgCode()).eq("htid", htid));
		
		//删除证照提醒表配置
		HtzzAssoZztx.builder().build().delete(new QueryWrapper<HtzzAssoZztx>().lambda().eq(HtzzAssoZztx::getZzdaId, htid));
		
yuquan.zhu committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
		// 设置证照删除状态
		return ResultUtil.data(HtzzAdminZzda.builder().id(htid).isDelete(1).build().updateById());
	}

	/**
	 * 修改提醒状态
	 * 
	 * @param id
	 * @return
	 */
	@PostMapping(value = "/changeTx")
	@ApiOperation(value = "修改提醒状态", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> changeTx(@CurrentUser UserBean userBean, @RequestParam Integer htid) {

		QueryWrapper<HtzzAdminZzda> queryWrapper = new QueryWrapper<>();
		queryWrapper.select("txkg_type").eq("id", htid);
		HtzzAdminZzda zzda = HtzzAdminZzda.builder().build().selectOne(queryWrapper);

		UpdateWrapper<HtzzAdminZzda> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("id", htid);
		HtzzAdminZzda w = HtzzAdminZzda.builder().orgCode(userBean.getOrgCode()).id(htid)
				.txkgType(zzda.getTxkgType() == 0 ? 1 : 0).build();
		htzzAdminZzdaMapper.update(w, updateWrapper);
		return ResultUtil.success("修改成功");

	}

	/**
	 * 查詢全部員工id、姓名
	 * 
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryYg")
	@ApiOperation(value = "查詢全部員工id、姓名", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryYg(@CurrentUser UserBean userBean) {
		return ResultUtil.data(YgglMainEmp.builder().build().selectList(
mobh committed
252
				new QueryWrapper<YgglMainEmp>().select("emp_num", "name", "phone").eq("org_code", userBean.getOrgCode())));
yuquan.zhu committed
253 254 255 256 257 258 259 260
	}

	@GetMapping(value = "/test")
	@ApiOperation(value = "test", httpMethod = "GET", notes = "接口发布说明")
	public Result<Void> test(String schedulingPattern) {
		CronUtil.schedule("*/2 * * 24 * *", new Task() {
			@Override
			public void execute() {
ilal committed
261
				Logoutput("start:" + new Date());
yuquan.zhu committed
262 263 264 265 266 267 268
			}
		});

		CronUtil.setMatchSecond(true);
		CronUtil.start();
		return ResultUtil.success("操作成功");
	}
ilal committed
269
	
yuquan.zhu committed
270

ilal committed
271 272 273 274 275 276 277 278 279 280 281 282 283
	@Value("${config-8timer.environmental-science}")
	public String environmental_science;
	
	public void Logoutput(String science) {
		
		if(!("pro").equals(environmental_science)) {
			
			System.out.println(science);
		}else {
			System.out.println("");
		}
		
	}
yuquan.zhu committed
284
}