You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							247 lines
						
					
					
						
							6.2 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							247 lines
						
					
					
						
							6.2 KiB
						
					
					
				
								'use strict';
							 | 
						|
								const { QueryTypes } = require('sequelize');
							 | 
						|
								
							 | 
						|
								async function get(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { type } = ctx.request.body;
							 | 
						|
								      const { name } = ctx.query;
							 | 
						|
								      const sequelize = ctx.fs.dc.orm
							 | 
						|
								      const sqlStr = `select sum(p.road_marking)  "标线(米)",sum(p.roadside_ditch) "边沟(米)",
							 | 
						|
								       sum(p.guardrail) "护栏(米)", sum(p.roadside_trees) "行道树(棵)",sum(p.wrong_lane) "错车道(个)"
							 | 
						|
								       from (
							 | 
						|
								   select t.*,row_number() over (partition by t.luduan order by t.time desc )  rn from (
							 | 
						|
								   select code_road||'-'||road_section_start||'-'||road_section_end luduan,
							 | 
						|
								   road_marking,roadside_ditch,guardrail,roadside_trees,wrong_lane,time from   report
							 | 
						|
								   where report_type='conserve') t ) p where p.rn=1`
							 | 
						|
								      const conserveData = await sequelize.query(sqlStr, { type: QueryTypes.SELECT })
							 | 
						|
								      let findOption = {
							 | 
						|
								         where: {
							 | 
						|
								            type
							 | 
						|
								         }
							 | 
						|
								      }
							 | 
						|
								      if (name) {
							 | 
						|
								         findOption.where.name = {
							 | 
						|
								            $like: `%${name}%`
							 | 
						|
								         }
							 | 
						|
								      }
							 | 
						|
								      const vehicleRes = await models.Statistic.findAll(findOption)
							 | 
						|
								      ctx.status = 200;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         vehicleRes: vehicleRes.filter(item => item.dataValues.name === '标志牌' || item.dataValues.name === '养护责任牌')
							 | 
						|
								         , conserveData, vehicleR: vehicleRes
							 | 
						|
								      }
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function edit(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { id, name, count, type } = ctx.request.body;
							 | 
						|
								
							 | 
						|
								      if (!id) {
							 | 
						|
								         await models.Statistic.create({
							 | 
						|
								            name, count, type: type
							 | 
						|
								         })
							 | 
						|
								      } else {
							 | 
						|
								         await models.Statistic.update({
							 | 
						|
								            name, count, type: type
							 | 
						|
								         }, {
							 | 
						|
								            where: {
							 | 
						|
								               id: id
							 | 
						|
								            }
							 | 
						|
								         })
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      ctx.status = 204
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function del(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { id } = ctx.params;
							 | 
						|
								
							 | 
						|
								      await models.Statistic.destroy({
							 | 
						|
								         where: {
							 | 
						|
								            id: id
							 | 
						|
								         }
							 | 
						|
								      })
							 | 
						|
								
							 | 
						|
								      ctx.status = 204
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function specificGet(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { type } = ctx.query;
							 | 
						|
								      const { nameOfBusinessOwner } = ctx.query;
							 | 
						|
								
							 | 
						|
								      let findOption = {
							 | 
						|
								         where: {
							 | 
						|
								            type
							 | 
						|
								         }
							 | 
						|
								      }
							 | 
						|
								      if (nameOfBusinessOwner) {
							 | 
						|
								         findOption.where.nameOfBusinessOwner = {
							 | 
						|
								            $like: `%${nameOfBusinessOwner}%`
							 | 
						|
								         }
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      const vehicleRes = await models.MunicipalVehicle.findAll(findOption)
							 | 
						|
								
							 | 
						|
								      ctx.status = 200;
							 | 
						|
								      ctx.body = vehicleRes
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function specificEdit(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const data = ctx.request.body;
							 | 
						|
								
							 | 
						|
								      if (!data.vehicleId) {
							 | 
						|
								         const vehicleRes = await models.Vehicle.create(data)
							 | 
						|
								      } else {
							 | 
						|
								         const vehicleRes = await models.Vehicle.update(data, {
							 | 
						|
								            where: {
							 | 
						|
								               id: data.vehicleId
							 | 
						|
								            }
							 | 
						|
								         })
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      ctx.status = 204
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function specificDel(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { vehicleId } = ctx.params;
							 | 
						|
								
							 | 
						|
								      const vehicleRes = await models.Vehicle.destroy({
							 | 
						|
								         where: {
							 | 
						|
								            id: vehicleId
							 | 
						|
								         }
							 | 
						|
								      })
							 | 
						|
								
							 | 
						|
								      ctx.status = 204
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function businessGet(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { nameOfBusinessOwner } = ctx.query;
							 | 
						|
								
							 | 
						|
								      let findOption = {
							 | 
						|
								         where: {
							 | 
						|
								
							 | 
						|
								         }
							 | 
						|
								      }
							 | 
						|
								      if (nameOfBusinessOwner) {
							 | 
						|
								         findOption.where.nameOfBusinessOwner = {
							 | 
						|
								            $like: `%${nameOfBusinessOwner}%`
							 | 
						|
								         }
							 | 
						|
								      }
							 | 
						|
								      const businessRes = await models.MunicipalBusiness.findAll(findOption)
							 | 
						|
								
							 | 
						|
								      ctx.status = 200;
							 | 
						|
								      ctx.body = businessRes
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function businessEdit(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const data = ctx.request.body;
							 | 
						|
								
							 | 
						|
								      if (!data.businessId) {
							 | 
						|
								         await models.MunicipalBusiness.create(data)
							 | 
						|
								      } else {
							 | 
						|
								         await models.MunicipalBusiness.update(data, {
							 | 
						|
								            where: {
							 | 
						|
								               id: data.businessId
							 | 
						|
								            }
							 | 
						|
								         })
							 | 
						|
								      }
							 | 
						|
								
							 | 
						|
								      ctx.status = 204
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function businessDel(ctx) {
							 | 
						|
								   try {
							 | 
						|
								      const models = ctx.fs.dc.models;
							 | 
						|
								      const { businessId } = ctx.params;
							 | 
						|
								
							 | 
						|
								      await models.Vehicle.MunicipalBusiness({
							 | 
						|
								         where: {
							 | 
						|
								            id: businessId
							 | 
						|
								         }
							 | 
						|
								      })
							 | 
						|
								
							 | 
						|
								      ctx.status = 204
							 | 
						|
								   } catch (error) {
							 | 
						|
								      ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								      ctx.status = 400;
							 | 
						|
								      ctx.body = {
							 | 
						|
								         message: typeof error == 'string' ? error : undefined
							 | 
						|
								      }
							 | 
						|
								   }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								module.exports = {
							 | 
						|
								   get, edit, del,
							 | 
						|
								   specificGet, specificEdit, specificDel,
							 | 
						|
								   businessGet, businessEdit, businessDel
							 | 
						|
								};
							 |